fix check dirty; fix input stack for editor
This commit is contained in:
parent
567691edce
commit
f29981ca77
|
@ -148,6 +148,7 @@ var Profile = {
|
||||||
|
|
||||||
/* These controls are available during editing, and during play of debug builds */
|
/* These controls are available during editing, and during play of debug builds */
|
||||||
var DebugControls = {};
|
var DebugControls = {};
|
||||||
|
DebugControls.toString = function() { return "Debug"; };
|
||||||
DebugControls.inputs = {};
|
DebugControls.inputs = {};
|
||||||
DebugControls.inputs.f1 = function () { Debug.draw_phys(!Debug.phys_drawing); };
|
DebugControls.inputs.f1 = function () { Debug.draw_phys(!Debug.phys_drawing); };
|
||||||
DebugControls.inputs.f1.doc = "Draw physics debugging aids.";
|
DebugControls.inputs.f1.doc = "Draw physics debugging aids.";
|
||||||
|
|
|
@ -19,6 +19,7 @@ var configs = {
|
||||||
};
|
};
|
||||||
|
|
||||||
var editor = {
|
var editor = {
|
||||||
|
toString() { return "editor"; },
|
||||||
dbg_ur: "arena.level1",
|
dbg_ur: "arena.level1",
|
||||||
selectlist: [],
|
selectlist: [],
|
||||||
grablist: [],
|
grablist: [],
|
||||||
|
@ -214,16 +215,18 @@ var editor = {
|
||||||
Register.gui.register(editor.ed_gui, editor);
|
Register.gui.register(editor.ed_gui, editor);
|
||||||
Debug.register_call(editor.ed_debug, editor);
|
Debug.register_call(editor.ed_debug, editor);
|
||||||
Register.update.register(gui_controls.update, gui_controls);
|
Register.update.register(gui_controls.update, gui_controls);
|
||||||
Player.players[0].control(gui_controls);
|
// Player.players[0].control(gui_controls);
|
||||||
|
|
||||||
this.desktop = Primum.spawn(ur.arena);
|
this.desktop = Primum.spawn(ur.arena);
|
||||||
this.edit_level = this.desktop;
|
this.edit_level = this.desktop;
|
||||||
|
this.desktop.toString = function() { return "desktop"; };
|
||||||
editor.edit_level._ed.selectable = false;
|
editor.edit_level._ed.selectable = false;
|
||||||
if (this.stash) {
|
if (this.stash) {
|
||||||
this.desktop.make_objs(this.stash.objects);
|
this.desktop.make_objs(this.stash.objects);
|
||||||
Object.dainty_assign(this.desktop, this.stash);
|
Object.dainty_assign(this.desktop, this.stash);
|
||||||
}
|
}
|
||||||
this.selectlist = [];
|
this.selectlist = [];
|
||||||
|
editor.camera = Primum.spawn(ur.camera2d);
|
||||||
Game.view_camera(editor.camera);
|
Game.view_camera(editor.camera);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -231,17 +234,15 @@ var editor = {
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
openpanel(panel, dontsteal) {
|
openpanel(panel) {
|
||||||
if (this.curpanel)
|
if (this.curpanel) {
|
||||||
this.curpanel.close();
|
this.curpanel.close();
|
||||||
|
Player.players[0].uncontrol(this.curpanel);
|
||||||
|
}
|
||||||
|
|
||||||
this.curpanel = panel;
|
this.curpanel = panel;
|
||||||
|
Player.players[0].control(this.curpanel);
|
||||||
var stolen = this;
|
this.curpanel.open();
|
||||||
if (dontsteal)
|
|
||||||
stolen = undefined;
|
|
||||||
|
|
||||||
this.curpanel.open(stolen);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
curpanels: [],
|
curpanels: [],
|
||||||
|
@ -437,11 +438,7 @@ var editor = {
|
||||||
|
|
||||||
this.selectlist.forEach(function(x) {
|
this.selectlist.forEach(function(x) {
|
||||||
var sname = x.__proto__.toString();
|
var sname = x.__proto__.toString();
|
||||||
if (!x.json_obj().empty)
|
x._ed.check_dirty();
|
||||||
x._ed.dirty = true;
|
|
||||||
else
|
|
||||||
x._ed.dirty = false;
|
|
||||||
|
|
||||||
if (x._ed.dirty) sname += "*";
|
if (x._ed.dirty) sname += "*";
|
||||||
|
|
||||||
GUI.text(sname, world2screen(x.worldpos()).add([0, 16]), 1, lvlcolor);
|
GUI.text(sname, world2screen(x.worldpos()).add([0, 16]), 1, lvlcolor);
|
||||||
|
@ -807,22 +804,30 @@ editor.inputs.escape = function() { editor.openpanel(quitpanel); }
|
||||||
editor.inputs.escape.doc = "Quit editor.";
|
editor.inputs.escape.doc = "Quit editor.";
|
||||||
|
|
||||||
editor.inputs['C-s'] = function() {
|
editor.inputs['C-s'] = function() {
|
||||||
|
var saveobj = undefined;
|
||||||
if (editor.selectlist.length === 0) {
|
if (editor.selectlist.length === 0) {
|
||||||
saveaspanel.stem = editor.edit_level.ur.toString();
|
if (editor.edit_level === editor.desktop) {
|
||||||
saveaspanel.obj = editor.edit_level;
|
saveaspanel.stem = editor.edit_level.ur.toString();
|
||||||
editor.openpanel(saveaspanel);
|
saveaspanel.obj = editor.edit_level;
|
||||||
return;
|
editor.openpanel(saveaspanel);
|
||||||
};
|
return;
|
||||||
|
} else
|
||||||
|
saveobj = editor.edit_level;
|
||||||
|
} else if (editor.selectlist.length === 1)
|
||||||
|
saveobj = editor.selectlist[0];
|
||||||
|
|
||||||
if (editor.selectlist.length !== 1 || !editor.selectlist[0]._ed.dirty) return;
|
Log.warn("Attempgint to save " + saveobj.toString());
|
||||||
var saveobj = editor.selectlist[0].json_obj();
|
saveobj.check_dirty();
|
||||||
Object.merge(editor.selectlist[0].__proto__, saveobj);
|
if (!saveobj._ed.dirty) return;
|
||||||
editor.selectlist[0].__proto__.objects = saveobj.objects;
|
|
||||||
var path = editor.selectlist[0].ur.toString();
|
var savejs = saveobj.json_obj();
|
||||||
|
Object.merge(saveobj.__proto__, savejs);
|
||||||
|
saveobj.__proto__.objects = savejs.objects;
|
||||||
|
var path = saveobj.ur.toString();
|
||||||
path = path.replaceAll('.','/');
|
path = path.replaceAll('.','/');
|
||||||
path = path + "/" + path.name() + ".json";
|
path = path + "/" + path.name() + ".json";
|
||||||
|
|
||||||
IO.slurpwrite(JSON.stringify(editor.selectlist[0].__proto__,null,1), path);
|
IO.slurpwrite(JSON.stringify(saveobj.__proto__,null,1), path);
|
||||||
Log.warn(`Wrote to file ${path}`);
|
Log.warn(`Wrote to file ${path}`);
|
||||||
};
|
};
|
||||||
editor.inputs['C-s'].doc = "Save selected.";
|
editor.inputs['C-s'].doc = "Save selected.";
|
||||||
|
@ -1285,9 +1290,9 @@ editor.inputs.s.released = function() { this.scalelist = []; };
|
||||||
|
|
||||||
var inputpanel = {
|
var inputpanel = {
|
||||||
title: "untitled",
|
title: "untitled",
|
||||||
|
toString() { return this.title; },
|
||||||
value: "",
|
value: "",
|
||||||
on: false,
|
on: false,
|
||||||
stolen: {},
|
|
||||||
pos:[100,Window.height-50],
|
pos:[100,Window.height-50],
|
||||||
wh:[350,600],
|
wh:[350,600],
|
||||||
anchor: [0,1],
|
anchor: [0,1],
|
||||||
|
@ -1316,14 +1321,9 @@ var inputpanel = {
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
|
|
||||||
open(steal) {
|
open() {
|
||||||
this.on = true;
|
this.on = true;
|
||||||
this.value = "";
|
this.value = "";
|
||||||
if (steal) {
|
|
||||||
this.stolen = steal;
|
|
||||||
Player.players[0].uncontrol(this.stolen);
|
|
||||||
Player.players[0].control(this);
|
|
||||||
}
|
|
||||||
this.start();
|
this.start();
|
||||||
this.keycb();
|
this.keycb();
|
||||||
},
|
},
|
||||||
|
@ -1332,11 +1332,6 @@ var inputpanel = {
|
||||||
|
|
||||||
close() {
|
close() {
|
||||||
Player.players[0].uncontrol(this);
|
Player.players[0].uncontrol(this);
|
||||||
if (this.stolen) {
|
|
||||||
Player.players[0].control(this.stolen);
|
|
||||||
this.stolen = undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.on = false;
|
this.on = false;
|
||||||
if ('on_close' in this)
|
if ('on_close' in this)
|
||||||
this.on_close();
|
this.on_close();
|
||||||
|
@ -1418,49 +1413,6 @@ inputpanel.inputs['C-k'] = function() {
|
||||||
this.value = this.value.slice(0,this.caret);
|
this.value = this.value.slice(0,this.caret);
|
||||||
};
|
};
|
||||||
|
|
||||||
function proto_count_lvls(name)
|
|
||||||
{
|
|
||||||
if (!this.occs) this.occs = {};
|
|
||||||
if (name in this.occs) return this.occs[name];
|
|
||||||
var lvls = IO.extensions("lvl");
|
|
||||||
var occs = {};
|
|
||||||
var total = 0;
|
|
||||||
lvls.forEach(function(lvl) {
|
|
||||||
var json = JSON.parse(IO.slurp(lvl));
|
|
||||||
var count = 0;
|
|
||||||
json.forEach(function(x) { if (x.from === name) count++; });
|
|
||||||
occs[lvl] = count;
|
|
||||||
total += count;
|
|
||||||
});
|
|
||||||
|
|
||||||
this.occs[name] = occs;
|
|
||||||
this.occs[name].total = total;
|
|
||||||
|
|
||||||
return this.occs[name];
|
|
||||||
}
|
|
||||||
proto_count_lvls = proto_count_lvls.bind(proto_count_lvls);
|
|
||||||
|
|
||||||
function proto_used(name) {
|
|
||||||
var occs = proto_count_lvls(name);
|
|
||||||
var used = false;
|
|
||||||
occs.forEach(function(x) { if (x > 0) used = true; });
|
|
||||||
|
|
||||||
Log.info(used);
|
|
||||||
}
|
|
||||||
|
|
||||||
function proto_total_use(name) {
|
|
||||||
return proto_count_lvls(name).total;
|
|
||||||
}
|
|
||||||
|
|
||||||
function proto_children(name) {
|
|
||||||
var children = [];
|
|
||||||
|
|
||||||
for (var key in gameobjects)
|
|
||||||
if (gameobjects[key].from === name) children.push(gameobjects[key]);
|
|
||||||
|
|
||||||
return children;
|
|
||||||
}
|
|
||||||
|
|
||||||
load("scripts/textedit.js");
|
load("scripts/textedit.js");
|
||||||
|
|
||||||
var replpanel = Object.copy(inputpanel, {
|
var replpanel = Object.copy(inputpanel, {
|
||||||
|
@ -1511,6 +1463,7 @@ var replpanel = Object.copy(inputpanel, {
|
||||||
replpanel.inputs = Object.create(inputpanel.inputs);
|
replpanel.inputs = Object.create(inputpanel.inputs);
|
||||||
replpanel.inputs.tab = function() {
|
replpanel.inputs.tab = function() {
|
||||||
this.resetscroll();
|
this.resetscroll();
|
||||||
|
if (!this.value) return;
|
||||||
var obj = globalThis;
|
var obj = globalThis;
|
||||||
var keys = [];
|
var keys = [];
|
||||||
var keyobj = this.value.tolast('.');
|
var keyobj = this.value.tolast('.');
|
||||||
|
@ -1595,6 +1548,15 @@ replpanel.inputs.mouse.scroll = function(scroll)
|
||||||
if (this.scrolloffset.y < 0) this.scrolloffset.y = 0;
|
if (this.scrolloffset.y < 0) this.scrolloffset.y = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
replpanel.inputs.mm = function() { this.mm = true; };
|
||||||
|
replpanel.inputs.mm.released = function() { this.mm = false; };
|
||||||
|
|
||||||
|
replpanel.inputs.mouse.move = function(pos,dpos)
|
||||||
|
{
|
||||||
|
if (this.mm)
|
||||||
|
this.scrolloffset.y -= dpos.y;
|
||||||
|
}
|
||||||
|
|
||||||
replpanel.inputs.up = function()
|
replpanel.inputs.up = function()
|
||||||
{
|
{
|
||||||
this.scrolloffset.y += 40;
|
this.scrolloffset.y += 40;
|
||||||
|
@ -1774,7 +1736,6 @@ var openlevelpanel = Object.copy(inputpanel, {
|
||||||
this.assets = this.allassets.slice();
|
this.assets = this.allassets.slice();
|
||||||
this.caret = 0;
|
this.caret = 0;
|
||||||
var click_ur = function(btn) {
|
var click_ur = function(btn) {
|
||||||
Log.warn(btn.str);
|
|
||||||
this.value = btn.str;
|
this.value = btn.str;
|
||||||
this.keycb();
|
this.keycb();
|
||||||
this.submit();
|
this.submit();
|
||||||
|
@ -1783,7 +1744,7 @@ var openlevelpanel = Object.copy(inputpanel, {
|
||||||
|
|
||||||
this.mumlist = [];
|
this.mumlist = [];
|
||||||
this.assets.forEach(function(x) {
|
this.assets.forEach(function(x) {
|
||||||
this.mumlist[x] = Mum.button({str:x, action:click_ur});
|
this.mumlist[x] = Mum.text({str:x, action:click_ur, color: Color.blue, hovered: {color:Color.red}, selectable:true});
|
||||||
}, this);
|
}, this);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1978,7 +1939,6 @@ if (IO.exists("editor.config"))
|
||||||
load_configs("editor.config");
|
load_configs("editor.config");
|
||||||
|
|
||||||
/* This is the editor level & camera - NOT the currently edited level, but a level to hold editor things */
|
/* This is the editor level & camera - NOT the currently edited level, but a level to hold editor things */
|
||||||
editor.camera = Game.camera;
|
|
||||||
Game.stop();
|
Game.stop();
|
||||||
Game.editor_mode(true);
|
Game.editor_mode(true);
|
||||||
Debug.draw_phys(true);
|
Debug.draw_phys(true);
|
||||||
|
|
|
@ -488,8 +488,6 @@ register(9, Log.stack, this);
|
||||||
|
|
||||||
Register.gamepad_playermap[0] = Player.players[0];
|
Register.gamepad_playermap[0] = Player.players[0];
|
||||||
|
|
||||||
Player.players[0].control(GUI);
|
|
||||||
|
|
||||||
var Signal = {
|
var Signal = {
|
||||||
signals: [],
|
signals: [],
|
||||||
obj_begin(fn, obj, go) {
|
obj_begin(fn, obj, go) {
|
||||||
|
@ -665,8 +663,6 @@ var Game = {
|
||||||
stop()
|
stop()
|
||||||
{
|
{
|
||||||
Game.pause();
|
Game.pause();
|
||||||
/* And return to editor .. */
|
|
||||||
Log.warn("Stopping not implemented. Paused, and go to editor.");
|
|
||||||
},
|
},
|
||||||
|
|
||||||
step()
|
step()
|
||||||
|
@ -724,6 +720,7 @@ var Primum = World;
|
||||||
Primum.level = undefined;
|
Primum.level = undefined;
|
||||||
Primum.toString = function() { return "Primum"; };
|
Primum.toString = function() { return "Primum"; };
|
||||||
Primum._ed.selectable = false;
|
Primum._ed.selectable = false;
|
||||||
|
Primum._ed.check_dirty = function() { };
|
||||||
World.reparent = function(parent) { Log.warn("Cannot reparent the Primum."); }
|
World.reparent = function(parent) { Log.warn("Cannot reparent the Primum."); }
|
||||||
|
|
||||||
/* Load configs */
|
/* Load configs */
|
||||||
|
|
|
@ -325,18 +325,18 @@ var gameobject = {
|
||||||
return d;
|
return d;
|
||||||
},
|
},
|
||||||
|
|
||||||
instance_obj() {
|
|
||||||
var t = this.transform_obj();
|
|
||||||
t.ur = this.ur;
|
|
||||||
return t;
|
|
||||||
},
|
|
||||||
|
|
||||||
transform_obj() {
|
transform_obj() {
|
||||||
var t = this.json_obj();
|
var t = this.json_obj();
|
||||||
Object.assign(t, this.transform());
|
Object.assign(t, this.transform());
|
||||||
return t;
|
return t;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
instance_obj() {
|
||||||
|
var t = this.transform_obj();
|
||||||
|
t.ur = this.ur;
|
||||||
|
return t;
|
||||||
|
},
|
||||||
|
|
||||||
ur_obj() {
|
ur_obj() {
|
||||||
var ur = this.json_obj();
|
var ur = this.json_obj();
|
||||||
for (var k in ur)
|
for (var k in ur)
|
||||||
|
@ -426,6 +426,7 @@ var gameobject = {
|
||||||
assign_impl(obj, gameobject.impl);
|
assign_impl(obj, gameobject.impl);
|
||||||
obj._ed = {
|
obj._ed = {
|
||||||
selectable: true,
|
selectable: true,
|
||||||
|
check_dirty() { this.dirty = !obj.json_obj().empty; },
|
||||||
dirty: false,
|
dirty: false,
|
||||||
};
|
};
|
||||||
obj.ur = this.toString();
|
obj.ur = this.toString();
|
||||||
|
|
|
@ -65,6 +65,7 @@ var GUI = {
|
||||||
};
|
};
|
||||||
|
|
||||||
var gui_controls = {};
|
var gui_controls = {};
|
||||||
|
//gui_controls.toString = function() { return "GUI controls"; };
|
||||||
gui_controls.update = function() { };
|
gui_controls.update = function() { };
|
||||||
|
|
||||||
gui_controls.set_mum = function(mum)
|
gui_controls.set_mum = function(mum)
|
||||||
|
@ -89,7 +90,6 @@ gui_controls.inputs.mouse.move = function(pos,dpos)
|
||||||
}
|
}
|
||||||
gui_controls.inputs.mouse.scroll = function(scroll)
|
gui_controls.inputs.mouse.scroll = function(scroll)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gui_controls.inputs.lm = function() {
|
gui_controls.inputs.lm = function() {
|
||||||
|
|
|
@ -174,12 +174,16 @@ var Player = {
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
print_pawns() {
|
||||||
|
for (var pawn of this.pawns.reversed())
|
||||||
|
Log.say(pawn.toString());
|
||||||
|
},
|
||||||
|
|
||||||
create() {
|
create() {
|
||||||
var n = Object.create(this);
|
var n = Object.create(this);
|
||||||
n.pawns = [];
|
n.pawns = [];
|
||||||
n.gamepads = [];
|
n.gamepads = [];
|
||||||
n.control = function(pawn) {
|
n.control = function(pawn) {
|
||||||
Log.info(`Player taking control of ${pawn.toString()}`);
|
|
||||||
n.pawns.push_unique(pawn);
|
n.pawns.push_unique(pawn);
|
||||||
};
|
};
|
||||||
n.uncontrol = function(pawn) { n.pawns = n.pawns.filter(x => x !== pawn); };
|
n.uncontrol = function(pawn) { n.pawns = n.pawns.filter(x => x !== pawn); };
|
||||||
|
|
Loading…
Reference in a new issue