forked from Kode/khamake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHtml5Exporter.js
120 lines (106 loc) · 3.81 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
"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');
const HaxeProject = require('./HaxeProject.js');
class Html5Exporter extends KhaExporter {
constructor(khaDirectory, directory) {
super(khaDirectory);
this.directory = directory;
this.addSourceDirectory(path.join(khaDirectory.toString(), 'Backends/HTML5'));
}
sysdir() {
return 'html5';
}
exportSolution(name, platform, khaDirectory, haxeDirectory, from, callback) {
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'
]
}
const options = {
from: from.toString(),
to: path.join(this.sysdir(), 'kha.js'),
sources: this.sources,
defines: defines,
haxeDirectory: haxeDirectory.toString(),
system: this.sysdir(),
language: 'js',
width: this.width,
height: this.height,
name: name
};
HaxeProject(this.directory.toString(), options);
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) {
Haxe.executeHaxe(this.directory, haxeDirectory, ['project-' + this.sysdir() + '.hxml'], callback);
}
else {
callback();
}
}
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, 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);
});
});
}
copyImage(platform, from, to, asset, callback) {
exportImage(from, this.directory.resolve(this.sysdir()).resolve(to), asset, undefined, false, (format) => {
callback([to + '.' + format]);
});
}
copyBlob(platform, from, to, callback) {
this.copyFile(from, this.directory.resolve(this.sysdir()).resolve(to));
callback([to]);
}
copyVideo(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 + ".mp4"), encoders.h264Encoder, (mp4) => {
Converter.convert(from, this.directory.resolve(this.sysdir()).resolve(to + ".webm"), encoders.webmEncoder, (webm) => {
let files = [];
if (mp4) files.push(to + '.mp4');
if (webm) files.push(to + '.webm');
callback(files);
});
});
}
}
module.exports = Html5Exporter;