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;
|
||||
|
||||
case 124:
|
||||
pack_engine();
|
||||
str = JS_ToCString(js, argv[1]);
|
||||
pack_engine(str);
|
||||
break;
|
||||
|
||||
case 125:
|
||||
|
|
|
@ -254,18 +254,18 @@ static int ftw_pack(const char *path, const struct stat *sb, int flag)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void pack_engine()
|
||||
void pack_engine(const char *fname)
|
||||
{
|
||||
int fd;
|
||||
char *key, *va;
|
||||
unsigned klen, vlen;
|
||||
fd = open("test.cdb", O_RDWR|O_CREAT);
|
||||
fd = open(fname, O_RDWR|O_CREAT);
|
||||
cdb_make_start(&cdbm, fd);
|
||||
ftw(".", ftw_pack, 20);
|
||||
cdb_make_finish(&cdbm);
|
||||
}
|
||||
#else
|
||||
void pack_engine(){
|
||||
void pack_engine(const char *fname){
|
||||
YughError("Cannot pack engine on a web build.");
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -20,6 +20,6 @@ unsigned char *slurp_file(const char *filename, long *size);
|
|||
char *slurp_text(const char *filename);
|
||||
int slurp_write(const char *txt, const char *filename);
|
||||
|
||||
void pack_engine();
|
||||
void pack_engine(const char *fname);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -146,6 +146,8 @@ static char **args;
|
|||
|
||||
void c_init() {
|
||||
render_init();
|
||||
|
||||
script_evalf("initialize();");
|
||||
}
|
||||
|
||||
int frame_fps() {
|
||||
|
|
|
@ -65,7 +65,6 @@ var sprite = clone(component, {
|
|||
|
||||
kill() { cmd(9,this.id); },
|
||||
});
|
||||
sprite = new Proxy(sprite, sync_proxy);
|
||||
sprite.obscure('boundingbox');
|
||||
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'].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, {
|
||||
name: "polygon 2d",
|
||||
points: [],
|
||||
|
@ -288,8 +279,6 @@ var polygon2d = clone(collider2d, {
|
|||
|
||||
poly.defn('points', this.points.copy());
|
||||
|
||||
poly = new Proxy(poly, sync_proxy);
|
||||
|
||||
Object.defineProperty(poly, 'id', {enumerable:false});
|
||||
Object.defineProperty(poly, 'shape', {enumerable:false});
|
||||
|
||||
|
@ -466,7 +455,6 @@ var bucket = clone(collider2d, {
|
|||
make(go) {
|
||||
var edge = Object.create(this);
|
||||
Object.assign(edge, make_edge2d(go, this.points, this.thickness));
|
||||
edge = new Proxy(edge, sync_proxy);
|
||||
complete_assign(edge, {
|
||||
set thickness(x) {
|
||||
cmd_edge2d(1,this.id,x);
|
||||
|
|
|
@ -16,11 +16,11 @@ function compile(file) {
|
|||
var Cmdline = {};
|
||||
|
||||
Cmdline.cmds = [];
|
||||
Cmdline.register_cmd = function(flag, fn, desc) {
|
||||
Cmdline.register_cmd = function(flag, fn, doc) {
|
||||
Cmdline.cmds.push({
|
||||
flag: flag,
|
||||
fn: fn,
|
||||
desc: desc
|
||||
doc: doc
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -31,19 +31,37 @@ function cmd_args(cmdargs)
|
|||
|
||||
Cmdline.play = false;
|
||||
|
||||
for (var i = 0; i < cmds.length; i++) {
|
||||
if (cmds[i][0] !== '-')
|
||||
for (var i = 1; i < cmds.length; i++) {
|
||||
if (cmds[i][0] !== '-') {
|
||||
Log.warn(`Command '${cmds[i]}' should start with a '-'.`);
|
||||
continue;
|
||||
}
|
||||
|
||||
var c = Cmdline.cmds.find(function(cmd) { return cmd.flag === cmds[i].slice(1); });
|
||||
if (c && c.fn) {
|
||||
if (cmds[i+1] && cmds[i+1][0] !== '-')
|
||||
c.fn(cmds[i+1]);
|
||||
else
|
||||
c.fn();
|
||||
if (!c) {
|
||||
Log.warn(`Command ${cmds[i]} not recognized.`);
|
||||
continue;
|
||||
}
|
||||
|
||||
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)
|
||||
run("scripts/play.js");
|
||||
else
|
||||
|
@ -51,20 +69,40 @@ function cmd_args(cmdargs)
|
|||
}
|
||||
|
||||
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("c", null, "Redirect logging to console.");
|
||||
Cmdline.register_cmd("l", null, "Set logging file name.");
|
||||
Cmdline.register_cmd("h", function() {
|
||||
Cmdline.register_cmd("v", function() { Log.say(cmd(120)); Game.quit(); }, "Display engine info.");
|
||||
Cmdline.register_cmd("c", function() {}, "Redirect logging to console.");
|
||||
Cmdline.register_cmd("l", function(n) {
|
||||
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();
|
||||
},
|
||||
"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) {
|
||||
run("scripts/editor.js");
|
||||
eval(`Log.write(Input.print_md_kbm(${pawn}));`);
|
||||
Game.quit();
|
||||
}, "Print input documentation for a given object." );
|
||||
}, "Print input documentation for a given object in a markdown table." );
|
||||
|
||||
function run(file)
|
||||
{
|
||||
|
@ -141,6 +179,7 @@ var Log = {
|
|||
};
|
||||
|
||||
load("scripts/diff.js");
|
||||
Log.level = 1;
|
||||
|
||||
var Physics = {
|
||||
dynamic: 0,
|
||||
|
@ -2362,12 +2401,6 @@ gameobject.clone("sprite", {
|
|||
sprite: sprite.clone(),
|
||||
});
|
||||
|
||||
|
||||
//if (IO.exists("config.js"))
|
||||
// load("config.js");
|
||||
|
||||
|
||||
|
||||
var prototypes = {};
|
||||
prototypes.load_all = function()
|
||||
{
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
Game.play();
|
||||
|
||||
|
||||
if (!IO.exists("game.js"))
|
||||
load("scripts/nogame.js");
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue