Moved all parsing into Query
This commit is contained in:
parent
f8959216cd
commit
527da673c8
@ -7,6 +7,7 @@
|
||||
<script type="text/javascript" src="scripts/modules/line.js"></script>
|
||||
|
||||
<script type="text/javascript" src="scripts/grid.js"></script>
|
||||
<script type="text/javascript" src="scripts/guide.js"></script>
|
||||
<script type="text/javascript" src="scripts/io.js"></script>
|
||||
<script type="text/javascript" src="scripts/query.js"></script>
|
||||
<script type="text/javascript" src="scripts/keyboard.js"></script>
|
||||
|
@ -39,6 +39,7 @@ function Commander()
|
||||
this.on_input = function(e)
|
||||
{
|
||||
ronin.hint.update();
|
||||
ronin.guide.update();
|
||||
}
|
||||
|
||||
this.blur = function()
|
||||
|
14
sources/scripts/guide.js
Normal file
14
sources/scripts/guide.js
Normal file
@ -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());
|
||||
}
|
||||
}
|
@ -18,6 +18,11 @@ function Frame()
|
||||
{
|
||||
}
|
||||
|
||||
this.methods.crop = function(p)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
this.resize_to = function(size)
|
||||
{
|
||||
ronin.frame.settings.width = size.width;
|
||||
|
@ -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 = [];
|
||||
|
@ -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])};
|
||||
}
|
||||
}
|
||||
}
|
@ -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:$&$&$>>$&$&$";
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user