From 70910f7cb92ebd7dccba2644862334b98882f8a0 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Mon, 17 Apr 2017 16:02:40 -1000 Subject: [PATCH] * --- index.html | 2 +- links/main.css | 35 ++- presets/default.rin | 22 +- scripts/core/init.js | 6 +- scripts/core/keyboard.js | 7 +- scripts/core/ronin.js | 10 +- scripts/core/widget.js | 28 -- scripts/filters/stencil.js | 2 + scripts/modules/brush.js | 5 +- scripts/modules/brush.pointer.js | 2 +- scripts/modules/cursor.js | 26 +- scripts/modules/default.js | 30 +- scripts/modules/eye.js | 2 +- scripts/modules/frame.js | 13 +- scripts/modules/layer.js | 13 +- scripts/modules/magnet.js | 3 + scripts/modules/module.js | 3 +- scripts/modules/overlay.js | 6 +- scripts/modules/path.js | 16 +- scripts/modules/source.js | 5 +- scripts/modules/terminal.js | 260 ++++++------------ .../modules/{widget.js => terminal.widget.js} | 2 +- scripts/modules/type.js | 18 +- 23 files changed, 203 insertions(+), 313 deletions(-) delete mode 100644 scripts/core/widget.js rename scripts/modules/{widget.js => terminal.widget.js} (96%) diff --git a/index.html b/index.html index c3211a5..7b52aff 100644 --- a/index.html +++ b/index.html @@ -28,7 +28,7 @@ - + diff --git a/links/main.css b/links/main.css index 84381b3..78255f5 100644 --- a/links/main.css +++ b/links/main.css @@ -2,18 +2,17 @@ body { margin:0px; padding:0px; overflow:hidden; font-family:"input_mono_medium" *:focus {outline: none; } #ronin { width:100%; height:100%; overflow:hidden; background:#111; background-image:url(../media/graphics/grid.svg); background-position: center center; } -#frame { width:50vw; height:50vh; overflow:hidden; position:fixed; left:50%; top:50%; background:none; border-radius:5px; border:1px solid #333;} +#frame { width:50vw; height:50vh; overflow:hidden; position:fixed; left: calc(40vw + 15px); top:100px; background:none; border-radius:5px; border:1px solid #333;} #frame > .layer { position:absolute; top:0px; left:0px; width:100%; height:100%;} #frame.bright widget { color:#000; } #overlay { position:absolute; z-index:1000;} #frame { cursor:none;} -#terminal { position: fixed; bottom:0px; left:0px; background:#000; width:100vw; height: 125px;overflow: hidden;} -#terminal input { display: block; position:absolute; bottom:0px; width:100vw; padding:0px 5px; font-size:10px; line-height: 20px; background:none; z-index:900; color:white;} -#terminal hint { background:#000; position:absolute; bottom:0px; line-height: 20px; padding:0px 5px; width:100vw; color:#777; font-size:10px; white-space: pre;} -#terminal hint b { font-family: "input_mono_regular"; color:#999; } -#terminal hint i { font-style: italic; color:#fff; } -#terminal logs { display: block;position: absolute;bottom:20px;width:100vw;color:white} +#terminal { position: fixed;top: 0px;left: 0px;background: #000;width: 40vw;height: 100vh;overflow: hidden;} +#terminal textarea { display: block;position: fixed;top: 100px;width: calc(40vw - 16px);height: calc(100vh - 130px);padding: 0px 15px;line-height: 20px;font-size: 12px;background: none;color: #999;border-left:1px solid #333;margin-left:15px} +#terminal textarea:hover { border-left:1px solid #555; } +#terminal textarea { z-index:900; } +#terminal logs { display: none;position: absolute;bottom:20px;width:100vw;color:white} #terminal logs log { display: block; font-size:10px; line-height:25px; padding:0px 5px; color:#666;} #terminal logs log .rune { color:white; } #terminal logs log.error .rune { color:red; } @@ -21,15 +20,23 @@ body { margin:0px; padding:0px; overflow:hidden; font-family:"input_mono_medium" #terminal logs log.image img { height:85px;width:auto;border-radius: 3px } #terminal menu { display: inline-block;position: absolute;bottom: 0px;right: 0px;padding: 0px 5px;font-size: 10px;line-height: 20px;color:white } #terminal.locked input { color:red; } +#terminal status { display: block;position: absolute;bottom: 0px;left: 0px;padding: 5px 15px 5px 31px;font-size: 12px;line-height: 20px;color: white;width:calc(40vw - 45px) } +#terminal status .details { float:right; color:#555; } #terminal.hide { height:25px; } #terminal.mini { height:120px; } #terminal.full { height:100vh; } -#widget { position: absolute; top:0px; left:0px; line-height: 20px; font-size:10px; z-index:9000; color:white; width:100%; height:100%; } -#widget span { display:inline-block; line-height:15px; padding:0px 5px; vertical-align: top; min-width:100px;} -#widget span name { display: block; border-bottom: 1px solid #333; line-height:25px; margin-bottom:5px;} -#widget li { display:block; } -#widget li.active { color:#72dec2; } -#widget li.inactive { color:#fff; } -#widget li.managed { color:#777; } \ No newline at end of file +#terminal #widget { display:none; position: absolute; top:0px; left:0px; line-height: 20px; font-size:10px; z-index:9000; color:white; width:50vw; height:100px; } +#terminal #widget span { display:inline-block; line-height:15px; padding:0px 5px; vertical-align: top; min-width:100px;} +#terminal #widget span name { display: block; border-bottom: 1px solid #333; line-height:25px; margin-bottom:5px;} +#terminal #widget li { display:block; } +#terminal #widget li.active { color:#72dec2; } +#terminal #widget li.inactive { color:#fff; } +#terminal #widget li.managed { color:#777; }#terminal + +#terminal hint { display: block;position: fixed;top: 100px;width: calc(40vw - 60px);height: calc(100vh - 130px);padding: 0px 15px;line-height: 20px;font-size: 12px;background: none;color: #999;border-left:1px solid #333;margin-left:15px} + +#terminal hint line { display: inline; width:calc(100% - 30px); } +#terminal hint line .input { background:red; } +#terminal hint line .status { position: absolute;right:30px; } \ No newline at end of file diff --git a/presets/default.rin b/presets/default.rin index 6f6a9d6..268064e 100644 --- a/presets/default.rin +++ b/presets/default.rin @@ -1,11 +1,11 @@ -frame.select background ; -frame.resize 400x400 ; -brush:color #ff0000 ; -brush.add_pointer 1,1 ; -brush.add_pointer 2,2 ; -layer.fill #A1A1A1 ; -render.stencil #72dec2 ; -type:size 50 ; -type.write 50,150 "RONIN" ; -type:size 15 ; -type.write 55,180 "VER 0.1 " ; \ No newline at end of file +~ Default + +frame.resize 300x300 +frame.select background +layer.fill #000000 +path:line_width 43 +path:line_color #EEEEEE +path.stroke M105,240 a-45,-45 0 0,0 -45,-45 M150,240 a-90,-90 0 0,0 -90,-90 M150,60 a90,90 0 0,0 90,90 M195,60 a45,45 0 0,0 45,45 M60,105 a45,-45 0 0,0 45,-45 M240,195 a-45,45 0 0,0 -45,45 +type:size 10 +type.write 38,262 "RONIN" +type.write 38,252 "B07" diff --git a/scripts/core/init.js b/scripts/core/init.js index 0906ad0..12a8e39 100644 --- a/scripts/core/init.js +++ b/scripts/core/init.js @@ -10,7 +10,7 @@ ronin.cursor.mode = ronin.brush; document.addEventListener('mousedown', function(e){ ronin.cursor.mouse_down(ronin.position_in_canvas(e));}, false); document.addEventListener('mousemove', function(e){ ronin.cursor.mouse_move(ronin.position_in_canvas(e));}, false); document.addEventListener('mouseup', function(e){ ronin.cursor.mouse_up(ronin.position_in_canvas(e));}, false); -document.addEventListener('contextmenu', function(ev){ ev.preventDefault(); return false;}, false); +// document.addEventListener('contextmenu', function(ev){ ev.preventDefault(); return false;}, false); window.addEventListener('resize', function(){ ronin.on_resize(); }, true); // Keyboard @@ -31,8 +31,4 @@ starting_canvas.height = window.innerHeight - 300; starting_canvas.width = parseInt(starting_canvas.width/40) * 40; starting_canvas.height = parseInt(starting_canvas.height/40) * 40; -ronin.terminal.query("terminal.load default.rin"); - -ronin.terminal.input_element.focus(); -ronin.terminal.update_hint(); ronin.widget.update(); \ No newline at end of file diff --git a/scripts/core/keyboard.js b/scripts/core/keyboard.js index 541358e..4291894 100644 --- a/scripts/core/keyboard.js +++ b/scripts/core/keyboard.js @@ -13,7 +13,8 @@ function Keyboard() } ronin.cursor.update(event); ronin.widget.update(); - ronin.terminal.update_hint(); + ronin.terminal.timer = 0; + ronin.terminal.update_status(); } this.listen_onkeyup = function(event) @@ -44,9 +45,8 @@ function Keyboard() } // Passive - ronin.terminal.passive(ronin.terminal.input_element.value); ronin.widget.update(); - ronin.terminal.update_hint(); + ronin.terminal.update_status(); }; this.key_tab = function() @@ -55,7 +55,6 @@ function Keyboard() this.key_enter = function() { - ronin.terminal.query(ronin.terminal.input_element.value); } this.key_space = function() diff --git a/scripts/core/ronin.js b/scripts/core/ronin.js index 86c5ee5..06a1e45 100644 --- a/scripts/core/ronin.js +++ b/scripts/core/ronin.js @@ -43,7 +43,7 @@ function Ronin() this.modules[key].install(); } - this.terminal.install(); + // this.terminal.install(); this.widget.install(); } @@ -52,11 +52,11 @@ function Ronin() this.position_in_canvas = function(e) { var x = e.clientX; - x -= (window.innerWidth - this.frame.settings["size"].width)/2; - x -= parseInt(this.frame.element.style.marginLeft) + (this.frame.settings["size"].width/2); + x -= (window.innerWidth - this.frame.settings["size"].width) * 0.4 - 25; + x -= parseInt(0) + (this.frame.settings["size"].width/2); var y = e.clientY; - y -= (window.innerHeight - this.frame.settings["size"].height)/2; - y -= parseInt(this.frame.element.style.marginTop) + parseInt(this.frame.settings["size"].height/2); + // y -= (window.innerHeight - this.frame.settings["size"].height)/2; + y -= parseInt(-100) + parseInt(this.frame.settings["size"].height/2); return new Position(x,y); } diff --git a/scripts/core/widget.js b/scripts/core/widget.js deleted file mode 100644 index 776cf0e..0000000 --- a/scripts/core/widget.js +++ /dev/null @@ -1,28 +0,0 @@ -function Widget() -{ - this.element = null; - - this.update = function() - { - var s = ""; - - s += "
"; - for (var key in ronin.modules){ - s += ronin.modules[key].widget() ? ronin.modules[key].widget()+"
" : ""; - } - s += "
"; - - s += "
"+ronin.cursor.mode.widget_cursor()+"
"; - - this.element.innerHTML = s; - } - - this.on_resize = function() - { - this.element.style.left = (window.innerWidth/2)-(ronin.frame.settings["size"].width/2); - this.element.style.top = (window.innerHeight/2)+(ronin.frame.settings["size"].height/2)+20; - this.element.style.width = ronin.frame.settings["size"].width+"px"; - - this.update(); - } -} \ No newline at end of file diff --git a/scripts/filters/stencil.js b/scripts/filters/stencil.js index 25d11f2..e92a5e3 100644 --- a/scripts/filters/stencil.js +++ b/scripts/filters/stencil.js @@ -10,6 +10,8 @@ function Filter_Stencil() ronin.frame.active_layer.clear(); this.draw(ronin.frame.context(),angle,color); + + return 1, "ok"; } this.preview = function(cmd) diff --git a/scripts/modules/brush.js b/scripts/modules/brush.js index 1acefb1..6cf1b7b 100644 --- a/scripts/modules/brush.js +++ b/scripts/modules/brush.js @@ -4,7 +4,7 @@ function Brush(rune) // this.parameters = {"offset":Position,"mirror":Rect,"angle":Angle,"reset":Bang}; this.parameters = []; - this.settings = {"color":"#ff0000","size":1}; + this.settings = {"color":"#ff0000","size":4}; this.pointers = [new Pointer(new Position("0,0"))]; this.add_method(new Method("add_pointer",["Position"])); @@ -18,7 +18,8 @@ function Brush(rune) this.pointers.push(pointer); ronin.terminal.log(new Log(this,"Added pointer at: "+pointer.offset.render())); - ronin.widget.update(); + + return 1, "ok"; } this.passive = function(cmd) diff --git a/scripts/modules/brush.pointer.js b/scripts/modules/brush.pointer.js index 364940e..7c655c8 100644 --- a/scripts/modules/brush.pointer.js +++ b/scripts/modules/brush.pointer.js @@ -12,7 +12,7 @@ function Pointer(offset = new Position(), color = new Color('000000')) { var ratio = 10/this.position().distance_to(this.position_prev[0]); ratio = ratio > 1 ? 1 : ratio; - return ronin.brush.settings["size"].float * ratio; + return parseInt(ronin.brush.settings["size"]) * ratio; } // diff --git a/scripts/modules/cursor.js b/scripts/modules/cursor.js index e696da0..e4ebca8 100644 --- a/scripts/modules/cursor.js +++ b/scripts/modules/cursor.js @@ -130,6 +130,8 @@ function Cursor(rune) this.update = function(event) { + // this.set_mode(ronin.brush); + return; if(event.altKey == true && event.shiftKey == true){ this.set_mode(ronin.frame.active_layer); } @@ -157,10 +159,10 @@ function Cursor(rune) if(this.mode.constructor.name != Cursor.name){ this.mode.mouse_from = this.position; this.mode.mouse_held = true; - this.mode.mouse_down(this.position); + if(!position.is_outside()){ + this.mode.mouse_down(this.position); + } } - - ronin.terminal.update_hint(); } this.mouse_move = function(position) @@ -184,7 +186,7 @@ function Cursor(rune) this.mode.mouse_move(this.position,rect); this.mode.mouse_prev = this.position; } - ronin.terminal.update_hint(); + // ronin.terminal.update_hint(); } this.mouse_up = function(position) @@ -195,15 +197,25 @@ function Cursor(rune) rect.width = this.position.x - this.mode.mouse_from.x; rect.height = this.position.y - this.mode.mouse_from.y; + if(!this.mode){ return; } + if(this.mode.constructor.name != Cursor.name){ - this.mode.mouse_up(this.position,rect); + if(!position.is_outside()){ + this.mode.mouse_up(this.position,rect); + } this.mode.mouse_held = false; } - ronin.terminal.input_element.focus(); - ronin.terminal.update_hint(); this.mode.mouse_from = null; } + this.release = function() + { + this.mode.mouse_held = false; + this.mode.mouse_from = null; + this.mode = ronin.brush; + ronin.terminal.textarea.focus(); + } + this.widget = function() { return this.mode.mouse_mode(); diff --git a/scripts/modules/default.js b/scripts/modules/default.js index f454b2c..bfec344 100644 --- a/scripts/modules/default.js +++ b/scripts/modules/default.js @@ -3,34 +3,8 @@ function Default(rune) Module.call(this,rune); this.hint = function() - { - if(ronin.terminal.input_element.value == ""){ - var s = ""; - for(module in ronin.modules){ - s += ronin.modules[module].constructor.name+" "; - } - return s; - } - - // - - var candidates = []; - - for(module in ronin.modules){ - for(method in ronin.modules[module].methods){ - candidates.push(module.toLowerCase()+"."+method); - } - } - - var s = ""; - - for(candidate in candidates){ - if(candidates[candidate].indexOf(ronin.terminal.input_element.value) > -1){ - s += candidates[candidate]+" "; - } - } - - return s; + { + return ""; } // Cursor diff --git a/scripts/modules/eye.js b/scripts/modules/eye.js index edf2106..a4ac325 100644 --- a/scripts/modules/eye.js +++ b/scripts/modules/eye.js @@ -17,7 +17,7 @@ function Eye(rune) { var imgData = ronin.frame.context().getImageData(position.x*2, position.y*2, 1, 1).data; var c = new Color(); - ronin.terminal.input_element.value = "* "+(c.rgb_to_hex(imgData)); + // ronin.terminal.input_element.value = "* "+(c.rgb_to_hex(imgData)); ronin.terminal.update_hint(); } diff --git a/scripts/modules/frame.js b/scripts/modules/frame.js index 02fd4f5..983959b 100644 --- a/scripts/modules/frame.js +++ b/scripts/modules/frame.js @@ -16,6 +16,11 @@ function Frame(rune) this.install = function() { this.blink(); + var l = new Layer("background"); + this.add_layer(l); + this.select_layer(l); + + this.resize(new Command(["300x300"])); } // Methods @@ -34,10 +39,10 @@ function Frame(rune) ronin.frame.element.height = this.settings["size"].height * 2; ronin.frame.element.style.width = this.settings["size"].width+"px"; ronin.frame.element.style.height = this.settings["size"].height+"px"; - ronin.frame.element.style.marginLeft = -(this.settings["size"].width/2); - ronin.frame.element.style.marginTop = -(this.settings["size"].height/2); ronin.on_resize(); + + return 1, "ok"; } this.crop = function(params, preview = false) @@ -61,6 +66,8 @@ function Frame(rune) this.select_layer(this.layers[layer_name]); ronin.modules["layer"] = this.layers[layer_name]; ronin.layer = this.layers[layer_name]; + + return 1, "ok"; } this.context = function() @@ -132,7 +139,7 @@ function Frame(rune) this.mouse_move = function(position,rect) { - ronin.terminal.input_element.value = "frame."+ronin.terminal.method_name+" "+this.mouse_from.render()+" "+rect.render()+" "; + // ronin.terminal.input_element.value = "frame."+ronin.terminal.method_name+" "+this.mouse_from.render()+" "+rect.render()+" "; ronin.terminal.passive(); } diff --git a/scripts/modules/layer.js b/scripts/modules/layer.js index a2bc580..922e7c6 100644 --- a/scripts/modules/layer.js +++ b/scripts/modules/layer.js @@ -51,6 +51,8 @@ function Layer(name,manager = null) ronin.frame.context().rotate(-angle*Math.PI/180); ronin.frame.context().restore(); ronin.render.get_layer().clear(); + + return 1, "ok"; } this.translate = function(params,preview = false) @@ -62,6 +64,8 @@ function Layer(name,manager = null) this.clear(); this.context().putImageData(data, params.position().x * 2, params.position().y * 2); ronin.overlay.get_layer(true).clear(); + + return 1, "ok"; } this.fill = function(params,preview = false) @@ -76,7 +80,8 @@ function Layer(name,manager = null) this.context().rect(position.x, position.y, rect.width, rect.height); this.context().fillStyle = params.color().hex; this.context().fill(); - ronin.terminal.log(new Log(this,"Filled layer "+this.name+": "+params.color().hex)); + + return 1, "ok"; } this.rename = function(params, preview = false) @@ -150,7 +155,7 @@ function Layer(name,manager = null) this.mouse_down = function(position) { - ronin.terminal.input_element.value = "layer."+ronin.terminal.method_name+" 0,0"; + // ronin.terminal.input_element.value = "layer."+ronin.terminal.method_name+" 0,0"; ronin.terminal.passive(); } @@ -163,7 +168,7 @@ function Layer(name,manager = null) ronin.overlay.draw_cross(position); ronin.overlay.draw_line(this.mouse_from,position); - ronin.terminal.input_element.value = "layer."+ronin.terminal.method_name+" "+offset.render(); + // ronin.terminal.input_element.value = "layer."+ronin.terminal.method_name+" "+offset.render(); ronin.terminal.passive(); } @@ -176,7 +181,7 @@ function Layer(name,manager = null) ronin.overlay.draw_circle(this.mouse_from); ronin.overlay.draw_line(this.mouse_from,position); - ronin.terminal.input_element.value = "layer."+ronin.terminal.method_name+" "+offset.render(); + // ronin.terminal.input_element.value = "layer."+ronin.terminal.method_name+" "+offset.render(); ronin.terminal.passive(); // if(this.coordinates.length == 0){ diff --git a/scripts/modules/magnet.js b/scripts/modules/magnet.js index 9142348..ad53c3c 100644 --- a/scripts/modules/magnet.js +++ b/scripts/modules/magnet.js @@ -26,6 +26,9 @@ function Magnet(rune) if(!rect){ rect = new Rect("20x20"); } if(!grid){ grid = new Position("4,4"); } + this.settings["grid"] = rect; + this.settings["marker"] = grid; + if(rect.width < 5 || rect.height < 5){ return; } var horizontal = ronin.frame.settings["size"].width/rect.width; diff --git a/scripts/modules/module.js b/scripts/modules/module.js index 42c506a..57a00b5 100644 --- a/scripts/modules/module.js +++ b/scripts/modules/module.js @@ -41,8 +41,7 @@ function Module(rune) this.update_setting = function(name,value) { this.settings[name] = value.content.join(" "); - ronin.terminal.log(new Log(this,"Updated setting: "+name+", to "+this.settings[name])); - ronin.widget.update(); + return 1, "ok"; } this.add_method = function(method) diff --git a/scripts/modules/overlay.js b/scripts/modules/overlay.js index fc2aa62..38ed778 100644 --- a/scripts/modules/overlay.js +++ b/scripts/modules/overlay.js @@ -180,7 +180,7 @@ function Overlay(rune) ronin.overlay.clear(); ronin.overlay.draw_pointer(position); this.live_draw_from = position; - ronin.terminal.input_element.value = "| "+this.live_draw_from.render(); + // ronin.terminal.input_element.value = "| "+this.live_draw_from.render(); } this.mouse_move = function(position) @@ -194,7 +194,7 @@ function Overlay(rune) rect.height = position.y - this.live_draw_from.y; ronin.overlay.draw_rect(this.live_draw_from,rect); - ronin.terminal.input_element.value = "| "+this.live_draw_from.render()+" "+rect.render(); + // ronin.terminal.input_element.value = "| "+this.live_draw_from.render()+" "+rect.render(); ronin.terminal.update_hint(); } @@ -202,7 +202,7 @@ function Overlay(rune) this.mouse_up = function(position) { this.live_draw_from = null; - ronin.terminal.input_element.focus(); + // ronin.terminal.input_element.focus(); } // Widget diff --git a/scripts/modules/path.js b/scripts/modules/path.js index 210bbf3..4a02898 100644 --- a/scripts/modules/path.js +++ b/scripts/modules/path.js @@ -26,6 +26,8 @@ function Path(rune) context.strokeStyle = this.settings["line_color"]; context.stroke(new Path2D(params.content)); context.closePath(); + + return 1, preview ? "preview" : "ok"; } this.fill = function(params,preview = false) @@ -38,6 +40,8 @@ function Path(rune) context.fillStyle = this.settings["fill_color"]; context.fill(new Path2D(params.content)); + + return 1, preview ? "preview" : "ok"; } // Tools @@ -87,15 +91,15 @@ function Path(rune) this.mouse_down = function(position) { - ronin.terminal.input_element.value = "path."+ronin.terminal.method_name+" "+this.create_path(); - ronin.terminal.input_element.value += "M"+position.render(); + // ronin.terminal.input_element.value = "path."+ronin.terminal.method_name+" "+this.create_path(); + // ronin.terminal.input_element.value += "M"+position.render(); ronin.terminal.passive(); } this.mouse_move = function(position) { - ronin.terminal.input_element.value = "path."+ronin.terminal.method_name+" "+this.create_path(); - ronin.terminal.input_element.value += "L"+position.render(); + // ronin.terminal.input_element.value = "path."+ronin.terminal.method_name+" "+this.create_path(); + // ronin.terminal.input_element.value += "L"+position.render(); ronin.terminal.passive(); } @@ -121,7 +125,7 @@ function Path(rune) } } - ronin.terminal.input_element.value = "path."+ronin.terminal.method_name+" "+this.create_path(); + // ronin.terminal.input_element.value = "path."+ronin.terminal.method_name+" "+this.create_path(); this.last_pos = position; ronin.terminal.passive(); } @@ -131,7 +135,7 @@ function Path(rune) if(this.layer){ this.layer.remove(this); } this.coordinates = []; this.last_pos = null; - ronin.terminal.input_element.value = ""; + // ronin.terminal.input_element.value = ""; ronin.terminal.passive(); } } \ No newline at end of file diff --git a/scripts/modules/source.js b/scripts/modules/source.js index 31a54aa..01e9f2a 100644 --- a/scripts/modules/source.js +++ b/scripts/modules/source.js @@ -9,7 +9,8 @@ function Source(rune) this.load = function(params,preview = false) // source.load ../assets/todo.jpg 200x200 40,40 { - if(!params.filepath() || !params.rect()){ ronin.terminal.log(new Log(this,"Missing image path.","error")); return; } + if(!params.filepath()){ return 0, "Path?"; } + if(!params.rect()){ return 0,"Rect?"; } this.get_layer(true).clear(); @@ -41,6 +42,8 @@ function Source(rune) } if(!preview){ ronin.overlay.get_layer(true).clear(); } + + return 1,"ok"; } this.save = function(params,preview = false) diff --git a/scripts/modules/terminal.js b/scripts/modules/terminal.js index d601f59..a8ca99b 100644 --- a/scripts/modules/terminal.js +++ b/scripts/modules/terminal.js @@ -2,11 +2,12 @@ function Terminal(rune) { Module.call(this,">"); - this.element = null; - this.input_element = document.createElement("input"); + this.element = document.createElement("div"); + this.textarea = document.createElement("textarea"); this.hint_element = document.createElement("hint"); this.logs_element = document.createElement("logs"); this.menu_element = document.createElement("menu"); + this.status_element = document.createElement("status"); this.history = []; this.locks = []; @@ -15,120 +16,68 @@ function Terminal(rune) this.add_method(new Method("load",["path"])); this.add_method(new Method("display",["mini/hide/full"])); - this.load = function readTextFile(params, preview = false) - { - if(preview){ return; } - - this.locks = []; - - var file = "presets/"+params.content+'?'+new Date().getTime(); - var rawFile = new XMLHttpRequest(); - rawFile.open("GET", file, false); - rawFile.onreadystatechange = function () - { - if(rawFile.readyState === 4) - { - if(rawFile.status === 200 || rawFile.status == 0) - { - var allText = rawFile.responseText; - ronin.terminal.query(allText); - } - } - } - rawFile.send(null); - } - - this.display = function(params,preview = false) - { - if(preview){ return; } - this.element.setAttribute("class",params.content); - } - // Module this.install = function(cmd) { - this.element.appendChild(this.input_element); + this.element.appendChild(this.textarea); this.element.appendChild(this.hint_element); this.element.appendChild(this.logs_element); this.element.appendChild(this.menu_element); + this.element.appendChild(this.status_element); - this.hint_element.innerHTML = "_"; + this.status_element.innerHTML = "Ready."; + this.textarea.value = "frame.select background\nframe.resize 400x400\nbrush:color #ff0000\nbrush.add_pointer 1,1\nbrush.add_pointer 2,2\nlayer.fill #A1A1A1\nrender.stencil #72dec2\ntype:size 50\ntype.write 50,150 \"RONIN\"\ntype:size 15\ntype.write 55,180 \"VER 0.1\"" + this.hint_element.innerHTML = ""; - this.update_log(); + this.validation_timer(); + this.load("default.rin"); + this.timer = 20; } - this.active = function(cmd) + this.timer = 0; + this.history = ""; + + this.validation_timer = function() { + this.timer += 1; + setTimeout(function(){ ronin.terminal.validation_timer(); }, 100); + this.validate(); } - this.cmd = function() + this.has_changed = function() { - var content = this.input_element.value.trim(); - var key = content[0]; - var cmd = new Command(content.substring(1).trim().split(" ")); - return cmd; + return ronin.terminal.history != ronin.terminal.textarea.value ? true : false; } - // Locks - - this.lock = function(key) + this.validate = function() { - console.log("Added lock: ",key); - this.locks.push(key); - this.element.setAttribute("class","locked"); - } + if(this.timer < 10){ return; } - this.unlock = function(key) - { - console.log("Removed lock: ",key); - this.locks.splice(this.locks.indexOf(key), 1); - - if(this.locks.length < 1){ - this.element.setAttribute("class","unlocked"); + if(ronin.terminal.has_changed() == true){ + ronin.terminal.run(); } - } - // Queue + this.update_status(); - this.queue = []; - - this.query = function(input_str) - { - if(input_str.trim() == ""){ return; } - if(this.locks.length > 0){ console.warn("Trying: "+input_str+", Locked: ",this.locks); return; } - - this.lock("query"); - this.input_element.value = ""; - - if(input_str.indexOf(";") > 0){ - var parts = input_str.replace("\n","").split(";"); - for(id in parts){ - parts[id] = parts[id].replace("\n","").trim(); - } - this.queue = parts; - } - else{ - this.queue = []; - this.queue.push(input_str) - } - this.run(); + this.history = this.textarea.value; + this.timer = 0; } this.run = function() { - if(!ronin.terminal.queue[0]){ this.unlock("query"); return; } - - var entry = ronin.terminal.queue.shift(); - console.info(entry); - active(entry); - ronin.widget.update(); - - setTimeout(function(){ ronin.terminal.run(); }, 100); + this.hint_element.innerHTML = ""; + var queue = ronin.terminal.textarea.value.split("\n") + for(id in queue){ + this.hint_element.innerHTML += ""+this.syntax_highlight(queue[id])+""+this.run_line(queue.length - id,queue[id])+"
"; + } } - function active(content) + this.run_line = function(id,line) { - ronin.terminal.log(new Log(ronin.terminal,content,"input")); + var content = line; + + if(content.trim() == ""){ return "~"; } + if(content.trim()[0] == "~"){ return "~"; } if(content.indexOf(".") > -1){ var module_name = content.split(" ")[0].split(".")[0] @@ -146,133 +95,90 @@ function Terminal(rune) var parameters = content.split(" "); parameters.shift(); var parameters = new Command(parameters); + if(id == 1){ ronin.cursor.set_mode(ronin[module_name]); } + if(ronin[module_name] && ronin[module_name][method_name]){ - ronin[module_name][method_name](parameters); + return ronin[module_name][method_name](parameters,id == 1 ? true : false); } else if(ronin[module_name] && ronin[module_name].settings[setting_name]){ - ronin[module_name].update_setting(setting_name,parameters); + return ronin[module_name].update_setting(setting_name,parameters); } else if(ronin["render"].collection[method_name]){ - ronin["render"].collection[method_name].render(parameters); + return ronin["render"].collection[method_name].render(parameters); } else if(ronin[module_name]){ - ronin.terminal.log(new Log(ronin.terminal,"Unknown method: "+method_name)); + return 0, "Unknown Method"; } else if(module_name == "render"){ - ronin.terminal.log(new Log(ronin.terminal,"Unknown filter: "+method_name)); + return 0, "Unknown Filter"; } else{ - ronin.terminal.log(new Log(ronin.terminal,"Unknown module: "+module_name)); + return 0, "Unknown Module"; } + return 0, "Unknown"; } - - this.module_name = null; - this.method_name = null; - this.method_params = null; - this.passive = function() + this.syntax_highlight = function(line) { - var content = this.input_element.value; - var parts = content.split(" "); - var key = parts.shift(); - - this.module_name = key.split(".")[0]; - this.method_name = key.indexOf(".") > -1 ? key.split(".")[1] : null; - this.method_params = new Command(parts); - - if(ronin[this.module_name]){ - ronin.cursor.set_mode(ronin[this.module_name]); - if(ronin[this.module_name][this.method_name]){ - ronin[this.module_name][this.method_name](this.method_params,true); - } - } - else{ - ronin.cursor.set_mode(); - } - - this.hint(content); + return line; } - // Hint - - this.update_hint = function(content = this.input_element.value) + this.update_active_line = function(new_line) { - var module_name = content.indexOf(".") > -1 ? content.split(" ")[0].split(".")[0] : content.split(" ")[0]; + var lines = this.textarea.value.split("\n"); - if(ronin[module_name]){ - this.hint_element.innerHTML = this.pad(content)+ronin[module_name].hint(content.replace(module_name+".","")); - } - else{ - this.hint_element.innerHTML = this.pad(content)+ronin["default"].hint(content); - } + lines[lines.length-1] = new_line; + + this.textarea.value = lines.join("\n"); + this.timer = 10; } - this.update_menu = function() + this.update_status = function() { - this.menu_element.innerHTML = ronin.terminal.history.length; - } - - this.key_escape = function() - { - this.input_element.value = ""; - } - - this.key_arrow_up = function() - { - this.history_index -= 1; - - if(this.history_index < 0){ this.history_index = 0; } - - ronin.terminal.input_element.value = "> "+ronin.terminal.history[this.history_index]; - } - - this.key_arrow_down = function() - { - this.history_index += 1; - - if(this.history_index >= this.history.length){ this.history_index = this.history.length-1; } - - ronin.terminal.input_element.value = "> "+ronin.terminal.history[this.history_index]; - } - - this.pad = function(input) - { - var s = ""; - for (i = 0; i < input.length+1; i++){ - s += "_"; + if(ronin.terminal.has_changed() == true){ + this.status_element.innerHTML = "Changes Pending."; } - return ""+s+""; + else{ + this.status_element.innerHTML = "Idle."; + } + + this.status_element.innerHTML += ""+this.textarea.value.length+"c "+this.textarea.value.split("\n").length+"l"; } - // - - this.logs = []; - this.log = function(log) { - this.logs.push(log); + } - this.update_log = function() - { - if(ronin.terminal.logs[0]){ - ronin.terminal.logs_element.appendChild(ronin.terminal.logs[0].element); - ronin.terminal.logs.shift(); + this.load = function readTextFile(name) + { + var file = "presets/"+name+'?'+new Date().getTime(); + var rawFile = new XMLHttpRequest(); + rawFile.open("GET", file, false); + rawFile.onreadystatechange = function () + { + if(rawFile.readyState === 4) + { + if(rawFile.status === 200 || rawFile.status == 0) + { + var allText = rawFile.responseText; + ronin.terminal.textarea.value = allText; + } + } } - - setTimeout(function(){ ronin.terminal.update_log(); }, 200); + rawFile.send(null); } } // Log -function Log(host,message,type = "default") +function Log(host,message,error = false) { this.host = host; this.message = message; - this.type = type; + this.error = error; this.element = document.createElement("log"); - this.element.setAttribute("class",type); + this.element.setAttribute("class",error ? "error" : "okay"); this.element.innerHTML = ""+(host.rune ? host.rune : ">")+" "+message; - console.log(this.host.constructor.name,this.message) + console.log(this.host.constructor.name,this.message); } \ No newline at end of file diff --git a/scripts/modules/widget.js b/scripts/modules/terminal.widget.js similarity index 96% rename from scripts/modules/widget.js rename to scripts/modules/terminal.widget.js index c7b94be..6be11d9 100644 --- a/scripts/modules/widget.js +++ b/scripts/modules/terminal.widget.js @@ -7,7 +7,7 @@ function Widget(rune) this.install = function() { - ronin.element.appendChild(this.element); + ronin.terminal.element.appendChild(this.element); } this.update = function() diff --git a/scripts/modules/type.js b/scripts/modules/type.js index 6ea6def..053ffcc 100644 --- a/scripts/modules/type.js +++ b/scripts/modules/type.js @@ -23,7 +23,7 @@ function Type(rune) target_layer.context().fillStyle = color; target_layer.context().fillText(text,position.x,position.y); - console.log(target_layer.context()); + return 1, preview ? "preview" : "ok"; } // Mouse @@ -35,26 +35,26 @@ function Type(rune) this.mouse_down = function(position) { - ronin.terminal.input_element.value = "type."+ronin.terminal.method_name+" "+position.render(); - ronin.terminal.passive(); + var line = "type.write "+position.render()+" \"Placeholder\""; + ronin.terminal.update_active_line(line); } this.mouse_move = function(position,rect) { - ronin.terminal.input_element.value = "type."+ronin.terminal.method_name+" "+position.render(); - ronin.terminal.passive(); + var line = "type.write "+position.render()+" \"Placeholder\""; + ronin.terminal.update_active_line(line); } this.mouse_up = function(position) { - ronin.terminal.input_element.value = "type."+ronin.terminal.method_name+" "+position.render(); - ronin.terminal.passive(); + var line = "type.write "+position.render()+" \"Placeholder\""; + ronin.terminal.update_active_line(line); + ronin.terminal.textarea.value += "\n"; + ronin.cursor.release(); } this.key_escape = function() { if(this.layer){ this.layer.remove(this); } - ronin.terminal.input_element.value = ""; - ronin.terminal.passive(); } } \ No newline at end of file