2022-01-13 05:24:03 +01:00
enum JUNCTION_CONNECT {
input,
output
}
enum VALUE_TYPE {
integer = 0,
float = 1,
boolean = 2,
color = 3,
surface = 4,
path = 5,
curve = 6,
text = 7,
object = 8,
2022-01-25 14:13:47 +01:00
node = 9,
2022-12-13 09:20:36 +01:00
d3object = 10,
2022-01-25 10:58:11 +01:00
2022-01-25 14:13:47 +01:00
any = 11,
2023-02-14 02:51:14 +01:00
pathnode = 12,
particle = 13,
rigid = 14,
fdomain = 15,
2023-03-11 01:40:17 +01:00
struct = 16,
2023-03-19 09:17:39 +01:00
strands = 17,
mesh = 18,
2023-03-28 06:58:28 +02:00
trigger = 19,
2023-04-16 15:26:52 +02:00
atlas = 20,
2023-03-28 06:58:28 +02:00
2023-05-22 20:31:55 +02:00
d3vertex = 21,
2023-05-28 20:00:51 +02:00
gradient = 22,
2023-06-20 19:43:19 +02:00
armature = 23,
2023-06-24 22:12:35 +02:00
buffer = 24,
2023-05-03 21:42:17 +02:00
2023-07-21 12:40:20 +02:00
pbBox = 25,
2023-03-28 06:58:28 +02:00
action = 99,
2022-01-13 05:24:03 +01:00
}
enum VALUE_DISPLAY {
_default,
range,
//Int
enum_scroll,
enum_button,
rotation,
rotation_range,
slider,
slider_range,
//Color
palette,
//Int array
padding,
vector,
vector_range,
area,
2023-01-04 02:30:04 +01:00
kernel,
2023-06-21 20:36:53 +02:00
transform,
2023-07-21 12:40:20 +02:00
corner,
2022-01-13 05:24:03 +01:00
//Curve
curve,
//Misc
puppet_control,
button,
label,
//Array
path_array,
//Text
export_format,
2023-01-04 02:30:04 +01:00
code,
2023-02-14 02:51:14 +01:00
node_title,
2023-02-21 04:48:50 +01:00
text_array,
2022-01-13 05:24:03 +01:00
//path
path_save,
2022-09-27 06:37:28 +02:00
path_load,
2022-12-16 09:18:09 +01:00
path_font,
2023-05-03 21:42:17 +02:00
//vertex
d3vertex,
2022-01-13 05:24:03 +01:00
}
function value_color(i) {
2023-02-14 02:51:14 +01:00
static JUNCTION_COLORS = [
$6691ff, //int
$78e4ff, //float
$5d3f8c, //bool
$5dde8f, //color
$976bff, //surface
$4b00eb, //path
$d1c2c2, //curve
$e3ff66, //text
$b5b5ff, //object
$ffa64d, //node
#c1007c, //3D
$808080, //any
$b5b5ff, //path
$5dde8f, //particle
$e3ff66, //rigid
#4da6ff, //fdomain
2023-03-11 01:40:17 +01:00
$5d3f8c, //struct
2023-03-19 09:17:39 +01:00
$6691ff, //strand
$d1c2c2, //mesh
2023-03-28 06:58:28 +02:00
$5dde8f, //trigger
2023-04-16 15:26:52 +02:00
$976bff, //atlas
2023-05-03 21:42:17 +02:00
#c1007c, //d3vertex
2023-05-28 20:00:51 +02:00
$5dde8f, //gradient
2023-06-23 15:39:24 +02:00
$6691ff, //armature
2023-06-24 22:12:35 +02:00
$808080, //buffer
2023-07-21 12:40:20 +02:00
$976bff, //pbBox
2023-02-14 02:51:14 +01:00
];
2023-03-28 06:58:28 +02:00
if(i == 99) return $5dde8f;
2022-01-13 05:24:03 +01:00
return JUNCTION_COLORS[safe_mod(max(0, i), array_length(JUNCTION_COLORS))];
}
function value_bit(i) {
switch(i) {
case VALUE_TYPE.integer : return 1 << 0 | 1 << 1;
2022-12-23 04:45:52 +01:00
case VALUE_TYPE.float : return 1 << 2 | 1 << 1;
case VALUE_TYPE.boolean : return 1 << 3 | 1 << 1;
case VALUE_TYPE.color : return 1 << 4;
2023-05-28 20:00:51 +02:00
case VALUE_TYPE.gradient : return 1 << 25;
2022-12-23 04:45:52 +01:00
case VALUE_TYPE.surface : return 1 << 5;
2022-01-13 05:24:03 +01:00
case VALUE_TYPE.path : return 1 << 10;
2023-01-25 06:49:00 +01:00
case VALUE_TYPE.text : return 1 << 10;
2023-02-14 02:51:14 +01:00
case VALUE_TYPE.object : return 1 << 13;
case VALUE_TYPE.d3object : return 1 << 14;
2023-05-03 21:42:17 +02:00
case VALUE_TYPE.d3vertex : return 1 << 24;
2023-02-14 02:51:14 +01:00
case VALUE_TYPE.pathnode : return 1 << 15;
case VALUE_TYPE.particle : return 1 << 16;
case VALUE_TYPE.rigid : return 1 << 17;
case VALUE_TYPE.fdomain : return 1 << 18;
2023-03-11 01:40:17 +01:00
case VALUE_TYPE.struct : return 1 << 19;
2023-03-19 09:17:39 +01:00
case VALUE_TYPE.strands : return 1 << 20;
case VALUE_TYPE.mesh : return 1 << 21;
2023-04-16 15:26:52 +02:00
case VALUE_TYPE.atlas : return 1 << 23;
2023-06-24 22:12:35 +02:00
case VALUE_TYPE.armature : return 1 << 26 | 1 << 19;
2023-02-14 02:51:14 +01:00
case VALUE_TYPE.node : return 1 << 32;
2022-01-13 05:24:03 +01:00
2023-06-24 22:12:35 +02:00
case VALUE_TYPE.buffer : return 1 << 27;
2023-07-21 12:40:20 +02:00
case VALUE_TYPE.pbBox : return 1 << 28;
2023-03-28 06:58:28 +02:00
case VALUE_TYPE.trigger : return 1 << 22;
case VALUE_TYPE.action : return 1 << 22 | 1 << 3;
2023-02-14 02:51:14 +01:00
case VALUE_TYPE.any : return ~0 & ~(1 << 32);
2022-01-13 05:24:03 +01:00
}
return 0;
}
function value_type_directional(f, t) {
2023-05-28 20:00:51 +02:00
if(f == VALUE_TYPE.surface && t == VALUE_TYPE.integer) return true;
if(f == VALUE_TYPE.surface && t == VALUE_TYPE.float) return true;
2022-12-23 04:45:52 +01:00
2023-02-14 02:51:14 +01:00
if(f == VALUE_TYPE.integer && t == VALUE_TYPE.text) return true;
if(f == VALUE_TYPE.float && t == VALUE_TYPE.text) return true;
if(f == VALUE_TYPE.boolean && t == VALUE_TYPE.text) return true;
2022-12-23 04:45:52 +01:00
2023-05-28 20:00:51 +02:00
if(f == VALUE_TYPE.integer && t == VALUE_TYPE.color) return true;
if(f == VALUE_TYPE.float && t == VALUE_TYPE.color) return true;
if(f == VALUE_TYPE.color && t == VALUE_TYPE.integer) return true;
if(f == VALUE_TYPE.color && t == VALUE_TYPE.float ) return true;
if(f == VALUE_TYPE.color && t == VALUE_TYPE.gradient) return true;
2022-12-23 04:45:52 +01:00
2023-03-19 09:17:39 +01:00
if(f == VALUE_TYPE.strands && t == VALUE_TYPE.pathnode ) return true;
if(f == VALUE_TYPE.color && t == VALUE_TYPE.struct ) return true;
if(f == VALUE_TYPE.mesh && t == VALUE_TYPE.struct ) return true;
2022-01-13 05:24:03 +01:00
return false;
}
function typeArray(_type) {
switch(_type) {
case VALUE_DISPLAY.range :
case VALUE_DISPLAY.vector_range :
case VALUE_DISPLAY.rotation_range :
case VALUE_DISPLAY.slider_range :
case VALUE_DISPLAY.vector :
case VALUE_DISPLAY.padding :
case VALUE_DISPLAY.area :
case VALUE_DISPLAY.puppet_control :
2023-01-04 02:30:04 +01:00
case VALUE_DISPLAY.kernel :
2023-06-23 15:39:24 +02:00
case VALUE_DISPLAY.transform :
2022-01-13 05:24:03 +01:00
case VALUE_DISPLAY.curve :
case VALUE_DISPLAY.path_array :
case VALUE_DISPLAY.palette :
2023-02-21 04:48:50 +01:00
case VALUE_DISPLAY.text_array :
2023-05-03 21:42:17 +02:00
case VALUE_DISPLAY.d3vertex :
2023-02-28 09:43:01 +01:00
return 1;
2022-01-13 05:24:03 +01:00
}
return 0;
}
2023-02-14 02:51:14 +01:00
function typeArrayDynamic(_type) {
switch(_type) {
case VALUE_DISPLAY.curve :
case VALUE_DISPLAY.palette :
return true;
}
return false;
}
function typeCompatible(fromType, toType, directional_cast = true) {
if(value_bit(fromType) & value_bit(toType) != 0)
return true;
if(!directional_cast)
return false;
return value_type_directional(fromType, toType);
}
2023-02-19 02:13:19 +01:00
function typeIncompatible(from, to) {
if(from.type == VALUE_TYPE.surface && (to.type == VALUE_TYPE.integer || to.type == VALUE_TYPE.float)) {
switch(to.display_type) {
case VALUE_DISPLAY.area :
case VALUE_DISPLAY.kernel :
case VALUE_DISPLAY.vector_range :
case VALUE_DISPLAY.puppet_control :
case VALUE_DISPLAY.padding :
2023-03-11 01:40:17 +01:00
case VALUE_DISPLAY.curve :
return true;
2023-02-19 02:13:19 +01:00
}
}
return false;
}
2022-01-13 05:24:03 +01:00
enum KEYFRAME_END {
hold,
loop,
2023-01-09 03:14:20 +01:00
ping,
wrap,
2022-01-13 05:24:03 +01:00
}
2023-01-09 03:14:20 +01:00
globalvar ON_END_NAME;
ON_END_NAME = [ "Hold", "Loop", "Ping pong", "Wrap" ];
2022-08-30 07:36:37 +02:00
enum VALIDATION {
pass,
warning,
error
}
2022-12-27 04:00:50 +01:00
enum VALUE_UNIT {
constant,
reference
}
2023-03-05 07:16:44 +01:00
function isGraphable(prop) {
2023-05-16 21:28:16 +02:00
if(prop.type == VALUE_TYPE.integer || prop.type == VALUE_TYPE.float) {
if(prop.display_type == VALUE_DISPLAY.puppet_control)
return false;
2023-03-05 07:16:44 +01:00
return true;
2023-05-16 21:28:16 +02:00
}
2023-03-05 07:16:44 +01:00
if(prop.type == VALUE_TYPE.color && prop.display_type == VALUE_DISPLAY._default)
return true;
2022-01-13 05:24:03 +01:00
return false;
}
2022-12-27 04:00:50 +01:00
function nodeValueUnit(value) constructor {
self.value = value;
mode = VALUE_UNIT.constant;
reference = noone;
triggerButton = button(function() {
mode = !mode;
2023-02-14 02:51:14 +01:00
value.cache_value[0] = false;
2022-12-27 04:00:50 +01:00
value.unitConvert(mode);
2023-03-28 06:58:28 +02:00
value.node.doUpdate();
2022-12-27 04:00:50 +01:00
});
triggerButton.icon_blend = COLORS._main_icon_light;
triggerButton.icon = THEME.unit_ref;
static draw = function(_x, _y, _w, _h, _m) {
triggerButton.icon_index = mode;
triggerButton.tooltip = (mode? "Fraction" : "Pixel") + " unit";
triggerButton.draw(_x, _y, _w, _h, _m, THEME.button_hide);
}
static invApply = function(value, index = 0) {
if(mode == VALUE_UNIT.constant)
return value;
if(reference == noone)
return value;
return convertUnit(value, VALUE_UNIT.reference, index);
}
static apply = function(value, index = 0) {
if(mode == VALUE_UNIT.constant)
return value;
if(reference == noone)
return value;
return convertUnit(value, VALUE_UNIT.constant, index);
}
static convertUnit = function(value, unitTo, index = 0) {
var disp = self.value.display_type;
var base = reference(index);
var inv = unitTo == VALUE_UNIT.reference;
2022-12-27 13:30:02 +01:00
if(!is_array(base) && !is_array(value))
2022-12-27 04:00:50 +01:00
return inv? value / base : value * base;
2022-12-27 13:30:02 +01:00
if(!is_array(base) && is_array(value)) {
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(value); i < n; i++ )
2022-12-27 04:00:50 +01:00
value[i] = inv? value[i] / base : value[i] * base;
return value;
}
2022-12-27 13:30:02 +01:00
if(is_array(base) && !is_array(value)) {
2022-12-27 04:00:50 +01:00
return value;
2022-12-27 13:30:02 +01:00
}
2022-12-27 04:00:50 +01:00
switch(disp) {
case VALUE_DISPLAY.padding :
case VALUE_DISPLAY.vector :
case VALUE_DISPLAY.vector_range :
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(value); i < n; i++ )
2022-12-27 04:00:50 +01:00
value[i] = inv? value[i] / base[i % 2] : value[i] * base[i % 2];
return value;
case VALUE_DISPLAY.area :
for( var i = 0; i < 4; i++ )
value[i] = inv? value[i] / base[i % 2] : value[i] * base[i % 2];
return value;
}
return value;
}
}
2023-03-21 03:01:53 +01:00
global.displaySuffix_Range = [ "min", "max" ];
global.displaySuffix_Area = [ "x", "y", "w", "h" ];
global.displaySuffix_Padding = [ "right", "top", "left", "bottom" ];
global.displaySuffix_VecRange = [ "x min", "x max", "y min", "y max" ];
global.displaySuffix_Axis = [ "x", "y", "z", "w"];
2023-03-28 06:58:28 +02:00
function nodeValue(_name, _node, _connect, _type, _value, _tooltip = "") {
return new NodeValue(_name, _node, _connect, _type, _value, _tooltip);
}
2023-02-14 02:51:14 +01:00
function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constructor {
2022-01-13 05:24:03 +01:00
node = _node;
2022-01-26 06:57:34 +01:00
x = node.x;
2022-01-13 05:24:03 +01:00
y = node.y;
2023-02-14 02:51:14 +01:00
index = _connect == JUNCTION_CONNECT.input? ds_list_size(node.inputs) : ds_list_size(node.outputs);
2022-01-13 05:24:03 +01:00
type = _type;
2023-06-01 10:32:21 +02:00
forward = true;
2022-01-13 05:24:03 +01:00
2023-06-13 14:42:06 +02:00
_initName = _name;
name = __txt_junction_name(instanceof(node), type, index, _name);
name = _name;
2023-06-21 20:36:53 +02:00
static updateName = function() {
internalName = string_lower(string_replace_all(name, " ", "_"));
} updateName();
2023-06-05 18:27:53 +02:00
2023-04-15 14:48:29 +02:00
if(struct_has(node, "inputMap")) {
2023-05-07 20:55:13 +02:00
if(_connect == JUNCTION_CONNECT.input) node.inputMap[? internalName] = self;
else if(_connect == JUNCTION_CONNECT.output) node.outputMap[? internalName] = self;
2023-04-15 14:48:29 +02:00
}
2023-04-23 16:47:33 +02:00
tooltip = _tooltip;
2023-02-14 02:51:14 +01:00
editWidget = noone;
2022-01-13 05:24:03 +01:00
connect_type = _connect;
value_from = noone;
value_to = ds_list_create();
2023-01-17 08:11:55 +01:00
value_to_arr = [];
2022-01-13 05:24:03 +01:00
accept_array = true;
2023-02-21 04:48:50 +01:00
array_depth = 0;
2023-02-14 02:51:14 +01:00
auto_connect = true;
setFrom_condition = -1;
2022-01-13 05:24:03 +01:00
2023-03-21 03:01:53 +01:00
is_anim = false;
sep_axis = false;
sepable = is_array(_value) && array_length(_value) > 1;
animator = new valueAnimator(_value, self, false);
animators = [];
if(is_array(_value))
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(_value); i < n; i++ ) {
2023-03-21 03:01:53 +01:00
animators[i] = new valueAnimator(_value[i], self, true);
animators[i].index = i;
}
2022-09-23 13:28:42 +02:00
def_val = _value;
on_end = KEYFRAME_END.hold;
2023-07-12 21:00:05 +02:00
loop_range = -1;
2022-12-27 04:00:50 +01:00
unit = new nodeValueUnit(self);
2023-07-15 20:01:29 +02:00
extra_data = {};
2022-12-23 04:45:52 +01:00
dyna_depo = ds_list_create();
2022-01-13 05:24:03 +01:00
2023-03-28 06:58:28 +02:00
draw_line_shift_x = 0;
draw_line_shift_y = 0;
2023-06-17 14:30:49 +02:00
draw_line_thick = 1;
2023-03-02 07:59:14 +01:00
draw_line_shift_hover = false;
2023-03-05 07:16:44 +01:00
drawLineIndex = 1;
2023-07-25 20:12:40 +02:00
draw_line_vb = noone;
2023-03-02 07:59:14 +01:00
2023-03-21 03:01:53 +01:00
show_graph = false;
graph_h = ui(64);
2022-11-21 06:38:44 +01:00
visible = _connect == JUNCTION_CONNECT.output || _type == VALUE_TYPE.surface || _type == VALUE_TYPE.path;
2022-01-13 05:24:03 +01:00
show_in_inspector = true;
display_type = VALUE_DISPLAY._default;
2023-05-03 21:42:17 +02:00
if(_type == VALUE_TYPE.curve) display_type = VALUE_DISPLAY.curve;
else if(_type == VALUE_TYPE.d3vertex) display_type = VALUE_DISPLAY.d3vertex;
2022-01-13 05:24:03 +01:00
display_data = -1;
2023-03-05 07:16:44 +01:00
display_attribute = noone;
2022-01-13 05:24:03 +01:00
2022-08-30 07:36:37 +02:00
value_validation = VALIDATION.pass;
2023-02-14 02:51:14 +01:00
error_notification = noone;
2022-08-30 07:36:37 +02:00
2023-01-09 03:14:20 +01:00
extract_node = "";
2023-02-14 02:51:14 +01:00
is_changed = true;
2023-05-16 21:28:16 +02:00
cache_value = [ false, false, undefined ];
2023-02-14 02:51:14 +01:00
cache_array = [ false, false ];
2023-07-25 20:12:40 +02:00
use_cache = true;
2023-02-14 02:51:14 +01:00
2023-04-15 14:48:29 +02:00
expUse = false;
expression = "";
expTree = noone;
2023-04-16 11:53:46 +02:00
express_edit = new textArea(TEXTBOX_INPUT.text, function(str) {
2023-04-15 14:48:29 +02:00
expression = str;
2023-06-17 14:30:49 +02:00
expressionUpdate();
2023-03-08 07:35:51 +01:00
});
2023-07-12 21:00:05 +02:00
express_edit.autocomplete_server = pxl_autocomplete_server;
express_edit.function_guide_server = pxl_function_guide_server;
express_edit.parser_server = pxl_document_parser;
2023-07-12 16:28:32 +02:00
express_edit.format = TEXT_AREA_FORMAT.code;
express_edit.font = f_code;
2023-04-16 11:53:46 +02:00
express_edit.boxColor = COLORS._main_value_positive;
express_edit.align = fa_left;
2023-03-08 07:35:51 +01:00
2023-05-28 20:00:51 +02:00
process_array = true;
2023-06-04 12:38:40 +02:00
validateValue = true;
2023-05-28 20:00:51 +02:00
2023-07-21 12:40:20 +02:00
fullUpdate = false;
2023-02-14 02:51:14 +01:00
static setDefault = function(vals) {
if(LOADING || APPENDING) return self;
ds_list_clear(animator.values);
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(vals); i < n; i++ )
2023-02-14 02:51:14 +01:00
ds_list_add(animator.values, new valueKey(vals[i][0], vals[i][1], animator));
return self;
}
2023-05-16 21:28:16 +02:00
static resetValue = function() { setValue(def_val); }
2022-12-27 13:30:02 +01:00
static setUnitRef = function(ref, mode = VALUE_UNIT.constant) {
2023-03-08 07:35:51 +01:00
unit.reference = ref;
unit.mode = mode;
cache_value[0] = false;
2022-12-27 04:00:50 +01:00
return self;
}
2022-01-19 03:05:13 +01:00
static setVisible = function(inspector) {
2023-02-14 02:51:14 +01:00
if(connect_type == JUNCTION_CONNECT.input) {
show_in_inspector = inspector;
visible = argument_count > 1? argument[1] : visible;
} else
visible = inspector;
2022-01-13 05:24:03 +01:00
return self;
}
2023-03-05 07:16:44 +01:00
static setDisplay = function(_type = VALUE_DISPLAY._default, _data = -1, _attr = noone) {
display_type = _type;
display_data = _data;
display_attribute = _attr;
2022-01-13 05:24:03 +01:00
resetDisplay();
return self;
}
2022-12-21 02:30:23 +01:00
static rejectArray = function() {
accept_array = false;
2022-01-13 05:24:03 +01:00
return self;
}
2023-07-25 20:12:40 +02:00
static uncache = function() {
use_cache = false;
return self;
}
2023-03-07 14:29:47 +01:00
static setArrayDepth = function(aDepth) {
array_depth = aDepth;
return self;
}
2023-02-14 02:51:14 +01:00
static rejectConnect = function() {
auto_connect = false;
return self;
}
2023-05-28 20:00:51 +02:00
static rejectArrayProcess = function() {
process_array = false;
return self;
}
2023-06-01 10:32:21 +02:00
static nonForward = function() {
forward = false;
return self;
}
2023-06-04 12:38:40 +02:00
static nonValidate = function() {
validateValue = false;
return self;
}
2023-01-09 03:14:20 +01:00
static isAnimable = function() {
2023-07-11 14:18:23 +02:00
//if(type == VALUE_TYPE.gradient) return false;
2023-02-21 04:48:50 +01:00
if(display_type == VALUE_DISPLAY.text_array) return false;
2023-01-09 03:14:20 +01:00
return true;
}
2023-03-26 07:13:36 +02:00
static setDropKey = function() {
switch(type) {
case VALUE_TYPE.integer : drop_key = "Number"; break;
case VALUE_TYPE.float : drop_key = "Number"; break;
case VALUE_TYPE.boolean : drop_key = "Bool"; break;
case VALUE_TYPE.color :
switch(display_type) {
case VALUE_DISPLAY.palette : drop_key = "Palette"; break;
default : drop_key = "Color";
}
break;
2023-05-28 20:00:51 +02:00
case VALUE_TYPE.gradient : drop_key = "Gradient"; break;
2023-03-26 07:13:36 +02:00
case VALUE_TYPE.path : drop_key = "Asset"; break;
case VALUE_TYPE.text : drop_key = "Text"; break;
case VALUE_TYPE.pathnode : drop_key = "Path"; break;
case VALUE_TYPE.struct : drop_key = "Struct"; break;
default:
drop_key = "None";
}
}
setDropKey();
2022-01-13 05:24:03 +01:00
static resetDisplay = function() {
editWidget = noone;
switch(display_type) {
case VALUE_DISPLAY.button :
editWidget = button(display_data[0]);
editWidget.text = display_data[1];
visible = false;
return;
}
switch(type) {
case VALUE_TYPE.float :
case VALUE_TYPE.integer :
2023-02-14 02:51:14 +01:00
var _txt = TEXTBOX_INPUT.number;
2023-01-09 03:14:20 +01:00
2022-01-13 05:24:03 +01:00
switch(display_type) {
case VALUE_DISPLAY._default :
2022-12-18 03:20:38 +01:00
editWidget = new textBox(_txt, function(val) {
2023-02-14 02:51:14 +01:00
return setValueDirect(val);
2022-01-13 05:24:03 +01:00
} );
editWidget.slidable = true;
2023-02-14 02:51:14 +01:00
if(type == VALUE_TYPE.integer) editWidget.slide_speed = 1;
2022-01-13 05:24:03 +01:00
if(display_data != -1) editWidget.slide_speed = display_data;
2023-01-09 03:14:20 +01:00
extract_node = "Node_Number";
2022-01-13 05:24:03 +01:00
break;
case VALUE_DISPLAY.range :
editWidget = new rangeBox(_txt, function(index, val) {
2023-03-21 03:01:53 +01:00
//var _val = animator.getValue();
//_val[index] = val;
return setValueDirect(val, index);
2022-01-13 05:24:03 +01:00
} );
2023-02-14 02:51:14 +01:00
if(type == VALUE_TYPE.integer) editWidget.setSlideSpeed(1);
2022-01-13 05:24:03 +01:00
if(display_data != -1) editWidget.extras = display_data;
2023-01-09 03:14:20 +01:00
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(animators); i < n; i++ )
2023-03-21 03:01:53 +01:00
animators[i].suffix = " " + array_safe_get(global.displaySuffix_Range, i);
2023-01-09 03:14:20 +01:00
extract_node = "Node_Number";
2022-01-13 05:24:03 +01:00
break;
case VALUE_DISPLAY.vector :
2023-01-09 03:14:20 +01:00
var val = animator.getValue();
if(array_length(val) <= 4) {
2023-05-03 21:42:17 +02:00
editWidget = new vectorBox(array_length(animator.getValue()), function(index, val) {
2023-03-21 03:01:53 +01:00
//var _val = animator.getValue();
//_val[index] = val;
return setValueDirect(val, index);
2022-12-27 04:00:50 +01:00
}, unit );
2023-02-14 02:51:14 +01:00
if(type == VALUE_TYPE.integer) editWidget.setSlideSpeed(1);
2022-01-13 05:24:03 +01:00
if(display_data != -1) editWidget.extras = display_data;
2023-01-09 03:14:20 +01:00
2023-07-15 20:01:29 +02:00
if(array_length(val) == 2) {
extract_node = [ "Node_Vector2", "Node_Path" ];
} else if(array_length(val) == 3)
2023-01-09 03:14:20 +01:00
extract_node = "Node_Vector3";
else if(array_length(val) == 4)
extract_node = "Node_Vector4";
2022-01-13 05:24:03 +01:00
}
2023-03-21 03:01:53 +01:00
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(animators); i < n; i++ )
2023-03-28 06:58:28 +02:00
animators[i].suffix = " " + string(array_safe_get(global.displaySuffix_Axis, i));
2023-03-21 03:01:53 +01:00
2022-01-13 05:24:03 +01:00
break;
case VALUE_DISPLAY.vector_range :
2023-01-09 03:14:20 +01:00
var val = animator.getValue();
editWidget = new vectorRangeBox(array_length(val), _txt, function(index, val) {
2023-03-21 03:01:53 +01:00
//var _val = animator.getValue();
//_val[index] = val;
return setValueDirect(val, index);
2022-12-27 04:00:50 +01:00
}, unit );
2023-02-14 02:51:14 +01:00
if(type == VALUE_TYPE.integer) editWidget.setSlideSpeed(1);
2022-01-13 05:24:03 +01:00
if(display_data != -1) editWidget.extras = display_data;
2023-01-09 03:14:20 +01:00
if(array_length(val) == 2)
extract_node = "Node_Vector2";
else if(array_length(val) == 3)
extract_node = "Node_Vector3";
else if(array_length(val) == 4)
extract_node = "Node_Vector4";
2023-03-21 03:01:53 +01:00
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(animators); i < n; i++ )
2023-03-28 06:58:28 +02:00
animators[i].suffix = " " + string(array_safe_get(global.displaySuffix_VecRange, i));
2023-03-21 03:01:53 +01:00
2022-01-13 05:24:03 +01:00
break;
case VALUE_DISPLAY.rotation :
2023-03-21 03:01:53 +01:00
editWidget = new rotator(function(val) {
return setValueDirect(val);
2022-12-16 09:18:09 +01:00
}, display_data );
2023-01-09 03:14:20 +01:00
extract_node = "Node_Number";
2022-01-13 05:24:03 +01:00
break;
case VALUE_DISPLAY.rotation_range :
editWidget = new rotatorRange(function(index, val) {
2023-03-21 03:01:53 +01:00
//var _val = animator.getValue();
//_val[index] = round(val);
return setValueDirect(val, index);
2022-01-13 05:24:03 +01:00
} );
2023-01-09 03:14:20 +01:00
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(animators); i < n; i++ )
2023-03-21 03:01:53 +01:00
animators[i].suffix = " " + array_safe_get(global.displaySuffix_Range, i);
2023-01-09 03:14:20 +01:00
extract_node = "Node_Vector2";
2022-01-13 05:24:03 +01:00
break;
case VALUE_DISPLAY.slider :
editWidget = new slider(display_data[0], display_data[1], display_data[2], function(val) {
2023-02-14 02:51:14 +01:00
return setValueDirect(toNumber(val));
2022-01-13 05:24:03 +01:00
} );
2023-02-14 02:51:14 +01:00
if(type == VALUE_TYPE.integer) editWidget.setSlideSpeed(1);
2023-01-09 03:14:20 +01:00
extract_node = "Node_Number";
2022-01-13 05:24:03 +01:00
break;
case VALUE_DISPLAY.slider_range :
2023-02-23 07:02:19 +01:00
editWidget = new sliderRange(display_data[0], display_data[1], display_data[2], function(index, val) {
2023-03-21 03:01:53 +01:00
//var _val = animator.getValue();
//_val[index] = val;
return setValueDirect(val, index);
2022-01-13 05:24:03 +01:00
} );
2023-02-14 02:51:14 +01:00
if(type == VALUE_TYPE.integer) editWidget.setSlideSpeed(1);
2023-01-09 03:14:20 +01:00
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(animators); i < n; i++ )
2023-03-21 03:01:53 +01:00
animators[i].suffix = " " + array_safe_get(global.displaySuffix_Range, i);
2023-01-09 03:14:20 +01:00
extract_node = "Node_Vector2";
2022-01-13 05:24:03 +01:00
break;
case VALUE_DISPLAY.area :
editWidget = new areaBox(function(index, val) {
2023-03-21 03:01:53 +01:00
return setValueDirect(val, index);
2022-12-27 04:00:50 +01:00
}, unit);
2023-02-14 02:51:14 +01:00
if(type == VALUE_TYPE.integer) editWidget.setSlideSpeed(1);
2022-01-13 05:24:03 +01:00
if(display_data != -1) editWidget.onSurfaceSize = display_data;
2023-01-09 03:14:20 +01:00
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(animators); i < n; i++ )
2023-03-23 13:38:50 +01:00
animators[i].suffix = " " + array_safe_get(global.displaySuffix_Area, i, "");
2023-03-21 03:01:53 +01:00
2023-07-15 20:01:29 +02:00
extra_data.area_type = AREA_MODE.area;
2023-01-09 03:14:20 +01:00
extract_node = "Node_Area";
2022-01-13 05:24:03 +01:00
break;
case VALUE_DISPLAY.padding :
editWidget = new paddingBox(function(index, val) {
2023-03-21 03:01:53 +01:00
//var _val = animator.getValue();
//_val[index] = val;
return setValueDirect(val, index);
2022-12-27 04:00:50 +01:00
}, unit);
2023-02-14 02:51:14 +01:00
if(type == VALUE_TYPE.integer) editWidget.setSlideSpeed(1);
2023-01-09 03:14:20 +01:00
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(animators); i < n; i++ )
2023-07-21 12:40:20 +02:00
animators[i].suffix = " " + array_safe_get(global.displaySuffix_Padding, i);
extract_node = "Node_Vector4";
break;
case VALUE_DISPLAY.corner :
editWidget = new cornerBox(function(index, val) {
return setValueDirect(val, index);
}, unit);
if(type == VALUE_TYPE.integer) editWidget.setSlideSpeed(1);
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(animators); i < n; i++ )
2023-03-21 03:01:53 +01:00
animators[i].suffix = " " + array_safe_get(global.displaySuffix_Padding, i);
2023-01-09 03:14:20 +01:00
extract_node = "Node_Vector4";
2022-01-13 05:24:03 +01:00
break;
case VALUE_DISPLAY.puppet_control :
2022-09-23 13:28:42 +02:00
editWidget = new controlPointBox(function(index, val) {
2023-03-21 03:01:53 +01:00
//var _val = animator.getValue();
//_val[index] = val;
return setValueDirect(val, index);
2022-09-23 13:28:42 +02:00
});
2023-01-09 03:14:20 +01:00
extract_node = "";
2022-01-13 05:24:03 +01:00
break;
case VALUE_DISPLAY.enum_scroll :
editWidget = new scrollBox(display_data, function(val) {
if(val == -1) return;
2023-02-14 02:51:14 +01:00
return setValueDirect(toNumber(val));
2022-01-13 05:24:03 +01:00
} );
2023-03-05 07:16:44 +01:00
if(is_struct(display_attribute)) {
editWidget.update_hover = display_attribute[$ "update_hover"];
}
2023-01-09 03:14:20 +01:00
2023-02-14 02:51:14 +01:00
rejectConnect();
2023-01-09 03:14:20 +01:00
extract_node = "";
2022-01-13 05:24:03 +01:00
break;
case VALUE_DISPLAY.enum_button :
2023-07-30 13:56:22 +02:00
editWidget = new buttonGroup(display_data, function(val) {
2023-02-14 02:51:14 +01:00
return setValueDirect(val);
2022-01-13 05:24:03 +01:00
} );
2023-01-09 03:14:20 +01:00
2023-02-14 02:51:14 +01:00
rejectConnect();
2023-01-09 03:14:20 +01:00
extract_node = "";
2022-01-13 05:24:03 +01:00
break;
2023-01-04 02:30:04 +01:00
case VALUE_DISPLAY.kernel :
2023-02-23 07:02:19 +01:00
editWidget = new matrixGrid(_txt, function(index, val) {
2023-01-04 02:30:04 +01:00
var _val = animator.getValue();
_val[index] = val;
2023-02-14 02:51:14 +01:00
return setValueDirect(_val);
2023-01-04 02:30:04 +01:00
}, unit );
2023-02-14 02:51:14 +01:00
if(type == VALUE_TYPE.integer) editWidget.setSlideSpeed(1);
2023-01-04 02:30:04 +01:00
if(display_data != -1) editWidget.extras = display_data;
2023-01-09 03:14:20 +01:00
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(animators); i < n; i++ )
2023-03-21 03:01:53 +01:00
animators[i].suffix = " " + string(i);
2023-06-21 20:36:53 +02:00
extract_node = "";
break;
case VALUE_DISPLAY.transform :
2023-06-23 15:39:24 +02:00
editWidget = new transformBox(function(index, val) {
2023-06-21 20:36:53 +02:00
var _val = animator.getValue();
_val[index] = val;
return setValueDirect(_val);
});
2023-07-05 15:09:52 +02:00
extract_node = "Node_Transform_Array";
2023-01-04 02:30:04 +01:00
break;
2022-01-13 05:24:03 +01:00
}
break;
case VALUE_TYPE.boolean :
editWidget = new checkBox(function() {
2023-02-14 02:51:14 +01:00
return setValueDirect(!animator.getValue());
2022-01-13 05:24:03 +01:00
} );
2023-01-09 03:14:20 +01:00
extract_node = "Node_Boolean";
2022-01-13 05:24:03 +01:00
break;
case VALUE_TYPE.color :
switch(display_type) {
case VALUE_DISPLAY._default :
2023-02-28 09:43:01 +01:00
editWidget = new buttonColor(function(color) {
2023-02-14 02:51:14 +01:00
return setValueDirect(color);
2022-01-13 05:24:03 +01:00
} );
2023-01-09 03:14:20 +01:00
2023-03-05 07:16:44 +01:00
graph_h = ui(16);
2023-01-09 03:14:20 +01:00
extract_node = "Node_Color";
break;
2022-01-13 05:24:03 +01:00
case VALUE_DISPLAY.palette :
2023-02-28 09:43:01 +01:00
editWidget = new buttonPalette(function(color) {
2023-02-14 02:51:14 +01:00
return setValueDirect(color);
2022-01-13 05:24:03 +01:00
} );
2023-01-09 03:14:20 +01:00
extract_node = "Node_Palette";
break;
2022-01-13 05:24:03 +01:00
}
break;
2023-05-28 20:00:51 +02:00
case VALUE_TYPE.gradient :
editWidget = new buttonGradient(function(gradient) {
return setValueDirect(gradient);
} );
extract_node = "Node_Gradient_Out";
break;
2022-01-13 05:24:03 +01:00
case VALUE_TYPE.path :
switch(display_type) {
case VALUE_DISPLAY.path_array :
2023-02-23 07:02:19 +01:00
editWidget = new pathArrayBox(node, display_data, function(path) { setValueDirect(path); } );
2023-01-01 02:06:02 +01:00
break;
case VALUE_DISPLAY.path_load :
editWidget = new textBox(TEXTBOX_INPUT.text, function(str) { setValueDirect(str); },
button(function() {
var path = get_open_filename(display_data[0], display_data[1]);
2023-02-28 09:43:01 +01:00
key_release();
2023-01-01 02:06:02 +01:00
if(path == "") return noone;
2023-02-14 02:51:14 +01:00
return setValueDirect(path);
2023-01-01 02:06:02 +01:00
}, THEME.button_path_icon)
);
editWidget.align = fa_left;
2023-01-09 03:14:20 +01:00
extract_node = "Node_String";
2022-01-13 05:24:03 +01:00
break;
case VALUE_DISPLAY.path_save :
2023-01-01 02:06:02 +01:00
editWidget = new textBox(TEXTBOX_INPUT.text, function(str) { setValueDirect(str); },
button(function() {
var path = get_save_filename(display_data[0], display_data[1]);
2023-02-28 09:43:01 +01:00
key_release();
2023-01-01 02:06:02 +01:00
if(path == "") return noone;
2023-02-14 02:51:14 +01:00
return setValueDirect(path);
2023-01-01 02:06:02 +01:00
}, THEME.button_path_icon)
);
editWidget.align = fa_left;
2023-01-09 03:14:20 +01:00
extract_node = "Node_String";
2022-01-13 05:24:03 +01:00
break;
2023-01-01 02:06:02 +01:00
2022-12-16 09:18:09 +01:00
case VALUE_DISPLAY.path_font :
2023-01-17 08:11:55 +01:00
editWidget = new fontScrollBox(
2022-12-16 09:18:09 +01:00
function(val) {
2023-03-08 12:14:01 +01:00
return setValueDirect(DIRECTORY + "Fonts/" + FONT_INTERNAL[val]);
2022-12-16 09:18:09 +01:00
}
);
break;
2022-01-13 05:24:03 +01:00
}
break;
case VALUE_TYPE.curve :
display_type = VALUE_DISPLAY.curve;
2023-02-14 02:51:14 +01:00
editWidget = new curveBox(function(_modified) {
return setValueDirect(_modified);
});
2022-01-13 05:24:03 +01:00
break;
case VALUE_TYPE.text :
2023-02-21 04:48:50 +01:00
switch(display_type) {
case VALUE_DISPLAY._default :
editWidget = new textArea(TEXTBOX_INPUT.text, function(str) {
return setValueDirect(str);
});
extract_node = "Node_String";
break;
case VALUE_DISPLAY.code :
editWidget = new textArea(TEXTBOX_INPUT.text, function(str) {
return setValueDirect(str);
});
editWidget.font = f_code;
editWidget.format = TEXT_AREA_FORMAT.code;
editWidget.min_lines = 4;
extract_node = "Node_String";
break;
case VALUE_DISPLAY.text_array :
2023-02-23 07:02:19 +01:00
editWidget = new textArrayBox(function() {
2023-03-28 06:58:28 +02:00
return animator.values[| 0].value; }, display_data, function() { node.doUpdate();
2023-02-23 07:02:19 +01:00
});
2023-02-21 04:48:50 +01:00
break;
2023-01-04 02:30:04 +01:00
}
2022-01-13 05:24:03 +01:00
break;
2022-09-27 06:37:28 +02:00
case VALUE_TYPE.surface :
2023-02-14 02:51:14 +01:00
editWidget = new surfaceBox(function(ind) {
return setValueDirect(ind);
}, display_data );
2022-09-27 06:37:28 +02:00
show_in_inspector = true;
2023-07-18 17:51:40 +02:00
extract_node = "Node_Canvas";
2022-09-27 06:37:28 +02:00
break;
2023-07-15 20:01:29 +02:00
case VALUE_TYPE.pathnode :
extract_node = "Node_Path";
break;
2022-01-13 05:24:03 +01:00
}
2023-03-26 07:13:36 +02:00
setDropKey();
2022-01-13 05:24:03 +01:00
}
resetDisplay();
2023-06-17 14:30:49 +02:00
static expressionUpdate = function() {
2023-07-12 21:00:05 +02:00
expTree = evaluateFunctionList(expression);
2023-06-17 14:30:49 +02:00
node.triggerRender();
}
2022-08-30 07:36:37 +02:00
static onValidate = function() {
2023-06-04 12:38:40 +02:00
if(!validateValue) return;
2022-11-03 11:44:49 +01:00
var _val = value_validation, str = "";
2022-08-30 07:36:37 +02:00
value_validation = VALIDATION.pass;
switch(type) {
case VALUE_TYPE.path:
switch(display_type) {
case VALUE_DISPLAY.path_load:
2022-09-23 13:28:42 +02:00
var path = animator.getValue();
2022-12-27 13:30:02 +01:00
if(is_array(path)) path = path[0];
2022-11-03 11:44:49 +01:00
if(try_get_path(path) == -1) {
2022-08-30 07:36:37 +02:00
value_validation = VALIDATION.error;
2023-01-04 02:30:04 +01:00
str = "File not exist: " + string(path);
2022-11-03 11:44:49 +01:00
}
2022-08-30 07:36:37 +02:00
break;
case VALUE_DISPLAY.path_array:
2022-09-23 13:28:42 +02:00
var paths = animator.getValue();
2022-09-21 06:09:40 +02:00
if(is_array(paths)) {
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(paths); i < n; i++ ) {
2022-12-27 13:30:02 +01:00
if(try_get_path(paths[i]) != -1) continue;
value_validation = VALIDATION.error;
2023-01-04 02:30:04 +01:00
str = "File not exist: " + string(paths[i]);
2022-08-30 07:36:37 +02:00
}
2022-11-03 11:44:49 +01:00
} else {
2022-08-30 07:36:37 +02:00
value_validation = VALIDATION.error;
2023-01-04 02:30:04 +01:00
str = "File not exist: " + string(paths);
2022-11-03 11:44:49 +01:00
}
2022-08-30 07:36:37 +02:00
break;
}
break;
}
2022-12-27 13:30:02 +01:00
2022-08-30 07:36:37 +02:00
node.onValidate();
2022-12-27 13:30:02 +01:00
if(_val == value_validation) return self;
#region notification
2022-11-03 11:44:49 +01:00
if(value_validation == VALIDATION.error && error_notification == noone) {
error_notification = noti_error(str);
2023-01-25 06:49:00 +01:00
error_notification.onClick = function() { PANEL_GRAPH.focusNode(node); };
2022-11-03 11:44:49 +01:00
}
if(value_validation == VALIDATION.pass && error_notification != noone) {
noti_remove(error_notification);
error_notification = noone;
}
2022-12-27 13:30:02 +01:00
#endregion
2022-11-03 11:44:49 +01:00
2022-08-30 07:36:37 +02:00
return self;
}
2023-01-17 08:11:55 +01:00
static valueProcess = function(value, nodeFrom, applyUnit = true, arrIndex = 0) {
var typeFrom = nodeFrom.type;
var display = nodeFrom.display_type;
2023-05-28 20:00:51 +02:00
if(type == VALUE_TYPE.gradient && typeFrom == VALUE_TYPE.color) {
if(is_struct(value) && instanceof(value) == "gradientObject")
2023-02-28 09:43:01 +01:00
return value;
if(is_array(value)) {
2023-01-01 02:06:02 +01:00
var amo = array_length(value);
2023-02-14 02:51:14 +01:00
var grad = array_create(amo);
for( var i = 0; i < amo; i++ )
2023-02-28 09:43:01 +01:00
grad[i] = new gradientKey(i / amo, value[i]);
2023-03-02 07:59:14 +01:00
var g = new gradientObject();
g.keys = grad;
return g;
2023-02-28 09:43:01 +01:00
}
2023-01-25 06:49:00 +01:00
2023-03-02 07:59:14 +01:00
var grad = new gradientObject(value);
2023-02-28 09:43:01 +01:00
return grad;
2022-12-16 09:18:09 +01:00
}
2023-01-01 02:06:02 +01:00
2023-02-14 02:51:14 +01:00
if(display_type == VALUE_DISPLAY.palette && !is_array(value)) {
return [ value ];
}
2023-08-01 11:16:23 +02:00
if(display_type == VALUE_DISPLAY.area) {
var dispType = struct_try_get(nodeFrom.extra_data, "area_type", AREA_MODE.area);
var surfGet = nodeFrom.display_data;
if(!applyUnit || surfGet == -1) {
//print($" {value}");
return value;
}
var surf = surfGet();
var ww = surf[0];
var hh = surf[1];
switch(dispType) {
case AREA_MODE.area :
return value;
case AREA_MODE.padding :
var cx = (ww - value[0] + value[2]) / 2
var cy = (value[1] + hh - value[3]) / 2;
var sw = abs((ww - value[0]) - value[2]) / 2;
var sh = abs(value[1] - (hh - value[3])) / 2;
return [cx, cy, sw, sh, value[4]];
case AREA_MODE.two_point :
var cx = (value[0] + value[2]) / 2
var cy = (value[1] + value[3]) / 2;
var sw = abs(value[0] - value[2]) / 2;
var sh = abs(value[1] - value[3]) / 2;
return [cx, cy, sw, sh, value[4]];
}
}
2023-02-21 04:48:50 +01:00
if(type == VALUE_TYPE.text) {
switch(display_type) {
case VALUE_DISPLAY.text_array :
return value;
default:
return string_real(value);
}
}
2023-01-01 02:06:02 +01:00
if(typeFrom == VALUE_TYPE.integer && type == VALUE_TYPE.color)
2023-03-02 07:59:14 +01:00
return value;
2023-01-01 02:06:02 +01:00
2023-03-02 07:59:14 +01:00
if((typeFrom == VALUE_TYPE.integer || typeFrom == VALUE_TYPE.float || typeFrom == VALUE_TYPE.boolean) && type == VALUE_TYPE.color)
return value >= 1? value : make_color_hsv(0, 0, value * 255);
2023-01-01 02:06:02 +01:00
if(typeFrom == VALUE_TYPE.boolean && type == VALUE_TYPE.text)
return value? "true" : "false";
2023-01-09 03:14:20 +01:00
2023-01-01 02:06:02 +01:00
if(type == VALUE_TYPE.integer || type == VALUE_TYPE.float) {
if(typeFrom == VALUE_TYPE.text)
value = toNumber(value);
2023-01-09 03:14:20 +01:00
if(applyUnit)
2023-01-01 02:06:02 +01:00
return unit.apply(value, arrIndex);
}
2023-03-28 06:58:28 +02:00
if(type == VALUE_TYPE.surface && connect_type == JUNCTION_CONNECT.input && !is_surface(value) && def_val == USE_DEF)
return DEF_SURFACE;
2022-12-23 04:45:52 +01:00
return value;
2022-12-16 09:18:09 +01:00
}
2023-07-25 20:12:40 +02:00
static resetCache = function() {
cache_value[0] = false;
}
2023-07-29 10:10:48 +02:00
static getValue = function(_time = PROJECT.animator.current_frame, applyUnit = true, arrIndex = 0, useCache = false) {
2023-06-13 14:42:06 +02:00
if(type == VALUE_TYPE.trigger)
useCache = false;
2023-07-14 20:34:35 +02:00
global.cache_call++;
2023-07-25 20:12:40 +02:00
if(useCache && use_cache) {
2023-05-16 21:28:16 +02:00
var cache_hit = cache_value[0];
2023-07-25 20:12:40 +02:00
cache_hit &= (!is_anim && value_from == noone) || cache_value[1] == _time;
2023-05-16 21:28:16 +02:00
cache_hit &= cache_value[2] != undefined;
cache_hit &= connect_type == JUNCTION_CONNECT.input;
2023-07-28 19:41:57 +02:00
cache_hit &= unit.reference == noone || unit.mode == VALUE_UNIT.constant;
2023-07-29 10:10:48 +02:00
cache_hit &= !expUse;
2023-07-23 20:21:35 +02:00
2023-07-14 20:34:35 +02:00
if(cache_hit) {
global.cache_hit++;
return cache_value[2];
}
2023-05-16 21:28:16 +02:00
}
2023-02-14 02:51:14 +01:00
var val = _getValue(_time, applyUnit, arrIndex);
2023-05-16 21:28:16 +02:00
if(useCache) {
2023-07-23 20:21:35 +02:00
is_changed = !isEqual(cache_value[2], val);
2023-05-16 21:28:16 +02:00
cache_value[0] = true;
2023-07-23 20:21:35 +02:00
cache_value[1] = _time;
2023-05-16 21:28:16 +02:00
}
2023-02-14 02:51:14 +01:00
2023-07-23 20:21:35 +02:00
cache_value[2] = val;
2023-02-14 02:51:14 +01:00
return val;
}
2023-07-06 19:49:16 +02:00
static __getAnimValue = function(_time = PROJECT.animator.current_frame) {
2023-03-21 03:01:53 +01:00
if(sep_axis) {
var val = [];
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(animators); i < n; i++ )
2023-03-21 03:01:53 +01:00
val[i] = animators[i].getValue(_time);
return val;
} else
return animator.getValue(_time);
}
2023-07-06 19:49:16 +02:00
static _getValue = function(_time = PROJECT.animator.current_frame, applyUnit = true, arrIndex = 0) {
2022-12-10 05:06:01 +01:00
var _val = getValueRecursive(_time);
2022-01-18 05:31:19 +01:00
var val = _val[0];
2022-12-23 04:45:52 +01:00
var nod = _val[1];
var typ = nod.type;
var dis = nod.display_type;
2022-01-18 05:31:19 +01:00
2023-01-25 06:49:00 +01:00
if(typ == VALUE_TYPE.surface && (type == VALUE_TYPE.integer || type == VALUE_TYPE.float) && accept_array) { //Dimension conversion
2022-01-18 05:31:19 +01:00
if(is_array(val)) {
2023-01-01 02:06:02 +01:00
var eqSize = true;
var sArr = [];
var _osZ = 0;
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(val); i < n; i++ ) {
2023-01-01 02:06:02 +01:00
if(!is_surface(val[i])) continue;
var surfSz = [ surface_get_width(val[i]), surface_get_height(val[i]) ];
array_push(sArr, surfSz);
if(i && !array_equals(surfSz, _osZ))
eqSize = false;
_osZ = surfSz;
}
if(eqSize) return _osZ;
return sArr;
} else if (is_surface(val))
2022-01-18 05:31:19 +01:00
return [ surface_get_width(val), surface_get_height(val) ];
2023-01-01 02:06:02 +01:00
return [1, 1];
}
2022-01-18 05:31:19 +01:00
2023-03-26 07:13:36 +02:00
if(is_array(def_val) && !typeArrayDynamic(display_type)) { //Balance array (generate uniform array from single values)
2023-01-09 03:14:20 +01:00
if(!is_array(val)) {
2023-03-26 07:13:36 +02:00
val = array_create(array_length(def_val), val);
2023-01-17 08:11:55 +01:00
return valueProcess(val, nod, applyUnit, arrIndex);
2023-03-26 07:13:36 +02:00
} else if(array_length(val) < array_length(def_val)) {
for( var i = array_length(val); i < array_length(def_val); i++ )
2022-01-13 05:24:03 +01:00
val[i] = 0;
}
}
2023-05-22 20:31:55 +02:00
if(isArray(val) && array_length(val) < 128) { //Process data
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(val); i < n; i++ )
2023-01-17 08:11:55 +01:00
val[i] = valueProcess(val[i], nod, applyUnit, arrIndex);
2022-12-16 09:18:09 +01:00
} else
2023-01-17 08:11:55 +01:00
val = valueProcess(val, nod, applyUnit, arrIndex);
2022-12-16 09:18:09 +01:00
2022-01-13 05:24:03 +01:00
return val;
}
2023-07-06 19:49:16 +02:00
static getValueRecursive = function(_time = PROJECT.animator.current_frame) {
2023-01-25 06:49:00 +01:00
var val = [ -1, self ];
2022-01-13 05:24:03 +01:00
2023-06-13 14:42:06 +02:00
if(type == VALUE_TYPE.trigger && connect_type == JUNCTION_CONNECT.output) //trigger even will not propagate from input to output, need to be done manually
return [ __getAnimValue(_time), self ];
2023-03-08 07:35:51 +01:00
if(value_from == noone) {
2023-03-21 03:01:53 +01:00
var _val = __getAnimValue(_time);
2023-04-15 14:48:29 +02:00
val = [ _val, self ];
2023-03-08 07:35:51 +01:00
} else if(value_from != self)
2022-12-10 05:06:01 +01:00
val = value_from.getValueRecursive(_time);
2022-01-13 05:24:03 +01:00
2023-07-11 20:36:44 +02:00
if(expUse && is_struct(expTree) && expTree.validate()) {
2023-07-14 20:34:35 +02:00
//print($"========== EXPRESSION CALLED ==========");
//print(debug_get_callstack(8));
if(global.EVALUATE_HEAD != noone && global.EVALUATE_HEAD == self) {
//noti_warning($"Expression evaluation error : recursive call detected.");
} else {
2023-07-29 10:10:48 +02:00
printIf(global.LOG_EXPRESSION, "==================== EVAL BEGIN {expTree} ====================");
2023-07-14 20:34:35 +02:00
global.EVALUATE_HEAD = self;
var params = {
name: name,
node_name: node.display_name,
value: val[0]
};
val[0] = expTree.eval(variable_clone(params));
global.EVALUATE_HEAD = noone;
}
2023-07-11 20:36:44 +02:00
}
2023-04-15 14:48:29 +02:00
2022-01-13 05:24:03 +01:00
return val;
}
2023-03-21 03:01:53 +01:00
static setAnim = function(anim) {
is_anim = anim;
2023-03-28 06:58:28 +02:00
PANEL_ANIMATION.updatePropertyList();
2023-03-21 03:01:53 +01:00
}
2022-01-13 05:24:03 +01:00
static __anim = function() {
2023-05-03 21:42:17 +02:00
if(node.update_on_frame) return true;
if(expUse) {
if(!is_struct(expTree)) return false;
var res = expTree.isAnimated();
switch(res) {
case EXPRESS_TREE_ANIM.none : return false;
case EXPRESS_TREE_ANIM.base_value : return is_anim;
case EXPRESS_TREE_ANIM.animated : return true;
}
}
return is_anim;
2022-01-13 05:24:03 +01:00
}
2023-03-21 03:01:53 +01:00
2022-12-12 09:08:03 +01:00
static isAnimated = function() {
2022-01-13 05:24:03 +01:00
if(value_from == noone) return __anim();
2022-12-12 09:08:03 +01:00
else return value_from.isAnimated() || value_from.__anim();
2022-01-13 05:24:03 +01:00
}
2023-07-25 20:12:40 +02:00
static showValue = function() {
2023-08-01 11:16:23 +02:00
var val = _getValue(, false);
2022-01-13 05:24:03 +01:00
if(isArray()) {
if(array_length(val) == 0) return 0;
2023-05-16 21:28:16 +02:00
var v = val[safe_mod(node.preview_index, array_length(val))];
if(array_length(v) >= 100) return $"[{array_length(v)}]";
2022-01-13 05:24:03 +01:00
}
return val;
}
2023-02-14 02:51:14 +01:00
static isArray = function(val = undefined) {
if(val == undefined) {
if(cache_array[0])
return cache_array[1];
val = getValue();
}
cache_array[0] = true;
2023-02-21 04:48:50 +01:00
if(!is_array(val)) { //Value is array
2023-02-14 02:51:14 +01:00
cache_array[1] = false;
return cache_array[1];
}
2023-02-21 04:48:50 +01:00
if(array_depth == 0 && !typeArray(display_type)) { //Value is not an array by default, and no array depth enforced
2023-02-14 02:51:14 +01:00
cache_array[1] = true;
return cache_array[1];
}
2023-02-21 04:48:50 +01:00
var ar = val;
repeat(array_depth + typeArray(display_type)) { //Recursively get the first member of subarray to check if value has depth of "array_depth" or not
if(!is_array(ar) || !array_length(ar)) { //empty array
cache_array[1] = false;
return cache_array[1];
}
2022-12-23 04:45:52 +01:00
2023-02-21 04:48:50 +01:00
ar = ar[0];
2023-02-14 02:51:14 +01:00
}
2022-01-13 05:24:03 +01:00
2023-02-21 04:48:50 +01:00
cache_array[1] = is_array(ar);
2023-02-14 02:51:14 +01:00
return cache_array[1];
2022-01-13 05:24:03 +01:00
}
2023-02-28 09:43:01 +01:00
static arrayLength = function(val = undefined) {
if(val == undefined)
val = getValue();
if(!isArray(val))
return 0;
if(array_depth == 0 && !typeArray(display_type))
return array_length(val);
var ar = val;
repeat(array_depth - 1 + typeArray(display_type))
ar = ar[0];
return array_length(ar);
}
2023-07-06 19:49:16 +02:00
static setValue = function(val = 0, record = true, time = PROJECT.animator.current_frame, _update = true) {
2023-05-03 21:42:17 +02:00
//if(type == VALUE_TYPE.d3vertex && !is_array(val))
// print(val);
2022-12-27 04:00:50 +01:00
val = unit.invApply(val);
2023-03-21 03:01:53 +01:00
return setValueDirect(val, noone, record, time, _update);
2022-12-27 04:00:50 +01:00
}
2023-07-06 19:49:16 +02:00
static setValueDirect = function(val = 0, index = noone, record = true, time = PROJECT.animator.current_frame, _update = true) {
2023-03-21 03:01:53 +01:00
var updated = false;
2023-08-01 11:16:23 +02:00
//if(display_type == VALUE_DISPLAY.area) {
// print($"===== Set: {index} = {val} =====");
// printCallStack();
// print("");
//}
2023-03-21 03:01:53 +01:00
if(sep_axis) {
if(index == noone) {
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(animators); i < n; i++ )
2023-03-21 03:01:53 +01:00
updated |= animators[i].setValue(val[i], connect_type == JUNCTION_CONNECT.input && record, time);
} else
updated = animators[index].setValue(val, connect_type == JUNCTION_CONNECT.input && record, time);
} else {
if(index != noone) {
2023-07-21 12:40:20 +02:00
var _val = variable_clone(animator.getValue(time));
2023-03-21 03:01:53 +01:00
_val[index] = val;
updated = animator.setValue(_val, connect_type == JUNCTION_CONNECT.input && record, time);
} else
updated = animator.setValue(val, connect_type == JUNCTION_CONNECT.input && record, time);
}
2022-01-13 05:24:03 +01:00
2023-06-23 15:39:24 +02:00
if(type == VALUE_TYPE.gradient) updated = true;
if(display_type == VALUE_DISPLAY.palette) updated = true;
if(display_type == VALUE_DISPLAY.transform) updated = true;
2023-01-04 02:30:04 +01:00
2022-01-13 05:24:03 +01:00
if(updated) {
2023-01-04 02:30:04 +01:00
if(connect_type == JUNCTION_CONNECT.input) {
2022-12-10 05:06:01 +01:00
node.triggerRender();
2023-05-07 20:55:13 +02:00
if(_update) node.valueUpdate(self.index);
2023-03-02 07:59:14 +01:00
node.clearCacheForward();
2023-03-29 15:02:03 +02:00
2023-07-21 12:40:20 +02:00
if(fullUpdate) UPDATE |= RENDER_TYPE.full;
else UPDATE |= RENDER_TYPE.partial;
2023-01-04 02:30:04 +01:00
}
2022-01-13 05:24:03 +01:00
2023-07-30 13:56:22 +02:00
if(!LOADING) PROJECT.modified = true;
cache_value[0] = false;
2022-01-13 05:24:03 +01:00
}
2022-08-30 07:36:37 +02:00
onValidate();
2023-02-14 02:51:14 +01:00
2022-01-13 05:24:03 +01:00
return updated;
}
2023-03-05 07:16:44 +01:00
static isConnectable = function(_valueFrom, checkRecur = true, log = false) {
2023-01-09 03:14:20 +01:00
if(_valueFrom == -1 || _valueFrom == undefined || _valueFrom == noone) {
2023-01-25 06:49:00 +01:00
if(log)
noti_warning("LOAD: Cannot set node connection from " + string(_valueFrom) + " to " + string(name) + " of node " + string(node.name) + ".",, node);
2022-01-16 05:17:35 +01:00
return false;
2022-01-13 05:24:03 +01:00
}
2022-01-25 10:58:11 +01:00
if(_valueFrom == value_from) {
2023-06-19 20:28:30 +02:00
print("whaT");
2022-01-16 05:17:35 +01:00
return false;
2022-01-13 05:24:03 +01:00
}
if(_valueFrom == self) {
2023-01-25 06:49:00 +01:00
if(log)
noti_warning("setFrom: Self connection is not allowed.",, node);
2022-01-16 05:17:35 +01:00
return false;
2022-01-13 05:24:03 +01:00
}
2023-03-05 07:16:44 +01:00
if(!typeCompatible(_valueFrom.type, type)) {
2023-02-14 02:51:14 +01:00
if(log)
2023-07-25 20:12:40 +02:00
noti_warning($"setFrom: Type mismatch {_valueFrom.type} to {type}",, node);
2022-01-16 05:17:35 +01:00
return false;
2023-02-19 02:13:19 +01:00
}
if(typeIncompatible(_valueFrom, self)) {
if(log)
noti_warning("setFrom: Type mismatch",, node);
return false;
2022-01-13 05:24:03 +01:00
}
if(connect_type == _valueFrom.connect_type) {
2023-01-25 06:49:00 +01:00
if(log)
noti_warning("setFrom: Connect type mismatch",, node);
2022-01-16 05:17:35 +01:00
return false;
2022-01-13 05:24:03 +01:00
}
if(checkRecur && _valueFrom.searchNodeBackward(node)) {
2023-01-25 06:49:00 +01:00
if(log)
2023-03-05 07:16:44 +01:00
noti_warning("setFrom: Cyclic connection not allowed.",, node);
2022-01-16 05:17:35 +01:00
return false;
2022-01-13 05:24:03 +01:00
}
2023-02-14 02:51:14 +01:00
if(!accept_array && isArray(_valueFrom.getValue())) {
2023-01-25 06:49:00 +01:00
if(log)
noti_warning("setFrom: Array mismatch",, node);
2022-01-16 05:17:35 +01:00
return false;
2022-01-13 05:24:03 +01:00
}
2023-01-25 06:49:00 +01:00
if(!accept_array && _valueFrom.type == VALUE_TYPE.surface && (type == VALUE_TYPE.integer || type == VALUE_TYPE.float)) {
if(log)
noti_warning("setFrom: Array mismatch",, node);
return false;
2022-01-25 10:58:11 +01:00
}
2023-01-25 06:49:00 +01:00
return true;
}
2023-07-25 20:12:40 +02:00
static setFrom = function(_valueFrom, _update = true, checkRecur = true, log = false) {
2023-02-14 02:51:14 +01:00
if(_valueFrom == noone)
return removeFrom();
2023-03-28 06:58:28 +02:00
2023-07-25 20:12:40 +02:00
if(!isConnectable(_valueFrom, checkRecur, log))
return -1;
2023-01-25 06:49:00 +01:00
2023-03-28 06:58:28 +02:00
if(setFrom_condition != -1 && !setFrom_condition(_valueFrom))
2023-07-25 20:12:40 +02:00
return -2;
2023-02-14 02:51:14 +01:00
2023-01-25 06:49:00 +01:00
if(value_from != noone)
ds_list_remove(value_from.value_to, self);
2022-01-25 10:58:11 +01:00
2022-09-23 13:28:42 +02:00
var _o = animator.getValue();
2022-01-13 05:24:03 +01:00
recordAction(ACTION_TYPE.junction_connect, self, value_from);
value_from = _valueFrom;
ds_list_add(_valueFrom.value_to, self);
2022-01-16 05:17:35 +01:00
//show_debug_message("connected " + name + " to " + _valueFrom.name)
2022-01-13 05:24:03 +01:00
2023-02-14 02:51:14 +01:00
node.valueUpdate(index, _o);
2023-01-04 02:30:04 +01:00
if(_update && connect_type == JUNCTION_CONNECT.input) {
2023-01-09 03:14:20 +01:00
node.onValueFromUpdate(index);
2022-12-12 09:08:03 +01:00
node.triggerRender();
2023-02-23 07:02:19 +01:00
node.clearCacheForward();
2023-03-29 15:02:03 +02:00
2023-03-31 06:59:08 +02:00
UPDATE |= RENDER_TYPE.partial;
2022-12-12 09:08:03 +01:00
}
2022-01-16 05:17:35 +01:00
2023-02-14 02:51:14 +01:00
cache_array[0] = false;
cache_value[0] = false;
2023-03-02 07:59:14 +01:00
draw_line_shift_x = 0;
draw_line_shift_y = 0;
2023-07-06 19:49:16 +02:00
if(!LOADING) PROJECT.modified = true;
2023-03-28 06:58:28 +02:00
2022-01-16 05:17:35 +01:00
return true;
2022-01-13 05:24:03 +01:00
}
2022-01-26 06:57:34 +01:00
static removeFrom = function(_remove_list = true) {
2023-02-14 02:51:14 +01:00
recordAction(ACTION_TYPE.junction_disconnect, self, value_from);
2022-01-26 06:57:34 +01:00
if(_remove_list && value_from != noone)
2022-01-25 10:58:11 +01:00
ds_list_remove(value_from.value_to, self);
2022-01-13 05:24:03 +01:00
value_from = noone;
2023-01-04 02:30:04 +01:00
if(connect_type == JUNCTION_CONNECT.input)
2023-01-09 03:14:20 +01:00
node.onValueFromUpdate(index);
2023-04-14 12:23:25 +02:00
node.clearCacheForward();
2023-02-14 02:51:14 +01:00
return false;
2022-01-13 05:24:03 +01:00
}
static getShowString = function() {
var val = showValue();
2023-02-17 04:48:54 +01:00
return string_real(val);
2022-01-13 05:24:03 +01:00
}
static setString = function(str) {
2022-09-23 13:28:42 +02:00
var _o = animator.getValue();
2022-01-13 05:24:03 +01:00
if(string_pos(",", str) > 0) {
string_replace(str, "[", "");
string_replace(str, "]", "");
var ss = str, pos, val = [], ind = 0;
while(string_length(ss) > 0) {
pos = string_pos(",", ss);
if(pos == 0) {
val[ind++] = toNumber(ss);
ss = "";
} else {
val[ind++] = toNumber(string_copy(ss, 1, pos - 1));
ss = string_copy(ss, pos + 1, string_length(ss) - pos);
}
}
var _t = typeArray(display_type);
if(_t) {
2023-02-14 02:51:14 +01:00
if(array_length(_o) == array_length(val) || _t == 2)
2022-01-13 05:24:03 +01:00
setValue(val);
} else if(array_length(val) > 0) {
setValue(val[0]);
}
} else {
if(is_array(_o)) {
setValue(array_create(array_length(_o), toNumber(str)));
} else {
setValue(toNumber(str));
}
}
}
2022-01-26 06:57:34 +01:00
static checkConnection = function(_remove_list = true) {
if(value_from == noone) return;
if(value_from.node.active) return;
removeFrom(_remove_list);
2022-01-13 05:24:03 +01:00
}
static searchNodeBackward = function(_node) {
if(node == _node) return true;
for(var i = 0; i < ds_list_size(node.inputs); i++) {
var _in = node.inputs[| i].value_from;
if(_in && _in.searchNodeBackward(_node))
return true;
}
return false;
}
2022-12-27 04:00:50 +01:00
static unitConvert = function(mode) {
var _v = animator.values;
for( var i = 0; i < ds_list_size(_v); i++ )
_v[| i].value = unit.convertUnit(_v[| i].value, mode);
}
2022-01-13 05:24:03 +01:00
drag_type = 0;
drag_mx = 0;
drag_my = 0;
drag_sx = 0;
drag_sy = 0;
2022-12-19 13:35:30 +01:00
static drawOverlay = function(active, _x, _y, _s, _mx, _my, _snx, _sny) {
2023-04-05 20:13:27 +02:00
if(type != VALUE_TYPE.integer && type != VALUE_TYPE.float) return -1;
2023-01-01 02:06:02 +01:00
2023-04-05 20:13:27 +02:00
switch(display_type) {
case VALUE_DISPLAY._default :
var _angle = argument_count > 8? argument[ 8] : 0;
var _scale = argument_count > 9? argument[ 9] : 1;
var _spr = argument_count > 10? argument[10] : THEME.anchor_selector;
2023-04-07 21:25:27 +02:00
return preview_overlay_scalar(value_from == noone, active, _x, _y, _s, _mx, _my, _snx, _sny, _angle, _scale, _spr);
2022-01-13 05:24:03 +01:00
2023-04-05 20:13:27 +02:00
case VALUE_DISPLAY.rotation :
var _rad = argument_count > 8? argument[ 8] : 64;
2023-04-07 21:25:27 +02:00
return preview_overlay_rotation(value_from == noone, active, _x, _y, _s, _mx, _my, _snx, _sny, _rad);
2022-01-13 05:24:03 +01:00
2023-04-05 20:13:27 +02:00
case VALUE_DISPLAY.vector :
var _spr = argument_count > 8? argument[8] : THEME.anchor_selector;
var _sca = argument_count > 9? argument[9] : 1;
2023-04-07 21:25:27 +02:00
return preview_overlay_vector(value_from == noone, active, _x, _y, _s, _mx, _my, _snx, _sny, _spr);
2022-01-13 05:24:03 +01:00
2023-04-05 20:13:27 +02:00
case VALUE_DISPLAY.area :
2023-04-07 21:25:27 +02:00
return preview_overlay_area(value_from == noone, active, _x, _y, _s, _mx, _my, _snx, _sny, display_data);
2022-09-23 13:28:42 +02:00
2023-04-05 20:13:27 +02:00
case VALUE_DISPLAY.puppet_control :
2023-04-07 21:25:27 +02:00
return preview_overlay_puppet(value_from == noone, active, _x, _y, _s, _mx, _my, _snx, _sny);
2022-01-13 05:24:03 +01:00
}
2023-04-05 20:13:27 +02:00
2023-01-17 08:11:55 +01:00
return -1;
2022-01-13 05:24:03 +01:00
}
2023-07-12 16:28:32 +02:00
junction_drawing = [ THEME.node_junctions_single, type ];
2023-03-12 02:28:21 +01:00
static drawJunction = function(_s, _mx, _my, sca = 1) {
2022-01-26 06:57:34 +01:00
if(!isVisible()) return false;
var ss = max(0.25, _s / 2);
var is_hover = false;
2023-03-12 02:28:21 +01:00
if(PANEL_GRAPH.pHOVER && point_in_circle(_mx, _my, x, y, 10 * _s * sca)) {
2023-06-01 10:32:21 +02:00
//var _to = getJunctionTo();
//var _ss = "";
2023-07-25 20:12:40 +02:00
//for( var i = 0, n = array_length(_to); i < n; i++ )
2023-06-01 10:32:21 +02:00
// _ss += (i? ", " : "") + _to[i].internalName;
//TOOLTIP = _ss;
2022-01-26 06:57:34 +01:00
is_hover = true;
2023-03-28 06:58:28 +02:00
if(type == VALUE_TYPE.action)
2023-07-12 16:28:32 +02:00
junction_drawing = [THEME.node_junction_inspector, 1];
else
junction_drawing = [isArray()? THEME.node_junctions_array_hover : THEME.node_junctions_single_hover, type];
2023-03-28 06:58:28 +02:00
} else {
if(type == VALUE_TYPE.action)
2023-07-12 16:28:32 +02:00
junction_drawing = [THEME.node_junction_inspector, 0];
else
junction_drawing = [isArray()? THEME.node_junctions_array : THEME.node_junctions_single, type];
2023-03-28 06:58:28 +02:00
}
2022-09-27 06:37:28 +02:00
2023-07-12 16:28:32 +02:00
draw_sprite_ext(junction_drawing[0], junction_drawing[1], x, y, ss, ss, 0, c_white, 1);
2022-09-27 06:37:28 +02:00
return is_hover;
}
static drawNameBG = function(_s) {
if(!isVisible()) return false;
draw_set_text(f_p1, fa_left, fa_center);
2022-12-10 05:06:01 +01:00
2023-03-28 06:58:28 +02:00
var tw = string_width(name) + 32;
2022-09-27 06:37:28 +02:00
var th = string_height(name) + 16;
2023-03-28 06:58:28 +02:00
if(type == VALUE_TYPE.action) {
var tx = x;
draw_sprite_stretched_ext(THEME.node_junction_name_bg, 0, tx - tw / 2, y - th, tw, th, c_white, 0.5);
} else if(connect_type == JUNCTION_CONNECT.input) {
2022-09-27 06:37:28 +02:00
var tx = x - 12 * _s;
2023-03-28 06:58:28 +02:00
draw_sprite_stretched_ext(THEME.node_junction_name_bg, 0, tx - tw + 16, y - th / 2, tw, th, c_white, 0.5);
2022-09-27 06:37:28 +02:00
} else {
var tx = x + 12 * _s;
2023-03-28 06:58:28 +02:00
draw_sprite_stretched_ext(THEME.node_junction_name_bg, 0, tx - 16, y - th / 2, tw, th, c_white, 0.5);
2022-01-26 06:57:34 +01:00
}
2022-09-27 06:37:28 +02:00
}
static drawName = function(_s, _mx, _my) {
if(!isVisible()) return false;
2022-01-26 06:57:34 +01:00
2023-02-23 07:02:19 +01:00
var _hover = PANEL_GRAPH.pHOVER && point_in_circle(_mx, _my, x, y, 10 * _s);
2022-11-18 03:20:31 +01:00
var _draw_cc = _hover? COLORS._main_text : COLORS._main_text_sub;
2022-09-27 06:37:28 +02:00
draw_set_text(f_p1, fa_left, fa_center, _draw_cc);
2023-03-28 06:58:28 +02:00
if(type == VALUE_TYPE.action) {
var tx = x;
draw_set_text(f_p1, fa_center, fa_center, _draw_cc);
2023-05-28 20:00:51 +02:00
draw_text(tx, y - (line_get_height() + 16) / 2, name);
2023-03-28 06:58:28 +02:00
} else if(connect_type == JUNCTION_CONNECT.input) {
2022-09-27 06:37:28 +02:00
var tx = x - 12 * _s;
draw_set_halign(fa_right);
draw_text(tx, y, name);
} else {
var tx = x + 12 * _s;
draw_set_halign(fa_left);
draw_text(tx, y, name);
}
2022-01-26 06:57:34 +01:00
}
2023-07-25 20:12:40 +02:00
static drawConnections = function(_x, _y, _s, mx, my, _active, aa = 1, minx = undefined, miny = undefined, maxx = undefined, maxy = undefined) {
if(value_from == noone) return noone;
if(!value_from.node.active) return noone;
if(!isVisible()) return noone;
var hovering = noone;
var jx = x;
var jy = y;
var frx = value_from.x;
var fry = value_from.y;
if(!is_undefined(minx)) {
if(jx < minx && frx < minx) return noone;
if(jx > maxx && frx > maxx) return noone;
if(jy < miny && fry < miny) return noone;
if(jy > maxy && fry > maxy) return noone;
}
var c0 = value_color(value_from.type);
var c1 = value_color(type);
var shx = draw_line_shift_x * _s;
var shy = draw_line_shift_y * _s;
var cx = round((frx + jx) / 2 + shx);
var cy = round((fry + jy) / 2 + shy);
var hover = false;
var th = max(1, PREF_MAP[? "connection_line_width"] * _s);
draw_line_shift_hover = false;
var downDirection = type == VALUE_TYPE.action || value_from.type == VALUE_TYPE.action;
if(PANEL_GRAPH.pHOVER)
switch(PREF_MAP[? "curve_connection_line"]) {
case 0 :
hover = distance_to_line(mx, my, jx, jy, frx, fry) < max(th * 2, 6);
break;
case 1 :
if(downDirection)
hover = distance_to_curve_corner(mx, my, jx, jy, frx, fry, _s) < max(th * 2, 6);
else
hover = distance_to_curve(mx, my, jx, jy, frx, fry, cx, cy, _s) < max(th * 2, 6);
if(PANEL_GRAPH._junction_hovering == noone)
draw_line_shift_hover = hover;
break;
case 2 :
if(downDirection)
hover = distance_to_elbow_corner(mx, my, frx, fry, jx, jy) < max(th * 2, 6);
else
hover = distance_to_elbow(mx, my, frx, fry, jx, jy, cx, cy, _s, value_from.drawLineIndex, drawLineIndex) < max(th * 2, 6);
if(PANEL_GRAPH._junction_hovering == noone)
draw_line_shift_hover = hover;
break;
case 3 :
if(downDirection)
hover = distance_to_elbow_diag_corner(mx, my, frx, fry, jx, jy) < max(th * 2, 6);
else
hover = distance_to_elbow_diag(mx, my, frx, fry, jx, jy, cx, cy, _s, value_from.drawLineIndex, drawLineIndex) < max(th * 2, 6);
if(PANEL_GRAPH._junction_hovering == noone)
draw_line_shift_hover = hover;
break;
}
if(_active && hover)
hovering = self;
var thicken = false;
thicken |= PANEL_GRAPH.nodes_junction_d == self;
thicken |= _active && PANEL_GRAPH.junction_hovering == self && PANEL_GRAPH._junction_hovering == noone;
thicken |= instance_exists(o_dialog_add_node) && o_dialog_add_node.junction_hovering == self;
th *= thicken? 2 : 1;
var corner = PREF_MAP[? "connection_line_corner"] * _s;
var ty = LINE_STYLE.solid;
if(type == VALUE_TYPE.node)
ty = LINE_STYLE.dashed;
var ss = _s * aa;
jx *= aa;
jy *= aa;
frx *= aa;
fry *= aa;
th *= aa;
cx *= aa;
cy *= aa;
corner *= aa;
th = max(1, round(th));
draw_set_color(c0);
var fromIndex = value_from.drawLineIndex;
var toIndex = drawLineIndex;
switch(PREF_MAP[? "curve_connection_line"]) {
case 0 :
if(ty == LINE_STYLE.solid)
draw_line_width_color(jx, jy, frx, fry, th, c1, c0);
else
draw_line_dashed_color(jx, jy, frx, fry, th, c1, c0, 12 * ss);
break;
case 1 :
if(downDirection)
draw_line_curve_corner(jx, jy, frx, fry, ss, th, c0, c1);
else
draw_line_curve_color(jx, jy, frx, fry, cx, cy, ss, th, c0, c1, ty);
break;
case 2 :
if(downDirection)
draw_line_elbow_corner(frx, fry, jx, jy, ss, th, c0, c1, corner, fromIndex, toIndex, ty);
else
draw_line_elbow_color(frx, fry, jx, jy, cx, cy, ss, th, c0, c1, corner, fromIndex, toIndex, ty);
break;
case 3 :
if(downDirection)
draw_line_elbow_diag_corner(frx, fry, jx, jy, ss, th, c0, c1, corner, fromIndex, toIndex, ty);
else
draw_line_elbow_diag_color(frx, fry, jx, jy, cx, cy, ss, th, c0, c1, corner, fromIndex, toIndex, ty);
break;
}
return hovering;
}
2022-01-13 05:24:03 +01:00
static isVisible = function() {
2023-02-14 02:51:14 +01:00
if(!node.active)
return false;
if(value_from)
return true;
2023-06-04 12:38:40 +02:00
if(connect_type == JUNCTION_CONNECT.input) {
if(!visible)
return false;
if(is_array(node.input_display_list))
return array_exists(node.input_display_list, index);
}
2023-02-14 02:51:14 +01:00
return visible;
2022-01-13 05:24:03 +01:00
}
2023-07-15 20:01:29 +02:00
static extractNode = function(_type = extract_node) {
if(_type == "") return noone;
2023-01-09 03:14:20 +01:00
2023-07-15 20:01:29 +02:00
var ext = nodeBuild(_type, node.x, node.y);
2023-01-25 06:49:00 +01:00
ext.x -= ext.w + 32;
2023-07-15 20:01:29 +02:00
for( var i = 0; i < ds_list_size(ext.outputs); i++ ) {
if(setFrom(ext.outputs[| i])) break;
}
2023-01-25 06:49:00 +01:00
var animFrom = animator.values;
var len = 2;
2023-07-15 20:01:29 +02:00
switch(_type) {
2023-01-25 06:49:00 +01:00
case "Node_Vector4": len++;
case "Node_Vector3": len++;
case "Node_Vector2":
for( var j = 0; j < len; j++ ) {
var animTo = ext.inputs[| j].animator;
var animLs = animTo.values;
2023-04-21 19:08:10 +02:00
ext.inputs[| j].setAnim(is_anim);
2023-01-25 06:49:00 +01:00
ds_list_clear(animLs);
}
for( var i = 0; i < ds_list_size(animFrom); i++ ) {
for( var j = 0; j < len; j++ ) {
var animTo = ext.inputs[| j].animator;
var animLs = animTo.values;
var a = animFrom[| i].clone(animTo);
a.value = a.value[j];
ds_list_add(animLs, a);
}
}
break;
2023-07-15 20:01:29 +02:00
case "Node_Path":
break;
2023-01-25 06:49:00 +01:00
default:
var animTo = ext.inputs[| 0].animator;
var animLs = animTo.values;
2023-04-21 19:08:10 +02:00
ext.inputs[| 0].setAnim(is_anim);
2023-01-25 06:49:00 +01:00
ds_list_clear(animLs);
for( var i = 0; i < ds_list_size(animFrom); i++ )
ds_list_add(animLs, animFrom[| i].clone(animTo));
break;
}
2023-01-09 03:14:20 +01:00
2023-03-28 06:58:28 +02:00
ext.doUpdate();
2023-01-25 06:49:00 +01:00
PANEL_ANIMATION.updatePropertyList();
2023-01-09 03:14:20 +01:00
}
2023-06-01 10:32:21 +02:00
static getJunctionTo = function() {
var to = [];
for(var j = 0; j < ds_list_size(value_to); j++) {
var _to = value_to[| j];
if(!_to.node.active || _to.value_from == noone) continue;
if(_to.value_from != self) continue;
array_push(to, _to);
}
return to;
}
2023-03-26 07:13:36 +02:00
static dragValue = function() {
if(drop_key == "None") return;
DRAGGING = {
type: drop_key,
data: showValue(),
}
if(type == VALUE_TYPE.path) {
DRAGGING.data = new FileObject(node.name, DRAGGING.data);
DRAGGING.data.getSpr();
}
if(connect_type == JUNCTION_CONNECT.input)
DRAGGING.from = self;
}
2023-02-14 02:51:14 +01:00
static serialize = function(scale = false, preset = false) {
2023-06-13 14:42:06 +02:00
var _map = {};
2022-01-13 05:24:03 +01:00
2023-06-13 14:42:06 +02:00
_map.visible = visible;
2023-04-07 21:25:27 +02:00
if(connect_type == JUNCTION_CONNECT.output)
return _map;
2023-07-15 20:01:29 +02:00
_map.name = name;
2023-06-13 14:42:06 +02:00
_map.on_end = on_end;
2023-07-12 21:00:05 +02:00
_map.loop_range = loop_range;
2023-06-13 14:42:06 +02:00
_map.unit = unit.mode;
_map.sep_axis = sep_axis;
_map.shift_x = draw_line_shift_x;
_map.shift_y = draw_line_shift_y;
_map.from_node = !preset && value_from? value_from.node.node_id : -1;
_map.from_index = !preset && value_from? value_from.index : -1;
_map.global_use = expUse;
_map.global_key = expression;
_map.anim = is_anim;
2023-03-21 03:01:53 +01:00
2023-06-13 14:42:06 +02:00
_map.raw_value = animator.serialize(scale);
2023-03-21 03:01:53 +01:00
2023-06-13 14:42:06 +02:00
var _anims = [];
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(animators); i < n; i++ )
2023-06-13 14:42:06 +02:00
array_push(_anims, animators[i].serialize(scale));
_map.animators = _anims;
_map.data = extra_data;
2022-01-13 05:24:03 +01:00
return _map;
}
con_node = -1;
con_index = -1;
2022-12-21 02:30:23 +01:00
2023-02-14 02:51:14 +01:00
static applyDeserialize = function(_map, scale = false, preset = false) {
2022-12-22 03:09:55 +01:00
if(_map == undefined) return;
2023-06-17 18:59:20 +02:00
if(_map == noone) return;
if(!is_struct(_map)) return;
2023-01-01 02:06:02 +01:00
2023-06-17 18:59:20 +02:00
visible = struct_try_get(_map, "visible", visible);
2023-04-07 21:25:27 +02:00
if(connect_type == JUNCTION_CONNECT.output)
return;
2023-03-25 12:27:04 +01:00
//printIf(TESTING, " |- Applying deserialize to junction " + name + " of node " + node.name);
2023-07-15 20:01:29 +02:00
name = struct_try_get(_map, "name", name);
2023-06-13 14:42:06 +02:00
on_end = struct_try_get(_map, "on_end");
2023-07-12 21:00:05 +02:00
loop_range = struct_try_get(_map, "loop_range", -1);
2023-06-13 14:42:06 +02:00
unit.mode = struct_try_get(_map, "unit");
expUse = struct_try_get(_map, "global_use");
expression = struct_try_get(_map, "global_key");
2023-07-12 21:00:05 +02:00
expTree = evaluateFunctionList(expression);
2023-04-15 14:48:29 +02:00
2023-06-13 14:42:06 +02:00
sep_axis = struct_try_get(_map, "sep_axis");
is_anim = struct_try_get(_map, "anim");
2023-03-21 03:01:53 +01:00
2023-06-13 14:42:06 +02:00
draw_line_shift_x = struct_try_get(_map, "shift_x");
draw_line_shift_y = struct_try_get(_map, "shift_y");
2022-12-27 04:00:50 +01:00
2023-06-13 14:42:06 +02:00
animator.deserialize(struct_try_get(_map, "raw_value"), scale);
2022-12-27 13:30:02 +01:00
2023-06-13 14:42:06 +02:00
if(struct_has(_map, "animators")) {
2023-06-17 14:30:49 +02:00
var anims = _map.animators;
var amo = min(array_length(anims), array_length(animators));
for( var i = 0; i < amo; i++ )
2023-06-13 14:42:06 +02:00
animators[i].deserialize(anims[i], scale);
2023-03-21 03:01:53 +01:00
}
2023-02-14 02:51:14 +01:00
if(!preset) {
2023-06-13 14:42:06 +02:00
con_node = struct_try_get(_map, "from_node", -1);
con_index = struct_try_get(_map, "from_index", -1);
2023-02-14 02:51:14 +01:00
}
2022-01-13 05:24:03 +01:00
2023-07-15 20:01:29 +02:00
if(struct_has(_map, "data") && is_struct(_map.data))
2023-06-13 14:42:06 +02:00
extra_data = _map.data;
2022-12-27 13:30:02 +01:00
2023-05-16 21:28:16 +02:00
if(APPENDING) def_val = getValue(0);
2022-08-30 07:36:37 +02:00
onValidate();
2022-01-13 05:24:03 +01:00
}
2022-09-21 06:09:40 +02:00
static connect = function(log = false) {
if(con_node == -1 || con_index == -1)
return true;
2022-01-13 05:24:03 +01:00
2022-09-21 06:09:40 +02:00
var _node = con_node;
2022-12-21 02:30:23 +01:00
if(APPENDING) {
2022-09-21 06:09:40 +02:00
_node = GetAppendID(con_node);
2023-02-28 09:43:01 +01:00
if(_node == noone)
2022-12-21 02:30:23 +01:00
return true;
}
2023-07-06 19:49:16 +02:00
if(!ds_map_exists(PROJECT.nodeMap, _node)) {
2023-06-13 14:42:06 +02:00
var txt = $"Node connect error : Node ID {_node} not found.";
log_warning("LOAD", $"[Connect] {txt}", node);
2022-12-21 02:30:23 +01:00
return false;
}
2022-01-19 03:05:13 +01:00
2023-07-06 19:49:16 +02:00
var _nd = PROJECT.nodeMap[? _node];
2022-12-21 02:30:23 +01:00
var _ol = ds_list_size(_nd.outputs);
2023-02-14 02:51:14 +01:00
2023-07-25 20:12:40 +02:00
if(log) log_warning("LOAD", $"[Connect] Reconnecting {node.name} to {_nd.name}", node);
2022-12-21 02:30:23 +01:00
if(con_index < _ol) {
2023-07-25 20:12:40 +02:00
var _set = setFrom(_nd.outputs[| con_index], false, true);
if(_set) return true;
if(_set == -1) log_warning("LOAD", $"[Connect] Connection conflict {node.name} to {_nd.name} : Not connectable.", node);
else if(_set == -2) log_warning("LOAD", $"[Connect] Connection conflict {node.name} to {_nd.name} : Condition not met.", node);
2022-12-21 02:30:23 +01:00
return false;
2022-01-13 05:24:03 +01:00
}
2023-07-25 20:12:40 +02:00
log_warning("LOAD", $"[Connect] Connection conflict {node.name} to {_nd.name} : Output not exist.", node);
2022-01-19 03:05:13 +01:00
return false;
2022-01-13 05:24:03 +01:00
}
2022-01-19 06:11:17 +01:00
2023-02-23 07:02:19 +01:00
static destroy = function() {
if(error_notification != noone) {
noti_remove(error_notification);
error_notification = noone;
}
}
2022-01-19 06:11:17 +01:00
static cleanUp = function() {
ds_list_destroy(value_to);
2022-09-23 13:28:42 +02:00
animator.cleanUp();
delete animator;
2022-01-19 06:11:17 +01:00
}
2022-01-13 05:24:03 +01:00
}