From 7984c90140c8b29f6a05abd525324080b8934beb Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Wed, 27 Sep 2023 14:37:20 +0000 Subject: [PATCH] remove ur from components --- scripts/base.js | 6 +++++- scripts/components.js | 16 +++++---------- scripts/editor.js | 3 +++ scripts/engine.js | 42 -------------------------------------- scripts/entity.js | 5 +++-- scripts/std.js | 2 +- source/engine/2dphysics.c | 1 + source/engine/datastream.c | 2 +- source/engine/ffi.c | 7 +------ 9 files changed, 20 insertions(+), 64 deletions(-) diff --git a/scripts/base.js b/scripts/base.js index a0db6e5..34c71db 100644 --- a/scripts/base.js +++ b/scripts/base.js @@ -87,6 +87,7 @@ Object.isAccessor = function(obj, prop) Object.mergekey = function(o1,o2,k) { + if (!o2) return; if (Object.isAccessor(o2,k)) Object.defineProperty(o1, k, Object.getOwnPropertyDescriptor(o2,k)); else if (typeof o2[k] === 'object') { @@ -94,7 +95,10 @@ Object.mergekey = function(o1,o2,k) o1[k] = o2[k].slice(); else { if (!o1[k]) o1[k] = {}; - Object.merge(o1[k], o2[k]); + if (typeof o1[k] === 'object') + Object.merge(o1[k], o2[k]); + else + o1[k] = o2[k]; } } else o1[k] = o2[k]; diff --git a/scripts/components.js b/scripts/components.js index cba1ebb..3968c87 100644 --- a/scripts/components.js +++ b/scripts/components.js @@ -54,8 +54,6 @@ var component = { }, }; -//component.toJSON = ur_json; - component.sprite = { pos:[0,0], color:[1,1,1], @@ -353,8 +351,6 @@ collider2d.inputs['M-t'] = function() { this.enabled = !this.enabled; } collider2d.inputs['M-t'].doc = "Toggle if this collider is enabled."; component.polygon2d = Object.copy(collider2d, { - points: [], - ur: { flipx: false, flipy: false @@ -371,11 +367,10 @@ component.polygon2d = Object.copy(collider2d, { make(go) { var poly = Object.create(this); poly.gameobject = go; - Object.assign(poly, make_poly2d(go.body, this.points)); - poly.defn('points', this.points.copy()); - - poly.sync(); - + poly.points = []; + poly.flipx = false; + poly.flipy = false; + Object.assign(poly, make_poly2d(go.body, poly.points)); return poly; }, @@ -726,8 +721,7 @@ component.circle2d = Object.copy(collider2d, { make(go) { var circle = Object.create(this); circle.gameobject = go; - Object.assign(circle, make_circle2d(go.body, circle.radius, circle.offset)); - Object.merge(circle, this.ur); + Object.assign(circle, make_circle2d(go.body)); return circle; }, diff --git a/scripts/editor.js b/scripts/editor.js index f0f27be..156c7ac 100644 --- a/scripts/editor.js +++ b/scripts/editor.js @@ -770,7 +770,10 @@ editor.inputs.escape.doc = "Quit editor."; editor.inputs['C-s'] = function() { if (editor.selectlist.length !== 1 || !editor.selectlist[0].dirty) return; + Log.warn(JSON.stringify(editor.selectlist[0],null,1)); + Log.warn(JSON.stringify(editor.selectlist[0].ur,null,1)); Object.merge(editor.selectlist[0].ur, editor.selectlist[0].json_obj()); + Log.warn(JSON.stringify(editor.selectlist[0].ur,null,1)); var path = editor.selectlist[0].toString(); path = path.replaceAll('.','/'); path = path + "/" + path.name() + ".json"; diff --git a/scripts/engine.js b/scripts/engine.js index d6c2aaf..c8c15fb 100644 --- a/scripts/engine.js +++ b/scripts/engine.js @@ -550,11 +550,6 @@ var ur_json = function() if (typeof to === 'object' && !(key in to)) continue; if (typeof from[key] === 'object') { - if ('ur' in from[key]) { - var urdiff = objdiff(from[key],from[key].ur); - if (urdiff && !urdiff.empty) ret[key] = urdiff; - continue; - } var diff = objdiff(from[key], to[key]); if (diff && !diff.empty) ret[key] = diff; continue; @@ -572,45 +567,8 @@ var ur_json = function() return ur ? ur : {}; } - load("scripts/components.js"); -function replacer_empty_nil(key, val) { - if (typeof val === 'object' && JSON.stringify(val) === '{}') - return undefined; - -// if (typeof val === 'number') -// return parseFloat(val.toFixed(4)); - - return val; -}; - -function clean_object(obj) { - Object.keys(obj).forEach(function(x) { - if (!(x in obj.__proto__)) return; - - switch(typeof obj[x]) { - case 'object': - if (Array.isArray(obj[x])) { - if (obj[x].equal(obj.__proto__[x])) { - delete obj[x]; - } - } else - clean_object(obj[x]); - - break; - - case 'function': - return; - - default: - if (obj[x] === obj.__proto__[x]) - delete obj[x]; - break; - } - }); -}; - function find_com(objects) { if (!objects || objects.length === 0) diff --git a/scripts/entity.js b/scripts/entity.js index 1bf17e5..cb101a3 100644 --- a/scripts/entity.js +++ b/scripts/entity.js @@ -360,10 +360,11 @@ var gameobject = { obj[prop] = obj.spawn(prototypes.get_ur(p.ur)); obj.$[prop] = obj[prop]; } else if ('comp' in p) { + Log.warn(`spawning a ${p.comp}`); obj[prop] = component[p.comp].make(obj); obj.components[prop] = obj[prop]; - obj[prop].ur = Object.create(obj[prop].ur); - Object.totalmerge(obj[prop].ur, p); +// obj[prop].ur = Object.create(obj[prop].ur); +// Object.totalmerge(obj[prop].ur, p); } }; diff --git a/scripts/std.js b/scripts/std.js index e1f469e..c26251e 100644 --- a/scripts/std.js +++ b/scripts/std.js @@ -29,7 +29,7 @@ var Log = { var lmatch = nnn.match(/\:\d*\)/); var line = lmatch ? lmatch[0].shift(1).shift(-1) : "0"; - yughlog(lvl, msg, file, line); + yughlog(lvl, lg, file, line); }, info(msg) { diff --git a/source/engine/2dphysics.c b/source/engine/2dphysics.c index e6b1a4c..b028b59 100644 --- a/source/engine/2dphysics.c +++ b/source/engine/2dphysics.c @@ -203,6 +203,7 @@ struct phys2d_circle *Make2DCircle(int go) { new->shape.moi = phys2d_circle_moi; new->shape.apply = phys2d_applycircle; init_phys2dshape(&new->shape, go, new); + phys2d_applycircle(new); return new; } diff --git a/source/engine/datastream.c b/source/engine/datastream.c index 0a27369..1410a31 100644 --- a/source/engine/datastream.c +++ b/source/engine/datastream.c @@ -51,7 +51,7 @@ static void render_audio(plm_t *mpeg, plm_samples_t *samples, void *user) { } void ds_openvideo(struct datastream *ds, const char *video, const char *adriver) { - long rawlen; + size_t rawlen; void *raw; raw = slurp_file(video, &rawlen); ds->plm = plm_create_with_memory(raw, rawlen, 0); diff --git a/source/engine/ffi.c b/source/engine/ffi.c index fa7dda7..d71f9f1 100644 --- a/source/engine/ffi.c +++ b/source/engine/ffi.c @@ -1458,13 +1458,8 @@ JSValue duk_cmd_box2d(JSContext *js, JSValueConst this, int argc, JSValueConst * JSValue duk_make_circle2d(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) { int go = js2int(argv[0]); - double radius = js2number(argv[1]); struct phys2d_circle *circle = Make2DCircle(go); - circle->radius = radius; - circle->offset = js2vec2(argv[2]); - - phys2d_applycircle(circle); JSValue circleval = JS_NewObject(js); JS_SetPropertyStr(js, circleval, "id", ptr2js(circle)); @@ -1657,7 +1652,7 @@ void ffi_load() { DUK_FUNC(make_box2d, 3) DUK_FUNC(cmd_box2d, 6) - DUK_FUNC(make_circle2d, 3) + DUK_FUNC(make_circle2d, 1) DUK_FUNC(cmd_circle2d, 6) DUK_FUNC(make_poly2d, 2) DUK_FUNC(cmd_poly2d, 6)