From 6dba090b1fc325ed3bb562ca26b40b4b2fa0af13 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Wed, 25 Jan 2017 16:21:27 -0700 Subject: [PATCH] Vector positions are now relative --- scripts/modules/file.save.js | 8 ++++++-- scripts/modules/vector.js | 31 ++++++++++++++++++++----------- scripts/units/position.js | 5 +++++ 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/scripts/modules/file.save.js b/scripts/modules/file.save.js index 41bb94e..f4faa63 100644 --- a/scripts/modules/file.save.js +++ b/scripts/modules/file.save.js @@ -3,7 +3,7 @@ function FileSave(rune) Module.call(this,rune); this.parameters = []; - this.variables = {"format" : "[png/jpg]"}; + this.variables = {"format" : "[png/jpg/svg]"}; this.docs = "Creates a new window with a image of the resulting canvas in the specified format."; @@ -19,7 +19,11 @@ function FileSave(rune) { var d = null; - if(cmd.variable("format") && cmd.variable("format").value == "jpg"){ + if(cmd.variable("format") && cmd.variable("format").value == "svg"){ + // TODO + return; + } + else if(cmd.variable("format") && cmd.variable("format").value == "jpg"){ var d = this.merge().element.toDataURL('image/jpeg'); } else{ diff --git a/scripts/modules/vector.js b/scripts/modules/vector.js index 4cac6d9..8849321 100644 --- a/scripts/modules/vector.js +++ b/scripts/modules/vector.js @@ -7,6 +7,7 @@ function Vector(rune) this.layer = null; this.coordinates = []; + this.last_pos = null; this.install = function() { @@ -61,7 +62,7 @@ function Vector(rune) var command = "+ "; for (var i = 0; i < this.coordinates.length; i++) { - command += i == 0 ? "M"+this.coordinates[i]+" " : this.coordinates[i]+" "; + command += this.coordinates[i]+" "; } return command; } @@ -88,22 +89,30 @@ function Vector(rune) { this.click = null; - // Add the right thing - if(keyboard.shift_held == true && keyboard.alt_held == true){ + if(this.coordinates.length == 0){ this.coordinates.push("M"+position.render()); } - else if(keyboard.shift_held == true){ - this.coordinates.push("A1,1 0 0,1 "+position.render()); - } - else if(keyboard.alt_held == true){ - this.coordinates.push("A1,1 0 0,0 "+position.render()); - } else{ - this.coordinates.push(position.render()); + + var offset = this.last_pos ? position.offset(this.last_pos) : position; + + if(keyboard.shift_held == true && keyboard.alt_held == true){ + this.coordinates.push("M"+position.render()); + } + else if(keyboard.shift_held == true){ + this.coordinates.push("A1,1 0 0,1 "+position.render()); + } + else if(keyboard.alt_held == true){ + this.coordinates.push("A1,1 0 0,0 "+position.render()); + } + else{ + this.coordinates.push("l"+offset.render()); + } } - + commander.element_input.value = this.create_command(); commander.hint.update(); this.passive(commander.cmd()); + this.last_pos = position; } } \ No newline at end of file diff --git a/scripts/units/position.js b/scripts/units/position.js index 4203e78..4ef8e13 100644 --- a/scripts/units/position.js +++ b/scripts/units/position.js @@ -24,6 +24,11 @@ function Position(position_str = "0,0",y = null) if(!target){ return 0; } return Math.sqrt( (this.x-target.x)*(this.x-target.x) + (this.y-target.y)*(this.y-target.y) ); } + + this.offset = function(position = new Position(0,0)) + { + return new Position(this.x - position.x,this.y - position.y); + } this.normalize = function(rect) {