From 27117db46c295f592ae4db079799278f782453b0 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Tue, 20 Dec 2016 11:16:47 -0700 Subject: [PATCH] Implemented variables properly. --- links/main.css | 4 ++- scripts/core/hint.js | 17 +++++++++++ scripts/core/init.js | 6 +++- scripts/modules/brush.js | 51 +++++++++++++++----------------- scripts/modules/brush.pointer.js | 38 ++++++++++++------------ scripts/modules/eraser.js | 2 +- scripts/modules/module.js | 11 ++++++- scripts/modules/stroke.js | 4 +-- scripts/units/position.js | 5 ++++ scripts/units/variable.js | 5 +++- 10 files changed, 90 insertions(+), 53 deletions(-) diff --git a/links/main.css b/links/main.css index 02400ec..7d1cfbc 100644 --- a/links/main.css +++ b/links/main.css @@ -23,4 +23,6 @@ canvas:hover { cursor: crosshair;} #commander_hint .param:last-child:after { content:"";} #commander_hint .value { color:#ff0000;} #commander_hint .value:after { content:", "; color:#999; } -#commander_hint .value:last-child:after { content:"";} \ No newline at end of file +#commander_hint .value:last-child:after { content:"";} +#commander_hint .variable_key { color:#ccc; font-weight:bold;} +#commander_hint .variable_value { color:#ccc;} \ No newline at end of file diff --git a/scripts/core/hint.js b/scripts/core/hint.js index aff0579..8a19c81 100644 --- a/scripts/core/hint.js +++ b/scripts/core/hint.js @@ -28,6 +28,23 @@ function Hint(element) e += 1; } + s += " "; + + s += this.print_variables(module); + + return s; + } + + this.print_variables = function(module) + { + if(module.variables.length < 1){ return "";} + + var s = ""; + + for (var key in module.variables){ + s += ""+key+"="+module.variables[key]+" "; + } + return s; } diff --git a/scripts/core/init.js b/scripts/core/init.js index f874c04..7eefc12 100644 --- a/scripts/core/init.js +++ b/scripts/core/init.js @@ -25,4 +25,8 @@ starting_canvas.width = window.innerWidth - 200; starting_canvas.height = window.innerHeight - 200; commander.query("~ "+ronin.timestamp()); -commander.query("@ "+starting_canvas.render()); \ No newline at end of file +commander.query("@ "+starting_canvas.render()); +commander.query("> 1 0,0 #000000"); +commander.query("> banking=true"); +commander.query("> natural=true"); +commander.query("> -5,0"); \ No newline at end of file diff --git a/scripts/modules/brush.js b/scripts/modules/brush.js index 22d84a8..e4a06ce 100644 --- a/scripts/modules/brush.js +++ b/scripts/modules/brush.js @@ -3,7 +3,8 @@ function Brush(rune) Module.call(this,rune); this.parameters = [Position,Rect,Angle,Color,Value,Bang]; - this.pointers = [new Pointer(new Position())]; + this.variables = {"natural" : false,"banking" : false}; + this.pointers = []; this.size = 1; this.opacity = 1; @@ -15,31 +16,20 @@ function Brush(rune) { if(cmd.bang()){ this.pointers = []; } - var pointer = new Pointer(); + // Pointer + if(cmd.rect() || cmd.position() || cmd.angle()){ + this.add_pointer(cmd); + } - if(cmd.position()){ - pointer.offset = cmd.position(); - } - if(cmd.rect()){ - pointer.mirror = cmd.rect(); - } - if(cmd.variable("osc_scale") && cmd.variable("osc_rate")){ - pointer.osc_rate = parseFloat(cmd.variable("osc_rate")); - pointer.osc_scale = parseFloat(cmd.variable("osc_scale")); - } - if(cmd.angle()){ - pointer.angle = cmd.angle(); - } - if(cmd.rect() || cmd.position() || cmd.variable("osc_rate") || cmd.angle()){ - this.add_pointer(pointer); - } + // Global if(cmd.color()){ this.color = cmd.color(); } if(cmd.value()){ this.size = cmd.value().float; } - ronin.widget.update(); + + this.update_variables(cmd); } this.passive = function(cmd) @@ -55,19 +45,26 @@ function Brush(rune) } } - this.add_pointer = function(pointer) + this.add_pointer = function(cmd) { + var pointer = new Pointer(); + + if(cmd.position()){ + pointer.offset = cmd.position(); + } + if(cmd.rect()){ + pointer.mirror = cmd.rect(); + } + if(cmd.angle()){ + pointer.angle = cmd.angle(); + } + this.pointers.push(pointer); } - - this.widget = function() - { - return "> "+this.size+" "+this.color.render()+" "; - } this.widget_cursor = function() { - return "Brush "+this.size; + return "Brush "+this.size+", "+this.pointers.length+" pointers"; } // Cursor @@ -104,6 +101,6 @@ function Brush(rune) ronin.brush.pointers[i].stop(); } - ronin.stroke.save_stroke(); + ronin.stroke.save_stroke("brush"); } } \ No newline at end of file diff --git a/scripts/modules/brush.pointer.js b/scripts/modules/brush.pointer.js index 2bde913..3dec91e 100644 --- a/scripts/modules/brush.pointer.js +++ b/scripts/modules/brush.pointer.js @@ -5,11 +5,21 @@ function Pointer(offset = new Position(), color = new Color('000000')) this.position_prev = null; this.angle = null; this.distance = 0; + + // Parameters + + this.thickness = function() + { + var ratio = 10/this.position().distance_to(this.position_prev); + ratio = ratio > 1 ? 1 : ratio; + return ronin.brush.size * ratio; + } + + // this.draw = function() { if(!this.position_prev){this.position_prev = this.position(); } - if(ronin.brush.size < 0){ this.erase(); return; } var position = this.position(); @@ -29,22 +39,8 @@ function Pointer(offset = new Position(), color = new Color('000000')) this.position_prev = position; } - this.erase = function() - { - ronin.canvas.context().clearRect(this.position().x - (ronin.brush.size/2), this.position().y - (ronin.brush.size/2), ronin.brush.size, ronin.brush.size); - } - - this.thickness = function() - { - var ratio = 10/this.position().distance_to(this.position_prev); - ratio = ratio > 1 ? 1 : ratio; - return ronin.brush.size * ratio; - } - this.position = function() { - return ronin.cursor.position; - if(this.angle){ var angle_radian = this.angle.degrees * Math.PI / 180; var deltaX = ronin.brush.position.x - this.offset.x; @@ -62,10 +58,14 @@ function Pointer(offset = new Position(), color = new Color('000000')) return new Position((ronin.brush.position.x + this.offset.x), (2 * this.mirror.height) - (ronin.brush.position.y + this.offset.y)); } - console.log(ronin.brush.position); - console.log(this.offset); - return; - return new Position(ronin.brush.position.x + this.offset.x, ronin.brush.position.y + this.offset.y); + return this.position_default(); + } + + // Effects + + this.position_default = function() + { + return ronin.cursor.position.add(this.offset); } this.start = function() diff --git a/scripts/modules/eraser.js b/scripts/modules/eraser.js index 4710849..a884120 100644 --- a/scripts/modules/eraser.js +++ b/scripts/modules/eraser.js @@ -74,6 +74,6 @@ function Eraser(rune) this.is_drawing = false; this.position_prev = null; - ronin.stroke.save_stroke(); + ronin.stroke.save_stroke("eraser"); } } \ No newline at end of file diff --git a/scripts/modules/module.js b/scripts/modules/module.js index 2402f1d..d83aabe 100644 --- a/scripts/modules/module.js +++ b/scripts/modules/module.js @@ -3,7 +3,7 @@ function Module(rune) this.rune = rune; this.element = null; this.parameters = []; - this.variables = []; + this.variables = {}; this.active = function(cmd) { @@ -15,6 +15,15 @@ function Module(rune) console.log("Nothing to do."); } + this.update_variables = function(cmd) + { + for (var key in this.variables){ + if(!cmd.variable(key)){ continue; } + this.variables[key] = cmd.variable(key).value; + } + console.log(this.variables); + } + this.hint = function(cmd) { return "unknown"; diff --git a/scripts/modules/stroke.js b/scripts/modules/stroke.js index 7a42359..b8f2bf7 100644 --- a/scripts/modules/stroke.js +++ b/scripts/modules/stroke.js @@ -18,9 +18,9 @@ function Stroke(rune) this.positions.push(p); } - this.save_stroke = function() + this.save_stroke = function(mode) { - s = "_ "; + s = "_ mode:"+mode+" "; for (i = 0; i < this.positions.length; i++) { s += this.positions[i].render()+" "; } diff --git a/scripts/units/position.js b/scripts/units/position.js index b8a59a6..5523291 100644 --- a/scripts/units/position.js +++ b/scripts/units/position.js @@ -8,6 +8,11 @@ function Position(position_str = "0,0",y = null) this.x = y ? position_str : parseFloat(this.position_str.split(",")[0]); this.y = y ? y : parseFloat(this.position_str.split(",")[1]); + this.add = function(position) + { + return new Position(this.x + position.x, this.y + position.y); + } + this.is_equal = function(target) { if(target.x == this.x && target.y == this.y){ return true; } diff --git a/scripts/units/variable.js b/scripts/units/variable.js index 6998d73..2d59f7f 100644 --- a/scripts/units/variable.js +++ b/scripts/units/variable.js @@ -4,7 +4,10 @@ function Variable(key,value) this.candidates = []; this.key = key; - this.value = value; + + if(value == "true"){ this.value = true; } + else if(value == "false"){ this.value = false; } + else{ this.value = value; } this.render = function() {