unify grabbing controls
This commit is contained in:
@@ -197,9 +197,9 @@ var editor = {
|
||||
stash: "",
|
||||
|
||||
start_play_ed() {
|
||||
this.stash = this.edit_level.save();
|
||||
this.edit_level.kill();
|
||||
load_configs("game.config");
|
||||
// this.stash = this.edit_level.save();
|
||||
// this.edit_level.kill();
|
||||
// load_configs("game.config");
|
||||
Game.play();
|
||||
Player.players[0].uncontrol(this);
|
||||
Player.players[0].control(limited_editor);
|
||||
@@ -719,7 +719,7 @@ editor.inputs['C-p'] = function() {
|
||||
if (!Game.playing()) {
|
||||
editor.start_play_ed();
|
||||
// if (!Level.loadlevel("debug"))
|
||||
World.loadlevel("game");
|
||||
Primum.spawn(ur.start);
|
||||
} else {
|
||||
Game.pause();
|
||||
}
|
||||
@@ -856,9 +856,7 @@ editor.inputs['C-y'] = function() {
|
||||
texteditor.on_close = function() { editor.edit_level.script = texteditor.value;};
|
||||
|
||||
editor.openpanel(texteditor);
|
||||
if (!editor.edit_level.script)
|
||||
editor.edit_level.script = "";
|
||||
texteditor.value = editor.edit_level.script;
|
||||
texteditor.value = "";
|
||||
texteditor.start();
|
||||
};
|
||||
editor.inputs['C-y'].doc = "Open script editor for the level.";
|
||||
@@ -983,6 +981,29 @@ editor.inputs.rm = function() {
|
||||
editor.unselect();
|
||||
};
|
||||
|
||||
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.selectlist.length > 0) {
|
||||
editor.grabselect = editor.selectlist.slice();
|
||||
return;
|
||||
}
|
||||
|
||||
var grabobj = editor.try_select();
|
||||
|
||||
if (!grabobj) return;
|
||||
editor.grabselect = [grabobj];
|
||||
editor.selectlist = [grabobj];
|
||||
}
|
||||
|
||||
editor.inputs.mm = function() {
|
||||
if (editor.brush_obj) {
|
||||
editor.selectlist = editor.dup_objects([editor.brush_obj]);
|
||||
@@ -990,24 +1011,8 @@ editor.inputs.mm = function() {
|
||||
editor.grabselect = editor.selectlist[0];
|
||||
return;
|
||||
}
|
||||
|
||||
if (editor.sel_comp && 'pick' in editor.sel_comp) {
|
||||
var o = editor.sel_comp.pick(Mouse.worldpos);
|
||||
if (o)
|
||||
editor.grabselect = [o];
|
||||
return;
|
||||
}
|
||||
|
||||
var grabobj = editor.try_select();
|
||||
editor.grabselect = [];
|
||||
if (!grabobj) return;
|
||||
|
||||
if (Keys.ctrl()) {
|
||||
grabobj = editor.dup_objects([grabobj])[0];
|
||||
}
|
||||
|
||||
editor.grabselect = [grabobj];
|
||||
editor.selectlist = [grabobj];
|
||||
editor.try_pick();
|
||||
};
|
||||
editor.inputs['C-mm'] = editor.inputs.mm;
|
||||
|
||||
@@ -1075,14 +1080,12 @@ editor.inputs.mouse.scroll = function(scroll)
|
||||
editor.grabselect?.forEach(function(x) {
|
||||
x.pos = x.pos.add(scroll.scale(editor.camera.zoom));
|
||||
});
|
||||
}
|
||||
|
||||
editor.inputs.mouse['C-scroll'] = function(scroll)
|
||||
{
|
||||
scroll.y *= -1;
|
||||
editor.camera.pos = editor.camera.pos.sub(scroll.scale(editor.camera.zoom * 3).scale([1,-1]));
|
||||
}
|
||||
|
||||
editor.inputs.mouse['C-M-scroll'] = function(scroll)
|
||||
editor.inputs.mouse['C-scroll'] = function(scroll)
|
||||
{
|
||||
editor.camera.zoom += scroll.y/100;
|
||||
}
|
||||
@@ -1116,16 +1119,7 @@ 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.grabselect = [];
|
||||
|
||||
if (this.sel_comp) {
|
||||
if ('pos' in this.sel_comp)
|
||||
editor.grabselect = [this.sel_comp];
|
||||
} else
|
||||
editor.grabselect = editor.selectlist.slice();
|
||||
|
||||
if (!editor.grabselect.empty)
|
||||
Mouse.disabled();
|
||||
editor.try_pick();
|
||||
};
|
||||
editor.inputs.g.doc = "Move selected objects.";
|
||||
editor.inputs.g.released = function() { editor.grabselect = []; Mouse.normal(); };
|
||||
|
||||
@@ -466,28 +466,14 @@ prototypes.from_file = function(file)
|
||||
var newur = Object.create(upperur);
|
||||
file = file.replaceAll('.','/');
|
||||
|
||||
var jsfile = file + ".js";
|
||||
var jsonfile = file + ".json";
|
||||
var jsfile = prototypes.get_ur_file(urpath, ".js");
|
||||
var jsonfile = prototypes.get_ur_file(urpath, ".json");
|
||||
|
||||
var script = undefined;
|
||||
var json = undefined;
|
||||
|
||||
if (IO.exists(jsfile))
|
||||
script = IO.slurp(jsfile);
|
||||
else {
|
||||
jsfile = urpath + "/" + path.at(-1) + ".js";
|
||||
if (IO.exists(jsfile)) script = IO.slurp(jsfile);
|
||||
}
|
||||
|
||||
try {
|
||||
try {json = JSON.parse(IO.slurp(jsonfile)); }
|
||||
catch(e) {
|
||||
jsonfile = file + "/" + path.at(-1) + ".json";
|
||||
if (IO.exists(jsonfile)) json = JSON.parse(IO.slurp(jsonfile));
|
||||
}
|
||||
} catch(e) {
|
||||
Log.warn(`JSON in file ${jsonfile} is malformed.${e}`);
|
||||
}
|
||||
if (jsfile) script = IO.slurp(jsfile);
|
||||
if (jsonfile) json = JSON.parse(IO.slurp(jsonfile));
|
||||
|
||||
if (!json && !script) {
|
||||
Log.warn(`Could not make ur from ${file}`);
|
||||
@@ -535,6 +521,11 @@ prototypes.list_ur = function()
|
||||
return list_obj(ur);
|
||||
}
|
||||
|
||||
prototypes.ur2file = function(urpath)
|
||||
{
|
||||
return urpath.replaceAll('.', '/');
|
||||
}
|
||||
|
||||
prototypes.file2ur = function(file)
|
||||
{
|
||||
file = file.strip_ext();
|
||||
@@ -564,6 +555,16 @@ prototypes.get_ur = function(name)
|
||||
return prototypes.ur[urpath];
|
||||
}
|
||||
|
||||
prototypes.get_ur_file = function(path, ext)
|
||||
{
|
||||
var urpath = prototypes.ur2file(path);
|
||||
var file = urpath + ext;
|
||||
if (IO.exists(file)) return file;
|
||||
file = urpath + "/" + path.split('.').at(-1) + ext;
|
||||
if (IO.exists(file)) return file;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
prototypes.generate_ur = function(path)
|
||||
{
|
||||
var ob = IO.glob("**.js");
|
||||
|
||||
@@ -135,8 +135,7 @@ var GUI = {
|
||||
};
|
||||
|
||||
def.items.forEach(function(item,idx) {
|
||||
Object.setPrototypeOf(def.items[idx], def);
|
||||
|
||||
def.items[idx].__proto__ = def;
|
||||
if (def.items[idx-1])
|
||||
def.up = def.items[idx-1];
|
||||
|
||||
|
||||
@@ -78,26 +78,6 @@ var texteditor = Object.copy(inputpanel, {
|
||||
this.cursor++;
|
||||
},
|
||||
|
||||
input_enter_pressrep() {
|
||||
var white = this.line_starting_whitespace(this.cursor);
|
||||
this.insert_char('\n');
|
||||
|
||||
for (var i = 0; i < white; i++)
|
||||
this.insert_char(" ");
|
||||
|
||||
},
|
||||
|
||||
input_text(char) {
|
||||
if (Keys.ctrl() || Keys.alt()) return;
|
||||
this.insert_char(char);
|
||||
this.keycb();
|
||||
},
|
||||
|
||||
input_backspace_pressrep() {
|
||||
this.value = this.value.slice(0,this.cursor-1) + this.value.slice(this.cursor);
|
||||
this.cursor--;
|
||||
},
|
||||
|
||||
line_starting_whitespace(p) {
|
||||
var white = 0;
|
||||
var l = this.line_start(p);
|
||||
@@ -189,6 +169,27 @@ var texteditor = Object.copy(inputpanel, {
|
||||
});
|
||||
|
||||
texteditor.inputs = {};
|
||||
texteditor.inputs.char = function(char) {
|
||||
this.insert_char(char);
|
||||
this.keycb();
|
||||
},
|
||||
|
||||
texteditor.inputs.enter = function(){
|
||||
var white = this.line_starting_whitespace(this.cursor);
|
||||
this.insert_char('\n');
|
||||
|
||||
for (var i = 0; i < white; i++)
|
||||
this.insert_char(" ");
|
||||
};
|
||||
texteditor.inputs.enter.rep = true;
|
||||
|
||||
texteditor.inputs.backspace = function(){
|
||||
this.value = this.value.slice(0,this.cursor-1) + this.value.slice(this.cursor);
|
||||
this.cursor--;
|
||||
};
|
||||
texteditor.inputs.backspace.rep = true;
|
||||
|
||||
|
||||
texteditor.inputs['C-s'] = function() {
|
||||
editor.edit_level.script = texteditor.value;
|
||||
editor.save_current();
|
||||
|
||||
Reference in New Issue
Block a user