Started to clean up and migrate units.
This commit is contained in:
parent
f42bd9cbaf
commit
288c26a11e
@ -1,8 +1,14 @@
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" type="text/css" href="links/main.css"/>
|
||||
|
||||
<script type="text/javascript" src="scripts/unit.rect.js"></script>
|
||||
|
||||
<script type="text/javascript" src="scripts/ronin.module.js"></script>
|
||||
<script type="text/javascript" src="scripts/ronin.canvas.js"></script>
|
||||
<script type="text/javascript" src="scripts/ronin.overlay.js"></script>
|
||||
|
||||
<script type="text/javascript" src="scripts/position.js"></script>
|
||||
<script type="text/javascript" src="scripts/rect.js"></script>
|
||||
<script type="text/javascript" src="scripts/color.js"></script>
|
||||
<script type="text/javascript" src="scripts/pointer.js"></script>
|
||||
<script type="text/javascript" src="scripts/brush.js"></script>
|
||||
|
@ -15,9 +15,53 @@ function Commander(element,element_input)
|
||||
this.element_input.value = "";
|
||||
}
|
||||
|
||||
this.validate = function(command)
|
||||
this.active = function(command)
|
||||
{
|
||||
var parts = command;
|
||||
var key = parts[0];
|
||||
parts.shift();
|
||||
var params = parts;
|
||||
|
||||
switch(key) {
|
||||
case "@":
|
||||
ronin.canvas.active(params);
|
||||
break;
|
||||
case "~":
|
||||
ronin.history.active(params);
|
||||
break;
|
||||
case "$":
|
||||
ronin.save.active(params);
|
||||
break;
|
||||
case "/":
|
||||
ronin.load.active(params);
|
||||
break;
|
||||
case "&":
|
||||
ronin.brush.active(params);
|
||||
break;
|
||||
case ">":
|
||||
ronin.pointer.active(params);
|
||||
break;
|
||||
case "|":
|
||||
ronin.guide.active(params);
|
||||
break;
|
||||
case "^":
|
||||
ronin.translate.active(params);
|
||||
break;
|
||||
case "=":
|
||||
ronin.zoom.active(params);
|
||||
break;
|
||||
case "#":
|
||||
ronin.layers.active(params);
|
||||
break;
|
||||
case ":":
|
||||
ronin.filter.active(params);
|
||||
break;
|
||||
}
|
||||
|
||||
this.hide();
|
||||
|
||||
/*
|
||||
var parts = command;
|
||||
|
||||
// Canvas
|
||||
if(parts[0] == "@"){
|
||||
@ -63,13 +107,51 @@ function Commander(element,element_input)
|
||||
parts.shift();
|
||||
ronin.add_guide(parts);
|
||||
}
|
||||
this.hide();
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
this.passive = function()
|
||||
this.passive = function(command)
|
||||
{
|
||||
var parts = this.element_input.value.split(" ");
|
||||
var parts = command;
|
||||
var key = parts[0];
|
||||
parts.shift();
|
||||
var params = parts;
|
||||
|
||||
switch(key) {
|
||||
case "@":
|
||||
ronin.canvas.passive(params);
|
||||
break;
|
||||
case "~":
|
||||
ronin.history.passive(params);
|
||||
break;
|
||||
case "/":
|
||||
ronin.load.passive(params);
|
||||
break;
|
||||
case "&":
|
||||
ronin.brush.passive(params);
|
||||
break;
|
||||
case ">":
|
||||
ronin.pointer.passive(params);
|
||||
break;
|
||||
case "|":
|
||||
ronin.guide.passive(params);
|
||||
break;
|
||||
case "^":
|
||||
ronin.translate.passive(params);
|
||||
break;
|
||||
case "=":
|
||||
ronin.zoom.passive(params);
|
||||
break;
|
||||
case "#":
|
||||
ronin.layers.passive(params);
|
||||
break;
|
||||
case ":":
|
||||
ronin.filter.passive(params);
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
// Guides
|
||||
if(parts[0] == "|"){
|
||||
parts.shift();
|
||||
@ -82,5 +164,6 @@ function Commander(element,element_input)
|
||||
parts.shift();
|
||||
ronin.guide(parts);
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
@ -1,7 +1,25 @@
|
||||
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;
|
||||
@ -31,7 +49,19 @@ function Keyboard()
|
||||
case 27: this.key_escape(); break;
|
||||
}
|
||||
|
||||
commander.passive();
|
||||
// Passive
|
||||
var cmd = commander.element_input.value;
|
||||
|
||||
if(cmd.indexOf(";") > 0){
|
||||
var cmds = cmd.split(";");
|
||||
for (i = 0; i < cmds.length; i++) {
|
||||
cmd = cmds[i].replace(/^\s+|\s+$/g, '');
|
||||
commander.passive(cmd.split(" "));
|
||||
}
|
||||
}
|
||||
else{
|
||||
commander.passive(cmd.split(" "));
|
||||
}
|
||||
};
|
||||
|
||||
this.key_tab = function()
|
||||
@ -47,11 +77,11 @@ function Keyboard()
|
||||
var cmds = cmd.split(";");
|
||||
for (i = 0; i < cmds.length; i++) {
|
||||
cmd = cmds[i].replace(/^\s+|\s+$/g, '');
|
||||
commander.validate(cmd.split(" "));
|
||||
commander.active(cmd.split(" "));
|
||||
}
|
||||
}
|
||||
else{
|
||||
commander.validate(cmd.split(" "));
|
||||
commander.active(cmd.split(" "));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,26 @@
|
||||
var canvas = document.getElementById('myCanvas');
|
||||
var context = canvas.getContext('2d');
|
||||
|
||||
var ronin = new Ronin();
|
||||
ronin.canvas.element = canvas;
|
||||
ronin.overlay.element = canvas;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ronin.element = document.getElementById('ronin');
|
||||
ronin.guides_element = document.getElementById('guides');
|
||||
ronin.guides_context = ronin.guides_element.getContext('2d');
|
||||
|
||||
var canvas = document.getElementById('myCanvas');
|
||||
var context = canvas.getContext('2d');
|
||||
|
||||
var brush = new Brush();
|
||||
|
||||
|
||||
|
||||
|
||||
var commander = new Commander(document.getElementById("commander"),document.getElementById("commander_input"));
|
||||
|
||||
document.addEventListener('mousemove', function(e) {
|
||||
|
@ -1,5 +0,0 @@
|
||||
function Rect(w = 0,h = 0)
|
||||
{
|
||||
this.w = parseFloat(w);
|
||||
this.h = parseFloat(h);
|
||||
}
|
33
scripts/ronin.canvas.js
Normal file
33
scripts/ronin.canvas.js
Normal file
@ -0,0 +1,33 @@
|
||||
function Canvas(element)
|
||||
{
|
||||
Module.call(this);
|
||||
|
||||
this.element = element;
|
||||
|
||||
this.active = function(p)
|
||||
{
|
||||
if(p[0].indexOf("x") >= 0){
|
||||
var rect = new Rect(p[0]);
|
||||
this.resize(rect);
|
||||
ronin.overlay.resize(rect);
|
||||
}
|
||||
|
||||
if(p.length > 1 && p[1].indexOf("#") >= 0){
|
||||
var color = new Color(p[1]);
|
||||
console.log("TODO: Fill with color");
|
||||
}
|
||||
}
|
||||
|
||||
this.passive = function(p)
|
||||
{
|
||||
console.log("TODO: Show guide");
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
this.resize = function(rect)
|
||||
{
|
||||
this.element.setAttribute('width',rect.width+"px");
|
||||
this.element.setAttribute('height',rect.height+"px");
|
||||
}
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
function Ronin()
|
||||
{
|
||||
this.element = null;
|
||||
this.canvas = new Canvas();
|
||||
this.overlay = new Overlay();
|
||||
|
||||
this.load_image = function(p)
|
||||
{
|
||||
|
12
scripts/ronin.module.js
Normal file
12
scripts/ronin.module.js
Normal file
@ -0,0 +1,12 @@
|
||||
function Module()
|
||||
{
|
||||
this.active = function()
|
||||
{
|
||||
console.log("Nothing to do.");
|
||||
}
|
||||
|
||||
this.passive = function()
|
||||
{
|
||||
console.log("Nothing to do.");
|
||||
}
|
||||
}
|
12
scripts/ronin.overlay.js
Normal file
12
scripts/ronin.overlay.js
Normal file
@ -0,0 +1,12 @@
|
||||
function Overlay(element)
|
||||
{
|
||||
Module.call(this);
|
||||
|
||||
this.element = element;
|
||||
|
||||
this.resize = function(rect)
|
||||
{
|
||||
this.element.setAttribute('width',rect.width+"px");
|
||||
this.element.setAttribute('height',rect.height+"px");
|
||||
}
|
||||
}
|
7
scripts/unit.rect.js
Normal file
7
scripts/unit.rect.js
Normal file
@ -0,0 +1,7 @@
|
||||
function Rect(rect_str)
|
||||
{
|
||||
this.rect_str = rect_str;
|
||||
|
||||
this.width = parseFloat(this.rect_str.split("x")[0]);
|
||||
this.height = parseFloat(this.rect_str.split("x")[1]);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user