Started to implement methods
This commit is contained in:
parent
e6f7f62d0b
commit
3f17f37458
@ -93,4 +93,15 @@ function Command(content)
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
this.methods = function()
|
||||
{
|
||||
var a = [];
|
||||
for(i in this.content){
|
||||
if(this.content[i].indexOf(":") > 0){
|
||||
a.push(this.content[i]);
|
||||
}
|
||||
}
|
||||
return a;
|
||||
}
|
||||
}
|
@ -32,14 +32,10 @@ starting_canvas.width = parseInt(starting_canvas.width/40) * 40;
|
||||
starting_canvas.height = parseInt(starting_canvas.height/40) * 40;
|
||||
|
||||
ronin.terminal.query("~ "+ronin.timestamp());
|
||||
ronin.terminal.query("@ size="+starting_canvas.render());
|
||||
ronin.terminal.query("@ layer=Main");
|
||||
ronin.terminal.query("@ resize:"+starting_canvas.render());
|
||||
ronin.terminal.query("@ select:Main");
|
||||
ronin.terminal.query("- color=#ff0000");
|
||||
// ronin.terminal.query("# fill=#ff0000");
|
||||
// ronin.terminal.query("- 0,0");
|
||||
// ronin.terminal.query("- 1,1");
|
||||
// ronin.terminal.query("- 2,2");
|
||||
|
||||
ronin.terminal.query("# fill=#ff0000");
|
||||
ronin.terminal.query("~ Ready.");
|
||||
|
||||
ronin.terminal.input_element.focus();
|
||||
|
@ -54,6 +54,8 @@ function Magnet(rune)
|
||||
|
||||
this.draw_helper = function(position)
|
||||
{
|
||||
if(this.settings["grid"].width < 5 || this.settings["grid"].height < 5){ return; }
|
||||
|
||||
var magnetized = this.magnetic_position(position);
|
||||
this.context().beginPath();
|
||||
this.context().arc(magnetized.x, magnetized.y, 4, 0, 2 * Math.PI, false);
|
||||
@ -62,7 +64,6 @@ function Magnet(rune)
|
||||
this.context().closePath();
|
||||
}
|
||||
|
||||
|
||||
this.draw_marker = function(position,size = 0.5)
|
||||
{
|
||||
this.context().beginPath();
|
||||
|
@ -45,17 +45,34 @@ function Module(rune)
|
||||
}
|
||||
ronin.terminal.log(new Log(this,"Unknown setting: "+key));
|
||||
}
|
||||
|
||||
this.run_methods = function(cmd)
|
||||
{
|
||||
var methods = cmd.methods();
|
||||
for(i in methods){
|
||||
var content = methods[i].split(":");
|
||||
var name = content.shift();
|
||||
var params = content;
|
||||
if(this[name]){
|
||||
this[name](params);
|
||||
}
|
||||
else{
|
||||
ronin.terminal.log(new Log(this,name+" is not a method of "+this.constructor.name,"error"));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
this.hint = function(content)
|
||||
{
|
||||
var h = "<b>"+ronin.module.constructor.name+"</b> ";
|
||||
|
||||
for(setting in ronin.module.settings){
|
||||
h += setting+"="+ronin.module.settings[setting].render()+" ";
|
||||
}
|
||||
for(method in ronin.module.methods){
|
||||
h += ronin.module.methods[method].render()+" ";
|
||||
}
|
||||
for(setting in ronin.module.settings){
|
||||
h += setting+"="+ronin.module.settings[setting].render()+" ";
|
||||
}
|
||||
|
||||
h += ronin.module.mouse_mode() ? "<i>"+ronin.module.mouse_mode()+"</i>" : "";
|
||||
|
||||
|
@ -4,7 +4,7 @@ function Surface(rune)
|
||||
|
||||
this.element = null;
|
||||
this.settings = {"size":new Rect("200x200")};
|
||||
this.methods = {"layer":new Method("layer",["name"])}
|
||||
this.methods = [new Method("resize",[new Rect().name])]
|
||||
|
||||
this.layers = {};
|
||||
this.active_layer = null;
|
||||
@ -26,23 +26,11 @@ function Surface(rune)
|
||||
setTimeout(function(){ ronin.surface.blink(); }, 30);
|
||||
}
|
||||
|
||||
this.active = function(cmd)
|
||||
this.resize = function(params)
|
||||
{
|
||||
if(cmd.setting("size")){
|
||||
this.resize(this.settings["size"],cmd.position());
|
||||
}
|
||||
var rect = new Rect(params[0]);
|
||||
this.settings["size"] = rect;
|
||||
|
||||
if(cmd.setting("layer")){
|
||||
var name = cmd.setting("layer").value;
|
||||
if(!this.layers[name]){
|
||||
this.add_layer(new Layer(name));
|
||||
}
|
||||
this.select_layer(this.layers[name]);
|
||||
}
|
||||
}
|
||||
|
||||
this.resize = function(rect, position = null)
|
||||
{
|
||||
Object.keys(ronin.surface.layers).forEach(function (key) {
|
||||
ronin.surface.layers[key].resize(rect);
|
||||
});
|
||||
@ -58,6 +46,15 @@ function Surface(rune)
|
||||
ronin.terminal.log(new Log(this,"Resized Surface to "+this.settings["size"].render()));
|
||||
}
|
||||
|
||||
this.select = function(params)
|
||||
{
|
||||
var layer_name = params[0];
|
||||
if(!ronin.surface.layers[layer_name]){
|
||||
this.add_layer(new Layer(name));
|
||||
}
|
||||
this.select_layer(this.layers[name]);
|
||||
}
|
||||
|
||||
this.select_layer = function(layer)
|
||||
{
|
||||
console.log("Selecting layer:"+layer.name);
|
||||
@ -78,13 +75,6 @@ function Surface(rune)
|
||||
this.layers[layer.name] = layer;
|
||||
this.element.appendChild(layer.element);
|
||||
}
|
||||
|
||||
this.passive = function(cmd)
|
||||
{
|
||||
if(cmd.rect()){
|
||||
ronin.overlay.draw(cmd.position(),cmd.rect());
|
||||
}
|
||||
}
|
||||
|
||||
this.widget = function()
|
||||
{
|
||||
|
@ -89,7 +89,8 @@ function Terminal(rune)
|
||||
|
||||
if(ronin.modules[key]){
|
||||
ronin.modules[key].update_settings(cmd);
|
||||
ronin.modules[key].active(cmd);
|
||||
ronin.modules[key].run_methods(cmd);
|
||||
// ronin.modules[key].active(cmd);
|
||||
ronin.terminal.history.push(content);
|
||||
ronin.terminal.history_index = ronin.terminal.history.length-1;
|
||||
ronin.terminal.update_menu();
|
||||
|
@ -1,6 +1,7 @@
|
||||
function Unit()
|
||||
{
|
||||
this.example = "unknown";
|
||||
this.name = this.constructor.name;
|
||||
|
||||
this.render = function()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user