From 288c26a11e727a884d11984628dc6dd1831c562d Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Mon, 14 Nov 2016 10:35:38 -0800 Subject: [PATCH] Started to clean up and migrate units. --- index.html | 8 +++- scripts/commander.js | 91 ++++++++++++++++++++++++++++++++++++++-- scripts/keyboard.js | 38 +++++++++++++++-- scripts/main.js | 18 +++++++- scripts/rect.js | 5 --- scripts/ronin.canvas.js | 33 +++++++++++++++ scripts/ronin.js | 2 + scripts/ronin.module.js | 12 ++++++ scripts/ronin.overlay.js | 12 ++++++ scripts/unit.rect.js | 7 ++++ 10 files changed, 210 insertions(+), 16 deletions(-) delete mode 100644 scripts/rect.js create mode 100644 scripts/ronin.canvas.js create mode 100644 scripts/ronin.module.js create mode 100644 scripts/ronin.overlay.js create mode 100644 scripts/unit.rect.js diff --git a/index.html b/index.html index f5291f0..99b2dad 100644 --- a/index.html +++ b/index.html @@ -1,8 +1,14 @@ + + + + + + + - diff --git a/scripts/commander.js b/scripts/commander.js index db53416..1e00ba1 100644 --- a/scripts/commander.js +++ b/scripts/commander.js @@ -15,9 +15,53 @@ function Commander(element,element_input) this.element_input.value = ""; } - this.validate = function(command) + this.active = function(command) { var parts = command; + var key = parts[0]; + parts.shift(); + var params = parts; + + switch(key) { + case "@": + ronin.canvas.active(params); + break; + case "~": + ronin.history.active(params); + break; + case "$": + ronin.save.active(params); + break; + case "/": + ronin.load.active(params); + break; + case "&": + ronin.brush.active(params); + break; + case ">": + ronin.pointer.active(params); + break; + case "|": + ronin.guide.active(params); + break; + case "^": + ronin.translate.active(params); + break; + case "=": + ronin.zoom.active(params); + break; + case "#": + ronin.layers.active(params); + break; + case ":": + ronin.filter.active(params); + break; + } + + this.hide(); + + /* + var parts = command; // Canvas if(parts[0] == "@"){ @@ -63,13 +107,51 @@ function Commander(element,element_input) parts.shift(); ronin.add_guide(parts); } - this.hide(); + + */ } - this.passive = function() + this.passive = function(command) { - var parts = this.element_input.value.split(" "); + var parts = command; + var key = parts[0]; + parts.shift(); + var params = parts; + switch(key) { + case "@": + ronin.canvas.passive(params); + break; + case "~": + ronin.history.passive(params); + break; + case "/": + ronin.load.passive(params); + break; + case "&": + ronin.brush.passive(params); + break; + case ">": + ronin.pointer.passive(params); + break; + case "|": + ronin.guide.passive(params); + break; + case "^": + ronin.translate.passive(params); + break; + case "=": + ronin.zoom.passive(params); + break; + case "#": + ronin.layers.passive(params); + break; + case ":": + ronin.filter.passive(params); + break; + } + + /* // Guides if(parts[0] == "|"){ parts.shift(); @@ -82,5 +164,6 @@ function Commander(element,element_input) parts.shift(); ronin.guide(parts); } + */ } } \ No newline at end of file diff --git a/scripts/keyboard.js b/scripts/keyboard.js index 059d94f..b71a063 100644 --- a/scripts/keyboard.js +++ b/scripts/keyboard.js @@ -1,7 +1,25 @@ function Keyboard() { this.is_locked = false; - + + this.cmd = function() + { + var val = commander.element_input.value; + + if(val.indexOf(";") > 0){ + var cmds = val.split(";"); + var vals = []; + for (i = 0; i < cmds.length; i++) { + val = cmds[i].replace(/^\s+|\s+$/g, ''); + vals.push(val.split(" ")); + } + return vals; + } + else{ + return [val.split(" ")]; + } + } + this.lock = function() { this.is_locked = true; @@ -31,7 +49,19 @@ function Keyboard() case 27: this.key_escape(); break; } - commander.passive(); + // Passive + var cmd = commander.element_input.value; + + if(cmd.indexOf(";") > 0){ + var cmds = cmd.split(";"); + for (i = 0; i < cmds.length; i++) { + cmd = cmds[i].replace(/^\s+|\s+$/g, ''); + commander.passive(cmd.split(" ")); + } + } + else{ + commander.passive(cmd.split(" ")); + } }; this.key_tab = function() @@ -47,11 +77,11 @@ function Keyboard() var cmds = cmd.split(";"); for (i = 0; i < cmds.length; i++) { cmd = cmds[i].replace(/^\s+|\s+$/g, ''); - commander.validate(cmd.split(" ")); + commander.active(cmd.split(" ")); } } else{ - commander.validate(cmd.split(" ")); + commander.active(cmd.split(" ")); } } diff --git a/scripts/main.js b/scripts/main.js index 7ea117d..1c50151 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -1,12 +1,26 @@ +var canvas = document.getElementById('myCanvas'); +var context = canvas.getContext('2d'); + var ronin = new Ronin(); +ronin.canvas.element = canvas; +ronin.overlay.element = canvas; + + + + + + + ronin.element = document.getElementById('ronin'); ronin.guides_element = document.getElementById('guides'); ronin.guides_context = ronin.guides_element.getContext('2d'); -var canvas = document.getElementById('myCanvas'); -var context = canvas.getContext('2d'); + var brush = new Brush(); + + + var commander = new Commander(document.getElementById("commander"),document.getElementById("commander_input")); document.addEventListener('mousemove', function(e) { diff --git a/scripts/rect.js b/scripts/rect.js deleted file mode 100644 index b461815..0000000 --- a/scripts/rect.js +++ /dev/null @@ -1,5 +0,0 @@ -function Rect(w = 0,h = 0) -{ - this.w = parseFloat(w); - this.h = parseFloat(h); -} \ No newline at end of file diff --git a/scripts/ronin.canvas.js b/scripts/ronin.canvas.js new file mode 100644 index 0000000..77e9617 --- /dev/null +++ b/scripts/ronin.canvas.js @@ -0,0 +1,33 @@ +function Canvas(element) +{ + Module.call(this); + + this.element = element; + + this.active = function(p) + { + if(p[0].indexOf("x") >= 0){ + var rect = new Rect(p[0]); + this.resize(rect); + ronin.overlay.resize(rect); + } + + if(p.length > 1 && p[1].indexOf("#") >= 0){ + var color = new Color(p[1]); + console.log("TODO: Fill with color"); + } + } + + this.passive = function(p) + { + console.log("TODO: Show guide"); + } + + // + + this.resize = function(rect) + { + this.element.setAttribute('width',rect.width+"px"); + this.element.setAttribute('height',rect.height+"px"); + } +} \ No newline at end of file diff --git a/scripts/ronin.js b/scripts/ronin.js index 79fde40..08a0b9c 100644 --- a/scripts/ronin.js +++ b/scripts/ronin.js @@ -1,6 +1,8 @@ function Ronin() { this.element = null; + this.canvas = new Canvas(); + this.overlay = new Overlay(); this.load_image = function(p) { diff --git a/scripts/ronin.module.js b/scripts/ronin.module.js new file mode 100644 index 0000000..cc8f0de --- /dev/null +++ b/scripts/ronin.module.js @@ -0,0 +1,12 @@ +function Module() +{ + this.active = function() + { + console.log("Nothing to do."); + } + + this.passive = function() + { + console.log("Nothing to do."); + } +} \ No newline at end of file diff --git a/scripts/ronin.overlay.js b/scripts/ronin.overlay.js new file mode 100644 index 0000000..e720d3c --- /dev/null +++ b/scripts/ronin.overlay.js @@ -0,0 +1,12 @@ +function Overlay(element) +{ + Module.call(this); + + this.element = element; + + this.resize = function(rect) + { + this.element.setAttribute('width',rect.width+"px"); + this.element.setAttribute('height',rect.height+"px"); + } +} \ No newline at end of file diff --git a/scripts/unit.rect.js b/scripts/unit.rect.js new file mode 100644 index 0000000..5357c57 --- /dev/null +++ b/scripts/unit.rect.js @@ -0,0 +1,7 @@ +function Rect(rect_str) +{ + this.rect_str = rect_str; + + this.width = parseFloat(this.rect_str.split("x")[0]); + this.height = parseFloat(this.rect_str.split("x")[1]); +} \ No newline at end of file