2023-03-31 06:59:08 +02:00
|
|
|
#region data
|
2023-07-14 20:34:35 +02:00
|
|
|
global.EVALUATE_HEAD = noone;
|
|
|
|
|
2023-07-11 20:36:44 +02:00
|
|
|
global.FUNCTIONS = ds_map_create();
|
2023-09-11 16:08:58 +02:00
|
|
|
global.FUNCTIONS[? "sin"] = [ ["radian"], function(val) { return sin(array_safe_get(val, 0)); } ];
|
|
|
|
global.FUNCTIONS[? "cos"] = [ ["radian"], function(val) { return cos(array_safe_get(val, 0)); } ];
|
|
|
|
global.FUNCTIONS[? "tan"] = [ ["radian"], function(val) { return tan(array_safe_get(val, 0)); } ];
|
2023-07-14 20:34:35 +02:00
|
|
|
|
2023-09-11 16:08:58 +02:00
|
|
|
global.FUNCTIONS[? "dsin"] = [ ["degree"], function(val) { return dsin(array_safe_get(val, 0)); } ];
|
|
|
|
global.FUNCTIONS[? "dcos"] = [ ["degree"], function(val) { return dcos(array_safe_get(val, 0)); } ];
|
|
|
|
global.FUNCTIONS[? "dtan"] = [ ["degree"], function(val) { return dtan(array_safe_get(val, 0)); } ];
|
2023-08-13 09:00:58 +02:00
|
|
|
|
2023-09-11 16:08:58 +02:00
|
|
|
global.FUNCTIONS[? "arcsin"] = [ ["x"], function(val) { return arcsin(array_safe_get(val, 0)); } ];
|
|
|
|
global.FUNCTIONS[? "arccos"] = [ ["x"], function(val) { return arccos(array_safe_get(val, 0)); } ];
|
|
|
|
global.FUNCTIONS[? "arctan"] = [ ["x"], function(val) { return arctan(array_safe_get(val, 0)); } ];
|
|
|
|
global.FUNCTIONS[? "arctan2"] = [ ["y", "x"], function(val) { return arctan2(array_safe_get(val, 0), array_safe_get(val, 1)); } ];
|
2023-08-13 09:00:58 +02:00
|
|
|
|
2023-09-11 16:08:58 +02:00
|
|
|
global.FUNCTIONS[? "darcsin"] = [ ["x"], function(val) { return darcsin(array_safe_get(val, 0)); } ];
|
|
|
|
global.FUNCTIONS[? "darccos"] = [ ["x"], function(val) { return darccos(array_safe_get(val, 0)); } ];
|
|
|
|
global.FUNCTIONS[? "darctan"] = [ ["x"], function(val) { return darctan(array_safe_get(val, 0)); } ];
|
|
|
|
global.FUNCTIONS[? "darctan2"] = [ ["y", "x"], function(val) { return darctan2(array_safe_get(val, 0), array_safe_get(val, 1)); } ];
|
2023-07-11 20:36:44 +02:00
|
|
|
|
2023-09-11 16:08:58 +02:00
|
|
|
global.FUNCTIONS[? "abs"] = [ ["x"], function(val) { return abs(array_safe_get(val, 0)); } ];
|
|
|
|
global.FUNCTIONS[? "round"] = [ ["x"], function(val) { return round(array_safe_get(val, 0)); } ];
|
|
|
|
global.FUNCTIONS[? "ceil"] = [ ["x"], function(val) { return ceil(array_safe_get(val, 0)); } ];
|
|
|
|
global.FUNCTIONS[? "floor"] = [ ["x"], function(val) { return floor(array_safe_get(val, 0)); } ];
|
|
|
|
global.FUNCTIONS[? "fract"] = [ ["x"], function(val) { return frac(array_safe_get(val, 0)); } ];
|
|
|
|
global.FUNCTIONS[? "sign"] = [ ["x"], function(val) { return sign(array_safe_get(val, 0)); } ];
|
|
|
|
|
|
|
|
global.FUNCTIONS[? "min"] = [ ["x", "y"], function(val) { return min(array_safe_get(val, 0), array_safe_get(val, 1)); } ];
|
|
|
|
global.FUNCTIONS[? "max"] = [ ["x", "y"], function(val) { return max(array_safe_get(val, 0), array_safe_get(val, 1)); } ];
|
|
|
|
global.FUNCTIONS[? "clamp"] = [ ["x", "min = 0", "max = 1"], function(val) { return clamp(array_safe_get(val, 0), array_safe_get(val, 1, 0), array_safe_get(val, 2, 1)); } ];
|
|
|
|
|
|
|
|
global.FUNCTIONS[? "lerp"] = [ ["x", "y", "amount"], function(val) { return lerp(array_safe_get(val, 0), array_safe_get(val, 1), array_safe_get(val, 2)); } ];
|
2023-07-12 21:00:05 +02:00
|
|
|
|
2023-07-14 20:34:35 +02:00
|
|
|
global.FUNCTIONS[? "wiggle"] = [ ["time", "frequency", "octave = 1", "seed = 0"], function(val) {
|
2023-10-09 16:07:33 +02:00
|
|
|
return wiggle(0, 1, TOTAL_FRAMES / array_safe_get(val, 1),
|
2023-07-14 20:34:35 +02:00
|
|
|
array_safe_get(val, 0),
|
|
|
|
array_safe_get(val, 3, 0),
|
|
|
|
array_safe_get(val, 2, 1));
|
|
|
|
} ];
|
|
|
|
global.FUNCTIONS[? "random"] = [ ["min = 0", "max = 1"], function(val) {
|
|
|
|
return random_range(array_safe_get(val, 0, 0),
|
|
|
|
array_safe_get(val, 1, 1));
|
|
|
|
} ];
|
|
|
|
global.FUNCTIONS[? "irandom"] = [ ["min = 0", "max = 1"], function(val) {
|
|
|
|
return irandom_range(array_safe_get(val, 0, 0),
|
|
|
|
array_safe_get(val, 1, 1));
|
|
|
|
} ];
|
2023-07-17 19:58:33 +02:00
|
|
|
|
2023-07-18 17:51:40 +02:00
|
|
|
global.FUNCTIONS[? "range"] = [ ["length", "start = 0", "step = 1"], function(val) {
|
|
|
|
var arr = array_create(array_safe_get(val, 0, 0));
|
2023-07-25 20:12:40 +02:00
|
|
|
for( var i = 0, n = array_length(arr); i < n; i++ )
|
2023-07-18 17:51:40 +02:00
|
|
|
arr[i] = array_safe_get(val, 1, 0) + i * array_safe_get(val, 2, 1);
|
|
|
|
return arr;
|
|
|
|
} ];
|
2023-08-08 11:42:01 +02:00
|
|
|
|
2023-08-12 15:43:18 +02:00
|
|
|
global.FUNCTIONS[? "length"] = [ ["value"], function(val) {
|
|
|
|
if(is_array(val)) return array_length(val);
|
|
|
|
if(is_string(val)) return string_length(val);
|
|
|
|
return 0;
|
|
|
|
} ];
|
|
|
|
|
2023-09-11 16:08:58 +02:00
|
|
|
global.FUNCTIONS[? "string"] = [ ["value"], function(val) { return string(array_safe_get(val, 0)); } ];
|
|
|
|
global.FUNCTIONS[? "number"] = [ ["value"], function(val) { return toNumber(array_safe_get(val, 0)); } ];
|
|
|
|
global.FUNCTIONS[? "chr"] = [ ["x"], function(val) { return chr(array_safe_get(val, 0)); } ];
|
|
|
|
global.FUNCTIONS[? "ord"] = [ ["char"], function(val) { return ord(array_safe_get(val, 0)); } ];
|
|
|
|
|
|
|
|
global.FUNCTIONS[? "draw"] = [ ["surface", "x = 0", "y = 0", "xs = 1", "ys = 1", "rot = 0", "color = white", "alpha = 1"],
|
2023-09-13 15:06:39 +02:00
|
|
|
function(val) {
|
|
|
|
var _surface = array_safe_get(val, 0, -1);
|
|
|
|
if(!is_surface(_surface)) return false;
|
|
|
|
|
|
|
|
var _x = array_safe_get(val, 1, 0);
|
|
|
|
var _y = array_safe_get(val, 2, 0);
|
|
|
|
var _xs = array_safe_get(val, 3, 1);
|
|
|
|
var _ys = array_safe_get(val, 4, 1);
|
|
|
|
var _rot = array_safe_get(val, 5, 0);
|
|
|
|
var _col = array_safe_get(val, 6, c_white);
|
|
|
|
var _alp = array_safe_get(val, 7, 1);
|
|
|
|
draw_surface_ext_safe(_surface, _x, _y, _xs, _ys, _rot, _col, _alp);
|
|
|
|
return true;
|
|
|
|
} ];
|
2023-09-11 16:08:58 +02:00
|
|
|
|
2023-09-13 15:06:39 +02:00
|
|
|
global.FUNCTIONS[? "surface_get_width"] = [ ["surface"], function(val) { return surface_get_width_safe(array_safe_get(val, 0)); } ];
|
2023-09-11 16:08:58 +02:00
|
|
|
global.FUNCTIONS[? "surface_get_height"] = [ ["surface"], function(val) { return surface_get_height_safe(array_safe_get(val, 0)); } ];
|
2023-08-13 09:00:58 +02:00
|
|
|
|
2023-10-18 14:58:55 +02:00
|
|
|
global.FUNCTIONS[? "color_hex"] = [ ["char"], function(val) { return colorFromHex(array_safe_get(val, 0)); } ];
|
|
|
|
global.FUNCTIONS[? "color_rgb"] = [ ["red", "green", "blue"], function(val) { return make_color_rgb(array_safe_get(val, 0), array_safe_get(val, 1), array_safe_get(val, 2)); } ];
|
|
|
|
global.FUNCTIONS[? "color_hsv"] = [ ["red", "green", "blue"], function(val) { return make_color_hsv(array_safe_get(val, 0), array_safe_get(val, 1), array_safe_get(val, 2)); } ];
|
|
|
|
|
2023-08-05 14:00:33 +02:00
|
|
|
globalvar PROJECT_VARIABLES;
|
|
|
|
PROJECT_VARIABLES = {};
|
|
|
|
|
|
|
|
PROJECT_VARIABLES.Project = {};
|
2023-10-12 12:25:38 +02:00
|
|
|
PROJECT_VARIABLES.Project.frame = [ function() { return CURRENT_FRAME }, EXPRESS_TREE_ANIM.animated ];
|
|
|
|
PROJECT_VARIABLES.Project.progress = [ function() { return CURRENT_FRAME / (TOTAL_FRAMES - 1) }, EXPRESS_TREE_ANIM.animated ];
|
|
|
|
PROJECT_VARIABLES.Project.frameTotal = [ function() { return TOTAL_FRAMES }, EXPRESS_TREE_ANIM.none ];
|
|
|
|
PROJECT_VARIABLES.Project.fps = [ function() { return PROJECT.animator.framerate }, EXPRESS_TREE_ANIM.none ];
|
|
|
|
PROJECT_VARIABLES.Project.time = [ function() { return CURRENT_FRAME / PROJECT.animator.framerate }, EXPRESS_TREE_ANIM.animated ];
|
|
|
|
PROJECT_VARIABLES.Project.name = [ function() { return filename_name_only(PROJECT.path) }, EXPRESS_TREE_ANIM.none ];
|
2023-08-05 14:00:33 +02:00
|
|
|
|
|
|
|
PROJECT_VARIABLES.Program = {};
|
2023-10-02 14:41:44 +02:00
|
|
|
PROJECT_VARIABLES.Program.time = [ function() { return current_time / 1000 }, EXPRESS_TREE_ANIM.animated ];
|
2023-08-05 14:00:33 +02:00
|
|
|
|
|
|
|
PROJECT_VARIABLES.Device = {};
|
2023-10-02 14:41:44 +02:00
|
|
|
PROJECT_VARIABLES.Device.timeSecond = [ function() { return current_second }, EXPRESS_TREE_ANIM.animated ];
|
|
|
|
PROJECT_VARIABLES.Device.timeMinute = [ function() { return current_minute }, EXPRESS_TREE_ANIM.animated ];
|
|
|
|
PROJECT_VARIABLES.Device.timeHour = [ function() { return current_hour }, EXPRESS_TREE_ANIM.animated ];
|
|
|
|
PROJECT_VARIABLES.Device.timeDay = [ function() { return current_day }, EXPRESS_TREE_ANIM.animated ];
|
|
|
|
PROJECT_VARIABLES.Device.timeDayInWeek = [ function() { return current_weekday }, EXPRESS_TREE_ANIM.animated ];
|
|
|
|
PROJECT_VARIABLES.Device.timeMonth = [ function() { return current_month }, EXPRESS_TREE_ANIM.animated ];
|
|
|
|
PROJECT_VARIABLES.Device.timeYear = [ function() { return current_year }, EXPRESS_TREE_ANIM.animated ];
|
2023-03-31 06:59:08 +02:00
|
|
|
#endregion
|
2023-03-23 06:57:31 +01:00
|
|
|
|
2023-03-31 06:59:08 +02:00
|
|
|
#region evaluator
|
2023-06-20 19:43:19 +02:00
|
|
|
enum EXPRESS_TREE_ANIM {
|
|
|
|
none,
|
|
|
|
base_value,
|
|
|
|
animated
|
|
|
|
}
|
|
|
|
|
2023-09-11 16:08:58 +02:00
|
|
|
function __funcList() constructor { #region
|
2023-07-12 21:00:05 +02:00
|
|
|
funcTrees = [];
|
|
|
|
|
|
|
|
static addFunction = function(fn) {
|
|
|
|
array_push(funcTrees, fn);
|
|
|
|
}
|
|
|
|
|
|
|
|
static validate = function() {
|
2023-07-25 20:12:40 +02:00
|
|
|
for( var i = 0, n = array_length(funcTrees); i < n; i++ )
|
2023-07-12 21:00:05 +02:00
|
|
|
if(!funcTrees[i].validate())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-10-07 16:23:40 +02:00
|
|
|
static isDynamic = function() {
|
2023-10-02 14:41:44 +02:00
|
|
|
var anim = EXPRESS_TREE_ANIM.none;
|
2023-07-25 20:12:40 +02:00
|
|
|
for( var i = 0, n = array_length(funcTrees); i < n; i++ )
|
2023-10-07 16:23:40 +02:00
|
|
|
anim = max(anim, funcTrees[i].isDynamic());
|
2023-10-02 14:41:44 +02:00
|
|
|
return anim;
|
2023-07-12 21:00:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static eval = function(params = {}) {
|
|
|
|
//var _params = variable_clone(params);
|
|
|
|
var val = 0;
|
|
|
|
|
2023-07-25 20:12:40 +02:00
|
|
|
for( var i = 0, n = array_length(funcTrees); i < n; i++ )
|
2023-07-12 21:00:05 +02:00
|
|
|
val = funcTrees[i].eval(params);
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
2023-09-11 16:08:58 +02:00
|
|
|
} #endregion
|
2023-07-12 21:00:05 +02:00
|
|
|
|
2023-09-11 16:08:58 +02:00
|
|
|
function __funcIf() constructor { #region
|
2023-07-12 21:00:05 +02:00
|
|
|
condition = noone;
|
|
|
|
if_true = new __funcList();
|
|
|
|
if_false = new __funcList();
|
|
|
|
|
|
|
|
static validate = function() {
|
|
|
|
if(condition != noone && !condition.validate()) return false;
|
|
|
|
if(if_true != noone && !if_true.validate()) return false;
|
|
|
|
if(if_false != noone && !if_false.validate()) return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-10-07 16:23:40 +02:00
|
|
|
static isDynamic = function() {
|
2023-10-02 14:41:44 +02:00
|
|
|
var anim = EXPRESS_TREE_ANIM.none;
|
|
|
|
|
2023-10-07 16:23:40 +02:00
|
|
|
if(condition != noone) anim = max(anim, condition.isDynamic());
|
|
|
|
if(if_true != noone) anim = max(anim, if_true.isDynamic());
|
|
|
|
if(if_false != noone) anim = max(anim, if_false.isDynamic());
|
2023-10-02 14:41:44 +02:00
|
|
|
|
|
|
|
return anim;
|
2023-07-12 21:00:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static eval = function(params = {}) {
|
|
|
|
if(condition == noone) return 0;
|
|
|
|
|
|
|
|
var res = condition.eval(params);
|
2023-07-29 10:10:48 +02:00
|
|
|
printIf(global.LOG_EXPRESSION, $"<<<<<< IF {res} >>>>>>");
|
2023-07-12 21:00:05 +02:00
|
|
|
|
|
|
|
if(res) return if_true == noone? 0 : if_true.eval(params);
|
|
|
|
else return if_false == noone? 0 : if_false.eval(params);
|
|
|
|
}
|
2023-09-11 16:08:58 +02:00
|
|
|
} #endregion
|
2023-07-12 21:00:05 +02:00
|
|
|
|
2023-09-11 16:08:58 +02:00
|
|
|
function __funcFor() constructor { #region
|
2023-07-12 21:00:05 +02:00
|
|
|
itr_array = false;
|
|
|
|
|
|
|
|
cond_init = noone;
|
2023-08-02 19:11:57 +02:00
|
|
|
cond_indx = noone;
|
2023-07-12 21:00:05 +02:00
|
|
|
cond_iter = noone;
|
|
|
|
cond_term = noone;
|
|
|
|
|
|
|
|
cond_arr = noone;
|
|
|
|
|
|
|
|
cond_step = 1;
|
|
|
|
action = new __funcList();
|
|
|
|
|
|
|
|
static validate = function() {
|
|
|
|
if(itr_array) {
|
|
|
|
if(cond_arr == noone || !cond_arr.validate()) return false;
|
|
|
|
} else {
|
|
|
|
if(cond_init == noone || !cond_init.validate()) return false;
|
|
|
|
if(cond_term == noone || !cond_term.validate()) return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(action != noone && !action.validate()) return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-10-07 16:23:40 +02:00
|
|
|
static isDynamic = function() {
|
2023-10-02 14:41:44 +02:00
|
|
|
var anim = EXPRESS_TREE_ANIM.none;
|
|
|
|
|
2023-07-12 21:00:05 +02:00
|
|
|
if(itr_array) {
|
2023-10-07 16:23:40 +02:00
|
|
|
if(cond_arr == noone) anim = max(anim, cond_arr.isDynamic())
|
2023-07-12 21:00:05 +02:00
|
|
|
} else {
|
2023-10-07 16:23:40 +02:00
|
|
|
if(cond_init == noone) anim = max(anim, cond_init.isDynamic())
|
|
|
|
if(cond_term == noone) anim = max(anim, cond_term.isDynamic())
|
2023-07-12 21:00:05 +02:00
|
|
|
}
|
|
|
|
|
2023-10-07 16:23:40 +02:00
|
|
|
if(action != noone) anim = max(anim, action.isDynamic())
|
2023-07-12 21:00:05 +02:00
|
|
|
|
2023-10-02 14:41:44 +02:00
|
|
|
return anim;
|
2023-07-12 21:00:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static eval = function(params = {}) {
|
|
|
|
if(itr_array) {
|
|
|
|
var _arr = cond_arr.eval(params);
|
2023-07-29 10:10:48 +02:00
|
|
|
printIf(global.LOG_EXPRESSION, $"<<<<<< FOR EACH {_arr} >>>>>>");
|
2023-07-25 20:12:40 +02:00
|
|
|
for( var i = 0, n = array_length(_arr); i < n; i++ ) {
|
2023-07-12 21:00:05 +02:00
|
|
|
var val = _arr[i];
|
2023-08-02 19:11:57 +02:00
|
|
|
if(cond_indx != noone)
|
|
|
|
params[$ cond_indx] = i;
|
2023-07-12 21:00:05 +02:00
|
|
|
params[$ cond_iter] = val;
|
|
|
|
|
2023-07-29 10:10:48 +02:00
|
|
|
printIf(global.LOG_EXPRESSION, $"<< ITER {i}: {cond_iter} = {val} >>");
|
2023-07-12 21:00:05 +02:00
|
|
|
action.eval(params);
|
|
|
|
}
|
|
|
|
} else {
|
2023-07-29 10:10:48 +02:00
|
|
|
printIf(global.LOG_EXPRESSION, "<< FOR >>");
|
2023-07-12 21:00:05 +02:00
|
|
|
cond_init.eval(params);
|
|
|
|
|
|
|
|
while(cond_term.eval(params)) {
|
|
|
|
action.eval(params);
|
|
|
|
cond_iter.eval(params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-09-11 16:08:58 +02:00
|
|
|
} #endregion
|
2023-07-12 21:00:05 +02:00
|
|
|
|
2023-09-11 16:08:58 +02:00
|
|
|
function __funcTree(symbol, l = noone, r = noone) constructor { #region
|
2023-06-20 19:43:19 +02:00
|
|
|
self.symbol = symbol;
|
|
|
|
self.l = l;
|
|
|
|
self.r = r;
|
2023-07-12 16:28:32 +02:00
|
|
|
dependency = [];
|
2023-10-02 14:41:44 +02:00
|
|
|
anim_stat = undefined;
|
|
|
|
anim_cache = true;
|
2023-06-20 19:43:19 +02:00
|
|
|
|
2023-09-11 16:08:58 +02:00
|
|
|
static _string = function(str) { #region
|
2023-08-06 16:00:59 +02:00
|
|
|
return string_char_at(str, 1) == "\"" && string_char_at(str, string_length(str)) == "\"";
|
2023-09-11 16:08:58 +02:00
|
|
|
} #endregion
|
2023-06-20 19:43:19 +02:00
|
|
|
|
2023-09-11 16:08:58 +02:00
|
|
|
static _string_trim = function(str) { #region
|
2023-08-06 16:00:59 +02:00
|
|
|
return string_trim(str, [ "\"" ]);
|
2023-09-11 16:08:58 +02:00
|
|
|
} #endregion
|
2023-06-20 19:43:19 +02:00
|
|
|
|
2023-09-11 16:08:58 +02:00
|
|
|
static getVal = function(val, params = {}, getRaw = false) { #region
|
2023-07-23 20:21:35 +02:00
|
|
|
if(is_struct(val)) return val.eval(params, getRaw);
|
|
|
|
if(is_real(val)) return val;
|
|
|
|
if(getRaw) return val;
|
2023-07-12 21:00:05 +02:00
|
|
|
|
2023-07-11 20:36:44 +02:00
|
|
|
if(is_string(val)) val = string_trim(val);
|
2023-06-20 19:43:19 +02:00
|
|
|
|
|
|
|
if(struct_has(params, val))
|
|
|
|
return struct_try_get(params, val);
|
|
|
|
|
2023-08-06 16:00:59 +02:00
|
|
|
val = string_trim(val);
|
2023-10-12 14:14:08 +02:00
|
|
|
if(_string(val)) return _string_trim(val);
|
2023-08-06 16:00:59 +02:00
|
|
|
|
2023-10-12 14:14:08 +02:00
|
|
|
var _str = string_splice(val, ".");
|
|
|
|
if(array_length(_str) > 1 && _str[0] == "self" && struct_has(params, "node_values"))
|
|
|
|
return struct_try_get(params.node_values, _str[1]);
|
2023-06-20 19:43:19 +02:00
|
|
|
|
|
|
|
return nodeGetData(val);
|
2023-09-11 16:08:58 +02:00
|
|
|
} #endregion
|
2023-06-20 19:43:19 +02:00
|
|
|
|
2023-09-11 16:08:58 +02:00
|
|
|
static _validate = function(val) { #region
|
2023-06-20 19:43:19 +02:00
|
|
|
if(is_real(val)) return true;
|
|
|
|
if(is_string(val)) return true;
|
|
|
|
if(is_struct(val)) return val.validate();
|
|
|
|
|
|
|
|
if(val == "value") return true;
|
2023-07-06 19:49:16 +02:00
|
|
|
if(PROJECT.globalNode.inputExist(val)) return true;
|
2023-06-20 19:43:19 +02:00
|
|
|
|
|
|
|
var strs = string_splice(val, ".");
|
|
|
|
if(array_length(strs) < 2) return false;
|
|
|
|
|
2023-08-05 14:00:33 +02:00
|
|
|
if(struct_has(PROJECT_VARIABLES, strs[0]))
|
|
|
|
return struct_has(PROJECT_VARIABLES[$ strs[0]], strs[1]);
|
2023-07-12 16:28:32 +02:00
|
|
|
|
|
|
|
if(!ds_map_exists(PROJECT.nodeNameMap, strs[0]))
|
2023-06-20 19:43:19 +02:00
|
|
|
return false;
|
|
|
|
|
2023-07-14 20:34:35 +02:00
|
|
|
array_push_unique(dependency, strs[0]);
|
2023-07-12 16:28:32 +02:00
|
|
|
return true;
|
2023-09-11 16:08:58 +02:00
|
|
|
} #endregion
|
2023-06-20 19:43:19 +02:00
|
|
|
|
2023-09-11 16:08:58 +02:00
|
|
|
static validate = function() { #region
|
2023-07-12 16:28:32 +02:00
|
|
|
dependency = [];
|
|
|
|
|
2023-07-11 20:36:44 +02:00
|
|
|
if(ds_map_exists(global.FUNCTIONS, symbol)) {
|
|
|
|
if(!is_array(l)) return false;
|
2023-07-25 20:12:40 +02:00
|
|
|
for( var i = 0, n = array_length(l); i < n; i++ )
|
2023-07-11 20:36:44 +02:00
|
|
|
if(!_validate(l[i])) return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-06-20 19:43:19 +02:00
|
|
|
switch(symbol) {
|
|
|
|
case "@": return _validate(l);
|
2023-07-11 20:36:44 +02:00
|
|
|
case "【": return true;
|
|
|
|
case "": return true;
|
2023-06-20 19:43:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return _validate(l) && _validate(r);
|
2023-09-11 16:08:58 +02:00
|
|
|
} #endregion
|
2023-06-20 19:43:19 +02:00
|
|
|
|
2023-09-11 16:08:58 +02:00
|
|
|
static _isAnimated = function(val) { #region
|
2023-06-20 19:43:19 +02:00
|
|
|
if(is_real(val)) return EXPRESS_TREE_ANIM.none;
|
2023-10-07 16:23:40 +02:00
|
|
|
if(is_struct(val)) return val.isDynamic();
|
2023-10-02 14:41:44 +02:00
|
|
|
if(is_array(val)) {
|
|
|
|
var anim = EXPRESS_TREE_ANIM.none;
|
|
|
|
for( var i = 0, n = array_length(val); i < n; i++ )
|
|
|
|
anim = max(anim, _isAnimated(val[i]));
|
|
|
|
return anim;
|
|
|
|
}
|
2023-06-20 19:43:19 +02:00
|
|
|
|
|
|
|
if(val == "value") return EXPRESS_TREE_ANIM.base_value;
|
2023-10-02 14:41:44 +02:00
|
|
|
var anim = nodeGetDataAnim(val);
|
|
|
|
anim_cache &= anim[1];
|
2023-06-20 19:43:19 +02:00
|
|
|
|
2023-10-02 14:41:44 +02:00
|
|
|
return anim[0];
|
2023-09-11 16:08:58 +02:00
|
|
|
} #endregion
|
2023-06-20 19:43:19 +02:00
|
|
|
|
2023-10-07 16:23:40 +02:00
|
|
|
static isDynamic = function() { #region
|
2023-10-02 14:41:44 +02:00
|
|
|
if(anim_cache && anim_stat != undefined) return anim_stat;
|
2023-06-20 19:43:19 +02:00
|
|
|
|
2023-10-02 14:41:44 +02:00
|
|
|
anim_stat = EXPRESS_TREE_ANIM.none;
|
|
|
|
anim_stat = max(anim_stat, _isAnimated(l));
|
|
|
|
if(symbol != "@") anim_stat = max(anim_stat, _isAnimated(r));
|
|
|
|
|
|
|
|
return anim_stat;
|
2023-09-11 16:08:58 +02:00
|
|
|
} #endregion
|
2023-06-20 19:43:19 +02:00
|
|
|
|
2023-09-11 16:08:58 +02:00
|
|
|
static eval = function(params = {}, isLeft = false) { #region
|
2023-09-13 15:06:39 +02:00
|
|
|
//print($"{symbol}, {l} | {r}")
|
|
|
|
//print(params);
|
|
|
|
|
2023-07-11 20:36:44 +02:00
|
|
|
if(ds_map_exists(global.FUNCTIONS, symbol)) {
|
|
|
|
if(!is_array(l)) return 0;
|
|
|
|
|
|
|
|
var _fn = global.FUNCTIONS[? symbol];
|
|
|
|
var _ev = _fn[1];
|
|
|
|
var _l = array_create(array_length(l));
|
|
|
|
|
2023-07-25 20:12:40 +02:00
|
|
|
for( var i = 0, n = array_length(l); i < n; i++ )
|
2023-07-11 20:36:44 +02:00
|
|
|
_l[i] = getVal(l[i], params);
|
2023-09-13 15:06:39 +02:00
|
|
|
|
2023-10-02 14:41:44 +02:00
|
|
|
printIf(global.LOG_EXPRESSION, $"Function {symbol}{_l}");
|
|
|
|
|
2023-07-11 20:36:44 +02:00
|
|
|
var res = _ev(_l);
|
2023-10-02 14:41:44 +02:00
|
|
|
printIf(global.LOG_EXPRESSION, $" = {res}");
|
2023-07-29 10:10:48 +02:00
|
|
|
printIf(global.LOG_EXPRESSION, "====================");
|
2023-07-11 20:36:44 +02:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2023-08-02 19:11:57 +02:00
|
|
|
var getRaw = false;
|
|
|
|
switch(symbol) {
|
|
|
|
case "=":
|
2023-09-13 15:06:39 +02:00
|
|
|
case "≔":
|
2023-08-02 19:11:57 +02:00
|
|
|
case "【":
|
|
|
|
getRaw = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
var v1 = getVal(l, params, getRaw || isLeft);
|
2023-07-11 20:36:44 +02:00
|
|
|
var v2 = getVal(r, params);
|
|
|
|
|
|
|
|
var res = 0;
|
2023-06-20 19:43:19 +02:00
|
|
|
|
2023-07-11 20:36:44 +02:00
|
|
|
if(symbol == "") {
|
|
|
|
res = v1;
|
2023-08-12 15:43:18 +02:00
|
|
|
} else if(symbol == "【") { // array builder
|
2023-07-11 20:36:44 +02:00
|
|
|
res = array_create(array_length(v1));
|
2023-11-17 06:24:31 +01:00
|
|
|
for( var i = 0, n = array_length(v1); i < n; i++ )
|
2023-07-11 20:36:44 +02:00
|
|
|
res[i] = getVal(v1[i], params);
|
2023-08-12 15:43:18 +02:00
|
|
|
} else if(symbol == "@") { // array getter
|
|
|
|
if(isLeft)
|
|
|
|
res = [ v1, v2 ];
|
|
|
|
else if(is_real(v2)) {
|
|
|
|
if(is_array(v1)) {
|
|
|
|
if(v2 < 0) v2 = array_length(v1) + v2;
|
|
|
|
res = array_safe_get(v1, v2);
|
|
|
|
} else if(is_string(v1)) {
|
|
|
|
if(v2 < 0) v2 = string_length(v1) + v2;
|
|
|
|
res = string_char_at(v1, v2 + 1);
|
|
|
|
}
|
|
|
|
}
|
2023-10-12 12:25:38 +02:00
|
|
|
|
|
|
|
//print($"Array getter {v1}, {v2} = {res}");
|
2023-08-12 15:43:18 +02:00
|
|
|
} else if(symbol == "=") { // value assignment
|
2023-07-23 20:21:35 +02:00
|
|
|
if(is_array(v1)) {
|
|
|
|
var val = params[$ v1[0]];
|
2023-08-02 19:11:57 +02:00
|
|
|
val = array_safe_set(val, v1[1], v2);
|
2023-07-23 20:21:35 +02:00
|
|
|
params[$ v1[0]] = val;
|
|
|
|
res = val;
|
|
|
|
} else {
|
|
|
|
params[$ v1] = v2;
|
|
|
|
res = v2;
|
|
|
|
}
|
2023-09-11 16:08:58 +02:00
|
|
|
} else if(symbol == "≔") { // function default replacement
|
|
|
|
if(!struct_exists(params, v1))
|
|
|
|
params[$ v1] = v2;
|
|
|
|
res = params[$ v1];
|
2023-08-12 15:43:18 +02:00
|
|
|
} else if(is_array(v1) && !is_array(v2)) { // evaluate value
|
2023-07-11 20:36:44 +02:00
|
|
|
res = array_create(array_length(v1));
|
2023-07-25 20:12:40 +02:00
|
|
|
for( var i = 0, n = array_length(res); i < n; i++ )
|
2023-07-11 20:36:44 +02:00
|
|
|
res[i] = eval_real(array_safe_get(v1, i), v2);
|
|
|
|
} else if(!is_array(v1) && is_array(v2)) {
|
|
|
|
res = array_create(array_length(v2));
|
2023-07-25 20:12:40 +02:00
|
|
|
for( var i = 0, n = array_length(res); i < n; i++ )
|
2023-07-11 20:36:44 +02:00
|
|
|
res[i] = eval_real(v1, array_safe_get(v2, i));
|
|
|
|
} else if(is_array(v1) && is_array(v2)) {
|
|
|
|
res = array_create(max(array_length(v1), array_length(v2)));
|
2023-07-25 20:12:40 +02:00
|
|
|
for( var i = 0, n = array_length(res); i < n; i++ )
|
2023-07-11 20:36:44 +02:00
|
|
|
res[i] = eval_real(array_safe_get(v1, i), array_safe_get(v2, i));
|
|
|
|
} else
|
|
|
|
res = eval_real(v1, v2);
|
|
|
|
|
2023-08-02 19:11:57 +02:00
|
|
|
var _v1_var = getVal(l, params, true);
|
|
|
|
switch(symbol) {
|
|
|
|
case "⊕":
|
|
|
|
case "⊖":
|
|
|
|
case "⊗":
|
|
|
|
case "⊘":
|
|
|
|
if(is_array(_v1_var)) {
|
|
|
|
var val = params[$ _v1_var[0]];
|
|
|
|
val = array_safe_set(val, _v1_var[1], res);
|
|
|
|
params[$ _v1_var[0]] = val;
|
|
|
|
} else
|
|
|
|
params[$ _v1_var] = res;
|
|
|
|
|
|
|
|
printIf(global.LOG_EXPRESSION, $"|{_v1_var}| = {v1}|{symbol}|{v2}| = {res}");
|
|
|
|
printIf(global.LOG_EXPRESSION, $"symbol : {symbol}");
|
|
|
|
printIf(global.LOG_EXPRESSION, $"l : | {typeof(l)} |{l}|");
|
|
|
|
printIf(global.LOG_EXPRESSION, $"r : | {typeof(r)} |{r}|");
|
|
|
|
printIf(global.LOG_EXPRESSION, "====================");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printIf(global.LOG_EXPRESSION, $"|{v1}|{symbol}|{v2}| = {res}");
|
|
|
|
printIf(global.LOG_EXPRESSION, $"symbol : {symbol}");
|
|
|
|
printIf(global.LOG_EXPRESSION, $"l : | {typeof(l)} |{l}|");
|
|
|
|
printIf(global.LOG_EXPRESSION, $"r : | {typeof(r)} |{r}|");
|
|
|
|
printIf(global.LOG_EXPRESSION, "====================");
|
|
|
|
break;
|
|
|
|
}
|
2023-06-20 19:43:19 +02:00
|
|
|
|
2023-07-11 20:36:44 +02:00
|
|
|
return res;
|
2023-09-11 16:08:58 +02:00
|
|
|
} #endregion
|
2023-07-11 20:36:44 +02:00
|
|
|
|
2023-09-11 16:08:58 +02:00
|
|
|
static eval_real = function(v1, v2, _symbol = symbol) { #region
|
2023-08-02 19:11:57 +02:00
|
|
|
switch(_symbol) {
|
2023-06-20 19:43:19 +02:00
|
|
|
case "+":
|
2023-08-02 19:11:57 +02:00
|
|
|
case "⊕":
|
2023-08-06 16:00:59 +02:00
|
|
|
if(is_string(v1) || is_string(v2)) return string(v1) + string(v2);
|
|
|
|
if(is_real(v1) && is_real(v2)) return v1 + v2;
|
2023-06-20 19:43:19 +02:00
|
|
|
return 0;
|
2023-08-02 19:11:57 +02:00
|
|
|
case "-":
|
2023-08-12 15:43:18 +02:00
|
|
|
case "∸":
|
2023-08-02 19:11:57 +02:00
|
|
|
case "⊖": return (is_real(v1) && is_real(v2))? v1 - v2 : 0;
|
|
|
|
case "*":
|
|
|
|
case "⊗": return (is_real(v1) && is_real(v2))? v1 * v2 : 0;
|
2023-06-20 19:43:19 +02:00
|
|
|
case "$": return (is_real(v1) && is_real(v2))? power(v1, v2) : 0;
|
2023-08-02 19:11:57 +02:00
|
|
|
case "/":
|
|
|
|
case "⊘": return (is_real(v1) && is_real(v2) && v2 != 0)? v1 / v2 : 0;
|
2023-07-12 21:00:05 +02:00
|
|
|
case "%": return (is_real(v1) && is_real(v2) && v2 != 0)? v1 % v2 : 0;
|
2023-06-20 19:43:19 +02:00
|
|
|
|
|
|
|
case "&": return (is_real(v1) && is_real(v2))? v1 & v2 : 0;
|
|
|
|
case "|": return (is_real(v1) && is_real(v2))? v1 | v2 : 0;
|
|
|
|
case "^": return (is_real(v1) && is_real(v2))? v1 ^ v2 : 0;
|
|
|
|
case "«": return (is_real(v1) && is_real(v2))? v1 << v2 : 0;
|
|
|
|
case "»": return (is_real(v1) && is_real(v2))? v1 >> v2 : 0;
|
|
|
|
case "~": return is_real(v1)? ~v1 : 0;
|
|
|
|
|
2023-07-12 21:00:05 +02:00
|
|
|
case "⩵": return (is_real(v1) && is_real(v2))? v1 == v2 : 0;
|
2023-06-20 19:43:19 +02:00
|
|
|
case "≠": return (is_real(v1) && is_real(v2))? v1 != v2 : 0;
|
|
|
|
case "≤": return (is_real(v1) && is_real(v2))? v1 <= v2 : 0;
|
|
|
|
case "≥": return (is_real(v1) && is_real(v2))? v1 >= v2 : 0;
|
|
|
|
case ">": return (is_real(v1) && is_real(v2))? v1 > v2 : 0;
|
|
|
|
case "<": return (is_real(v1) && is_real(v2))? v1 < v2 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return v1;
|
2023-09-11 16:08:58 +02:00
|
|
|
} #endregion
|
|
|
|
} #endregion
|
2023-07-12 21:00:05 +02:00
|
|
|
|
2023-09-11 16:08:58 +02:00
|
|
|
function evaluateFunction(fx, params = {}) { #region
|
2023-06-23 15:39:24 +02:00
|
|
|
if(isNumber(fx)) return toNumber(fx);
|
2023-07-12 21:00:05 +02:00
|
|
|
return evaluateFunctionList(fx).eval(params);
|
2023-09-11 16:08:58 +02:00
|
|
|
} #endregion
|
2022-01-13 05:24:03 +01:00
|
|
|
#endregion
|