Getting back to normality

This commit is contained in:
Devine Lu Linvega 2017-05-21 09:26:25 -10:00
parent 84244c1437
commit de175e12e7
11 changed files with 188 additions and 163 deletions

View File

@ -1,8 +1,8 @@
body { margin:0px; padding:0px; overflow:hidden; font-family:"input_mono_medium",courier,monospace;}
*:focus {outline: none; }
#ronin { width:100%; height:100%; overflow:hidden; background:#111; background-image:url(../media/graphics/grid.svg); background-position: center center; }
#frame { width:50vw; height:50vh; overflow:hidden; position:fixed; left: calc(40vw + 15px); top:100px; background:none; border-radius:5px; border:1px solid #333;}
#ronin { width:100%; height:100%; overflow:hidden; background:#ccc; background-image:url(../media/graphics/grid.svg); background-position: center center; }
#frame { width:50vw; height:50vh; overflow:hidden; position:fixed; left: calc(40vw + 15px); top:100px; background:#ddd;}
#frame > .layer { position:absolute; top:0px; left:0px; width:100%; height:100%;}
#frame.bright widget { color:#000; }
#overlay { position:absolute; z-index:1000;}

View File

@ -1,3 +1,5 @@
<svg width="20px" height="20px" xmlns="http://www.w3.org/2000/svg" baseProfile="full" version="1.1">
<circle cx="20" cy="20" r="1" fill="#444"></circle>
<svg width="40px" height="40px" xmlns="http://www.w3.org/2000/svg" baseProfile="full" version="1.1">
<circle cx="20" cy="20" r="2" fill="#ddd"></circle>
<line x1="20" y1="0" x2="20" y2="40" stroke="#ddd"></line>
<line x1="0" y1="20" x2="40" y2="20" stroke="#ddd"></line>
</svg>

Before

Width:  |  Height:  |  Size: 161 B

After

Width:  |  Height:  |  Size: 283 B

View File

