forked from Kode/khamake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHtml5Exporter.js
143 lines (127 loc) · 5.15 KB
/
Html5Exporter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
"use strict";
const path = require('path');
const KhaExporter = require('./KhaExporter.js');
const Converter = require('./Converter.js');
const Files = require('./Files.js');
const Haxe = require('./Haxe.js');
const Options = require('./Options.js');
const Paths = require('./Paths.js');
const exportImage = require('./ImageTool.js');
const fs = require('fs-extra');
const HaxeProject = require('./HaxeProject.js');
class Html5Exporter extends KhaExporter {
constructor(khaDirectory, directory) {
super(khaDirectory, directory);
this.directory = directory;
this.addSourceDirectory(path.join(khaDirectory.toString(), 'Backends/HTML5'));
}
sysdir() {
return 'html5';
}
exportSolution(name, platform, khaDirectory, haxeDirectory, from, _targetOptions) {
this.createDirectory(this.directory.resolve(this.sysdir()));
let defines = [
'sys_' + platform,
'sys_g1', 'sys_g2', 'sys_g3', 'sys_g4',
'sys_a1', 'sys_a2'
];
if (this.sysdir() === 'node') {
defines = [
'sys_node',
'sys_server',
'nodejs'
]
}
if (this.sysdir() === 'debug-html5') {
defines.push('sys_debug_html5');
this.parameters.push('-debug');
}
const options = {
from: from.toString(),
to: path.join(this.sysdir(), 'kha.js'),
sources: this.sources,
defines: defines,
parameters: this.parameters,
haxeDirectory: haxeDirectory.toString(),
system: this.sysdir(),
language: 'js',
width: this.width,
height: this.height,
name: name
};
HaxeProject(this.directory.toString(), options);
if (this.sysdir() === 'debug-html5') {
let index = this.directory.resolve(Paths.get(this.sysdir(), 'index.html'));
if (!Files.exists(index)) {
let protoindex = fs.readFileSync(path.join(__dirname, 'Data', 'debug-html5', 'index.html'), {encoding: 'utf8'});
protoindex = protoindex.replaceAll('{Name}', name);
protoindex = protoindex.replaceAll('{Width}', this.width);
protoindex = protoindex.replaceAll('{Height}', this.height);
fs.writeFileSync(index.toString(), protoindex);
}
let pack = this.directory.resolve(Paths.get(this.sysdir(), 'package.json'));
let protopackage = fs.readFileSync(path.join(__dirname, 'Data', 'debug-html5', 'package.json'), {encoding: 'utf8'});
protopackage = protopackage.replaceAll('{Name}', name);
fs.writeFileSync(pack.toString(), protopackage);
let electron = this.directory.resolve(Paths.get(this.sysdir(), 'electron.js'));
let protoelectron = fs.readFileSync(path.join(__dirname, 'Data', 'debug-html5', 'electron.js'), {encoding: 'utf8'});
protoelectron = protoelectron.replaceAll('{Width}', this.width + 20);
protoelectron = protoelectron.replaceAll('{Height}', this.height + 20);
fs.writeFileSync(electron.toString(), protoelectron);
}
else {
let index = this.directory.resolve(Paths.get(this.sysdir(), 'index.html'));
if (!Files.exists(index)) {
let protoindex = fs.readFileSync(path.join(__dirname, 'Data', 'html5', 'index.html'), {encoding: 'utf8'});
protoindex = protoindex.replaceAll('{Name}', name);
protoindex = protoindex.replaceAll('{Width}', this.width);
protoindex = protoindex.replaceAll('{Height}', this.height);
fs.writeFileSync(index.toString(), protoindex);
}
}
if (Options.compilation) {
return Haxe.executeHaxe(this.directory, haxeDirectory, ['project-' + this.sysdir() + '.hxml']);
}
else {
return 0;
}
}
/*copyMusic(platform, from, to, encoders, callback) {
Files.createDirectories(this.directory.resolve(this.sysdir()).resolve(to).parent());
Converter.convert(from, this.directory.resolve(this.sysdir()).resolve(to + '.ogg'), encoders.oggEncoder, (ogg) => {
Converter.convert(from, this.directory.resolve(this.sysdir()).resolve(to + '.mp4'), encoders.aacEncoder, (mp4) => {
var files = [];
if (ogg) files.push(to + '.ogg');
if (mp4) files.push(to + '.mp4');
callback(files);
});
});
}*/
copySound(platform, from, to, encoders) {
Files.createDirectories(this.directory.resolve(this.sysdir()).resolve(to).parent());
let ogg = Converter.convert(from, this.directory.resolve(this.sysdir()).resolve(to + '.ogg'), encoders.oggEncoder);
let mp4 = Converter.convert(from, this.directory.resolve(this.sysdir()).resolve(to + '.mp4'), encoders.aacEncoder);
var files = [];
if (ogg) files.push(to + '.ogg');
if (mp4) files.push(to + '.mp4');
return files;
}
copyImage(platform, from, to, asset) {
let format = exportImage(from, this.directory.resolve(this.sysdir()).resolve(to), asset, undefined, false);
return [to + '.' + format];
}
copyBlob(platform, from, to) {
fs.copySync(from.toString(), this.directory.resolve(this.sysdir()).resolve(to).toString(), { clobber: true });
return [to];
}
copyVideo(platform, from, to, encoders) {
Files.createDirectories(this.directory.resolve(this.sysdir()).resolve(to).parent());
let mp4 = Converter.convert(from, this.directory.resolve(this.sysdir()).resolve(to + ".mp4"), encoders.h264Encoder);
let webm = Converter.convert(from, this.directory.resolve(this.sysdir()).resolve(to + ".webm"), encoders.webmEncoder);
let files = [];
if (mp4) files.push(to + '.mp4');
if (webm) files.push(to + '.webm');
return files;
}
}
module.exports = Html5Exporter;