Starting to implement into Electron.

This commit is contained in:
Devine Lu Linvega
2017-09-19 10:08:37 +13:00
parent fe65660544
commit f10671fec6
63 changed files with 154 additions and 21 deletions

View File

@@ -0,0 +1,13 @@
function Angle(angle_str = "0'")
{
Unit.call(this);
this.example = "45'";
this.degrees = parseFloat(angle_str.replace('\'',''));
this.toString = function()
{
return this.degrees+"'";
}
}

View File

@@ -0,0 +1,12 @@
function Any(str)
{
Unit.call(this);
this.example = "";
this.string = str;
this.toString = function()
{
return this.string;
}
}

View File

@@ -0,0 +1,11 @@
function Bang()
{
Unit.call(this);
this.example = "";
this.toString = function()
{
return "BANG";
}
}

View File

@@ -0,0 +1,48 @@
function Color(hex = '#000000')
{
Unit.call(this);
this.example = "#ff0000";
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.floats = function()
{
var rgb = this.rgb();
return { r:rgb.r/255, g:rgb.g/255, b:rgb.b/255 }
}
this.toString = function()
{
return this.hex;
}
this.rgb_to_hex = function(rgb)
{
return "#"+parseInt(rgb.r,10).toString(16)+parseInt(rgb.g,10).toString(16)+parseInt(rgb.b,10).toString(16);
}
this.brightness = function()
{
return this.rgb() ? (this.rgb().r + this.rgb().g + this.rgb().b)/3 : 0;
}
this.style = function()
{
return this.brightness() > 150 ? "bright" : "dark";
}
}

View File

@@ -0,0 +1,12 @@
function Filepath(path_str)
{
Unit.call(this);
this.example = "assets/demo.png";
this.path = path_str;
this.toString = function()
{
return this.path;
}
}

View File

@@ -0,0 +1,37 @@
function Method(name,params,options = null)
{
Unit.call(this);
this.host = null;
this.name = name;
this.params = params;
this.options = options;
this.example = "";
this.toString = function()
{
var params_str = "";
for(param in this.params){
params_str += this.params[param]+","
}
params_str = params_str.substr(0,params_str.length-1);
var options_str = "";
for(option in this.options){
options_str += this.options[option]+","
}
options_str = options_str.substr(0,options_str.length-1);
return "<span class='method'>.<span class='name'>"+this.name+"</span> "+params_str+(this.options ? ' <span class=\'options\'>['+options_str+']</span>' : '')+"</span>";
}
this.preview = function(cmd)
{
return this.host[this.name] ? this.host[this.name](cmd,true) : "";
}
this.run = function(cmd)
{
return this.host[this.name] ? ronin.terminal.log(new Log(this.host,this.host[this.name](cmd,false))) : null;
}
}

View File

@@ -0,0 +1,13 @@
function Mode(name,key = null)
{
Unit.call(this);
this.host = null;
this.name = name;
this.key = key;
this.toString = function()
{
return "<span class='mode'><span class='name'>~"+this.name+"</span>"+(this.key ? ' <span class="key">'+this.key+'</span>' : '')+"</span>"
}
}

View File

@@ -0,0 +1,7 @@
function Option(name)
{
Unit.call(this);
this.name = name.split("=")[0];
this.value = name.split("=")[1];
}

View File

@@ -0,0 +1,56 @@
function Position(position_str = "0,0",y = null)
{
Unit.call(this);
this.example = "100,150";
this.position_str = position_str;
this.x = y != null ? position_str : parseFloat(position_str.split(",")[0]);
this.y = y != null ? y : parseFloat(position_str.split(",")[1]);
this.add = function(position)
{
return new Position(this.x + position.x, this.y + position.y);
}
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.offset = function(position = new Position(0,0))
{
return new Position(this.x - position.x,this.y - position.y);
}
this.normalize = function(rect)
{
if(this.x == null){
this.x = ronin.canvas.element.width - rect.width - Math.abs(this.x);
}
if(this.y == null){
this.y = ronin.canvas.element.height - rect.height - Math.abs(this.y);
}
}
this.toString = function()
{
return (isNaN(this.x) ? 0 : this.x)+","+(isNaN(this.y) ? 0 : this.y);
}
this.is_outside = function()
{
if(this.x < 0){ return true; }
if(this.y < 0){ return true; }
if(this.x > ronin.frame.element.width/2){ return true; }
if(this.y > ronin.frame.element.height/2){ return true; }
return false;
}
}

View File

@@ -0,0 +1,15 @@
function Range(range_str)
{
Unit.call(this);
this.example = "10..50";
this.range_str = range_str;
this.from = parseFloat(this.range_str.split("..")[0]);
this.to = parseFloat(this.range_str.split("..")[1]);
this.toString = function()
{
return this.from+".."+this.to;
}
}

View File

@@ -0,0 +1,16 @@
function Rect(rect_str)
{
Unit.call(this);
this.rect_str = rect_str;
this.width = rect_str ? parseFloat(this.rect_str.split("x")[0]) : 0;
this.height = rect_str ? parseFloat(this.rect_str.split("x")[1]) : 0;
this.example = "200x300";
this.toString = function()
{
return (isNaN(this.width) ? 0 : this.width)+"x"+(isNaN(this.height) ? 0 : this.height);
}
}

View File

@@ -0,0 +1,39 @@
function Setting(name,value)
{
Unit.call(this);
this.host = null;
this.name = name;
this.value = value;
this.toString = function()
{
return "?";
}
this.toString = function()
{
return "<span class='setting'>:"+this.name+(this.value ? ' <span class="value">'+this.value+'</span>' : '')+"</span>"
}
this.update = function(value)
{
this.value = value;
}
this.to_f = function()
{
return parseFloat(this.value);
}
this.to_rect = function()
{
return new Rect(this.value);
}
this.to_pos = function()
{
return new Position(this.value);
}
}

View File

@@ -0,0 +1,5 @@
function Unit()
{
this.example = "unknown";
this.name = this.constructor.name;
}

View File

@@ -0,0 +1,14 @@
function Value(value_str)
{
Unit.call(this);
this.example = "20";
this.value = value_str;
this.float = parseFloat(this.value);
this.int = parseInt(this.value);
this.toString = function()
{
return this.value;
}
}