Command line arguments, err messages, help; remove Proxy functions from JS
This commit is contained in:
parent
4d577dadb7
commit
7ddf807efd
|
@ -1059,7 +1059,8 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 124:
|
case 124:
|
||||||
pack_engine();
|
str = JS_ToCString(js, argv[1]);
|
||||||
|
pack_engine(str);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 125:
|
case 125:
|
||||||
|
|
|
@ -254,18 +254,18 @@ static int ftw_pack(const char *path, const struct stat *sb, int flag)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pack_engine()
|
void pack_engine(const char *fname)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
char *key, *va;
|
char *key, *va;
|
||||||
unsigned klen, vlen;
|
unsigned klen, vlen;
|
||||||
fd = open("test.cdb", O_RDWR|O_CREAT);
|
fd = open(fname, O_RDWR|O_CREAT);
|
||||||
cdb_make_start(&cdbm, fd);
|
cdb_make_start(&cdbm, fd);
|
||||||
ftw(".", ftw_pack, 20);
|
ftw(".", ftw_pack, 20);
|
||||||
cdb_make_finish(&cdbm);
|
cdb_make_finish(&cdbm);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
void pack_engine(){
|
void pack_engine(const char *fname){
|
||||||
YughError("Cannot pack engine on a web build.");
|
YughError("Cannot pack engine on a web build.");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -20,6 +20,6 @@ unsigned char *slurp_file(const char *filename, long *size);
|
||||||
char *slurp_text(const char *filename);
|
char *slurp_text(const char *filename);
|
||||||
int slurp_write(const char *txt, const char *filename);
|
int slurp_write(const char *txt, const char *filename);
|
||||||
|
|
||||||
void pack_engine();
|
void pack_engine(const char *fname);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -146,6 +146,8 @@ static char **args;
|
||||||
|
|
||||||
void c_init() {
|
void c_init() {
|
||||||
render_init();
|
render_init();
|
||||||
|
|
||||||
|
script_evalf("initialize();");
|
||||||
}
|
}
|
||||||
|
|
||||||
int frame_fps() {
|
int frame_fps() {
|
||||||
|
|
|
@ -65,7 +65,6 @@ var sprite = clone(component, {
|
||||||
|
|
||||||
kill() { cmd(9,this.id); },
|
kill() { cmd(9,this.id); },
|
||||||
});
|
});
|
||||||
sprite = new Proxy(sprite, sync_proxy);
|
|
||||||
sprite.obscure('boundingbox');
|
sprite.obscure('boundingbox');
|
||||||
return sprite;
|
return sprite;
|
||||||
},
|
},
|
||||||
|
@ -250,14 +249,6 @@ collider2d.inputs['M-s'].doc = "Toggle if this collider is a sensor.";
|
||||||
collider2d.inputs['M-t'] = function() { this.enabled = !this.enabled; }
|
collider2d.inputs['M-t'] = function() { this.enabled = !this.enabled; }
|
||||||
collider2d.inputs['M-t'].doc = "Toggle if this collider is enabled.";
|
collider2d.inputs['M-t'].doc = "Toggle if this collider is enabled.";
|
||||||
|
|
||||||
var sync_proxy = {
|
|
||||||
set(t,p,v) {
|
|
||||||
t[p] = v;
|
|
||||||
t.sync();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var polygon2d = clone(collider2d, {
|
var polygon2d = clone(collider2d, {
|
||||||
name: "polygon 2d",
|
name: "polygon 2d",
|
||||||
points: [],
|
points: [],
|
||||||
|
@ -288,8 +279,6 @@ var polygon2d = clone(collider2d, {
|
||||||
|
|
||||||
poly.defn('points', this.points.copy());
|
poly.defn('points', this.points.copy());
|
||||||
|
|
||||||
poly = new Proxy(poly, sync_proxy);
|
|
||||||
|
|
||||||
Object.defineProperty(poly, 'id', {enumerable:false});
|
Object.defineProperty(poly, 'id', {enumerable:false});
|
||||||
Object.defineProperty(poly, 'shape', {enumerable:false});
|
Object.defineProperty(poly, 'shape', {enumerable:false});
|
||||||
|
|
||||||
|
@ -466,7 +455,6 @@ var bucket = clone(collider2d, {
|
||||||
make(go) {
|
make(go) {
|
||||||
var edge = Object.create(this);
|
var edge = Object.create(this);
|
||||||
Object.assign(edge, make_edge2d(go, this.points, this.thickness));
|
Object.assign(edge, make_edge2d(go, this.points, this.thickness));
|
||||||
edge = new Proxy(edge, sync_proxy);
|
|
||||||
complete_assign(edge, {
|
complete_assign(edge, {
|
||||||
set thickness(x) {
|
set thickness(x) {
|
||||||
cmd_edge2d(1,this.id,x);
|
cmd_edge2d(1,this.id,x);
|
||||||
|
|
|
@ -16,11 +16,11 @@ function compile(file) {
|
||||||
var Cmdline = {};
|
var Cmdline = {};
|
||||||
|
|
||||||
Cmdline.cmds = [];
|
Cmdline.cmds = [];
|
||||||
Cmdline.register_cmd = function(flag, fn, desc) {
|
Cmdline.register_cmd = function(flag, fn, doc) {
|
||||||
Cmdline.cmds.push({
|
Cmdline.cmds.push({
|
||||||
flag: flag,
|
flag: flag,
|
||||||
fn: fn,
|
fn: fn,
|
||||||
desc: desc
|
doc: doc
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -31,18 +31,36 @@ function cmd_args(cmdargs)
|
||||||
|
|
||||||
Cmdline.play = false;
|
Cmdline.play = false;
|
||||||
|
|
||||||
for (var i = 0; i < cmds.length; i++) {
|
for (var i = 1; i < cmds.length; i++) {
|
||||||
if (cmds[i][0] !== '-')
|
if (cmds[i][0] !== '-') {
|
||||||
|
Log.warn(`Command '${cmds[i]}' should start with a '-'.`);
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
var c = Cmdline.cmds.find(function(cmd) { return cmd.flag === cmds[i].slice(1); });
|
var c = Cmdline.cmds.find(function(cmd) { return cmd.flag === cmds[i].slice(1); });
|
||||||
if (c && c.fn) {
|
if (!c) {
|
||||||
if (cmds[i+1] && cmds[i+1][0] !== '-')
|
Log.warn(`Command ${cmds[i]} not recognized.`);
|
||||||
c.fn(cmds[i+1]);
|
continue;
|
||||||
else
|
|
||||||
c.fn();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
var sendstr = [];
|
||||||
|
var j = i+1;
|
||||||
|
while (cmds[j] && cmds[j][0] !== '-') {
|
||||||
|
sendstr.push(cmds[j]);
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
|
||||||
|
c.fn(sendstr);
|
||||||
|
i = j-1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function initialize()
|
||||||
|
{
|
||||||
|
if (IO.exists("config.js"))
|
||||||
|
load("config.js");
|
||||||
|
|
||||||
|
prototypes.load_all();
|
||||||
|
|
||||||
if (Cmdline.play)
|
if (Cmdline.play)
|
||||||
run("scripts/play.js");
|
run("scripts/play.js");
|
||||||
|
@ -51,20 +69,40 @@ function cmd_args(cmdargs)
|
||||||
}
|
}
|
||||||
|
|
||||||
Cmdline.register_cmd("p", function() { Cmdline.play = true; }, "Launch engine in play mode.");
|
Cmdline.register_cmd("p", function() { Cmdline.play = true; }, "Launch engine in play mode.");
|
||||||
Cmdline.register_cmd("v", function() { Log.say(cmd(120)); }, "Display engine info.");
|
Cmdline.register_cmd("v", function() { Log.say(cmd(120)); Game.quit(); }, "Display engine info.");
|
||||||
Cmdline.register_cmd("c", null, "Redirect logging to console.");
|
Cmdline.register_cmd("c", function() {}, "Redirect logging to console.");
|
||||||
Cmdline.register_cmd("l", null, "Set logging file name.");
|
Cmdline.register_cmd("l", function(n) {
|
||||||
Cmdline.register_cmd("h", function() {
|
Log.level = n;
|
||||||
|
}, "Set log level.");
|
||||||
|
Cmdline.register_cmd("h", function(str) {
|
||||||
|
for (var cmd of Cmdline.cmds) {
|
||||||
|
Log.say(`-${cmd.flag}: ${cmd.doc}`);
|
||||||
|
}
|
||||||
|
|
||||||
Game.quit();
|
Game.quit();
|
||||||
},
|
},
|
||||||
"Help.");
|
"Help.");
|
||||||
Cmdline.register_cmd("b", function() { cmd(124); Game.quit(); }, "Pack the game into the given name.");
|
Cmdline.register_cmd("b", function(str) {
|
||||||
|
var packname;
|
||||||
|
if (str.length === 0)
|
||||||
|
packname = "test.cdb";
|
||||||
|
else if (str.length > 1) {
|
||||||
|
Log.warn("Give me a single filename for the pack.");
|
||||||
|
Game.quit();
|
||||||
|
} else
|
||||||
|
packname = str[0];
|
||||||
|
|
||||||
|
Log.warn(`Packing into ${packname}`);
|
||||||
|
|
||||||
|
cmd(124, packname);
|
||||||
|
Game.quit();
|
||||||
|
}, "Pack the game into the given name.");
|
||||||
|
|
||||||
Cmdline.register_cmd("e", function(pawn) {
|
Cmdline.register_cmd("e", function(pawn) {
|
||||||
run("scripts/editor.js");
|
run("scripts/editor.js");
|
||||||
eval(`Log.write(Input.print_md_kbm(${pawn}));`);
|
eval(`Log.write(Input.print_md_kbm(${pawn}));`);
|
||||||
Game.quit();
|
Game.quit();
|
||||||
}, "Print input documentation for a given object." );
|
}, "Print input documentation for a given object in a markdown table." );
|
||||||
|
|
||||||
function run(file)
|
function run(file)
|
||||||
{
|
{
|
||||||
|
@ -141,6 +179,7 @@ var Log = {
|
||||||
};
|
};
|
||||||
|
|
||||||
load("scripts/diff.js");
|
load("scripts/diff.js");
|
||||||
|
Log.level = 1;
|
||||||
|
|
||||||
var Physics = {
|
var Physics = {
|
||||||
dynamic: 0,
|
dynamic: 0,
|
||||||
|
@ -2362,12 +2401,6 @@ gameobject.clone("sprite", {
|
||||||
sprite: sprite.clone(),
|
sprite: sprite.clone(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
//if (IO.exists("config.js"))
|
|
||||||
// load("config.js");
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var prototypes = {};
|
var prototypes = {};
|
||||||
prototypes.load_all = function()
|
prototypes.load_all = function()
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
Game.play();
|
Game.play();
|
||||||
|
|
||||||
|
|
||||||
if (!IO.exists("game.js"))
|
if (!IO.exists("game.js"))
|
||||||
load("scripts/nogame.js");
|
load("scripts/nogame.js");
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue