From 3b067f88557a67cb12397f0cc9e0540106a33457 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Mon, 14 Nov 2016 14:38:00 -0800 Subject: [PATCH] Normalized negative positions in guides. --- scripts/ronin.file.js | 1 - scripts/ronin.overlay.js | 8 +++++--- scripts/unit.position.js | 10 ++++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/scripts/ronin.file.js b/scripts/ronin.file.js index bc173b5..399ccd1 100644 --- a/scripts/ronin.file.js +++ b/scripts/ronin.file.js @@ -4,7 +4,6 @@ function File() this.active = function() { - console.log("Nothing to do."); ronin.overlay.clear(); } diff --git a/scripts/ronin.overlay.js b/scripts/ronin.overlay.js index f0d4a54..08bb128 100644 --- a/scripts/ronin.overlay.js +++ b/scripts/ronin.overlay.js @@ -27,13 +27,13 @@ function Overlay(element) if(rect){ this.draw_rect(position,rect); } - else if(position.x > 0 && position.y > 0){ + else if(position.x != 0 && position.y != 0){ this.draw_pointer(position); } - else if(position.x > 0 ){ + else if(position.x != 0 ){ this.draw_vertical_line(position); } - else if(position.y > 0 ){ + else if(position.y != 0 ){ this.draw_horizontal_line(position); } } @@ -42,6 +42,8 @@ function Overlay(element) { this.context().beginPath(); + position.normalize(rect); + this.context().moveTo(position.x,position.y); this.context().lineTo(position.x + rect.width,position.y); this.context().lineTo(position.x + rect.width,position.y + rect.height); diff --git a/scripts/unit.position.js b/scripts/unit.position.js index 24ba1f1..ef7f2ed 100644 --- a/scripts/unit.position.js +++ b/scripts/unit.position.js @@ -22,4 +22,14 @@ 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.normalize = function(rect) + { + if(this.x < 0){ + this.x = ronin.canvas.element.width - rect.width - Math.abs(this.x); + } + if(this.y < 0){ + this.y = ronin.canvas.element.height - rect.height - Math.abs(this.y); + } + } } \ No newline at end of file