Progress toward Ronin source files.
This commit is contained in:
90
scripts/core/command.js
Normal file
90
scripts/core/command.js
Normal file
@@ -0,0 +1,90 @@
|
||||
function Command(content)
|
||||
{
|
||||
this.content = content;
|
||||
|
||||
// Parser
|
||||
|
||||
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]); }
|
||||
}
|
||||
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]); }
|
||||
}
|
||||
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]); }
|
||||
}
|
||||
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]); }
|
||||
}
|
||||
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]); }
|
||||
}
|
||||
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]); }
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
this.bang = function()
|
||||
{
|
||||
for (i = 0; i < this.content.length; i++) {
|
||||
if(this.content[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]); }
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
this.variable = function(name)
|
||||
{
|
||||
for (i = 0; i < this.content.length; i++) {
|
||||
if(this.content[i].indexOf("=") >= 0){
|
||||
var parts = this.content[i].split("=");
|
||||
if(parts[0] == name){
|
||||
return new Variable(parts[0],parts[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
80
scripts/core/commander.js
Normal file
80
scripts/core/commander.js
Normal file
@@ -0,0 +1,80 @@
|
||||
function Commander(element,element_input)
|
||||
{
|
||||
this.element = element;
|
||||
this.element_input = element_input;
|
||||
this.cmd = null;
|
||||
this.storage = [];
|
||||
this.storage_index = 0;
|
||||
this.always_show = false;
|
||||
|
||||
this.show = function()
|
||||
{
|
||||
this.element.setAttribute('class','visible');
|
||||
this.element_input.focus();
|
||||
}
|
||||
|
||||
this.always = function() {
|
||||
this.always_show = !this.always_show;
|
||||
}
|
||||
|
||||
this.hide = function()
|
||||
{
|
||||
if (!this.always_show) {
|
||||
this.element.setAttribute('class','hidden');
|
||||
}
|
||||
this.element_input.value = "";
|
||||
}
|
||||
|
||||
this.clear = function()
|
||||
{
|
||||
this.element_input.value = "";
|
||||
}
|
||||
|
||||
this.next_cmd = function()
|
||||
{
|
||||
this.storage_index += this.storage_index < this.storage.length ? 1 : 0;
|
||||
this.element_input.value = this.storage[this.storage_index] ? this.storage[this.storage_index] : "";
|
||||
}
|
||||
|
||||
this.prev_cmd = function()
|
||||
{
|
||||
this.storage_index -= this.storage_index < 1 ? 0 : 1;
|
||||
this.element_input.value = this.storage[this.storage_index];
|
||||
}
|
||||
|
||||
this.active = function(content)
|
||||
{
|
||||
this.storage.push(content.join(" "));
|
||||
this.storage_index = this.storage.length;
|
||||
|
||||
var key = content[0][0];
|
||||
content[0] = content[0].slice(1);
|
||||
var cmd = new Command(content);
|
||||
|
||||
if(ronin.modules[key]){
|
||||
ronin.modules[key].active(this.cmd);
|
||||
}
|
||||
|
||||
switch(key) {
|
||||
case "~":
|
||||
this.always();
|
||||
break;
|
||||
}
|
||||
this.hide();
|
||||
|
||||
ronin.history.add(content.join(" "));
|
||||
}
|
||||
|
||||
this.passive = function(content)
|
||||
{
|
||||
var key = content[0][0];
|
||||
content[0] = content[0].slice(1);
|
||||
this.cmd = new Command(content);
|
||||
ronin.module = null;
|
||||
|
||||
if(ronin.modules[key]){
|
||||
ronin.modules[key].passive(this.cmd);
|
||||
ronin.module = ronin.modules[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
39
scripts/core/cursor.js
Normal file
39
scripts/core/cursor.js
Normal file
@@ -0,0 +1,39 @@
|
||||
function Cursor()
|
||||
{
|
||||
this.mode = new Mode_Paint();
|
||||
this.position = new Position();
|
||||
|
||||
this.update = function(event)
|
||||
{
|
||||
// if(event.ctrlKey === true){ this.set_mode(new Mode_Guide()); }
|
||||
// else if(event.altKey === true){ this.set_mode(new Mode_Drag()); }
|
||||
// else if(event.shiftKey === true){ this.set_mode(new Mode_Paint()); }
|
||||
// else{ this.set_mode(new Mode_Paint()); }
|
||||
}
|
||||
|
||||
this.set_mode = function(mode)
|
||||
{
|
||||
if(this.mode.name == mode.name){ return; }
|
||||
this.mode = mode;
|
||||
document.body.setAttribute("class",this.mode.name);
|
||||
ronin.widget.update();
|
||||
}
|
||||
|
||||
this.mouse_down = function(position)
|
||||
{
|
||||
this.position = position;
|
||||
this.mode.mouse_down(position);
|
||||
}
|
||||
|
||||
this.mouse_move = function(position)
|
||||
{
|
||||
this.position = position;
|
||||
this.mode.mouse_move(position);
|
||||
}
|
||||
|
||||
this.mouse_up = function(position)
|
||||
{
|
||||
this.position = position;
|
||||
this.mode.mouse_up(position);
|
||||
}
|
||||
}
|
||||
44
scripts/core/hint.js
Normal file
44
scripts/core/hint.js
Normal file
@@ -0,0 +1,44 @@
|
||||
function Hint(element)
|
||||
{
|
||||
Module.call(this);
|
||||
|
||||
this.element = element;
|
||||
|
||||
this.update = function()
|
||||
{
|
||||
if(ronin.module){
|
||||
this.element.innerHTML = this.message(ronin.module,commander.cmd);
|
||||
this.element.style.display = "block";
|
||||
}
|
||||
else{
|
||||
this.element.innerHTML = this.default();
|
||||
this.element.style.display = "block";
|
||||
}
|
||||
}
|
||||
|
||||
this.message = function(module,cmd)
|
||||
{
|
||||
var s = "<span class='module'>"+module.constructor.name+"</span>";
|
||||
|
||||
var e = 0;
|
||||
while(e < 10){
|
||||
if(!module.parameters[e]){ break; }
|
||||
var param_name = module.parameters[e].name;
|
||||
s += cmd[param_name.toLowerCase()]() ? "<span class='value'>"+cmd[param_name.toLowerCase()]().render()+"</span>" : "<span class='param'>"+param_name+"</span>";
|
||||
e += 1;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
this.default = function()
|
||||
{
|
||||
var s = "<span class='module'>Modules</span>";
|
||||
|
||||
for (var key in ronin.modules){
|
||||
s += "<span class='param'>"+ronin.modules[key].constructor.name+"<span> <span class='value'>"+key+"</span> ";
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
27
scripts/core/init.js
Normal file
27
scripts/core/init.js
Normal file
@@ -0,0 +1,27 @@
|
||||
var ronin = new Ronin();
|
||||
ronin.canvas.element = document.getElementById('workspace');
|
||||
ronin.overlay.element = document.getElementById('overlay');
|
||||
ronin.hint.element = document.getElementById('commander_hint');
|
||||
ronin.surface = document.getElementById('surface');
|
||||
ronin.widget.element = document.getElementById('widget');
|
||||
|
||||
var commander = new Commander(document.getElementById("commander"),document.getElementById("commander_input"));
|
||||
|
||||
// Cursor
|
||||
document.addEventListener('mousedown', function(e){ ronin.cursor.mouse_down(ronin.position_in_canvas(e));}, false);
|
||||
document.addEventListener('mousemove', function(e){ ronin.cursor.mouse_move(ronin.position_in_canvas(e));}, false);
|
||||
document.addEventListener('mouseup', function(e){ ronin.cursor.mouse_up(ronin.position_in_canvas(e));}, false);
|
||||
document.addEventListener('contextmenu', function(ev){ ev.preventDefault(); return false;}, false);
|
||||
|
||||
// Keyboard
|
||||
var keyboard = new Keyboard();
|
||||
document.onkeyup = function myFunction(){ keyboard.listen_onkeyup(event); };
|
||||
document.onkeydown = function myFunction(){ keyboard.listen_onkeydown(event); };
|
||||
|
||||
// Canvas
|
||||
var starting_canvas = new Rect();
|
||||
starting_canvas.width = window.innerWidth - 200;
|
||||
starting_canvas.height = window.innerHeight - 200;
|
||||
|
||||
ronin.canvas.resize(starting_canvas);
|
||||
ronin.overlay.resize(starting_canvas);
|
||||
122
scripts/core/keyboard.js
Normal file
122
scripts/core/keyboard.js
Normal file
@@ -0,0 +1,122 @@
|
||||
function Keyboard()
|
||||
{
|
||||
this.is_locked = false;
|
||||
|
||||
this.cmd = function()
|
||||
{
|
||||
var val = commander.element_input.value;
|
||||
|
||||
if(val.indexOf(";") > 0){
|
||||
var cmds = val.split(";");
|
||||
var vals = [];
|
||||
for (i = 0; i < cmds.length; i++) {
|
||||
val = cmds[i].replace(/^\s+|\s+$/g, '');
|
||||
vals.push(val.split(" "));
|
||||
}
|
||||
return vals;
|
||||
}
|
||||
else{
|
||||
return [val.split(" ")];
|
||||
}
|
||||
}
|
||||
|
||||
this.lock = function()
|
||||
{
|
||||
this.is_locked = true;
|
||||
interface.actions_panel.style.color = "red";
|
||||
}
|
||||
|
||||
this.unlock = function()
|
||||
{
|
||||
this.is_locked = false;
|
||||
interface.actions_panel.style.color = "black";
|
||||
}
|
||||
|
||||
this.listen_onkeyup = function(event)
|
||||
{
|
||||
if(this.is_locked === true){ return; }
|
||||
|
||||
if(event.keyCode == 9) this.key_tab();
|
||||
switch (event.key) {
|
||||
case "Enter": this.key_enter(); break;
|
||||
case " " : this.key_space(); 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 ":": this.key_colon(); break;
|
||||
//not sure if this one needed anymore
|
||||
case ";": if (event.shiftKey) this.key_colon(); break;
|
||||
case "Escape": this.key_escape(); break;
|
||||
}
|
||||
|
||||
// Passive
|
||||
var cmd = commander.element_input.value;
|
||||
commander.passive(cmd.split(" "));
|
||||
ronin.hint.update();
|
||||
|
||||
ronin.cursor.set_mode(new Mode_Paint());
|
||||
ronin.widget.update();
|
||||
};
|
||||
|
||||
this.listen_onkeydown = function(event)
|
||||
{
|
||||
ronin.cursor.update(event);
|
||||
}
|
||||
|
||||
this.key_tab = function()
|
||||
{
|
||||
}
|
||||
|
||||
this.key_enter = function()
|
||||
{
|
||||
var cmd = commander.element_input.value;
|
||||
|
||||
if(cmd.indexOf(";") > 0){
|
||||
var multi = cmd.split(";");
|
||||
var i = 0;
|
||||
while(i < 100){
|
||||
if(multi[i]){commander.active(multi[i].split(" "));}
|
||||
else{ break; }
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
else{
|
||||
commander.active(cmd.split(" "));
|
||||
}
|
||||
}
|
||||
|
||||
this.key_space = function()
|
||||
{
|
||||
}
|
||||
|
||||
this.key_arrow_up = function()
|
||||
{
|
||||
commander.prev_cmd();
|
||||
}
|
||||
|
||||
this.key_arrow_down = function()
|
||||
{
|
||||
commander.next_cmd();
|
||||
}
|
||||
|
||||
this.key_arrow_left = function()
|
||||
{
|
||||
}
|
||||
|
||||
this.key_arrow_right = function()
|
||||
{
|
||||
}
|
||||
|
||||
this.key_colon = function()
|
||||
{
|
||||
commander.show();
|
||||
return false;
|
||||
}
|
||||
|
||||
this.key_escape = function()
|
||||
{
|
||||
commander.hide();
|
||||
ronin.overlay.clear();
|
||||
}
|
||||
}
|
||||
39
scripts/core/ronin.js
Normal file
39
scripts/core/ronin.js
Normal file
@@ -0,0 +1,39 @@
|
||||
function Ronin()
|
||||
{
|
||||
this.modules = {};
|
||||
|
||||
this.hint = new Hint();
|
||||
this.widget = new Widget();
|
||||
this.surface = null;
|
||||
|
||||
this.canvas = new Canvas("@");
|
||||
this.overlay = new Overlay("|");
|
||||
this.brush = new Brush(">");
|
||||
this.fileload = new FileLoad("/");
|
||||
this.filesave = new FileSave("$");
|
||||
this.filter = new Filter("%");
|
||||
this.stroke = new Stroke("_");
|
||||
this.vector = new Vector("+");
|
||||
this.help = new Help("?");
|
||||
this.history = new History(";");
|
||||
|
||||
this.cursor = new Cursor();
|
||||
|
||||
this.modules[this.canvas.rune] = this.canvas;
|
||||
this.modules[this.overlay.rune] = this.overlay;
|
||||
this.modules[this.brush.rune] = this.brush;
|
||||
this.modules[this.fileload.rune] = this.fileload;
|
||||
this.modules[this.filesave.rune] = this.filesave;
|
||||
this.modules[this.filter.rune] = this.filter;
|
||||
this.modules[this.stroke.rune] = this.stroke;
|
||||
this.modules[this.vector.rune] = this.vector;
|
||||
this.modules[this.help.rune] = this.help;
|
||||
this.modules[this.history.rune] = this.history;
|
||||
|
||||
this.cursors = [];
|
||||
|
||||
this.position_in_canvas = function(e)
|
||||
{
|
||||
return new Position(e.clientX - parseFloat(ronin.surface.style.left) - parseFloat(ronin.canvas.element.style.left),e.clientY- parseFloat(ronin.surface.style.top) - parseFloat(ronin.canvas.element.style.top));
|
||||
}
|
||||
}
|
||||
17
scripts/core/widget.js
Normal file
17
scripts/core/widget.js
Normal file
@@ -0,0 +1,17 @@
|
||||
function Widget()
|
||||
{
|
||||
this.element = null;
|
||||
|
||||
this.update = function()
|
||||
{
|
||||
var s = "";
|
||||
|
||||
for (var key in ronin.modules){
|
||||
s += ronin.modules[key].widget();
|
||||
}
|
||||
|
||||
s += "<span class='cursor'>"+ronin.cursor.mode.widget()+"</span>";
|
||||
|
||||
this.element.innerHTML = s;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user