Improved commander hints.
This commit is contained in:
11
scripts/units/angle.js
Normal file
11
scripts/units/angle.js
Normal file
@@ -0,0 +1,11 @@
|
||||
function Angle(angle_str)
|
||||
{
|
||||
Unit.call(this);
|
||||
|
||||
this.degrees = parseFloat(angle_str.replace('\'',''));
|
||||
|
||||
this.render = function()
|
||||
{
|
||||
return this.degrees+"'";
|
||||
}
|
||||
}
|
||||
11
scripts/units/any.js
Normal file
11
scripts/units/any.js
Normal file
@@ -0,0 +1,11 @@
|
||||
function Any(str)
|
||||
{
|
||||
Unit.call(this);
|
||||
|
||||
this.string = str;
|
||||
|
||||
this.render = function()
|
||||
{
|
||||
return this.string;
|
||||
}
|
||||
}
|
||||
9
scripts/units/bang.js
Normal file
9
scripts/units/bang.js
Normal file
@@ -0,0 +1,9 @@
|
||||
function Bang()
|
||||
{
|
||||
Unit.call(this);
|
||||
|
||||
this.render = function()
|
||||
{
|
||||
return "BANG";
|
||||
}
|
||||
}
|
||||
26
scripts/units/color.js
Normal file
26
scripts/units/color.js
Normal file
@@ -0,0 +1,26 @@
|
||||
function Color(hex = '#000000')
|
||||
{
|
||||
Unit.call(this);
|
||||
|
||||
this.hex = hex;
|
||||
|
||||
this.rgb = function()
|
||||
{
|
||||
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(this.hex);
|
||||
return result ? {
|
||||
r: parseInt(result[1], 16),
|
||||
g: parseInt(result[2], 16),
|
||||
b: parseInt(result[3], 16)
|
||||
} : null;
|
||||
}
|
||||
|
||||
this.rgba = function()
|
||||
{
|
||||
return "rgba("+this.rgb().r+","+this.rgb().g+","+this.rgb().b+",1)";
|
||||
}
|
||||
|
||||
this.render = function()
|
||||
{
|
||||
return this.hex;
|
||||
}
|
||||
}
|
||||
11
scripts/units/filepath.js
Normal file
11
scripts/units/filepath.js
Normal file
@@ -0,0 +1,11 @@
|
||||
function Filepath(path_str)
|
||||
{
|
||||
Unit.call(this);
|
||||
|
||||
this.path = path_str;
|
||||
|
||||
this.render = function()
|
||||
{
|
||||
return this.path;
|
||||
}
|
||||
}
|
||||
36
scripts/units/position.js
Normal file
36
scripts/units/position.js
Normal file
@@ -0,0 +1,36 @@
|
||||
function Position(position_str = "0,0",y = null)
|
||||
{
|
||||
Unit.call(this);
|
||||
|
||||
this.position_str = position_str;
|
||||
|
||||
this.x = y ? position_str : parseFloat(this.position_str.split(",")[0]);
|
||||
this.y = y ? y : parseFloat(this.position_str.split(",")[1]);
|
||||
|
||||
this.is_equal = function(target)
|
||||
{
|
||||
if(target.x == this.x && target.y == this.y){ return true; }
|
||||
return null;
|
||||
}
|
||||
|
||||
this.distance_to = function(target)
|
||||
{
|
||||
if(!target){ return 0; }
|
||||
return Math.sqrt( (this.x-target.x)*(this.x-target.x) + (this.y-target.y)*(this.y-target.y) );
|
||||
}
|
||||
|
||||
this.normalize = function(rect)
|
||||
{
|
||||
if(this.x < 0){
|
||||
this.x = ronin.canvas.element.width - rect.width - Math.abs(this.x);
|
||||
}
|
||||
if(this.y < 0){
|
||||
this.y = ronin.canvas.element.height - rect.height - Math.abs(this.y);
|
||||
}
|
||||
}
|
||||
|
||||
this.render = function()
|
||||
{
|
||||
return (isNaN(this.x) ? 0 : this.x)+","+(isNaN(this.y) ? 0 : this.y);
|
||||
}
|
||||
}
|
||||
14
scripts/units/rect.js
Normal file
14
scripts/units/rect.js
Normal file
@@ -0,0 +1,14 @@
|
||||
function Rect(rect_str)
|
||||
{
|
||||
Unit.call(this);
|
||||
|
||||
this.rect_str = rect_str;
|
||||
|
||||
this.width = parseFloat(this.rect_str.split("x")[0]);
|
||||
this.height = parseFloat(this.rect_str.split("x")[1]);
|
||||
|
||||
this.render = function()
|
||||
{
|
||||
return (isNaN(this.width) ? 0 : this.width)+"x"+(isNaN(this.height) ? 0 : this.height);
|
||||
}
|
||||
}
|
||||
13
scripts/units/value.js
Normal file
13
scripts/units/value.js
Normal file
@@ -0,0 +1,13 @@
|
||||
function Value(value_str)
|
||||
{
|
||||
Unit.call(this);
|
||||
|
||||
this.value = value_str;
|
||||
this.float = parseFloat(this.value);
|
||||
this.int = parseInt(this.value);
|
||||
|
||||
this.render = function()
|
||||
{
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user