New paradigm, GO!

This commit is contained in:
Devine Lu Linvega 2017-03-26 12:10:36 -07:00
parent 061b832851
commit 8d7c25c489
7 changed files with 90 additions and 47 deletions

View File

@ -37,6 +37,8 @@ Enjoy
Load default.rin on startup Load default.rin on startup
* Eye * Eye
Swatches, handle all colors Swatches, handle all colors
+ Path
Rename vector to Path
this.collection = {}; this.collection = {};

View File

@ -2,6 +2,11 @@ function Default(rune)
{ {
Module.call(this,rune); Module.call(this,rune);
this.hint = function()
{
return "??";
}
// Cursor // Cursor
this.mouse_mode = function() this.mouse_mode = function()

View File

@ -15,7 +15,7 @@ function Module(rune)
this.context = function() this.context = function()
{ {
return this._layer().context(); return this.get_layer().context();
} }
this.create_layer = function() this.create_layer = function()
@ -25,9 +25,9 @@ function Module(rune)
ronin.surface.add_layer(this.layer); ronin.surface.add_layer(this.layer);
} }
this._layer = function() this.get_layer = function(is_blinking = false)
{ {
if(!this.layer){ this.create_layer(); } if(!this.layer){ this.create_layer(); this.layer.is_blinking = is_blinking }
return this.layer; return this.layer;
} }
@ -68,20 +68,27 @@ function Module(rune)
} }
} }
this.add_method = function(method)
{
this.methods[method.name] = method;
}
this.hint = function(content) this.hint = function(content)
{ {
var h = "<b>"+ronin.module.constructor.name+"</b> "; var s = "";
for(method in ronin.module.methods){ var method_name = content.split(" ")[0];
h += ronin.module.methods[method].render()+" ";
if(this.methods[method_name]){
console.log(this.methods[method_name].params)
s = this.methods[method_name].params;
} }
for(setting in ronin.module.settings){ else{
h += setting+"="+ronin.module.settings[setting].render()+" "; for(method in this.methods){
s += "."+method+"("+method_name+") ";
} }
}
h += ronin.module.mouse_mode() ? "<i>"+ronin.module.mouse_mode()+"</i>" : ""; return s;
return this.pad(content)+h;
} }
this.pad = function(input) this.pad = function(input)

View File

