Starting to implement into Electron.
This commit is contained in:
149
sources/scripts/core/command.js
Normal file
149
sources/scripts/core/command.js
Normal file
@@ -0,0 +1,149 @@
|
||||
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(this.parts[0].indexOf(".") > -1){
|
||||
module_name = this.parts[0].split(" ")[0].split(".")[0]
|
||||
}
|
||||
else if(this.parts[0].indexOf(":") > -1){
|
||||
module_name = this.parts[0].split(" ")[0].split(":")[0]
|
||||
}
|
||||
else{
|
||||
module_name = this.parts[0].split(" ")[0];
|
||||
}
|
||||
return ronin.modules[module_name] ? ronin.modules[module_name] : null;
|
||||
}
|
||||
|
||||
this.method = function()
|
||||
{
|
||||
var module = this.module();
|
||||
if(!module || content.indexOf(".") < 0){ 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.setting = function()
|
||||
{
|
||||
var content = this.content;
|
||||
var module = this.module();
|
||||
|
||||
if(!module){ return null; }
|
||||
if(content.indexOf(":") < 0){ return null; }
|
||||
|
||||
var setting_name = this.parts[0].split(":")[1];
|
||||
return module.settings[setting_name] ? setting_name : null;
|
||||
}
|
||||
|
||||
this.values = function()
|
||||
{
|
||||
var a = this.content.split(" ");
|
||||
a.shift();
|
||||
return a.join(" ").trim();
|
||||
}
|
||||
|
||||
|
||||
this.inject_position = function(injection)
|
||||
{
|
||||
console.log("> "+injection);
|
||||
console.log("- "+content);
|
||||
}
|
||||
|
||||
// Parser
|
||||
|
||||
this.any = function()
|
||||
{
|
||||
return new Any(this.content);
|
||||
}
|
||||
|
||||
this.rect = function()
|
||||
{
|
||||
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.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.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.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.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.parts.length; i++) {
|
||||
if(this.parts[i].indexOf("..") >= 0){ return new Range(this.parts[i]); }
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
this.option = function(name)
|
||||
{
|
||||
for (i = 0; i < this.parts.length; i++) {
|
||||
if(this.parts[i].indexOf(name+"=") >= 0){ return new Option(this.parts[i]); }
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
this.bang = function()
|
||||
{
|
||||
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.parts.length; i++) {
|
||||
if(this.parts[i].indexOf("'") >= 0){ return new Angle(this.parts[i]); }
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
this.text = function()
|
||||
{
|
||||
var content_str = this.parts.join(" ");
|
||||
if(content_str.indexOf("\"") < 0){ return null; }
|
||||
return content_str.split("\"")[1];
|
||||
}
|
||||
}
|
||||
118
sources/scripts/core/keyboard.js
Normal file
118
sources/scripts/core/keyboard.js
Normal file
@@ -0,0 +1,118 @@
|
||||
function Keyboard()
|
||||
{
|
||||
this.shift_held = false;
|
||||
this.alt_held = false;
|
||||
|
||||
document.onkeyup = function myFunction(){ keyboard.listen_onkeyup(event); };
|
||||
document.onkeydown = function myFunction(){ keyboard.listen_onkeydown(event); };
|
||||
|
||||
this.listen_onkeydown = function(event)
|
||||
{
|
||||
if(event.shiftKey == true){
|
||||
this.shift_held = true;
|
||||
}
|
||||
if(event.altKey == true){
|
||||
this.alt_held = true;
|
||||
}
|
||||
|
||||
// Autocomplete with tab
|
||||
if(event.keyCode === 9){
|
||||
event.preventDefault();
|
||||
var ac = ronin.terminal.find_autocomplete();
|
||||
if(ac){
|
||||
ronin.terminal.input.value += ac;
|
||||
}
|
||||
}
|
||||
|
||||
ronin.cursor.update(event);
|
||||
ronin.widget.update();
|
||||
ronin.terminal.update();
|
||||
}
|
||||
|
||||
this.listen_onkeyup = function(event)
|
||||
{
|
||||
this.shift_held = false;
|
||||
this.alt_held = false;
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
switch (event.key || event.keyCode || event.which) {
|
||||
case "Enter": this.key_enter(); break;
|
||||
case "ArrowUp": this.key_arrow_up(); break;
|
||||
case "ArrowDown": this.key_arrow_down(); break;
|
||||
case "ArrowLeft": this.key_arrow_left(); break;
|
||||
case "ArrowRight": this.key_arrow_right(); break;
|
||||
case "]": ronin.brush.size_up(); break;
|
||||
case "[": ronin.brush.size_down(); break;
|
||||
case ":": this.key_colon(); break;
|
||||
case "Escape": this.key_escape(); break;
|
||||
case 13: this.key_enter(); break;
|
||||
case 186: if(event.shiftKey){this.key_colon();} break;
|
||||
case 27: this.key_escape(); break;
|
||||
case 219: ronin.brush.size_up(); break;
|
||||
case 221: ronin.brush.size_down(); break;
|
||||
case 38: this.key_arrow_up(); break;
|
||||
case 40: this.key_arrow_down(); break;
|
||||
case 8: this.key_delete(); break;
|
||||
}
|
||||
|
||||
console.log(event)
|
||||
|
||||
// Passive
|
||||
ronin.widget.update();
|
||||
ronin.terminal.update();
|
||||
ronin.cursor.update();
|
||||
};
|
||||
|
||||
this.key_tab = function()
|
||||
{
|
||||
}
|
||||
|
||||
this.key_enter = function()
|
||||
{
|
||||
ronin.terminal.run();
|
||||
}
|
||||
|
||||
this.key_space = function()
|
||||
{
|
||||
}
|
||||
|
||||
this.key_arrow_up = function()
|
||||
{
|
||||
ronin.frame.select_layer(ronin.frame.layer_above());
|
||||
}
|
||||
|
||||
this.key_arrow_down = function()
|
||||
{
|
||||
ronin.frame.select_layer(ronin.frame.layer_below());
|
||||
}
|
||||
|
||||
this.key_arrow_left = function()
|
||||
{
|
||||
if(ronin.module){ ronin.module.key_arrow_left(); }
|
||||
}
|
||||
|
||||
this.key_arrow_right = function()
|
||||
{
|
||||
if(ronin.module){ ronin.module.key_arrow_right(); }
|
||||
}
|
||||
|
||||
this.key_colon = function()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this.key_escape = function()
|
||||
{
|
||||
ronin.overlay.key_escape();
|
||||
|
||||
for(var key in ronin.modules){
|
||||
ronin.modules[key].key_escape();
|
||||
}
|
||||
}
|
||||
|
||||
this.key_delete = function()
|
||||
{
|
||||
if(ronin.module){ ronin.module.key_delete(); }
|
||||
}
|
||||
}
|
||||
174
sources/scripts/core/ronin.js
Normal file
174
sources/scripts/core/ronin.js
Normal file
@@ -0,0 +1,174 @@
|
||||
function Ronin()
|
||||
{
|
||||
this.modules = {};
|
||||
this.element = document.getElementById('ronin');
|
||||
|
||||
this.default = new Default("`");
|
||||
|
||||
this.frame = new Frame("@");
|
||||
this.path = new Path("+");
|
||||
this.type = new Type("&");
|
||||
this.brush = new Brush("-");
|
||||
|
||||
this.source = new Source("$");
|
||||
|
||||
this.eye = new Eye("*");
|
||||
this.render = new Render("%");
|
||||
this.magnet = new Magnet("^");
|
||||
|
||||
this.overlay = new Overlay("|");
|
||||
this.terminal = new Terminal(">");
|
||||
this.cursor = new Cursor(".");
|
||||
this.widget = new Widget("?");
|
||||
|
||||
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.name] = this.brush;
|
||||
|
||||
this.modules[this.source.name] = this.source;
|
||||
this.modules[this.render.name] = this.render;
|
||||
this.modules[this.eye.name] = this.eye;
|
||||
this.modules[this.magnet.name] = this.magnet;
|
||||
|
||||
this.modules[this.cursor.name] = this.cursor;
|
||||
this.modules[this.terminal.name] = this.terminal;
|
||||
|
||||
// document.addEventListener('contextmenu', function(ev){ ev.preventDefault(); return false;}, false);
|
||||
window.addEventListener('resize', function(){ ronin.on_resize(); }, true);
|
||||
|
||||
this.install = function()
|
||||
{
|
||||
ronin.frame.element = document.getElementById('frame');
|
||||
ronin.cursor.element = document.getElementById('cursor');
|
||||
ronin.terminal.element = document.getElementById('terminal');
|
||||
|
||||
for(var key in this.modules){
|
||||
this.modules[key].install();
|
||||
}
|
||||
|
||||
this.widget.install();
|
||||
ronin.cursor.mode = ronin.brush;
|
||||
this.on_drag();
|
||||
}
|
||||
|
||||
this.start = function(hash = null)
|
||||
{
|
||||
var target_file = hash.length > 2 ? hash.substr(1,hash.length-1)+".rin" : "default.rin"
|
||||
|
||||
ronin.terminal.update();
|
||||
ronin.widget.update();
|
||||
ronin.terminal.input.focus();
|
||||
ronin.load(target_file);
|
||||
}
|
||||
|
||||
this.hint = function(method)
|
||||
{
|
||||
var html = "";
|
||||
if(this.terminal.input.value){
|
||||
for(id in ronin.modules){
|
||||
if(this.terminal.input.value != ronin.modules[id].name.substr(0,this.terminal.input.value.length)){ continue; }
|
||||
html += "<span class='module'>"+ronin.modules[id].name+"</span> ";
|
||||
}
|
||||
}
|
||||
else{
|
||||
for(id in ronin.modules){
|
||||
html += "<span class='module'>"+ronin.modules[id].name+"</span> ";
|
||||
}
|
||||
}
|
||||
return html;
|
||||
}
|
||||
|
||||
this.cursors = [];
|
||||
|
||||
this.position_in_canvas = function(e)
|
||||
{
|
||||
// x -= parseInt(this.frame.element.style.left) - parseInt(this.frame.element.style.width/2);
|
||||
var x = e.clientX - parseInt(this.frame.element.style.left);
|
||||
var y = e.clientY - parseInt(this.frame.element.style.top);
|
||||
return new Position(x,y);
|
||||
}
|
||||
|
||||
this.timestamp = function()
|
||||
{
|
||||
var currentdate = new Date();
|
||||
var date = currentdate.getFullYear()+""+(currentdate.getMonth()+1)+""+currentdate.getDate();
|
||||
return date+" "+currentdate.getHours()+":"+currentdate.getMinutes()+":"+currentdate.getSeconds();
|
||||
}
|
||||
|
||||
this.on_resize = function()
|
||||
{
|
||||
ronin.frame.center();
|
||||
}
|
||||
|
||||
this.on_drag = function()
|
||||
{
|
||||
// Position Background
|
||||
var bg_offset_parts = ronin.element.style.backgroundPosition == "" ? [0,0] : ronin.element.style.backgroundPosition.split(" ");
|
||||
|
||||
var x = parseInt(ronin.frame.element.style.left)/4;
|
||||
var y = parseInt(ronin.frame.element.style.top)/4;
|
||||
|
||||
ronin.element.style.backgroundPosition = x+"px "+y+"px";
|
||||
}
|
||||
|
||||
this.filename = "default.rin";
|
||||
|
||||
this.load = function readTextFile(name)
|
||||
{
|
||||
this.filename = name;
|
||||
var file = "presets/"+name+'?'+new Date().getTime();
|
||||
var rawFile = new XMLHttpRequest();
|
||||
rawFile.open("GET", file, false);
|
||||
rawFile.onreadystatechange = function ()
|
||||
{
|
||||
if(rawFile.readyState === 4)
|
||||
{
|
||||
if(rawFile.status === 200 || rawFile.status == 0)
|
||||
{
|
||||
var allText = rawFile.responseText;
|
||||
ronin.terminal.log(new Log(null,"Loaded file "+name));
|
||||
ronin.terminal.run_multi(allText.split("\n").join(";"));
|
||||
}
|
||||
}
|
||||
}
|
||||
rawFile.send(null);
|
||||
ronin.widget.update();
|
||||
ronin.terminal.update();
|
||||
}
|
||||
|
||||
// Drag file on canvas
|
||||
|
||||
this.element.addEventListener('dragover',function(e)
|
||||
{
|
||||
e.stopPropagation(); e.preventDefault(); e.dataTransfer.dropEffect = 'copy';
|
||||
});
|
||||
|
||||
this.element.addEventListener('drop', function(e)
|
||||
{
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
var files = e.dataTransfer.files;
|
||||
var file = files[0];
|
||||
|
||||
if (!file.type.match(/image.*/)) { console.log("Not image"); return false; }
|
||||
|
||||
var reader = new FileReader();
|
||||
|
||||
reader.onload = function(event)
|
||||
{
|
||||
base_image = new Image();
|
||||
base_image.src = event.target.result;
|
||||
|
||||
var width = base_image.naturalWidth;
|
||||
var height = base_image.naturalHeight;
|
||||
|
||||
// Display as large as the canvas
|
||||
var ratio = ronin.frame.size.width/width;
|
||||
ronin.frame.active_layer.context().drawImage(base_image, 0,0,width * ratio,height * ratio);
|
||||
}
|
||||
reader.readAsDataURL(file);
|
||||
});
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user