122 lines
2.5 KiB
JavaScript
122 lines
2.5 KiB
JavaScript
function Keyboard()
|
|
{
|
|
this.is_down = {};
|
|
|
|
this.key_up = function(e)
|
|
{
|
|
if(e.key == "tab" || e.keyCode == 9){
|
|
e.preventDefault();
|
|
ronin.cursor.update();
|
|
ronin.commander.autocomplete();
|
|
ronin.commander.show();
|
|
setTimeout(()=>{ronin.commander.focus},100)
|
|
return;
|
|
}
|
|
|
|
ronin.keyboard.is_down[e.key] = false;
|
|
ronin.hint.update(e);
|
|
}
|
|
|
|
this.key_down = function(e)
|
|
{
|
|
ronin.keyboard.is_down[e.key] = true;
|
|
|
|
if(e.key == "/"){
|
|
e.preventDefault();
|
|
ronin.commander.inject("~")
|
|
return;
|
|
}
|
|
|
|
if(e.key == "Enter"){
|
|
e.preventDefault();
|
|
ronin.commander.validate();
|
|
}
|
|
|
|
if(e.key == "Escape"){
|
|
e.preventDefault();
|
|
ronin.commander.input_el.blur();
|
|
ronin.commander.input_el.value = "";
|
|
ronin.guide.update();
|
|
ronin.guide.clear();
|
|
ronin.guide.inspect = false;
|
|
ronin.preview.clear();
|
|
if(!ronin.commander.is_focused()){
|
|
ronin.commander.hide();
|
|
}
|
|
}
|
|
|
|
// Macros
|
|
if(e.key == "f" && (e.ctrlKey || e.metaKey)){
|
|
e.preventDefault();
|
|
ronin.commander.inject(`frame fill:${ronin.cursor.color}`)
|
|
}
|
|
|
|
if(ronin.commander.is_focused()){
|
|
ronin.hint.update(e);
|
|
return;
|
|
}
|
|
|
|
if(e.key == "]"){
|
|
e.preventDefault();
|
|
ronin.brush.mod_size(1);
|
|
}
|
|
if(e.key == "["){
|
|
e.preventDefault();
|
|
ronin.brush.mod_size(-1);
|
|
}
|
|
|
|
if(e.key == "n" && (e.ctrlKey || e.metaKey)){
|
|
e.preventDefault();
|
|
ronin.guide.inspect = false;
|
|
ronin.guide.clear();
|
|
ronin.cursor.target.clear();
|
|
}
|
|
|
|
if(e.key == "N" && (e.ctrlKey || e.metaKey) && e.shiftKey){
|
|
e.preventDefault();
|
|
ronin.guide.inspect = false;
|
|
ronin.guide.clear();
|
|
ronin.layers.above.clear()
|
|
ronin.layers.below.clear()
|
|
}
|
|
|
|
// Open
|
|
if(e.key == "o" && (e.ctrlKey || e.metaKey)){
|
|
e.preventDefault();
|
|
ronin.io.methods.load.run();
|
|
}
|
|
|
|
// Save
|
|
if(e.key == "s" && (e.ctrlKey || e.metaKey)){
|
|
e.preventDefault();
|
|
ronin.io.methods.save.run();
|
|
}
|
|
|
|
if(e.key == "x"){
|
|
e.preventDefault();
|
|
ronin.cursor.swap_colors();
|
|
}
|
|
|
|
if(e.key == "z"){
|
|
e.preventDefault();
|
|
ronin.cursor.swap_layer();
|
|
}
|
|
|
|
if(e.key == "1"){
|
|
e.preventDefault();
|
|
ronin.frame.methods.zoom.run(1);
|
|
}
|
|
|
|
if(e.key == "2"){
|
|
e.preventDefault();
|
|
ronin.frame.methods.zoom.run(2);
|
|
}
|
|
|
|
if(e.key == "3"){
|
|
e.preventDefault();
|
|
ronin.frame.methods.zoom.run(4);
|
|
}
|
|
|
|
ronin.hint.update(e);
|
|
}
|
|
} |