@ -4,12 +4,14 @@ function Surface(rune)
this.element = null; this.element = null;
this.settings = {"size":new Rect("200x200")}; this.settings = {"size":new Rect("200x200")};
this.methods = [new Method("resize",[new Rect().name]),new Method("crop",[new Position().name,new Rect().name])]
this.layers = {}; this.layers = {};
this.active_layer = null; this.active_layer = null;
this.render_layer = null; this.render_layer = null;
this.add_method(new Method("resize",[new Rect().name]));
this.add_method(new Method("crop",[new Position().name,new Rect().name]));
this.widget_element = document.createElement("widget"); this.widget_element = document.createElement("widget");
this.install = function() this.install = function()
@ -18,13 +20,7 @@ function Surface(rune)
this.blink(); this.blink();
} }
this.blink = function() // Methods
{
Object.keys(ronin.surface.layers).forEach(function (key) {
ronin.surface.layers[key].blink();
});
setTimeout(function(){ ronin.surface.blink(); }, 30);
}
this.resize = function(params) this.resize = function(params)
{ {
@ -46,6 +42,11 @@ function Surface(rune)
ronin.terminal.log(new Log(this,"Resized Surface to "+this.settings["size"].render())); ronin.terminal.log(new Log(this,"Resized Surface to "+this.settings["size"].render()));
} }
this.crop = function(params)
{
}
this.select = function(params) this.select = function(params)
{ {
var layer_name = params[0]; var layer_name = params[0];
@ -55,6 +56,16 @@ function Surface(rune)
this.select_layer(this.layers[layer_name]); this.select_layer(this.layers[layer_name]);
} }
// Misc
this.blink = function()
{
Object.keys(ronin.surface.layers).forEach(function (key) {
ronin.surface.layers[key].blink();
});
setTimeout(function(){ ronin.surface.blink(); }, 30);
}
this.select_layer = function(layer) this.select_layer = function(layer)
{ {
console.log("Selecting layer:"+layer.name); console.log("Selecting layer:"+layer.name);
@ -98,14 +109,14 @@ function Surface(rune)
s += "<span class='cursor'>"+ronin.cursor.mode.mouse_mode()+"</span>"; s += "<span class='cursor'>"+ronin.cursor.mode.mouse_mode()+"</span>";
var keys = Object.keys(ronin.surface.layers); var keys = Object.keys(ronin.surface.layers);
// var loc = keys.indexOf(this.active_layer.name); var loc = keys.indexOf(this.active_layer.name);
// if(keys.length > 1){ if(keys.length > 1){
// s += "<span class='layer'>"+ronin.surface.active_layer.widget()+"("+(loc+1)+"/"+keys.length+")</span>"; s += "<span class='layer'>"+ronin.surface.active_layer.widget()+"("+(loc+1)+"/"+keys.length+")</span>";
// } }
// else{ else{
// s += "<span class='layer'>"+ronin.surface.active_layer.widget()+"</span>"; s += "<span class='layer'>"+ronin.surface.active_layer.widget()+"</span>";
// } }
this.widget_element.innerHTML = s; this.widget_element.innerHTML = s;
} }
@ -136,7 +147,7 @@ function Surface(rune)
if(crop && crop.params.length == 2){ if(crop && crop.params.length == 2){
console.log(crop); console.log(crop);
ronin.overlay.select_layer().clear(); ronin.overlay.get_layer(true).clear();
ronin.overlay.draw_rect(new Position(crop.params[0]),new Rect(crop.params[1])); ronin.overlay.draw_rect(new Position(crop.params[0]),new Rect(crop.params[1]));
} }
else{ else{
@ -154,7 +165,7 @@ function Surface(rune)
this.mouse_down = function(position) this.mouse_down = function(position)
{ {
ronin.overlay.select_layer().clear(); ronin.overlay.get_layer(true).clear();
ronin.overlay.draw_pointer(position); ronin.overlay.draw_pointer(position);
} }

View File

@ -29,6 +29,10 @@ function Terminal(rune)
this.passive = function(content) this.passive = function(content)
{ {
this.hint(content);
return;
var key = content[0]; var key = content[0];
var cmd = this.cmd(); var cmd = this.cmd();
@ -85,6 +89,16 @@ function Terminal(rune)
function active(content) function active(content)
{ {
var module_name = content.indexOf(".") > -1 ? content.split(" ")[0].split(".")[0] : content.split(" ")[0];
var method_name = content.indexOf(".") > -1 ? content.split(" ")[0].split(".")[1] : "default";
if(ronin[module_name] && ronin[module_name][method_name]){
ronin[module_name][method_name]();
}
else{
ronin.terminal.log(new Log(ronin.terminal,"Unknown module"));
}
var key = content[0]; var key = content[0];
var cmd = new Command(content.substring(1).trim().split(" ")); var cmd = new Command(content.substring(1).trim().split(" "));
@ -105,22 +119,13 @@ function Terminal(rune)
this.update_hint = function(content = this.input_element.value) this.update_hint = function(content = this.input_element.value)
{ {
// ronin.terminal.input_element.setAttribute("style","color:"+ronin.brush.color.hex); var module_name = content.indexOf(".") > -1 ? content.split(" ")[0].split(".")[0] : content.split(" ")[0];
if(content.indexOf(";") > -1){ if(ronin[module_name]){
this.hint_element.innerHTML = this.pad(content)+" "+content.split(";").length+" commands"; this.hint_element.innerHTML = this.pad(content)+ronin[module_name].hint(content.replace(module_name+".",""));
}
else if(ronin.module){
this.hint_element.innerHTML = ronin.module.hint(content);
}
else if(content == ""){
this.hint_element.innerHTML = "";
for(module in ronin.modules){
this.hint_element.innerHTML += "<b>"+module+"</b> "+ronin.modules[module].constructor.name+" ";
}
} }
else{ else{
this.hint_element.innerHTML = this.pad(content)+" Unknown Command." this.hint_element.innerHTML = this.pad(content)+ronin["default"].hint(content);
} }
} }

View File

@ -5,10 +5,24 @@ function Vector(rune)
this.parameters = [Any]; this.parameters = [Any];
this.variables = {"fill_color" : null,"stroke_width" : 5,"stroke_color" : "#ffffff", "line_cap" : "square"}; this.variables = {"fill_color" : null,"stroke_width" : 5,"stroke_color" : "#ffffff", "line_cap" : "square"};
this.add_method(new Method("stroke",["Positions"]));
this.add_method(new Method("fill",["Positions"]));
this.coordinates = []; this.coordinates = [];
this.last_pos = null; this.last_pos = null;
this.paths = []; this.paths = [];
this.stroke = function()
{
// TODO
console.warn("!!!!!")
}
this.fill = function()
{
}
// Module // Module
this.passive = function(cmd) this.passive = function(cmd)

View File

@ -1,10 +1,9 @@
function Method(method_str) function Method(name,params)
{ {
Unit.call(this); Unit.call(this);
var content = method_str.split(":"); this.name = name;
this.name = content.shift(); this.params = params;
this.params = content;
this.example = ""; this.example = "";
this.render = function() this.render = function()