Implemented variables properly.
This commit is contained in:
@@ -3,7 +3,8 @@ function Brush(rune)
|
||||
Module.call(this,rune);
|
||||
|
||||
this.parameters = [Position,Rect,Angle,Color,Value,Bang];
|
||||
this.pointers = [new Pointer(new Position())];
|
||||
this.variables = {"natural" : false,"banking" : false};
|
||||
this.pointers = [];
|
||||
|
||||
this.size = 1;
|
||||
this.opacity = 1;
|
||||
@@ -15,31 +16,20 @@ function Brush(rune)
|
||||
{
|
||||
if(cmd.bang()){ this.pointers = []; }
|
||||
|
||||
var pointer = new Pointer();
|
||||
// Pointer
|
||||
if(cmd.rect() || cmd.position() || cmd.angle()){
|
||||
this.add_pointer(cmd);
|
||||
}
|
||||
|
||||
if(cmd.position()){
|
||||
pointer.offset = cmd.position();
|
||||
}
|
||||
if(cmd.rect()){
|
||||
pointer.mirror = cmd.rect();
|
||||
}
|
||||
if(cmd.variable("osc_scale") && cmd.variable("osc_rate")){
|
||||
pointer.osc_rate = parseFloat(cmd.variable("osc_rate"));
|
||||
pointer.osc_scale = parseFloat(cmd.variable("osc_scale"));
|
||||
}
|
||||
if(cmd.angle()){
|
||||
pointer.angle = cmd.angle();
|
||||
}
|
||||
if(cmd.rect() || cmd.position() || cmd.variable("osc_rate") || cmd.angle()){
|
||||
this.add_pointer(pointer);
|
||||
}
|
||||
// Global
|
||||
if(cmd.color()){
|
||||
this.color = cmd.color();
|
||||
}
|
||||
if(cmd.value()){
|
||||
this.size = cmd.value().float;
|
||||
}
|
||||
ronin.widget.update();
|
||||
|
||||
this.update_variables(cmd);
|
||||
}
|
||||
|
||||
this.passive = function(cmd)
|
||||
@@ -55,19 +45,26 @@ function Brush(rune)
|
||||
}
|
||||
}
|
||||
|
||||
this.add_pointer = function(pointer)
|
||||
this.add_pointer = function(cmd)
|
||||
{
|
||||
var pointer = new Pointer();
|
||||
|
||||
if(cmd.position()){
|
||||
pointer.offset = cmd.position();
|
||||
}
|
||||
if(cmd.rect()){
|
||||
pointer.mirror = cmd.rect();
|
||||
}
|
||||
if(cmd.angle()){
|
||||
pointer.angle = cmd.angle();
|
||||
}
|
||||
|
||||
this.pointers.push(pointer);
|
||||
}
|
||||
|
||||
this.widget = function()
|
||||
{
|
||||
return "> "+this.size+" <span>"+this.color.render()+"</span> ";
|
||||
}
|
||||
|
||||
this.widget_cursor = function()
|
||||
{
|
||||
return "Brush "+this.size;
|
||||
return "Brush "+this.size+", "+this.pointers.length+" pointers";
|
||||
}
|
||||
|
||||
// Cursor
|
||||
@@ -104,6 +101,6 @@ function Brush(rune)
|
||||
ronin.brush.pointers[i].stop();
|
||||
}
|
||||
|
||||
ronin.stroke.save_stroke();
|
||||
ronin.stroke.save_stroke("brush");
|
||||
}
|
||||
}
|
@@ -5,11 +5,21 @@ function Pointer(offset = new Position(), color = new Color('000000'))
|
||||
this.position_prev = null;
|
||||
this.angle = null;
|
||||
this.distance = 0;
|
||||
|
||||
// Parameters
|
||||
|
||||
this.thickness = function()
|
||||
{
|
||||
var ratio = 10/this.position().distance_to(this.position_prev);
|
||||
ratio = ratio > 1 ? 1 : ratio;
|
||||
return ronin.brush.size * ratio;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
this.draw = function()
|
||||
{
|
||||
if(!this.position_prev){this.position_prev = this.position(); }
|
||||
if(ronin.brush.size < 0){ this.erase(); return; }
|
||||
|
||||
var position = this.position();
|
||||
|
||||
@@ -29,22 +39,8 @@ function Pointer(offset = new Position(), color = new Color('000000'))
|
||||
this.position_prev = position;
|
||||
}
|
||||
|
||||
this.erase = function()
|
||||
{
|
||||
ronin.canvas.context().clearRect(this.position().x - (ronin.brush.size/2), this.position().y - (ronin.brush.size/2), ronin.brush.size, ronin.brush.size);
|
||||
}
|
||||
|
||||
this.thickness = function()
|
||||
{
|
||||
var ratio = 10/this.position().distance_to(this.position_prev);
|
||||
ratio = ratio > 1 ? 1 : ratio;
|
||||
return ronin.brush.size * ratio;
|
||||
}
|
||||
|
||||
this.position = function()
|
||||
{
|
||||
return ronin.cursor.position;
|
||||
|
||||
if(this.angle){
|
||||
var angle_radian = this.angle.degrees * Math.PI / 180;
|
||||
var deltaX = ronin.brush.position.x - this.offset.x;
|
||||
@@ -62,10 +58,14 @@ function Pointer(offset = new Position(), color = new Color('000000'))
|
||||
return new Position((ronin.brush.position.x + this.offset.x), (2 * this.mirror.height) - (ronin.brush.position.y + this.offset.y));
|
||||
}
|
||||
|
||||
console.log(ronin.brush.position);
|
||||
console.log(this.offset);
|
||||
return;
|
||||
return new Position(ronin.brush.position.x + this.offset.x, ronin.brush.position.y + this.offset.y);
|
||||
return this.position_default();
|
||||
}
|
||||
|
||||
// Effects
|
||||
|
||||
this.position_default = function()
|
||||
{
|
||||
return ronin.cursor.position.add(this.offset);
|
||||
}
|
||||
|
||||
this.start = function()
|
||||
|
@@ -74,6 +74,6 @@ function Eraser(rune)
|
||||
this.is_drawing = false;
|
||||
this.position_prev = null;
|
||||
|
||||
ronin.stroke.save_stroke();
|
||||
ronin.stroke.save_stroke("eraser");
|
||||
}
|
||||
}
|
@@ -3,7 +3,7 @@ function Module(rune)
|
||||
this.rune = rune;
|
||||
this.element = null;
|
||||
this.parameters = [];
|
||||
this.variables = [];
|
||||
this.variables = {};
|
||||
|
||||
this.active = function(cmd)
|
||||
{
|
||||
@@ -15,6 +15,15 @@ function Module(rune)
|
||||
console.log("Nothing to do.");
|
||||
}
|
||||
|
||||
this.update_variables = function(cmd)
|
||||
{
|
||||
for (var key in this.variables){
|
||||
if(!cmd.variable(key)){ continue; }
|
||||
this.variables[key] = cmd.variable(key).value;
|
||||
}
|
||||
console.log(this.variables);
|
||||
}
|
||||
|
||||
this.hint = function(cmd)
|
||||
{
|
||||
return "unknown";
|
||||
|
@@ -18,9 +18,9 @@ function Stroke(rune)
|
||||
this.positions.push(p);
|
||||
}
|
||||
|
||||
this.save_stroke = function()
|
||||
this.save_stroke = function(mode)
|
||||
{
|
||||
s = "_ ";
|
||||
s = "_ mode:"+mode+" ";
|
||||
for (i = 0; i < this.positions.length; i++) {
|
||||
s += this.positions[i].render()+" ";
|
||||
}
|
||||
|
Reference in New Issue
Block a user