Let's get this party started

This commit is contained in:
Devine Lu Linvega
2019-07-12 20:10:53 +09:00
parent a56b66433b
commit 371c255022
30 changed files with 1390 additions and 1651 deletions

View File

@@ -1,148 +1,128 @@
function Commander()
{
this.el = document.createElement('yu');
this.el.id = "commander";
this.input_el = document.createElement('input');
this.input_el.value = "";
function Commander () {
this.el = document.createElement('yu')
this.el.id = 'commander'
this.input_el = document.createElement('input')
this.input_el.value = ''
this.install = function()
{
this.el.appendChild(this.input_el);
ronin.el.appendChild(this.el);
this.input_el.focus();
this.install = function () {
this.el.appendChild(this.input_el)
ronin.el.appendChild(this.el)
this.input_el.focus()
}
this.validate = function(q = ronin.commander.query())
{
if(!ronin.modules[q.module]){ console.log("Unknown module",q.module); return; }
if(q.raw.indexOf("$") > -1){ console.log("Variables present"); return; }
if(q.raw.indexOf(";") > -1){ this.validate_multi(q); return; }
this.validate = function (q = ronin.commander.query()) {
if (!ronin.modules[q.module]) { console.log('Unknown module', q.module); return }
if (q.raw.indexOf('$') > -1) { console.log('Variables present'); return }
if (q.raw.indexOf(';') > -1) { this.validate_multi(q); return }
// Run methods
for(method_id in q.methods){
var method_param = q.methods[method_id];
if(!ronin.modules[q.module].methods[method_id]){ console.log("Missing method",method_id); return; }
ronin.modules[q.module].methods[method_id].run(method_param);
for (method_id in q.methods) {
var method_param = q.methods[method_id]
if (!ronin.modules[q.module].methods[method_id]) { console.log('Missing method', method_id); return }
ronin.modules[q.module].methods[method_id].run(method_param)
}
ronin.commander.input_el.value = "";
ronin.hint.update();
ronin.guide.update();
ronin.commander.input_el.value = ''
ronin.hint.update()
ronin.guide.update()
}
this.queue = [];
this.queue = []
this.validate_multi = function(q)
{
var queue = [];
var queries = q.string.split(";");
this.validate_multi = function (q) {
var queue = []
var queries = q.string.split(';')
for(id in queries){
var q = new Query(queries[id].trim());
queue.push(q);
for (id in queries) {
var q = new Query(queries[id].trim())
queue.push(q)
}
this.queue = queue;
this.run_queue();
this.queue = queue
this.run_queue()
}
this.run_queue = function()
{
if(ronin.commander.queue.length == 0){ return; }
ronin.commander.validate(ronin.commander.queue[0]);
this.run_queue = function () {
if (ronin.commander.queue.length == 0) { return }
ronin.commander.queue = ronin.commander.queue.splice(1,ronin.commander.queue.length-1)
ronin.commander.validate(ronin.commander.queue[0])
setTimeout(ronin.commander.run_queue,250);
ronin.commander.queue = ronin.commander.queue.splice(1, ronin.commander.queue.length - 1)
setTimeout(ronin.commander.run_queue, 250)
}
this.update = function()
{
var q = ronin.commander.query();
if(ronin.modules[q.module] && ronin.modules[q.module]["preview"]){
ronin.modules[q.module].preview(q);
}
ronin.hint.update();
ronin.guide.update();
this.update = function () {
var q = ronin.commander.query()
if (ronin.modules[q.module] && ronin.modules[q.module]['preview']) {
ronin.modules[q.module].preview(q)
}
ronin.hint.update()
ronin.guide.update()
}
this.autocomplete = function()
{
this.autocomplete = function () {
var target_module = ronin.commander.query().module
var target_module = ronin.commander.query().module;
var ac = ronin.modules[target_module] ? ronin.hint.find_autocomplete(ronin.modules[target_module].methods, ':') : ronin.hint.find_autocomplete(ronin.modules, ' ')
var ac = ronin.modules[target_module] ? ronin.hint.find_autocomplete(ronin.modules[target_module].methods,":") : ronin.hint.find_autocomplete(ronin.modules," ")
this.focus()
if (ac.lenght < 1 || !ac[0]) { return }
if (ronin.commander.query().string.length < 1) { return }
this.focus();
if(ac.lenght < 1 || !ac[0]){ return; }
if(ronin.commander.query().string.length < 1){ return; }
this.append(ac[0]);
this.append(ac[0])
}
this.on_input = function(e)
{
ronin.commander.update();
this.on_input = function (e) {
ronin.commander.update()
}
this.is_focused = function()
{
return this.input_el === document.activeElement;
this.is_focused = function () {
return this.input_el === document.activeElement
}
this.focus = function()
{
this.input_el.focus();
this.focus = function () {
this.input_el.focus()
}
this.blur = function()
{
this.input_el.blur();
this.blur = function () {
this.input_el.blur()
}
this.active_module = function()
{
return this.query().module;
this.active_module = function () {
return this.query().module
}
this.inject = function(str)
{
ronin.commander.input_el.value = str;
ronin.commander.update();
ronin.commander.show();
this.inject = function (str) {
ronin.commander.input_el.value = str
ronin.commander.update()
ronin.commander.show()
}
this.append = function(str)
{
ronin.commander.input_el.value += str;
ronin.commander.update();
this.append = function (str) {
ronin.commander.input_el.value += str
ronin.commander.update()
}
this.activate = function()
{
ronin.commander.autocomplete();
ronin.commander.show();
setTimeout(()=>{ronin.commander.focus},100)
this.activate = function () {
ronin.commander.autocomplete()
ronin.commander.show()
setTimeout(() => { ronin.commander.focus }, 100)
}
this.deactivate = function()
{
this.blur();
this.hide();
this.deactivate = function () {
this.blur()
this.hide()
}
this.show = function()
{
this.el.className = "visible";
this.show = function () {
this.el.className = 'visible'
}
this.hide = function()
{
this.el.className = "hidden";
this.hide = function () {
this.el.className = 'hidden'
}
this.query = function()
{
return new Query(ronin.commander.input_el.value);
this.query = function () {
return new Query(ronin.commander.input_el.value)
}
}
}

View File

@@ -1,188 +1,160 @@
function Cursor(rune)
{
this.line = {origin:null,from:null,to:null,destination:null};
this.is_down = false;
this.query = null;
this.mode = "vertex";
function Cursor (rune) {
this.line = { origin: null, from: null, to: null, destination: null }
this.is_down = false
this.query = null
this.mode = 'vertex'
this.size = 2;
this.pos = {x:0,y:0};
this.size = 2
this.pos = { x: 0, y: 0 }
this.target = null;
this.mouse_pos = function(e)
{
var pos = {x:e.clientX,y:e.clientY};
this.target = null
pos.x = ((pos.x/ronin.frame.width) / ronin.frame.zoom.scale) * ronin.frame.width;
pos.y = ((pos.y/ronin.frame.height) / ronin.frame.zoom.scale) * ronin.frame.height;
this.mouse_pos = function (e) {
var pos = { x: e.clientX, y: e.clientY }
pos.x -= (ronin.frame.zoom.offset.x / ronin.frame.zoom.scale);
pos.y -= (ronin.frame.zoom.offset.y / ronin.frame.zoom.scale);
pos.x = ((pos.x / ronin.frame.width) / ronin.frame.zoom.scale) * ronin.frame.width
pos.y = ((pos.y / ronin.frame.height) / ronin.frame.zoom.scale) * ronin.frame.height
return pos;
pos.x -= (ronin.frame.zoom.offset.x / ronin.frame.zoom.scale)
pos.y -= (ronin.frame.zoom.offset.y / ronin.frame.zoom.scale)
return pos
}
this.mouse_down = function(e)
{
e.preventDefault();
this.mouse_down = function (e) {
e.preventDefault()
var pos = ronin.cursor.mouse_pos(e);
var pos = ronin.cursor.mouse_pos(e)
ronin.commander.blur();
ronin.commander.blur()
ronin.cursor.line.origin = {x:pos.x,y:pos.y};
ronin.cursor.line.from = {x:pos.x,y:pos.y};
ronin.cursor.line.origin = { x: pos.x, y: pos.y }
ronin.cursor.line.from = { x: pos.x, y: pos.y }
// Save original query
ronin.cursor.query = ronin.commander.input_el.value;
ronin.cursor.query = ronin.commander.input_el.value
if(ronin.commander.active_module()){ /* DO NOTHING */ }
else if(e.shiftKey){ /* DO NOTHING */ }
else if(e.altKey && e.shiftKey){ ronin.brush.methods.pick.run(pos); }
else if(e.altKey){ ronin.brush.erase(ronin.cursor.line); }
else{ ronin.brush.stroke(ronin.cursor.line); }
if (ronin.commander.active_module()) { /* DO NOTHING */ } else if (e.shiftKey) { /* DO NOTHING */ } else if (e.altKey && e.shiftKey) { ronin.brush.methods.pick.run(pos) } else if (e.altKey) { ronin.brush.erase(ronin.cursor.line) } else { ronin.brush.stroke(ronin.cursor.line) }
if(e.shiftKey){ ronin.cursor.mode = "rect"; }
if(e.altKey){ ronin.cursor.mode = "arc_to"; }
if(e.ctrlKey){ ronin.cursor.mode = "cc_arc_to"; }
if (e.shiftKey) { ronin.cursor.mode = 'rect' }
if (e.altKey) { ronin.cursor.mode = 'arc_to' }
if (e.ctrlKey) { ronin.cursor.mode = 'cc_arc_to' }
}
this.mouse_move = function(e)
{
e.preventDefault();
this.mouse_move = function (e) {
e.preventDefault()
var pos = ronin.cursor.mouse_pos(e);
ronin.cursor.pos = pos;
var pos = ronin.cursor.mouse_pos(e)
ronin.cursor.pos = pos
if(!ronin.cursor.line.from){ return; }
if (!ronin.cursor.line.from) { return }
ronin.cursor.line.to = {x:pos.x,y:pos.y};
ronin.cursor.line.to = { x: pos.x, y: pos.y }
if(ronin.commander.active_module()){ ronin.cursor.inject_query(); }
else if(e.altKey && e.shiftKey){ ronin.brush.methods.pick.run(pos); }
else if(e.shiftKey){ ronin.cursor.drag(ronin.cursor.line); }
else if(e.altKey){ ronin.brush.erase(ronin.cursor.line); }
else{ ronin.brush.stroke(ronin.cursor.line); }
if (ronin.commander.active_module()) { ronin.cursor.inject_query() } else if (e.altKey && e.shiftKey) { ronin.brush.methods.pick.run(pos) } else if (e.shiftKey) { ronin.cursor.drag(ronin.cursor.line) } else if (e.altKey) { ronin.brush.erase(ronin.cursor.line) } else { ronin.brush.stroke(ronin.cursor.line) }
ronin.cursor.line.from = {x:pos.x,y:pos.y};
ronin.cursor.line.from = { x: pos.x, y: pos.y }
}
this.mouse_up = function(e)
{
e.preventDefault();
this.mouse_up = function (e) {
e.preventDefault()
var pos = ronin.cursor.mouse_pos(e);
ronin.cursor.line.destination = {x:pos.x,y:pos.y};
var pos = ronin.cursor.mouse_pos(e)
ronin.cursor.inject_query();
ronin.cursor.is_down = false;
ronin.cursor.line = {};
ronin.cursor.mode = "vertex";
ronin.cursor.line.destination = { x: pos.x, y: pos.y }
ronin.cursor.query = ronin.commander.input_el.value;
ronin.brush.absolute_thickness = 0;
ronin.cursor.inject_query()
ronin.cursor.is_down = false
ronin.cursor.line = {}
ronin.cursor.mode = 'vertex'
ronin.cursor.query = ronin.commander.input_el.value
ronin.brush.absolute_thickness = 0
}
this.mouse_alt = function(e)
{
console.log(e);
this.mouse_alt = function (e) {
console.log(e)
}
this.drag = function(line)
{
var offset = make_offset(line.from,line.to);
var data = ronin.cursor.target.select();
ronin.cursor.target.clear();
ronin.cursor.target.context().putImageData(data, offset.x * -2, offset.y * -2);
this.drag = function (line) {
var offset = make_offset(line.from, line.to)
var data = ronin.cursor.target.select()
ronin.cursor.target.clear()
ronin.cursor.target.context().putImageData(data, offset.x * -2, offset.y * -2)
}
this.swap_layer = function()
{
this.target = this.target.name == "above" ? ronin.layers.below : ronin.layers.above;
ronin.commander.update();
this.swap_layer = function () {
this.target = this.target.name == 'above' ? ronin.layers.below : ronin.layers.above
ronin.commander.update()
}
this.select_layer = function(layer)
{
this.target = layer;
ronin.commander.update();
this.select_layer = function (layer) {
this.target = layer
ronin.commander.update()
}
function make_offset(a,b)
{
return {x:a.x-b.x,y:a.y-b.y};
function make_offset (a, b) {
return { x: a.x - b.x, y: a.y - b.y }
}
this.inject_query = function()
{
if(ronin.cursor.query && ronin.cursor.query.indexOf("$") < 0){ return; }
this.inject_query = function () {
if (ronin.cursor.query && ronin.cursor.query.indexOf('$') < 0) { return }
var a = ronin.cursor.line.origin;
var b = ronin.cursor.line.destination ? ronin.cursor.line.destination : ronin.cursor.line.from;
var a = ronin.cursor.line.origin
var b = ronin.cursor.line.destination ? ronin.cursor.line.destination : ronin.cursor.line.from
var str = "<error>";
var str = '<error>'
if(ronin.cursor.mode == "vertex"){
str = b.x+","+b.y;
if (ronin.cursor.mode == 'vertex') {
str = b.x + ',' + b.y
} else if (ronin.cursor.mode == 'rect') {
var offset = a.x + ',' + a.y
var rect = (b.x - a.x) + 'x' + (b.y - a.y)
str = offset + '|' + rect
} else if (ronin.cursor.mode == 'arc_to') {
str = '@>' + b.x + ',' + b.y
} else if (ronin.cursor.mode == 'cc_arc_to') {
str = '@<' + b.x + ',' + b.y
}
else if(ronin.cursor.mode == "rect"){
var offset = a.x+","+a.y;
var rect = (b.x - a.x)+"x"+(b.y - a.y);
str = offset+"|"+rect;
}
else if(ronin.cursor.mode == "arc_to"){
str = "@>"+b.x+","+b.y;
}
else if(ronin.cursor.mode == "cc_arc_to"){
str = "@<"+b.x+","+b.y;
}
//
var i = ronin.cursor.query ? ronin.cursor.query.indexOf("$") : '';
var i1 = ronin.cursor.query ? ronin.cursor.query.substr(i,2) : '';
var e1 = ronin.cursor.query ? ronin.cursor.query.substr(i-1,2) : '';
//
var i = ronin.cursor.query ? ronin.cursor.query.indexOf('$') : ''
var i1 = ronin.cursor.query ? ronin.cursor.query.substr(i, 2) : ''
var e1 = ronin.cursor.query ? ronin.cursor.query.substr(i - 1, 2) : ''
if(e1 == "#$"){
var r = parseInt((b.x/ronin.frame.width) * 255);
var g = 255 - parseInt((b.x/ronin.frame.width) * 255);
var b = parseInt((b.y/ronin.frame.height) * 255);
var str = new Color().rgb_to_hex([r,g,b]);
ronin.commander.inject(ronin.cursor.query.replace("#$",str+" "));
}
else if(i1 == "$+"){
ronin.commander.inject(ronin.cursor.query.replace("$+",str+"&$+"));
}
else if(ronin.cursor.query){
ronin.commander.inject(ronin.cursor.query.replace("$",str));
if (e1 == '#$') {
var r = parseInt((b.x / ronin.frame.width) * 255)
var g = 255 - parseInt((b.x / ronin.frame.width) * 255)
var b = parseInt((b.y / ronin.frame.height) * 255)
var str = new Color().rgb_to_hex([r, g, b])
ronin.commander.inject(ronin.cursor.query.replace('#$', str + ' '))
} else if (i1 == '$+') {
ronin.commander.inject(ronin.cursor.query.replace('$+', str + '&$+'))
} else if (ronin.cursor.query) {
ronin.commander.inject(ronin.cursor.query.replace('$', str))
}
}
this.hint = function()
{
var html = "";
this.hint = function () {
var html = ''
var mode = "paint";
var mode = 'paint'
if(ronin.keyboard.is_down["Alt"] && ronin.keyboard.is_down["Shift"]){
mode = "pick";
}
else if(ronin.keyboard.is_down["Alt"]){
mode = "erase";
}
else if(ronin.keyboard.is_down["Shift"]){
mode = "drag";
if (ronin.keyboard.is_down['Alt'] && ronin.keyboard.is_down['Shift']) {
mode = 'pick'
} else if (ronin.keyboard.is_down['Alt']) {
mode = 'erase'
} else if (ronin.keyboard.is_down['Shift']) {
mode = 'drag'
}
return `
<t class='frame'>${ronin.frame.width}X${ronin.frame.height} ${(ronin.frame.width/ronin.frame.height).toFixed(2)}:1</t>
<t class='frame'>${ronin.frame.width}X${ronin.frame.height} ${(ronin.frame.width / ronin.frame.height).toFixed(2)}:1</t>
<t class='target_${ronin.cursor.target.name}'></t><t class='size ${mode}'>${ronin.cursor.size}</t><t class='zoom'>${ronin.frame.zoom.scale}</t>
${ronin.brush.swatch.hint()}`;
${ronin.brush.swatch.hint()}`
}
function distance_between(a,b)
{
return Math.sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) );
function distance_between (a, b) {
return Math.sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y))
}
}
}

View File

@@ -1,67 +1,61 @@
function Docs()
{
this.export = function()
{
var html = "";
function Docs () {
this.export = function () {
var html = ''
html += this.print_intro();
html += this.print_intro()
html += "## Cursor\n";
html += "Include `$` in a query and click on the canvas to inject the cursor position in the query.\n";
html += "- `$ click` inject a **Pos**.\n";
html += "- `$+ click` inject a **Pos**, and append `$+` for multiple positions.\n";
html += "- `$ shift click` inject a **Rect**.\n";
html += "- `#$ click` inject a **Color**.\n";
html += "- `x` swap **Color** with secondary.\n\n";
html += "- `z` draw under render.\n\n";
html += "## Modules\n";
html += this.print_modules(ronin.modules);
html += this.print_license();
html += '## Cursor\n'
html += 'Include `$` in a query and click on the canvas to inject the cursor position in the query.\n'
html += '- `$ click` inject a **Pos**.\n'
html += '- `$+ click` inject a **Pos**, and append `$+` for multiple positions.\n'
html += '- `$ shift click` inject a **Rect**.\n'
html += '- `#$ click` inject a **Color**.\n'
html += '- `x` swap **Color** with secondary.\n\n'
html += '- `z` draw under render.\n\n'
fs.writeFile("/Users/VillaMoirai/Github/HundredRabbits/Ronin/README.md", html, (err) => {
if(err){ alert("An error ocurred creating the file "+ err.message); return; }
});
html += '## Modules\n'
html += this.print_modules(ronin.modules)
html += this.print_license()
return html;
fs.writeFile('/Users/VillaMoirai/Github/HundredRabbits/Ronin/README.md', html, (err) => {
if (err) { alert('An error ocurred creating the file ' + err.message) }
})
return html
}
this.print_intro = function()
{
html = "# Ronin\n";
html += "Ronin is a graphic design tool, to paint, resize and export graphics.\n\n";
html += "<img src='https://raw.githubusercontent.com/hundredrabbits/Ronin/master/PREVIEW.jpg' width='600'/>\n\n";
return html;
this.print_intro = function () {
html = '# Ronin\n'
html += 'Ronin is a graphic design tool, to paint, resize and export graphics.\n\n'
html += "<img src='https://raw.githubusercontent.com/hundredrabbits/Ronin/master/PREVIEW.jpg' width='600'/>\n\n"
return html
}
this.print_modules = function(modules)
{
var html = "";
this.print_modules = function (modules) {
var html = ''
for(module_name in modules){
var module = modules[module_name];
html += "## "+module_name+"\n\n";
html += module.docs+"\n\n";
html += this.print_methods(module.methods)+"\n";
for (module_name in modules) {
var module = modules[module_name]
html += '## ' + module_name + '\n\n'
html += module.docs + '\n\n'
html += this.print_methods(module.methods) + '\n'
}
return html+"\n";
return html + '\n'
}
this.print_methods = function(methods)
{
var html = "### Methods\n";
this.print_methods = function (methods) {
var html = '### Methods\n'
for(method_name in methods){
var method = methods[method_name];
html += "- `"+method_name+":"+method.params+"` "+method.info+"\n";
for (method_name in methods) {
var method = methods[method_name]
html += '- `' + method_name + ':' + method.params + '` ' + method.info + '\n'
}
return html;
return html
}
this.print_license = function()
{
html = "## License\n";
html += "See the [LICENSE](LICENSE.md) file for license rights and limitations.\n";
return html;
this.print_license = function () {
html = '## License\n'
html += 'See the [LICENSE](LICENSE.md) file for license rights and limitations.\n'
return html
}
}
}

View File

@@ -1,79 +1,68 @@
function Hint()
{
this.el = document.createElement('yu');
this.el.id = "hint";
this.cursor_hint_el = document.createElement('yu');
this.cursor_hint_el.id = "cursor_hint";
function Hint () {
this.el = document.createElement('yu')
this.el.id = 'hint'
this.cursor_hint_el = document.createElement('yu')
this.cursor_hint_el.id = 'cursor_hint'
this.install = function()
{
ronin.commander.el.appendChild(this.el);
ronin.commander.el.appendChild(this.cursor_hint_el);
this.install = function () {
ronin.commander.el.appendChild(this.el)
ronin.commander.el.appendChild(this.cursor_hint_el)
}
this.find_autocomplete = function(collection,append = "")
{
var target = ronin.commander.query().last;
var a = [];
this.find_autocomplete = function (collection, append = '') {
var target = ronin.commander.query().last
var a = []
for(id in collection){
var name = collection[id].name;
if(name && name.substr(0,target.length) == target){
a.push(name.substr(target.length,20)+append)
for (id in collection) {
var name = collection[id].name
if (name && name.substr(0, target.length) == target) {
a.push(name.substr(target.length, 20) + append)
}
}
return a;
return a
}
this.update = function(e = null)
{
var html = ""
this.update = function (e = null) {
var html = ''
for(module_id in ronin.modules){
var module = ronin.modules[module_id];
html += module_id+" ";
for (module_id in ronin.modules) {
var module = ronin.modules[module_id]
html += module_id + ' '
}
var target_module = ronin.commander.query().module;
var target_module = ronin.commander.query().module
var target_method = Object.keys(ronin.commander.query().methods).length > 0 ? Object.keys(ronin.commander.query().methods)[0] : null
if(ronin.commander.input_el.value == ""){
this.el.innerHTML = html;
}
else if(ronin.modules[target_module] && ronin.modules[target_module].methods[target_method]){
this.el.innerHTML = this.pad(ronin.commander.input_el.value)+" "+ronin.modules[target_module].methods[target_method].docs();
}
else if(ronin.modules[target_module]){
var ac = this.find_autocomplete(ronin.modules[target_module].methods,":");
if(ac.length > 0){
this.el.innerHTML = this.pad(ronin.commander.input_el.value)+"<span class='autocomplete'>"+ac[0]+"</span> > Press tab to autocomplete."
if (ronin.commander.input_el.value == '') {
this.el.innerHTML = html
} else if (ronin.modules[target_module] && ronin.modules[target_module].methods[target_method]) {
this.el.innerHTML = this.pad(ronin.commander.input_el.value) + ' ' + ronin.modules[target_module].methods[target_method].docs()
} else if (ronin.modules[target_module]) {
var ac = this.find_autocomplete(ronin.modules[target_module].methods, ':')
if (ac.length > 0) {
this.el.innerHTML = this.pad(ronin.commander.input_el.value) + "<span class='autocomplete'>" + ac[0] + '</span> > Press tab to autocomplete.'
} else {
this.el.innerHTML = this.pad(ronin.commander.input_el.value) + ' ' + ronin.modules[target_module].hint()
}
else{
this.el.innerHTML = this.pad(ronin.commander.input_el.value)+" "+ronin.modules[target_module].hint();
} else {
var ac = this.find_autocomplete(ronin.modules)
if (ac.length > 0) {
this.el.innerHTML = this.pad(ronin.commander.input_el.value) + "<span class='autocomplete'>" + ac[0] + '</span> > Press tab to autocomplete.'
} else if (ronin.commander.input_el.value == '~') {
this.el.innerHTML = this.pad(ronin.commander.input_el.value) + ' > Select a color.'
} else {
this.el.innerHTML = this.pad(ronin.commander.input_el.value) + ' > Unknown command.'
}
}
else{
var ac = this.find_autocomplete(ronin.modules);
if(ac.length > 0){
this.el.innerHTML = this.pad(ronin.commander.input_el.value)+"<span class='autocomplete'>"+ac[0]+"</span> > Press tab to autocomplete."
}
else if(ronin.commander.input_el.value == "~"){
this.el.innerHTML = this.pad(ronin.commander.input_el.value)+" > Select a color."
}
else{
this.el.innerHTML = this.pad(ronin.commander.input_el.value)+" > Unknown command."
}
}
this.cursor_hint_el.innerHTML = ronin.cursor.hint();
this.cursor_hint_el.innerHTML = ronin.cursor.hint()
}
this.pad = function(input)
{
var s = "";
for (i = 0; i < input.length; i++){
s += "_";
this.pad = function (input) {
var s = ''
for (i = 0; i < input.length; i++) {
s += '_'
}
return "<span style='color:RGBA(0,0,0,0)'>"+s+"</span>";
return "<span style='color:RGBA(0,0,0,0)'>" + s + '</span>'
}
}
}

View File

@@ -1,26 +1,23 @@
function Keyboard()
{
this.is_down = {};
function Keyboard () {
this.is_down = {}
this.key_up = function(e)
{
ronin.hint.update(e);
this.key_up = function (e) {
ronin.hint.update(e)
}
this.key_down = function(e)
{
ronin.keyboard.is_down[e.key] = true;
this.key_down = function (e) {
ronin.keyboard.is_down[e.key] = true
if(ronin.commander.is_focused() && e.key == "Enter"){
e.preventDefault();
ronin.commander.validate();
if (ronin.commander.is_focused() && e.key == 'Enter') {
e.preventDefault()
ronin.commander.validate()
}
if(ronin.commander.is_focused()){
ronin.hint.update(e);
return;
if (ronin.commander.is_focused()) {
ronin.hint.update(e)
return
}
ronin.hint.update(e);
ronin.hint.update(e)
}
}
}

View File

@@ -1,72 +1,61 @@
function Layer(name)
{
this.name = name;
this.el = document.createElement('canvas');
this.el.id = name;
this.el.className = "layer";
function Layer (name) {
this.name = name
this.el = document.createElement('canvas')
this.el.id = name
this.el.className = 'layer'
this.install = function()
{
ronin.frame.el.appendChild(this.el);
this.install = function () {
ronin.frame.el.appendChild(this.el)
}
this.update = function(zoom = {scale:1,offset:{x:0,y:0}})
{
this.update = function (zoom = { scale: 1, offset: { x: 0, y: 0 } }) {
}
this.context = function()
{
return this.el.getContext('2d');
this.context = function () {
return this.el.getContext('2d')
}
this.resize_to = function(size)
{
console.log(`Resized ${this.name}`);
this.el.width = ronin.frame.width * 2;
this.el.height = ronin.frame.height * 2;
this.update();
this.resize_to = function (size) {
console.log(`Resized ${this.name}`)
this.el.width = ronin.frame.width * 2
this.el.height = ronin.frame.height * 2
this.update()
}
this.select = function(x = 0,y = 0,width = ronin.frame.width,height = ronin.frame.width)
{
return this.context().getImageData(x, y, width * 2, height * 2);
this.select = function (x = 0, y = 0, width = ronin.frame.width, height = ronin.frame.width) {
return this.context().getImageData(x, y, width * 2, height * 2)
}
this.to_base64 = function(format = 'png', quality = 0.9)
{
return format == 'png' ? this.el.toDataURL('image/png') : this.el.toDataURL('image/jpeg',0.9);
this.to_base64 = function (format = 'png', quality = 0.9) {
return format == 'png' ? this.el.toDataURL('image/png') : this.el.toDataURL('image/jpeg', 0.9)
}
this.to_img = function()
{
var img = new Image();
img.src = this.to_base64();
return img;
this.to_img = function () {
var img = new Image()
img.src = this.to_base64()
return img
}
this.clear = function()
{
this.context().clearRect(0, 0, this.el.width * 2, this.el.height * 2);
this.clear = function () {
this.context().clearRect(0, 0, this.el.width * 2, this.el.height * 2)
}
this.fill = function(color = "red")
{
var ctx = this.context();
this.fill = function (color = 'red') {
var ctx = this.context()
ctx.beginPath();
ctx.globalCompositeOperation="source-over";
ctx.moveTo(0,0);
ctx.lineTo(this.el.width,0);
ctx.lineTo(this.el.width,this.el.height);
ctx.lineTo(0,this.el.height);
ctx.lineTo(0,0);
ctx.fillStyle = color;
ctx.fill();
ctx.closePath();
ctx.beginPath()
ctx.globalCompositeOperation = 'source-over'
ctx.moveTo(0, 0)
ctx.lineTo(this.el.width, 0)
ctx.lineTo(this.el.width, this.el.height)
ctx.lineTo(0, this.el.height)
ctx.lineTo(0, 0)
ctx.fillStyle = color
ctx.fill()
ctx.closePath()
}
this.zoom = function(zoom = {scale:1,offset:{x:0,y:0}})
{
this.update(zoom);
this.zoom = function (zoom = { scale: 1, offset: { x: 0, y: 0 } }) {
this.update(zoom)
}
}
}

View File

@@ -1,17 +1,14 @@
function Method(name,params,info = "Missing documentation",f)
{
this.name = name;
this.params = params;
this.info = info;
this.run = f;
function Method (name, params, info = 'Missing documentation', f) {
this.name = name
this.params = params
this.info = info
this.run = f
this.hint = function()
{
return "<b>"+this.name+"</b>:"+this.params+" ";
this.hint = function () {
return '<b>' + this.name + '</b>:' + this.params + ' '
}
this.docs = function()
{
return "<b>"+this.params+"</b> <i>"+this.info+"</i>";
this.docs = function () {
return '<b>' + this.params + '</b> <i>' + this.info + '</i>'
}
}
}

View File

@@ -1,19 +1,17 @@
function Module(name,docs = "Missing documentation.")
{
this.name = name;
this.methods = {};
function Module (name, docs = 'Missing documentation.') {
this.name = name
this.methods = {}
this.docs = docs;
this.docs = docs
this.hint = function()
{
var html = "";
this.hint = function () {
var html = ''
for(id in this.methods){
var v = this.methods[id];
html += v.hint();
for (id in this.methods) {
var v = this.methods[id]
html += v.hint()
}
return html.trim() != "" ? " "+html.trim() : "";
return html.trim() != '' ? ' ' + html.trim() : ''
}
}
}

View File

@@ -1,22 +1,20 @@
function Port(host,name,input,output,value,max,docs)
{
this.host = host;
function Port (host, name, input, output, value, max, docs) {
this.host = host
this.name = name;
this.input = input;
this.output = output;
this.value = value;
this.max = max;
this.docs = docs;
this.name = name
this.input = input
this.output = output
this.value = value
this.max = max
this.docs = docs
this.write = function(value)
{
this.value = value;
var target = this.host.routes[this.name];
this.write = function (value) {
this.value = value
var target = this.host.routes[this.name]
if(!this.output){ return; }
if(!target){ console.log("No output for",this.name); return; }
this.host.ports[target].write(this.value);
if (!this.output) { return }
if (!target) { console.log('No output for', this.name); return }
this.host.ports[target].write(this.value)
}
}
}

View File

@@ -1,113 +1,104 @@
function Query(query_str = "")
{
function Query (query_str = '') {
// Strip trailing variables
query_str = query_str.indexOf("&$+") > -1 ? query_str.replace("&$+","").trim() : query_str
query_str = query_str.indexOf('&$+') > -1 ? query_str.replace('&$+', '').trim() : query_str
this.string = query_str;
this.module = query_str.split(" ")[0];
var parts = query_str.split(" ").splice(1);
this.raw = parts.join(" ");
this.methods = {};
this.routes = {};
this.last = query_str.indexOf(" ") > -1 ? query_str.split(" ")[query_str.split(" ").length-1] : query_str;
this.last_char = query_str.trim().substr(query_str.trim().length-1,1);
this.string = query_str
this.module = query_str.split(' ')[0]
var parts = query_str.split(' ').splice(1)
this.raw = parts.join(' ')
this.methods = {}
this.routes = {}
this.last = query_str.indexOf(' ') > -1 ? query_str.split(' ')[query_str.split(' ').length - 1] : query_str
this.last_char = query_str.trim().substr(query_str.trim().length - 1, 1)
for(part_id in parts){
var part = parts[part_id];
for (part_id in parts) {
var part = parts[part_id]
// Method
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] = parse_parameters(value);
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] = parse_parameters(value)
}
// Port
else if(part.indexOf("->") > -1){
var key = part.indexOf("->") > -1 ? part.split("->")[0] : "any";
var value = part.indexOf("->") > -1 ? part.split("->")[1] : part;
this.routes[key] = value;
else if (part.indexOf('->') > -1) {
var key = part.indexOf('->') > -1 ? part.split('->')[0] : 'any'
var value = part.indexOf('->') > -1 ? part.split('->')[1] : part
this.routes[key] = value
}
}
function parse_parameters(param_str)
{
function parse_parameters (param_str) {
// Modifier
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);
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;
return param_str
}
function parse_modifier(mod_str)
{
var h = {};
function parse_modifier (mod_str) {
var h = {}
var parts = mod_str.split(">>");
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[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]);
if (parts[1].indexOf('&') > -1) {
h.to = parse_sequence(parts[1])
} else {
h.to = parse_unit(parts[1])
}
else{
h.to = parse_unit(parts[1]);
}
return h;
return h
}
function parse_sequence(seq_str)
{
var a = [];
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));
var parts = seq_str.split('&')
for (part_id in parts) {
var part = parts[part_id]
a.push(parse_unit(part))
}
return a;
return a
}
function parse_unit(unit_str)
{
function parse_unit (unit_str) {
// Arc
if(unit_str.indexOf("@") == 0 ){
unit_str = unit_str.substr(1,unit_str.length-1);
var clockwise = unit_str.indexOf(">") == 0 ? true : false;
unit_str = unit_str.substr(1,unit_str.length-1);
return {x:parseInt(unit_str.split(",")[0]),y:parseInt(unit_str.split(",")[1]),clockwise:clockwise};
if (unit_str.indexOf('@') == 0) {
unit_str = unit_str.substr(1, unit_str.length - 1)
var clockwise = unit_str.indexOf('>') == 0
unit_str = unit_str.substr(1, unit_str.length - 1)
return { x: parseInt(unit_str.split(',')[0]), y: parseInt(unit_str.split(',')[1]), clockwise: clockwise }
}
if(unit_str.indexOf(".") > -1 && unit_str.indexOf("/") > -1 ){
return unit_str;
if (unit_str.indexOf('.') > -1 && unit_str.indexOf('/') > -1) {
return unit_str
}
// Rect
if(unit_str.indexOf("|") > -1 && unit_str.indexOf(",") > -1 && unit_str.indexOf("x") > -1){
return Object.assign(parse_unit(unit_str.split("|")[0]), parse_unit(unit_str.split("|")[1]));
if (unit_str.indexOf('|') > -1 && unit_str.indexOf(',') > -1 && unit_str.indexOf('x') > -1) {
return Object.assign(parse_unit(unit_str.split('|')[0]), parse_unit(unit_str.split('|')[1]))
}
// Pos
if(unit_str.indexOf(",") > -1){
return {x:parseInt(unit_str.split(",")[0]),y:parseInt(unit_str.split(",")[1])};
if (unit_str.indexOf(',') > -1) {
return { x: parseInt(unit_str.split(',')[0]), y: parseInt(unit_str.split(',')[1]) }
}
// Size
if(unit_str.indexOf("x") > -1 && !isNaN(unit_str.split("x")[0]) && !isNaN(unit_str.split("x")[1])){
return {width:parseInt(unit_str.split("x")[0]),height:parseInt(unit_str.split("x")[1])};
if (unit_str.indexOf('x') > -1 && !isNaN(unit_str.split('x')[0]) && !isNaN(unit_str.split('x')[1])) {
return { width: parseInt(unit_str.split('x')[0]), height: parseInt(unit_str.split('x')[1]) }
}
// Float
if(unit_str.indexOf(".") > -1 ){
return parseFloat(unit_str);
if (unit_str.indexOf('.') > -1) {
return parseFloat(unit_str)
}
// Any
return unit_str;
return unit_str
}
}
}

View File

@@ -1,31 +1,25 @@
function Swatch()
{
this.index = 0;
this.colors = [];
this.start = function()
{
this.update();
}
this.update = function()
{
this.colors = [ronin.theme.active.f_high,ronin.theme.active.f_med,ronin.theme.active.f_low];
function Swatch () {
this.index = 0
this.colors = []
this.start = function () {
this.update()
}
this.swap = function()
{
this.index += 1;
this.update = function () {
this.colors = [ronin.theme.active.f_high, ronin.theme.active.f_med, ronin.theme.active.f_low]
}
this.color = function(offset = 0)
{
return this.colors[(this.index + offset) % this.colors.length];
this.swap = function () {
this.index += 1
}
this.hint = function()
{
this.update();
return `<svg width="20px" height="20px" xmlns="http://www.w3.org/2000/svg" baseProfile="full" version="1.1" id='swatch' style='background-color:${this.color(1)}'><circle cx='10' cy='10' r='${ronin.cursor.size * 0.75}' fill='${this.color()}'/></svg>`;
this.color = function (offset = 0) {
return this.colors[(this.index + offset) % this.colors.length]
}
}
this.hint = function () {
this.update()
return `<svg width="20px" height="20px" xmlns="http://www.w3.org/2000/svg" baseProfile="full" version="1.1" id='swatch' style='background-color:${this.color(1)}'><circle cx='10' cy='10' r='${ronin.cursor.size * 0.75}' fill='${this.color()}'/></svg>`
}
}