merge made functions into original prototype
This commit is contained in:
parent
266ad65ba7
commit
31331af57d
|
@ -34,21 +34,13 @@ var sprite = clone(component, {
|
|||
angle: 0,
|
||||
rect: {s0:0, s1: 1, t0: 0, t1: 1},
|
||||
|
||||
dimensions() { return cmd(64,this.path); },
|
||||
width() { return cmd(64,this.path).x; },
|
||||
height() { return cmd(64,this.path).y; },
|
||||
|
||||
make(go) {
|
||||
var sprite = Object.create(this);
|
||||
var id = make_sprite(go,this.path,this.pos);
|
||||
complete_assign(sprite, {
|
||||
get enabled() { return cmd(114,id); },
|
||||
set enabled(x) { cmd(20,id,x); },
|
||||
set color(x) { cmd(96,id,x); },
|
||||
get enabled() { return cmd(114,this.id); },
|
||||
set enabled(x) { cmd(20,this.id,x); },
|
||||
set color(x) { cmd(96,this.id,x); },
|
||||
get color() {return undefined; },
|
||||
get pos() { return cmd(111, id); },
|
||||
set pos(x) { cmd(37,id,x); },
|
||||
set layer(x) { cmd(60, id, x); },
|
||||
get pos() { return cmd(111, this.id); },
|
||||
set pos(x) { cmd(37,this.id,x); },
|
||||
set layer(x) { cmd(60, this.id, x); },
|
||||
get layer() { return undefined; },
|
||||
|
||||
boundingbox() {
|
||||
|
@ -62,12 +54,19 @@ var sprite = clone(component, {
|
|||
|
||||
sync() {
|
||||
if (this.path)
|
||||
cmd(12,id,this.path,this.rect);
|
||||
cmd(12,this.id,this.path,this.rect);
|
||||
},
|
||||
|
||||
kill() { cmd(9,id); },
|
||||
});
|
||||
kill() { cmd(9,this.id); },
|
||||
|
||||
|
||||
dimensions() { return cmd(64,this.path); },
|
||||
width() { return cmd(64,this.path).x; },
|
||||
height() { return cmd(64,this.path).y; },
|
||||
|
||||
make(go) {
|
||||
var sprite = Object.create(this);
|
||||
sprite.id = make_sprite(go);
|
||||
sprite.layer = 1;
|
||||
return sprite;
|
||||
},
|
||||
|
@ -634,13 +633,25 @@ var circle2d = clone(collider2d, {
|
|||
set pos(x) { this.offset = x; },
|
||||
|
||||
make(go) {
|
||||
var circle = clone(this);
|
||||
var circle = Object.create(this.made);
|
||||
var circ = make_circle2d(go, circle.radius, circle.offset);
|
||||
Object.assign(circle, circ);
|
||||
Object.defineProperty(circle, 'id', {enumerable:false});
|
||||
Object.defineProperty(circle, 'shape', {enumerable:false});
|
||||
return circle;
|
||||
},
|
||||
|
||||
complete_assign(circle, {
|
||||
gui() {
|
||||
Nuke.newline();
|
||||
Nuke.label("circle2d");
|
||||
this.radius = Nuke.pprop("Radius", this.radius);
|
||||
this.offset = Nuke.pprop("offset", this.offset);
|
||||
},
|
||||
});
|
||||
|
||||
circle2d.made = Object.create(circle2d);
|
||||
complete_assign(circle2d.made, collider2d.make_fns);
|
||||
complete_assign(circle2d.made, {
|
||||
set radius(x) { cmd_circle2d(0,this.id,x); },
|
||||
get radius() { return cmd_circle2d(2,this.id); },
|
||||
|
||||
|
@ -653,18 +664,6 @@ var circle2d = clone(collider2d, {
|
|||
},
|
||||
});
|
||||
|
||||
complete_assign(circle, this.make_fns);
|
||||
|
||||
return circle;
|
||||
},
|
||||
|
||||
gui() {
|
||||
Nuke.newline();
|
||||
Nuke.label("circle2d");
|
||||
this.radius = Nuke.pprop("Radius", this.radius);
|
||||
this.offset = Nuke.pprop("offset", this.offset);
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
/* ASSETS */
|
||||
|
|
|
@ -239,8 +239,8 @@ var DebugControls = {};
|
|||
DebugControls.inputs = {};
|
||||
DebugControls.inputs.f1 = function () { Debug.draw_phys(!Debug.phys_drawing); };
|
||||
DebugControls.inputs.f1.doc = "Draw physics debugging aids.";
|
||||
DebugControls.inputs.f3 = function() { Debug.draw_bb = !Debug.draw_bb; };
|
||||
DebugControls.inputs.f3.doc = "Toggle drawing bounding boxes.";
|
||||
//DebugControls.inputs.f3 = function() { Debug.draw_bb = !Debug.draw_bb; };
|
||||
//DebugControls.inputs.f3.doc = "Toggle drawing bounding boxes.";
|
||||
DebugControls.inputs.f4 = function() {
|
||||
Debug.draw_names = !Debug.draw_names;
|
||||
Debug.draw_gizmos = !Debug.draw_gizmos;
|
||||
|
|
|
@ -748,13 +748,13 @@ editor.inputs['C-d'] = function() {
|
|||
editor.inputs['C-d'].doc = "Duplicate all selected objects.";
|
||||
|
||||
editor.inputs.f3 = function() {
|
||||
Log.say("Selected JSON ...");
|
||||
editor.selectlist.forEach(x => Log.say(JSON.stringify(x,null,2)));
|
||||
Log.say("UR JSON ...");
|
||||
for (var key of Object.keys(editor.selectlist[0].ur.type))
|
||||
Log.say(key);
|
||||
|
||||
editor.selectlist.forEach(x => Log.say(JSON.stringify(x.ur.type,null,2)));
|
||||
editor.selectlist.forEach(function(x) {
|
||||
Log.say("Selected JSON ...");
|
||||
Log.say(JSON.stringify(x,null,2));
|
||||
Log.say("UR JSON");
|
||||
Log.say(JSON.stringify(x.__proto__,null,2))
|
||||
});
|
||||
};
|
||||
|
||||
editor.inputs['C-m'] = function() {
|
||||
|
|
|
@ -313,21 +313,28 @@ var gameobject = {
|
|||
right() { return [1,0].rotate(Math.deg2rad(this.angle));},
|
||||
left() { return [-1,0].rotate(Math.deg2rad(this.angle));},
|
||||
|
||||
/* Given an ur-type, spawn one attached to us */
|
||||
|
||||
toJSON() {
|
||||
function objdiff(from, to) {
|
||||
if (!to) return from; /* Everything on from is unique */
|
||||
var ret = {};
|
||||
for (var key in this) {
|
||||
var prop = Object.getOwnPropertyDescriptor(this, key);
|
||||
if (!prop) continue;
|
||||
if (prop.get) {
|
||||
if (prop.get() !== this.__proto__[key])
|
||||
ret[key] = prop.get();
|
||||
for (var key of Object.keys(from)) {
|
||||
if (typeof from[key] === 'object') {
|
||||
var diff = objdiff(from[key], to[key]);
|
||||
if (diff && !diff.empty) ret[key] = diff;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
ret[key] = this[key];
|
||||
if (from[key] !== to[key])
|
||||
ret[key] = from[key];
|
||||
}
|
||||
Log.say("Returning a obj with values ...");
|
||||
for (var key in ret)
|
||||
Log.say(key);
|
||||
|
||||
if (ret.empty) return undefined;
|
||||
return ret;
|
||||
}
|
||||
|
||||
return objdiff(this, this.__proto__);
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -339,6 +346,8 @@ var gameobject = {
|
|||
}
|
||||
};
|
||||
|
||||
dainty_assign(obj, this);
|
||||
|
||||
obj.check_registers(obj);
|
||||
|
||||
gameobject.make_parentable(obj);
|
||||
|
@ -402,6 +411,8 @@ gameobject.make_parentable = function(obj) {
|
|||
obj.objects = objects;
|
||||
}
|
||||
|
||||
gameobject.entity = {};
|
||||
|
||||
/* Default objects */
|
||||
var prototypes = {};
|
||||
prototypes.ur = {};
|
||||
|
|
|
@ -1400,17 +1400,7 @@ JSValue duk_q_body(JSContext *js, JSValueConst this, int argc, JSValueConst *arg
|
|||
}
|
||||
|
||||
JSValue duk_make_sprite(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
int go = js2int(argv[0]);
|
||||
const char *path = JS_ToCString(js, argv[1]);
|
||||
HMM_Vec2 pos = js2hmmv2(argv[2]);
|
||||
int sprite = make_sprite(go);
|
||||
struct sprite *sp = id2sprite(sprite);
|
||||
sprite_loadtex(sp, path, ST_UNIT);
|
||||
sp->pos = pos;
|
||||
|
||||
JS_FreeCString(js, path);
|
||||
|
||||
return JS_NewInt64(js, sprite);
|
||||
return JS_NewInt64(js, make_sprite(js2int(argv[0])));
|
||||
}
|
||||
|
||||
/* Make anim from texture */
|
||||
|
@ -1669,7 +1659,7 @@ void ffi_load() {
|
|||
|
||||
DUK_FUNC(sys_cmd, 1)
|
||||
|
||||
DUK_FUNC(make_sprite, 3)
|
||||
DUK_FUNC(make_sprite, 1)
|
||||
DUK_FUNC(make_anim2d, 3)
|
||||
DUK_FUNC(spline_cmd, 6)
|
||||
|
||||
|
|
Loading…
Reference in a new issue