-
Notifications
You must be signed in to change notification settings - Fork 122
/
Copy pathstartupgenerator.js
46 lines (42 loc) · 1.18 KB
/
startupgenerator.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
if (typeof load == "undefined") {
fs = require('fs');
vm = require('vm');
load = function(file) {
vm.runInThisContext(fs.readFileSync(file), file);
};
}
var mygame = "web/mygame/mygame.js";
load("web/navigator.js");
load("web/mygame/mygame.js");
console.log("*scene_list");
var firstScene;
for (var i = 0; i < nav._sceneList.length; i++) {
if (!nav._sceneList[i]) continue;
if (!firstScene) {
firstScene = nav._sceneList[i];
if (firstScene != "startup") console.log(" startup");
}
console.log(" " + nav._sceneList[i]);
}
console.log("");
var mygame = ""+fs.readFileSync("web/mygame/mygame.js");
var statBlock = /stats\s*=\s*{((\r|\n|.)*?)}/.exec(mygame)[1];
var lines = statBlock.split(/\r?\n/);
for (var i = 0; i < lines.length; i++) {
var line = lines[i].trim();
if (!line) {
console.log("\n");
continue;
}
if (/^,/.test(line)) line = line.substr(1);
var parts = /"?(.*?)"?\s*:\s*(.*)/.exec(line);
var stat = parts[1];
var value = parts[2];
var commentParts = /(.*?)\/\/(.*)$/.exec(value);
if (commentParts) {
value = commentParts[1];
console.log("\n*comment " + commentParts[2]);
}
console.log("*create " + stat + " " + value);
}
console.log("*goto_scene " + firstScene);