@ -1,6 +1,38 @@
function Command(content)
{
this.content = content;
this.parts = content.split(" ");
this.module_name = null;
this.method_name = null;
this.setting_name = null;
this.module = null;
this.setthing = null;
this.module = function()
{
var module_name = null;
if(content.indexOf(".") > -1){
module_name = content.split(" ")[0].split(".")[0]
}
else if(content.indexOf(":") > -1){
module_name = content.split(" ")[0].split(":")[0]
}
else{
module_name = content.split(" ")[0];
}
return ronin.modules[module_name] ? ronin.modules[module_name] : null;
}
this.method = function()
{
var module = this.module();
if(!module){ return null; }
var method_name = content.indexOf(".") > -1 ? content.split(" ")[0].split(".")[1] : "default";
return module.methods[method_name] ? module.methods[method_name] : null;
}
this.inject_position = function(injection)
{
@ -12,80 +44,79 @@ function Command(content)
this.any = function()
{
if(this.content.join() === ""){ return null; }
return new Any(this.content);
}
this.rect = function()
{
for (i = 0; i < this.content.length; i++) {
if(this.content[i].indexOf("x") >= 0 && this.content[i].indexOf("/") < 0){ return new Rect(this.content[i]); }
for (i = 0; i < this.parts.length; i++) {
if(this.parts[i].indexOf("x") >= 0 && this.parts[i].indexOf("/") < 0){ return new Rect(this.parts[i]); }
}
return null;
}
this.position = function()
{
for (i = 0; i < this.content.length; i++) {
if(this.content[i].indexOf(",") >= 0){ return new Position(this.content[i]); }
for (i = 0; i < this.parts.length; i++) {
if(this.parts[i].indexOf(",") >= 0){ return new Position(this.parts[i]); }
}
return null;
}
this.color = function()
{
for (i = 0; i < this.content.length; i++) {
if(this.content[i].indexOf("#") >= 0){ return new Color(this.content[i]); }
for (i = 0; i < this.parts.length; i++) {
if(this.parts[i].indexOf("#") >= 0){ return new Color(this.parts[i]); }
}
return null;
}
this.filepath = function()
{
for (i = 0; i < this.content.length; i++) {
if(this.content[i].indexOf("/") >= 0){ return new Filepath(this.content[i]); }
for (i = 0; i < this.parts.length; i++) {
if(this.parts[i].indexOf("/") >= 0){ return new Filepath(this.parts[i]); }
}
return null;
}
this.value = function()
{
for (i = 0; i < this.content.length; i++) {
var test = /[^$\-\d]/.test(this.content[i]);
if(!test && this.content[i] !== ""){ return new Value(this.content[i]); }
for (i = 0; i < this.parts.length; i++) {
var test = /[^$\-\d]/.test(this.parts[i]);
if(!test && this.parts[i] !== ""){ return new Value(this.parts[i]); }
}
return null;
}
this.range = function()
{
for (i = 0; i < this.content.length; i++) {
if(this.content[i].indexOf("..") >= 0){ return new Range(this.content[i]); }
for (i = 0; i < this.parts.length; i++) {
if(this.parts[i].indexOf("..") >= 0){ return new Range(this.parts[i]); }
}
return null;
}
this.bang = function()
{
for (i = 0; i < this.content.length; i++) {
if(this.content[i].indexOf("!") >= 0){ return new Bang(); }
for (i = 0; i < this.parts.length; i++) {
if(this.parts[i].indexOf("!") >= 0){ return new Bang(); }
}
return null;
}
this.angle = function()
{
for (i = 0; i < this.content.length; i++) {
if(this.content[i].indexOf("'") >= 0){ return new Angle(this.content[i]); }
for (i = 0; i < this.parts.length; i++) {
if(this.parts[i].indexOf("'") >= 0){ return new Angle(this.parts[i]); }
}
return null;
}
this.setting = function(name)
{
for (i = 0; i < this.content.length; i++) {
if(this.content[i].indexOf("=") >= 0){
var parts = this.content[i].split("=");
for (i = 0; i < this.parts.length; i++) {
if(this.parts[i].indexOf("=") >= 0){
var parts = this.parts[i].split("=");
if(parts[0] == name){
return new Setting(parts[0],parts[1]);
}
@ -96,27 +127,8 @@ function Command(content)
this.text = function()
{
var content_str = this.content.join(" ");
var content_str = this.parts.join(" ");
if(content_str.indexOf("\"") < 0){ return null; }
return content_str.split("\"")[1];
}
this.methods = function()
{
var a = [];
for(i in this.content){
if(this.content[i].indexOf(":") > 0){
a.push(this.content[i]);
}
}
return a;
}
this.method = function(name)
{
for(i in this.methods()){
var m = new Method(this.methods()[i]);
if(m.name == name){ return m; }
}
}
}

View File

@ -24,6 +24,6 @@ ronin.install();
var target_file = window.location.hash ? window.location.hash : "default";
target_file = target_file.substr(1,target_file.length-1);
ronin.start();
// ronin.terminal.load(window.location.hash ? target_file+".rin" : "default.rin");
ronin.widget.update();
ronin.terminal.input.focus();

View File

@ -21,19 +21,19 @@ function Ronin()
this.cursor = new Cursor(".");
this.widget = new Widget("?");
this.modules[this.frame.constructor.name] = this.frame;
this.modules[this.type.constructor.name] = this.type;
this.modules[this.path.constructor.name] = this.path;
this.modules[this.frame.name] = this.frame;
this.modules[this.type.name] = this.type;
this.modules[this.path.name] = this.path;
this.modules[this.brush.constructor.name] = this.brush;
this.modules[this.brush.name] = this.brush;
this.modules[this.source.constructor.name] = this.source;
this.modules[this.render.constructor.name] = this.render;
this.modules[this.source.name] = this.source;
this.modules[this.render.name] = this.render;
// this.modules[this.eye.constructor.name] = this.eye;
// this.modules[this.magnet.constructor.name] = this.magnet;
this.modules[this.cursor.constructor.name] = this.cursor;
this.modules[this.terminal.constructor.name] = this.terminal;
this.modules[this.cursor.name] = this.cursor;
this.modules[this.terminal.name] = this.terminal;
//
@ -47,14 +47,22 @@ function Ronin()
this.widget.install();
}
this.start = function()
{
ronin.terminal.update();
ronin.widget.update();
ronin.terminal.input.focus();
}
this.cursors = [];
this.position_in_canvas = function(e)
{
var x = e.clientX;
x -= (window.innerWidth - this.frame.settings["size"].width) * 0.4 - 25;
x -= parseInt(0) + (this.frame.settings["size"].width/2);
var y = e.clientY - 100;
var y = e.clientY;
// Canvas Size
x += (-window.innerWidth/2) + (parseInt(this.frame.element.style.width)/2);
y += (-window.innerHeight/2) + (parseInt(this.frame.element.style.height)/2);
return new Position(x,y);
}

View File

@ -3,20 +3,19 @@ function Frame(rune)
Module.call(this,rune);
this.element = null;
this.settings = {"size":new Rect("200x200")};
this.settings = {size:new Rect("200x200")};
this.layers = {};
this.active_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.add_method(new Method("select",["text"]));
this.install = function()
{
this.blink();
this.select(new Command(["background"]));
this.select(new Command("background"));
// Canvas
var starting_canvas = new Rect();
@ -28,44 +27,37 @@ function Frame(rune)
starting_canvas.width = parseInt(starting_canvas.width/40) * 40;
starting_canvas.height = parseInt(starting_canvas.height/40) * 40;
this.resize(new Command([starting_canvas.width+"x"+starting_canvas.height]));
this.resize(new Command(starting_canvas.width+"x"+starting_canvas.height));
}
// Methods
this.resize = function(params, preview = false)
this.resize = function(cmd, preview = false)
{
if(preview){ return; }
var rect = cmd.rect();
var position = cmd.position() ? cmd.position() : new Position(0,0);
this.settings["size"] = params.rect();
if(preview){ ronin.overlay.draw(position,rect); return; }
for(layer_name in ronin.frame.layers){
ronin.frame.layers[layer_name].resize(this.settings["size"]);
ronin.frame.layers[layer_name].resize(rect);
}
ronin.frame.element.width = this.settings["size"].width * 2;
ronin.frame.element.height = this.settings["size"].height * 2;
ronin.frame.element.style.width = this.settings["size"].width+"px";
ronin.frame.element.style.height = this.settings["size"].height+"px";
ronin.frame.element.width = rect.width * 2;
ronin.frame.element.height = rect.height * 2;
ronin.frame.element.style.width = rect.width+"px";
ronin.frame.element.style.height = rect.height+"px";
ronin.frame.element.style.left = (window.innerWidth - this.settings["size"].width)/2;
ronin.frame.element.style.top = (window.innerHeight - this.settings["size"].height)/2;
ronin.frame.element.style.left = (window.innerWidth - rect.width)/2;
ronin.frame.element.style.top = (window.innerHeight - rect.height)/2;
ronin.on_resize();
this.settings.size = rect;
return 1, "ok";
}
this.crop = function(params, preview = false)
{
if(!params.position() || !params.rect()){ return; }
this.settings["size"] = params.rect();
ronin.overlay.get_layer(true).clear();
if(preview){ronin.overlay.draw_rect(params.position(),params.rect());}
}
this.select = function(params, preview = false)
{
if(preview){ return; }

View File

@ -1,5 +1,6 @@
function Module(rune)
{
this.name = this.constructor.name.toLowerCase();
this.rune = rune;
this.element = null;
this.settings = {};
@ -46,30 +47,22 @@ function Module(rune)
this.add_method = function(method)
{
method.host = this;
this.methods[method.name] = method;
}
this.hint = function(content)
{
var s = "";
var html = "";
ronin.terminal.hint_element.innerHTML = "";
var method_name = content.split(" ")[0];
if(this.methods[method_name]){
s = this.methods[method_name].params;
s += this.methods[method_name].mouse_event ? " <i>"+this.methods[method_name].mouse_event+"</i> " : "";
for(method in this.methods){
html += ".<b>"+method+"</b> ";
}
else{
for(method in this.methods){
s += ".<b>"+method+"</b> ";
}
for(setting in this.settings){
s += setting+"="+this.settings[setting]+" ";
}
for(setting in this.settings){
html += setting+"="+this.settings[setting]+" ";
}
return s;
return html;
}
this.pad = function(input)

View File

@ -21,7 +21,7 @@ function Overlay(rune)
this.draw = function(position,rect)
{
this.clear();
this.get_layer().clear();
if(!position){ position = new Position("0,0"); }
@ -39,8 +39,10 @@ function Overlay(rune)
}
}
this.draw_rect = function(position,rect)
this.draw_rect = function(position = new Position(0,0),rect)
{
if(!position || !rect){ return; }
this.context().beginPath();
position.normalize(rect);

View File

@ -26,68 +26,42 @@ function Terminal(rune)
this.run = function()
{
var command = this.cmd();
var module = command.module();
var method = command.method();
if(method){
method.run(command);
}
this.hint_element.innerHTML = "";
this.run_line(this.input.value,false);
this.input.value = "";
}
this.run_line = function(line,is_preview)
{
var content = line;
if(content.trim() == ""){ ronin.cursor.set_mode(ronin.brush); return "~"; }
if(content.trim()[0] == "~"){ return "~"; }
if(content.indexOf(".") > -1){
var module_name = content.split(" ")[0].split(".")[0]
}
else if(content.indexOf(":") > -1){
var module_name = content.split(" ")[0].split(":")[0]
}
else{
var module_name = content.split(" ")[0];
}
var method_name = content.indexOf(".") > -1 ? content.split(" ")[0].split(".")[1] : "default";
var setting_name = content.indexOf(":") > -1 ? content.split(" ")[0].split(":")[1] : null;
var parameters = content.split(" "); parameters.shift();
var parameters = new Command(parameters);
ronin.cursor.set_mode(ronin[module_name]);
if(ronin[module_name] && ronin[module_name][method_name]){
return ronin[module_name][method_name](parameters,is_preview);
}
else if(ronin[module_name] && ronin[module_name].settings[setting_name]){
return ronin[module_name].update_setting(setting_name,parameters);
}
else if(ronin["render"].collection[method_name]){
return ronin["render"].collection[method_name].render(parameters);
}
else if(setting_name){
return 0, "Unknown Setting";
}
else if(ronin[module_name]){
return 0, "Unknown Method";
}
else if(module_name == "render"){
return 0, "Unknown Filter";
}
else{
return 0, "Unknown Module";
}
return 0, "Unknown";
}
this.log = function(log)
{
}
this.update = function()
{
this.hint_element.innerHTML = "<span class='input'>"+this.input.value+"</span> "+this.run_line(this.input.value,true);
var command = this.cmd();
var module = command.module();
var method = command.method();
if(method){
method.preview(command);
}
this.hint_element.innerHTML = "<span class='input'>"+this.input.value+"</span> "+(module ? module.hint() : this.hint());
}
this.hint = function()
{
var html = "";
for(id in ronin.modules){
html += ronin.modules[id].name+" ";
}
return html;
}
this.cmd = function()
{
return new Command(this.input.value);
}
this.filename = "default.rin";
@ -113,11 +87,30 @@ function Terminal(rune)
ronin.widget.update();
}
this.cmd = function()
this.parsed_input = function()
{
var lines = ronin.terminal.input.value.split("\n");
var last = lines[lines.length-1];
return new Command(last.split(" "));
var content = this.input.value;
if(content.trim() == ""){ ronin.cursor.set_mode(ronin.brush); return "~"; }
if(content.trim()[0] == "~"){ return "~"; }
if(content.indexOf(".") > -1){
var module_name = content.split(" ")[0].split(".")[0]
}
else if(content.indexOf(":") > -1){
var module_name = content.split(" ")[0].split(":")[0]
}
else{
var module_name = content.split(" ")[0];
}
var method_name = content.indexOf(".") > -1 ? content.split(" ")[0].split(".")[1] : "default";
var setting_name = content.indexOf(":") > -1 ? content.split(" ")[0].split(":")[1] : null;
var parameters = content.split(" "); parameters.shift();
var parameters = new Command(parameters);
return {module_name: module_name, method_name: method_name, setting_name: setting_name, parameters: parameters};
}
}

View File

@ -2,6 +2,7 @@ function Method(name,params,mouse_event)
{
Unit.call(this);
this.host = null;
this.name = name;
this.params = params;
this.mouse_event = mouse_event;
@ -17,4 +18,25 @@ function Method(name,params,mouse_event)
return s;
}
this.help = function()
{
var s = "";
for(id in this.params){
s += this.params[id]+":"
}
s = s.substr(0,s.length-1);
return s;
}
this.preview = function(cmd)
{
return this.host[this.name](cmd,true);
}
this.run = function(cmd)
{
return this.host[this.name](cmd,false);
}
}

View File

@ -2,12 +2,13 @@ function Rect(rect_str)
{
Unit.call(this);
this.example = "200x300";
this.rect_str = rect_str;
this.width = rect_str ? parseFloat(this.rect_str.split("x")[0]) : 0;
this.height = rect_str ? parseFloat(this.rect_str.split("x")[1]) : 0;
this.example = "200x300";
this.render = function()
{
return (isNaN(this.width) ? 0 : this.width)+"x"+(isNaN(this.height) ? 0 : this.height);