diff --git a/scripts/base.js b/scripts/base.js index 6eff29f..b1a0e47 100644 --- a/scripts/base.js +++ b/scripts/base.js @@ -32,6 +32,17 @@ Object.methods = function(o) return m; } +Object.dig = function(obj, path, def) +{ + def ??= {}; + var pp = path.split('.'); + for (var i = 0; i < pp.length-1; i++) { + obj = obj[pp[i]] = obj[pp[i]] || {}; + } + obj[pp[pp.length-1]] = def; + return def; +} + Object.rkeys = function(o) { var keys = []; diff --git a/scripts/editor.js b/scripts/editor.js index 8d4155b..5b55a03 100644 --- a/scripts/editor.js +++ b/scripts/editor.js @@ -210,7 +210,8 @@ var editor = { Player.players[0].uncontrol(this); Player.players[0].control(limited_editor); Register.unregister_obj(this); - Primum.spawn(this.dbg_ur); + editor.dbg_play = Primum.spawn(this.dbg_ur); + load("debug.js"); }, enter_editor() { @@ -268,13 +269,9 @@ var editor = { this.backshots = []; }, - check_snapshot() { - if (!this.selectlist.empty || this.grabselect) this.snapshot(); - }, - snapshot() { - var cur = this.edit_level.save(); - var dif = diff(cur, this.curlvl); + var cur = this.edit_level.json_obj(); + var dif = ediff(cur, this.curlvl); if (dif.empty) return; @@ -420,6 +417,8 @@ var editor = { } GUI.text("0,0", world2screen([0,0])); + GUI.text(editor.edit_level.worldpos().map(function(x) { return Math.round(x); }), world2screen(editor.edit_level.worldpos()), 1, Color.red); + GUI.text("+", world2screen(editor.edit_level.worldpos()), 1, Color.blue); var thiso = editor.get_this(); var clvl = thiso; @@ -442,6 +441,7 @@ var editor = { lvlchain.forEach(function(x,i) { depth = i; var lvlstr = x.toString(); + x._ed.check_dirty(); if (x._ed.dirty) lvlstr += "*"; if (i === lvlchain.length-1) lvlstr += "[this]"; @@ -467,6 +467,12 @@ var editor = { x.gizmo(); }); + Object.entries(thiso.objects).forEach(function(x) { + var p = x[0]; + if (x[1]._ed.dirty) p += "*"; + GUI.text(p, world2screen(x[1].worldpos()),1,editor.color_depths[depth]); + }); + var mg = Game.obj_at(Mouse.worldpos); if (mg) { @@ -631,7 +637,7 @@ var editor = { editor.inputs = {}; editor.inputs.release_post = function() { - editor.check_snapshot(); + editor.snapshot(); editor.edit_level.check_dirty(); }; editor.inputs['C-a'] = function() { @@ -824,8 +830,7 @@ editor.inputs['C-s'] = function() { } else if (editor.selectlist.length === 1) saveobj = editor.selectlist[0]; - Log.warn("Attempgint to save " + saveobj.toString()); - saveobj.check_dirty(); + saveobj._ed.check_dirty(); if (!saveobj._ed.dirty) return; var savejs = saveobj.json_obj(); @@ -1024,23 +1029,10 @@ editor.try_pick = function() { editor.grabselect = []; - if (editor.sel_comp && 'pick' in editor.sel_comp) { - var o = editor.sel_comp.pick(Mouse.worldpos); - if (o) - editor.grabselect = [o]; - return; - } + if (editor.sel_comp && 'pick' in editor.sel_comp) + return editor.sel_comp.pick(Mouse.worldpos); - if (editor.selectlist.length > 0) { - editor.grabselect = editor.selectlist.slice(); - return; - } - - var grabobj = editor.try_select(); - - if (!grabobj) return; - editor.grabselect = [grabobj]; - editor.selectlist = [grabobj]; + return editor.try_select(); } editor.inputs.mm = function() { @@ -1051,7 +1043,10 @@ editor.inputs.mm = function() { return; } - editor.try_pick(); + var o = editor.try_pick(); + if (!o) return; + editor.selectlist = [o]; + editor.grabselect = [o]; }; editor.inputs['C-mm'] = editor.inputs.mm; @@ -1165,7 +1160,13 @@ editor.inputs['C-S-g'] = function() { editor.openpanel(groupsaveaspanel); }; editor.inputs['C-S-g'].doc = "Save selected objects as a new level."; editor.inputs.g = function() { - editor.try_pick(); + if (editor.selectlist.length === 0) { + var o = editor.try_pick(); + if (!o) return; + editor.selectlist = [o]; + } + + editor.grabselect = editor.selectlist.slice(); }; editor.inputs.g.doc = "Move selected objects."; editor.inputs.g.released = function() { editor.grabselect = []; Mouse.normal(); }; @@ -1971,5 +1972,3 @@ Game.editor_mode(true); Debug.draw_phys(true); editor.enter_editor(); - -load("editorconfig.js"); diff --git a/scripts/engine.js b/scripts/engine.js index c8de35d..b1ec10e 100644 --- a/scripts/engine.js +++ b/scripts/engine.js @@ -9,10 +9,14 @@ load("scripts/std.js"); function initialize() { - if (!Game.edit) - load("scripts/play.js"); - else + if (!Game.edit) { + load("config.js"); + load("game.js"); + } + else { load("scripts/editor.js"); + load("editorconfig.js"); + } } function run(file) @@ -724,6 +728,8 @@ preprimum.gscale = function() { return 1; }; preprimum.pos = [0,0]; preprimum.angle = 0; preprimum.remove_obj = function() {}; +preprimum.instances = []; +preprimum.toString = function() { return "preprimum"; }; var World = preprimum.make(preprimum); var Primum = World; Primum.level = undefined; @@ -787,6 +793,7 @@ Game.view_camera = function(cam) { Game.camera = cam; cmd(61, Game.camera.body); + cam.zoom = cam.zoom; } Game.view_camera(Primum.spawn(ur.camera2d)); diff --git a/scripts/entity.js b/scripts/entity.js index 98cc132..38e29df 100644 --- a/scripts/entity.js +++ b/scripts/entity.js @@ -154,7 +154,7 @@ var gameobject = { if (typeof ur === 'string') ur = prototypes.get_ur(ur); if (!ur) { - Log.warn("Failed to make UR from " + ur); + Log.error("Failed to make UR from " + ur); return undefined; } @@ -410,7 +410,7 @@ var gameobject = { Player.uncontrol(this); Register.unregister_obj(this); -// this.instances.remove(this); +// ur[this.ur].instances.remove(this); this.body = -1; for (var key in this.components) { @@ -440,6 +440,8 @@ var gameobject = { obj.make = undefined; obj.level = level; // this.instances.push(obj); +// Log.warn(`Made an object from ${this.toString()}`); +// Log.warn(this.instances.length); obj.body = make_gameobject(); obj.components = {}; obj.objects = {}; @@ -455,11 +457,6 @@ var gameobject = { cmd(113, obj.body, obj); // set the internal obj reference to this obj - obj.level = undefined; - obj.reparent(level); - - Object.hide(obj, 'ur','body', 'components', 'objects', '_ed', 'level'); - for (var prop in this) { var p = this[prop]; if (typeof p !== 'object') continue; @@ -468,10 +465,15 @@ var gameobject = { obj.components[prop] = obj[prop]; } }; - + if (this.objects) obj.make_objs(this.objects); + obj.level = undefined; + obj.reparent(level); + + Object.hide(obj, 'ur','body', 'components', 'objects', '_ed', 'level'); + Object.dainty_assign(obj, this); obj.sync(); gameobject.check_registers(obj); @@ -594,8 +596,13 @@ prototypes.from_file = function(file) prototypes.list.push(urpath); newur.toString = function() { return urpath; }; ur[urpath] = newur; +// var urs = urpath.split('.'); +// var u = ur; +// for (var i = 0; i < urs.length; i++) +// u = u[urs[i]] = u[urs[i]] || newur; + //Object.dig(ur, urpath, newur); - return ur[urpath]; + return newur; } prototypes.from_file.doc = "Create a new ur-type from a given script file."; prototypes.list = []; diff --git a/scripts/gui.js b/scripts/gui.js index 4cd83ba..9632682 100644 --- a/scripts/gui.js +++ b/scripts/gui.js @@ -30,7 +30,8 @@ var GUI = { scissor_win() { cmd(140,0,0,Window.width,Window.height); }, - image(path,pos) { + image(path,pos,color) { + color ??= Color.black; var wh = cmd(64,path); gui_img(path,pos, [1.0,1.0], 0.0, 0.0, [0.0,0.0], 0.0, Color.black); return cwh2bb([0,0], wh);