From 527da673c8d9e6b2dd90a6817e7322ef97187377 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Wed, 27 Sep 2017 10:19:06 +1300 Subject: [PATCH] Moved all parsing into Query --- sources/index.html | 1 + sources/scripts/commander.js | 1 + sources/scripts/guide.js | 14 ++++++++ sources/scripts/modules/frame.js | 5 +++ sources/scripts/modules/line.js | 37 +++++++------------ sources/scripts/query.js | 62 +++++++++++++++++++++++++++++++- sources/scripts/ronin.js | 3 +- 7 files changed, 96 insertions(+), 27 deletions(-) create mode 100644 sources/scripts/guide.js diff --git a/sources/index.html b/sources/index.html index e78e232..ae8dc44 100644 --- a/sources/index.html +++ b/sources/index.html @@ -7,6 +7,7 @@ + diff --git a/sources/scripts/commander.js b/sources/scripts/commander.js index 758f8fa..61a84e2 100644 --- a/sources/scripts/commander.js +++ b/sources/scripts/commander.js @@ -39,6 +39,7 @@ function Commander() this.on_input = function(e) { ronin.hint.update(); + ronin.guide.update(); } this.blur = function() diff --git a/sources/scripts/guide.js b/sources/scripts/guide.js new file mode 100644 index 0000000..a87d67f --- /dev/null +++ b/sources/scripts/guide.js @@ -0,0 +1,14 @@ +function Guide() +{ + this.el = document.createElement('canvas'); this.el.id = "guide"; + + this.install = function() + { + ronin.el.appendChild(this.el); + } + + this.update = function() + { + console.log(ronin.commander.query()); + } +} \ No newline at end of file diff --git a/sources/scripts/modules/frame.js b/sources/scripts/modules/frame.js index e1a9772..4f3c78a 100644 --- a/sources/scripts/modules/frame.js +++ b/sources/scripts/modules/frame.js @@ -18,6 +18,11 @@ function Frame() { } + this.methods.crop = function(p) + { + + } + this.resize_to = function(size) { ronin.frame.settings.width = size.width; diff --git a/sources/scripts/modules/line.js b/sources/scripts/modules/line.js index 4cd8310..715742e 100644 --- a/sources/scripts/modules/line.js +++ b/sources/scripts/modules/line.js @@ -2,14 +2,17 @@ function Line() { Module.call(this,"line"); - this.settings = {steps:20}; + this.settings = {steps:100}; this.methods = {}; + this.ports = {}; + this.ports.index = 0; + this.methods.tween = function(q) { - var from = parse_sequence(q.split(">>")[0]); - var to = parse_sequence(q.split(">>")[1]); + var from = q.from; + var to = q.to; var s = 0; while(s < ronin.line.settings.steps){ @@ -20,6 +23,12 @@ function Line() } } + this.methods.stroke = function(q) + { + console.log(q) + ronin.line.stroke_multi(q) + } + this.stroke_multi = function(coordinates) { var from = coordinates[0]; @@ -45,28 +54,6 @@ function Line() ctx.closePath(); } - function parse_sequence(seq_str) - { - var a = []; - - var parts = seq_str.split("&"); - for(part_id in parts){ - var part = parts[part_id]; - a.push(parse_unit(part)); - } - return a; - } - - function parse_unit(unit_str) - { - if(unit_str.indexOf(",") > -1){ - return {x:parseInt(unit_str.split(",")[0]),y:parseInt(unit_str.split(",")[1])}; - } - if(unit_str.indexOf("x") > -1){ - return {width:parseInt(unit_str.split("x")[0]),height:parseInt(unit_str.split("x")[1])}; - } - } - function tween_positions(froms,tos,progress) { var a = []; diff --git a/sources/scripts/query.js b/sources/scripts/query.js index bcf584c..8cb9570 100644 --- a/sources/scripts/query.js +++ b/sources/scripts/query.js @@ -12,7 +12,7 @@ function Query(query_str) if(part.indexOf(":") > -1){ var key = part.indexOf(":") > -1 ? part.split(":")[0] : "any"; var value = part.indexOf(":") > -1 ? part.split(":")[1] : part; - this.methods[key] = value; + this.methods[key] = parse_parameters(value); } else if(part.indexOf("=") > -1){ var key = part.indexOf("=") > -1 ? part.split("=")[0] : "any"; @@ -25,4 +25,64 @@ function Query(query_str) this.routes[key] = value; } } + + function parse_parameters(param_str) + { + if(param_str.indexOf(">>") > -1){ + return parse_modifier(param_str); + } + else{ + if(param_str.indexOf("&") > -1){ + return parse_sequence(param_str); + } + else{ + return parse_unit(param_str); + } + } + return param_str; + } + + function parse_modifier(mod_str) + { + var h = {}; + + var parts = mod_str.split(">>"); + + if(parts[0].indexOf("&") > -1){ + h.from = parse_sequence(parts[0]); + } + else{ + h.from = parse_unit(parts[0]); + } + + if(parts[1].indexOf("&") > -1){ + h.to = parse_sequence(parts[1]); + } + else{ + h.to = parse_unit(parts[1]); + } + return h; + } + + function parse_sequence(seq_str) + { + var a = []; + + var parts = seq_str.split("&"); + for(part_id in parts){ + var part = parts[part_id]; + a.push(parse_unit(part)); + } + return a; + } + + function parse_unit(unit_str) + { + if(unit_str.indexOf(",") > -1){ + return {x:parseInt(unit_str.split(",")[0]),y:parseInt(unit_str.split(",")[1])}; + } + if(unit_str.indexOf("x") > -1){ + return {width:parseInt(unit_str.split("x")[0]),height:parseInt(unit_str.split("x")[1])}; + } + } } \ No newline at end of file diff --git a/sources/scripts/ronin.js b/sources/scripts/ronin.js index 4884c0c..6ab3e1e 100644 --- a/sources/scripts/ronin.js +++ b/sources/scripts/ronin.js @@ -10,6 +10,7 @@ function Ronin() this.cursor = new Cursor(); this.render = new Render(); this.hint = new Hint(); + this.guide = new Guide(); this.brush = new Brush(); this.eraser = new Eraser(); @@ -49,6 +50,6 @@ function Ronin() this.render.update(); this.grid.update(); - this.commander.input_el.value = "line tween:$&$&$>>$&$&$" + this.commander.input_el.value = "line tween:$&$&$>>$&$&$"; } } \ No newline at end of file