diff --git a/README.md b/README.md index 4b236d9..1e4bc9b 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,8 @@ Enjoy Load default.rin on startup * Eye Swatches, handle all colors + + Path + Rename vector to Path this.collection = {}; diff --git a/scripts/modules/default.js b/scripts/modules/default.js index 4ab56f0..3173c01 100644 --- a/scripts/modules/default.js +++ b/scripts/modules/default.js @@ -2,6 +2,11 @@ function Default(rune) { Module.call(this,rune); + this.hint = function() + { + return "??"; + } + // Cursor this.mouse_mode = function() diff --git a/scripts/modules/module.js b/scripts/modules/module.js index f185d69..cb69a6e 100644 --- a/scripts/modules/module.js +++ b/scripts/modules/module.js @@ -15,7 +15,7 @@ function Module(rune) this.context = function() { - return this._layer().context(); + return this.get_layer().context(); } this.create_layer = function() @@ -25,9 +25,9 @@ function Module(rune) ronin.surface.add_layer(this.layer); } - this._layer = function() + this.get_layer = function(is_blinking = false) { - if(!this.layer){ this.create_layer(); } + if(!this.layer){ this.create_layer(); this.layer.is_blinking = is_blinking } return this.layer; } @@ -67,21 +67,28 @@ function Module(rune) } } + + this.add_method = function(method) + { + this.methods[method.name] = method; + } this.hint = function(content) { - var h = ""+ronin.module.constructor.name+" "; - - for(method in ronin.module.methods){ - h += ronin.module.methods[method].render()+" "; - } - for(setting in ronin.module.settings){ - h += setting+"="+ronin.module.settings[setting].render()+" "; - } + var s = ""; - h += ronin.module.mouse_mode() ? ""+ronin.module.mouse_mode()+"" : ""; + var method_name = content.split(" ")[0]; - return this.pad(content)+h; + if(this.methods[method_name]){ + console.log(this.methods[method_name].params) + s = this.methods[method_name].params; + } + else{ + for(method in this.methods){ + s += "."+method+"("+method_name+") "; + } + } + return s; } this.pad = function(input) diff --git a/scripts/modules/surface.js b/scripts/modules/surface.js index 6823a99..c55139a 100644 --- a/scripts/modules/surface.js +++ b/scripts/modules/surface.js @@ -4,12 +4,14 @@ function Surface(rune) this.element = null; this.settings = {"size":new Rect("200x200")}; - this.methods = [new Method("resize",[new Rect().name]),new Method("crop",[new Position().name,new Rect().name])] this.layers = {}; this.active_layer = null; this.render_layer = null; + this.add_method(new Method("resize",[new Rect().name])); + this.add_method(new Method("crop",[new Position().name,new Rect().name])); + this.widget_element = document.createElement("widget"); this.install = function() @@ -18,13 +20,7 @@ function Surface(rune) this.blink(); } - this.blink = function() - { - Object.keys(ronin.surface.layers).forEach(function (key) { - ronin.surface.layers[key].blink(); - }); - setTimeout(function(){ ronin.surface.blink(); }, 30); - } + // Methods this.resize = function(params) { @@ -46,6 +42,11 @@ function Surface(rune) ronin.terminal.log(new Log(this,"Resized Surface to "+this.settings["size"].render())); } + this.crop = function(params) + { + + } + this.select = function(params) { var layer_name = params[0]; @@ -55,6 +56,16 @@ function Surface(rune) this.select_layer(this.layers[layer_name]); } + // Misc + + this.blink = function() + { + Object.keys(ronin.surface.layers).forEach(function (key) { + ronin.surface.layers[key].blink(); + }); + setTimeout(function(){ ronin.surface.blink(); }, 30); + } + this.select_layer = function(layer) { console.log("Selecting layer:"+layer.name); @@ -98,14 +109,14 @@ function Surface(rune) s += ""+ronin.cursor.mode.mouse_mode()+""; var keys = Object.keys(ronin.surface.layers); - // var loc = keys.indexOf(this.active_layer.name); + var loc = keys.indexOf(this.active_layer.name); - // if(keys.length > 1){ - // s += ""+ronin.surface.active_layer.widget()+"("+(loc+1)+"/"+keys.length+")"; - // } - // else{ - // s += ""+ronin.surface.active_layer.widget()+""; - // } + if(keys.length > 1){ + s += ""+ronin.surface.active_layer.widget()+"("+(loc+1)+"/"+keys.length+")"; + } + else{ + s += ""+ronin.surface.active_layer.widget()+""; + } this.widget_element.innerHTML = s; } @@ -136,7 +147,7 @@ function Surface(rune) if(crop && crop.params.length == 2){ console.log(crop); - ronin.overlay.select_layer().clear(); + ronin.overlay.get_layer(true).clear(); ronin.overlay.draw_rect(new Position(crop.params[0]),new Rect(crop.params[1])); } else{ @@ -154,7 +165,7 @@ function Surface(rune) this.mouse_down = function(position) { - ronin.overlay.select_layer().clear(); + ronin.overlay.get_layer(true).clear(); ronin.overlay.draw_pointer(position); } diff --git a/scripts/modules/terminal.js b/scripts/modules/terminal.js index 5c901c4..1633c7a 100644 --- a/scripts/modules/terminal.js +++ b/scripts/modules/terminal.js @@ -29,6 +29,10 @@ function Terminal(rune) this.passive = function(content) { + this.hint(content); + + + return; var key = content[0]; var cmd = this.cmd(); @@ -85,6 +89,16 @@ function Terminal(rune) function active(content) { + var module_name = content.indexOf(".") > -1 ? content.split(" ")[0].split(".")[0] : content.split(" ")[0]; + var method_name = content.indexOf(".") > -1 ? content.split(" ")[0].split(".")[1] : "default"; + + if(ronin[module_name] && ronin[module_name][method_name]){ + ronin[module_name][method_name](); + } + else{ + ronin.terminal.log(new Log(ronin.terminal,"Unknown module")); + } + var key = content[0]; var cmd = new Command(content.substring(1).trim().split(" ")); @@ -105,22 +119,13 @@ function Terminal(rune) this.update_hint = function(content = this.input_element.value) { - // ronin.terminal.input_element.setAttribute("style","color:"+ronin.brush.color.hex); + var module_name = content.indexOf(".") > -1 ? content.split(" ")[0].split(".")[0] : content.split(" ")[0]; - if(content.indexOf(";") > -1){ - this.hint_element.innerHTML = this.pad(content)+" "+content.split(";").length+" commands"; + if(ronin[module_name]){ + this.hint_element.innerHTML = this.pad(content)+ronin[module_name].hint(content.replace(module_name+".","")); } - else if(ronin.module){ - this.hint_element.innerHTML = ronin.module.hint(content); - } - else if(content == ""){ - this.hint_element.innerHTML = ""; - for(module in ronin.modules){ - this.hint_element.innerHTML += ""+module+" "+ronin.modules[module].constructor.name+" "; - } - } else{ - this.hint_element.innerHTML = this.pad(content)+" Unknown Command." + this.hint_element.innerHTML = this.pad(content)+ronin["default"].hint(content); } } diff --git a/scripts/modules/vector.js b/scripts/modules/vector.js index 56f7d0a..71c50e6 100644 --- a/scripts/modules/vector.js +++ b/scripts/modules/vector.js @@ -5,9 +5,23 @@ function Vector(rune) this.parameters = [Any]; this.variables = {"fill_color" : null,"stroke_width" : 5,"stroke_color" : "#ffffff", "line_cap" : "square"}; + this.add_method(new Method("stroke",["Positions"])); + this.add_method(new Method("fill",["Positions"])); + this.coordinates = []; this.last_pos = null; this.paths = []; + + this.stroke = function() + { + // TODO + console.warn("!!!!!") + } + + this.fill = function() + { + + } // Module diff --git a/scripts/units/method.js b/scripts/units/method.js index 4b680a0..c9767d6 100644 --- a/scripts/units/method.js +++ b/scripts/units/method.js @@ -1,10 +1,9 @@ -function Method(method_str) +function Method(name,params) { Unit.call(this); - var content = method_str.split(":"); - this.name = content.shift(); - this.params = content; + this.name = name; + this.params = params; this.example = ""; this.render = function()