add config startup files; add object.dig; editor gui additions; improved translating
This commit is contained in:
parent
b87cd41e70
commit
29698dbca5
|
@ -32,6 +32,17 @@ Object.methods = function(o)
|
||||||
return m;
|
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)
|
Object.rkeys = function(o)
|
||||||
{
|
{
|
||||||
var keys = [];
|
var keys = [];
|
||||||
|
|
|
@ -210,7 +210,8 @@ var editor = {
|
||||||
Player.players[0].uncontrol(this);
|
Player.players[0].uncontrol(this);
|
||||||
Player.players[0].control(limited_editor);
|
Player.players[0].control(limited_editor);
|
||||||
Register.unregister_obj(this);
|
Register.unregister_obj(this);
|
||||||
Primum.spawn(this.dbg_ur);
|
editor.dbg_play = Primum.spawn(this.dbg_ur);
|
||||||
|
load("debug.js");
|
||||||
},
|
},
|
||||||
|
|
||||||
enter_editor() {
|
enter_editor() {
|
||||||
|
@ -268,13 +269,9 @@ var editor = {
|
||||||
this.backshots = [];
|
this.backshots = [];
|
||||||
},
|
},
|
||||||
|
|
||||||
check_snapshot() {
|
|
||||||
if (!this.selectlist.empty || this.grabselect) this.snapshot();
|
|
||||||
},
|
|
||||||
|
|
||||||
snapshot() {
|
snapshot() {
|
||||||
var cur = this.edit_level.save();
|
var cur = this.edit_level.json_obj();
|
||||||
var dif = diff(cur, this.curlvl);
|
var dif = ediff(cur, this.curlvl);
|
||||||
|
|
||||||
if (dif.empty) return;
|
if (dif.empty) return;
|
||||||
|
|
||||||
|
@ -420,6 +417,8 @@ var editor = {
|
||||||
}
|
}
|
||||||
|
|
||||||
GUI.text("0,0", world2screen([0,0]));
|
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 thiso = editor.get_this();
|
||||||
var clvl = thiso;
|
var clvl = thiso;
|
||||||
|
@ -442,6 +441,7 @@ var editor = {
|
||||||
lvlchain.forEach(function(x,i) {
|
lvlchain.forEach(function(x,i) {
|
||||||
depth = i;
|
depth = i;
|
||||||
var lvlstr = x.toString();
|
var lvlstr = x.toString();
|
||||||
|
x._ed.check_dirty();
|
||||||
if (x._ed.dirty)
|
if (x._ed.dirty)
|
||||||
lvlstr += "*";
|
lvlstr += "*";
|
||||||
if (i === lvlchain.length-1) lvlstr += "[this]";
|
if (i === lvlchain.length-1) lvlstr += "[this]";
|
||||||
|
@ -467,6 +467,12 @@ var editor = {
|
||||||
x.gizmo();
|
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);
|
var mg = Game.obj_at(Mouse.worldpos);
|
||||||
|
|
||||||
if (mg) {
|
if (mg) {
|
||||||
|
@ -631,7 +637,7 @@ var editor = {
|
||||||
|
|
||||||
editor.inputs = {};
|
editor.inputs = {};
|
||||||
editor.inputs.release_post = function() {
|
editor.inputs.release_post = function() {
|
||||||
editor.check_snapshot();
|
editor.snapshot();
|
||||||
editor.edit_level.check_dirty();
|
editor.edit_level.check_dirty();
|
||||||
};
|
};
|
||||||
editor.inputs['C-a'] = function() {
|
editor.inputs['C-a'] = function() {
|
||||||
|
@ -824,8 +830,7 @@ editor.inputs['C-s'] = function() {
|
||||||
} else if (editor.selectlist.length === 1)
|
} else if (editor.selectlist.length === 1)
|
||||||
saveobj = editor.selectlist[0];
|
saveobj = editor.selectlist[0];
|
||||||
|
|
||||||
Log.warn("Attempgint to save " + saveobj.toString());
|
saveobj._ed.check_dirty();
|
||||||
saveobj.check_dirty();
|
|
||||||
if (!saveobj._ed.dirty) return;
|
if (!saveobj._ed.dirty) return;
|
||||||
|
|
||||||
var savejs = saveobj.json_obj();
|
var savejs = saveobj.json_obj();
|
||||||
|
@ -1024,23 +1029,10 @@ editor.try_pick = function()
|
||||||
{
|
{
|
||||||
editor.grabselect = [];
|
editor.grabselect = [];
|
||||||
|
|
||||||
if (editor.sel_comp && 'pick' in editor.sel_comp) {
|
if (editor.sel_comp && 'pick' in editor.sel_comp)
|
||||||
var o = editor.sel_comp.pick(Mouse.worldpos);
|
return editor.sel_comp.pick(Mouse.worldpos);
|
||||||
if (o)
|
|
||||||
editor.grabselect = [o];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (editor.selectlist.length > 0) {
|
return editor.try_select();
|
||||||
editor.grabselect = editor.selectlist.slice();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var grabobj = editor.try_select();
|
|
||||||
|
|
||||||
if (!grabobj) return;
|
|
||||||
editor.grabselect = [grabobj];
|
|
||||||
editor.selectlist = [grabobj];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
editor.inputs.mm = function() {
|
editor.inputs.mm = function() {
|
||||||
|
@ -1051,7 +1043,10 @@ editor.inputs.mm = function() {
|
||||||
return;
|
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;
|
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['C-S-g'].doc = "Save selected objects as a new level.";
|
||||||
|
|
||||||
editor.inputs.g = function() {
|
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.doc = "Move selected objects.";
|
||||||
editor.inputs.g.released = function() { editor.grabselect = []; Mouse.normal(); };
|
editor.inputs.g.released = function() { editor.grabselect = []; Mouse.normal(); };
|
||||||
|
@ -1971,5 +1972,3 @@ Game.editor_mode(true);
|
||||||
Debug.draw_phys(true);
|
Debug.draw_phys(true);
|
||||||
|
|
||||||
editor.enter_editor();
|
editor.enter_editor();
|
||||||
|
|
||||||
load("editorconfig.js");
|
|
||||||
|
|
|
@ -9,10 +9,14 @@ load("scripts/std.js");
|
||||||
|
|
||||||
function initialize()
|
function initialize()
|
||||||
{
|
{
|
||||||
if (!Game.edit)
|
if (!Game.edit) {
|
||||||
load("scripts/play.js");
|
load("config.js");
|
||||||
else
|
load("game.js");
|
||||||
|
}
|
||||||
|
else {
|
||||||
load("scripts/editor.js");
|
load("scripts/editor.js");
|
||||||
|
load("editorconfig.js");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function run(file)
|
function run(file)
|
||||||
|
@ -724,6 +728,8 @@ preprimum.gscale = function() { return 1; };
|
||||||
preprimum.pos = [0,0];
|
preprimum.pos = [0,0];
|
||||||
preprimum.angle = 0;
|
preprimum.angle = 0;
|
||||||
preprimum.remove_obj = function() {};
|
preprimum.remove_obj = function() {};
|
||||||
|
preprimum.instances = [];
|
||||||
|
preprimum.toString = function() { return "preprimum"; };
|
||||||
var World = preprimum.make(preprimum);
|
var World = preprimum.make(preprimum);
|
||||||
var Primum = World;
|
var Primum = World;
|
||||||
Primum.level = undefined;
|
Primum.level = undefined;
|
||||||
|
@ -787,6 +793,7 @@ Game.view_camera = function(cam)
|
||||||
{
|
{
|
||||||
Game.camera = cam;
|
Game.camera = cam;
|
||||||
cmd(61, Game.camera.body);
|
cmd(61, Game.camera.body);
|
||||||
|
cam.zoom = cam.zoom;
|
||||||
}
|
}
|
||||||
|
|
||||||
Game.view_camera(Primum.spawn(ur.camera2d));
|
Game.view_camera(Primum.spawn(ur.camera2d));
|
||||||
|
|
|
@ -154,7 +154,7 @@ var gameobject = {
|
||||||
if (typeof ur === 'string')
|
if (typeof ur === 'string')
|
||||||
ur = prototypes.get_ur(ur);
|
ur = prototypes.get_ur(ur);
|
||||||
if (!ur) {
|
if (!ur) {
|
||||||
Log.warn("Failed to make UR from " + ur);
|
Log.error("Failed to make UR from " + ur);
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,7 +410,7 @@ var gameobject = {
|
||||||
|
|
||||||
Player.uncontrol(this);
|
Player.uncontrol(this);
|
||||||
Register.unregister_obj(this);
|
Register.unregister_obj(this);
|
||||||
// this.instances.remove(this);
|
// ur[this.ur].instances.remove(this);
|
||||||
this.body = -1;
|
this.body = -1;
|
||||||
|
|
||||||
for (var key in this.components) {
|
for (var key in this.components) {
|
||||||
|
@ -440,6 +440,8 @@ var gameobject = {
|
||||||
obj.make = undefined;
|
obj.make = undefined;
|
||||||
obj.level = level;
|
obj.level = level;
|
||||||
// this.instances.push(obj);
|
// this.instances.push(obj);
|
||||||
|
// Log.warn(`Made an object from ${this.toString()}`);
|
||||||
|
// Log.warn(this.instances.length);
|
||||||
obj.body = make_gameobject();
|
obj.body = make_gameobject();
|
||||||
obj.components = {};
|
obj.components = {};
|
||||||
obj.objects = {};
|
obj.objects = {};
|
||||||
|
@ -455,11 +457,6 @@ var gameobject = {
|
||||||
|
|
||||||
cmd(113, obj.body, obj); // set the internal obj reference to this obj
|
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) {
|
for (var prop in this) {
|
||||||
var p = this[prop];
|
var p = this[prop];
|
||||||
if (typeof p !== 'object') continue;
|
if (typeof p !== 'object') continue;
|
||||||
|
@ -472,6 +469,11 @@ var gameobject = {
|
||||||
if (this.objects)
|
if (this.objects)
|
||||||
obj.make_objs(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);
|
Object.dainty_assign(obj, this);
|
||||||
obj.sync();
|
obj.sync();
|
||||||
gameobject.check_registers(obj);
|
gameobject.check_registers(obj);
|
||||||
|
@ -594,8 +596,13 @@ prototypes.from_file = function(file)
|
||||||
prototypes.list.push(urpath);
|
prototypes.list.push(urpath);
|
||||||
newur.toString = function() { return urpath; };
|
newur.toString = function() { return urpath; };
|
||||||
ur[urpath] = newur;
|
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.from_file.doc = "Create a new ur-type from a given script file.";
|
||||||
prototypes.list = [];
|
prototypes.list = [];
|
||||||
|
|
|
@ -30,7 +30,8 @@ var GUI = {
|
||||||
|
|
||||||
scissor_win() { cmd(140,0,0,Window.width,Window.height); },
|
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);
|
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);
|
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);
|
return cwh2bb([0,0], wh);
|
||||||
|
|
Loading…
Reference in a new issue