forked from Kode/khamake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.ts
51 lines (46 loc) · 1.85 KB
/
init.ts
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
import * as fs from 'fs';
import * as path from 'path';
export function run(name: string, from: string, projectfile: string) {
if (!fs.existsSync(path.join(from, projectfile))) {
fs.writeFileSync(path.join(from, projectfile),
"let project = new Project('New Project');\n"
+ "project.addAssets('Assets/**');\n"
+ "project.addSources('Sources');\n"
+ "resolve(project);\n",
{ encoding: 'utf8' });
}
if (!fs.existsSync(path.join(from, 'Assets'))) fs.mkdirSync(path.join(from, 'Assets'));
if (!fs.existsSync(path.join(from, 'Sources'))) fs.mkdirSync(path.join(from, 'Sources'));
var friendlyName = name;
friendlyName = friendlyName.replace(/ /g, '_');
friendlyName = friendlyName.replace(/-/g, '_');
if (!fs.existsSync(path.join(from, 'Sources', 'Main.hx'))) {
var mainsource = 'package;\n\nimport kha.System;\n\n'
+ 'class Main {\n'
+ '\tpublic static function main() {\n'
+ '\t\tSystem.init({title: "' + name + '", width: 1024, height: 768}, function () {\n'
+ '\t\t\tnew ' + friendlyName + '();\n'
+ '\t\t});\n'
+ '\t}\n'
+ '}\n';
fs.writeFileSync(path.join(from, 'Sources', 'Main.hx'), mainsource, { encoding: 'utf8' });
}
if (!fs.existsSync(path.join(from, 'Sources', friendlyName + '.hx'))) {
var projectsource = 'package;\n\nimport kha.Framebuffer;\nimport kha.Scheduler;\nimport kha.System;\n\n'
+ 'class ' + friendlyName + ' {\n'
+ '\tpublic function new() {\n'
+ '\t\tSystem.notifyOnRender(render);\n'
+ '\t\tScheduler.addTimeTask(update, 0, 1 / 60);\n'
+ '\t}\n'
+ '\n'
+ '\tfunction update(): Void {\n'
+ '\t\t\n'
+ '\t}\n'
+ '\n'
+ '\tfunction render(framebuffer: Framebuffer): Void {'
+ '\t\t\n'
+ '\t}\n'
+ '}\n';
fs.writeFileSync(path.join(from, 'Sources', friendlyName + '.hx'), projectsource, { encoding: 'utf8' });
}
}