Pixel-Composer/scripts/node_tunnel_in/node_tunnel_in.gml

167 lines
4.9 KiB
Text
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_Tunnel_In(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
2023-12-03 05:02:04 +01:00
name = "Tunnel In";
2023-01-25 06:49:00 +01:00
color = COLORS.node_blend_tunnel;
2023-12-04 12:09:31 +01:00
is_group_io = true;
preview_draw = false;
2023-01-25 06:49:00 +01:00
2024-04-02 14:33:25 +02:00
setDimension(96, 80);
2023-01-25 06:49:00 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 0] = nodeValue("Name", self, JUNCTION_CONNECT.input, VALUE_TYPE.text, "" )
2023-12-05 13:49:18 +01:00
.setDisplay(VALUE_DISPLAY.text_tunnel)
2023-02-14 05:32:32 +01:00
.rejectArray();
2023-01-25 06:49:00 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 1] = nodeValue("Value in", self, JUNCTION_CONNECT.input, VALUE_TYPE.any, noone )
2023-01-25 06:49:00 +01:00
.setVisible(true, true);
error_notification = noone;
2023-03-02 07:59:14 +01:00
insp2UpdateTooltip = "Create tunnel out";
insp2UpdateIcon = [ THEME.tunnel, 0, c_white ];
2023-10-27 13:55:31 +02:00
static onInspector2Update = function() { #region
2023-07-25 20:12:40 +02:00
var _node = nodeBuild("Node_Tunnel_Out", x + 128, y);
_node.inputs[| 0].setValue(getInputData(0));
2023-10-27 13:55:31 +02:00
} #endregion
2023-03-02 07:59:14 +01:00
2023-10-09 16:07:33 +02:00
static update = function(frame = CURRENT_FRAME) { onValueUpdate(); }
2023-01-25 06:49:00 +01:00
2023-10-27 13:55:31 +02:00
static resetMap = function() { #region
var _key = getInputData(0);
2023-01-25 06:49:00 +01:00
TUNNELS_IN_MAP[? node_id] = _key;
TUNNELS_IN[? _key] = inputs[| 1];
2023-10-27 13:55:31 +02:00
} #endregion
2023-01-25 06:49:00 +01:00
2023-10-27 13:55:31 +02:00
static checkDuplicate = function() { #region
var _key = getInputData(0);
2023-01-25 06:49:00 +01:00
var amo = ds_map_size(TUNNELS_IN_MAP);
var k = ds_map_find_first(TUNNELS_IN_MAP);
var dup = false;
repeat(amo) {
if(k != node_id && TUNNELS_IN_MAP[? k] == _key)
dup = true;
k = ds_map_find_next(TUNNELS_IN_MAP, k);
}
if(dup && error_notification == noone) {
error_notification = noti_error("Duplicated key: " + string(_key));
error_notification.onClick = function() { PANEL_GRAPH.focusNode(self); };
} else if(!dup && error_notification) {
noti_remove(error_notification);
error_notification = noone;
}
2023-10-27 13:55:31 +02:00
} #endregion
2023-01-25 06:49:00 +01:00
2023-10-27 13:55:31 +02:00
static onValueUpdate = function(index = -1) { #region
var _key = getInputData(0);
2023-01-25 06:49:00 +01:00
resetMap();
var amo = ds_map_size(TUNNELS_IN_MAP);
var k = ds_map_find_first(TUNNELS_IN_MAP);
repeat(amo) {
2023-07-06 19:49:16 +02:00
if(ds_map_exists(PROJECT.nodeMap, k) && struct_has(PROJECT.nodeMap[? k], "resetMap"))
PROJECT.nodeMap[? k].resetMap();
2023-01-25 06:49:00 +01:00
k = ds_map_find_next(TUNNELS_IN_MAP, k);
}
var k = ds_map_find_first(TUNNELS_IN_MAP);
repeat(amo) {
2023-07-06 19:49:16 +02:00
if(ds_map_exists(PROJECT.nodeMap, k) && struct_has(PROJECT.nodeMap[? k], "checkDuplicate"))
PROJECT.nodeMap[? k].checkDuplicate();
2023-01-25 06:49:00 +01:00
k = ds_map_find_next(TUNNELS_IN_MAP, k);
}
2023-03-05 07:16:44 +01:00
2023-10-07 16:23:40 +02:00
if(index == 0) { RENDER_ALL_REORDER }
2023-10-27 13:55:31 +02:00
} #endregion
2023-01-25 06:49:00 +01:00
2023-10-27 13:55:31 +02:00
static step = function() { #region
var _key = getInputData(0);
2023-01-25 06:49:00 +01:00
value_validation[VALIDATION.error] = error_notification != noone;
2023-10-27 13:55:31 +02:00
if(inputs[| 1].isLeaf()) {
2023-10-07 16:23:40 +02:00
inputs[| 1].setType(VALUE_TYPE.any);
2023-01-25 06:49:00 +01:00
inputs[| 1].display_type = VALUE_DISPLAY._default;
} else {
2023-10-07 16:23:40 +02:00
inputs[| 1].setType(inputs[| 1].value_from.type);
2023-01-25 06:49:00 +01:00
inputs[| 1].display_type = inputs[| 1].value_from.display_type;
}
2023-10-27 13:55:31 +02:00
} #endregion
2023-01-25 06:49:00 +01:00
2023-10-27 13:55:31 +02:00
static getNextNodes = function() { #region
2023-03-28 06:58:28 +02:00
var nodes = [];
2023-06-17 18:59:20 +02:00
var nodeNames = [];
var _key = getInputData(0);
2023-06-17 18:59:20 +02:00
var amo = ds_map_size(TUNNELS_OUT);
2023-01-25 06:49:00 +01:00
var k = ds_map_find_first(TUNNELS_OUT);
2023-06-17 18:59:20 +02:00
LOG_BLOCK_START();
LOG_IF(global.FLAG.render == 1, $"→→→→→ Call get next node from: {INAME}");
2023-06-17 18:59:20 +02:00
LOG_BLOCK_START();
2023-01-25 06:49:00 +01:00
repeat(amo) {
2023-06-17 18:59:20 +02:00
if(TUNNELS_OUT[? k] == _key) {
2023-07-06 19:49:16 +02:00
array_push(nodes, PROJECT.nodeMap[? k]);
array_push(nodeNames, PROJECT.nodeMap[? k].internalName);
2023-06-17 18:59:20 +02:00
}
2023-01-25 06:49:00 +01:00
k = ds_map_find_next(TUNNELS_OUT, k);
}
2023-03-28 06:58:28 +02:00
LOG_IF(global.FLAG.render == 1, $"→→ Push {nodeNames} to queue.");
2023-06-17 18:59:20 +02:00
LOG_BLOCK_END();
LOG_BLOCK_END();
2023-03-28 06:58:28 +02:00
return nodes;
2023-10-27 13:55:31 +02:00
} #endregion
2023-01-25 06:49:00 +01:00
2023-12-04 12:09:31 +01:00
static onDrawNodeBehind = function(_x, _y, _mx, _my, _s) { #region
var xx = _x + x * _s;
var yy = _y + y * _s;
var hover = PANEL_GRAPH.pHOVER && point_in_rectangle(_mx, _my, xx, yy, xx + w * _s, yy + h * _s);
var tun = findPanel("Panel_Tunnels");
hover |= tun && tun.tunnel_hover == self;
if(!hover) return;
var _key = getInputData(0);
var amo = ds_map_size(TUNNELS_OUT);
var k = ds_map_find_first(TUNNELS_OUT);
repeat(amo) {
if(TUNNELS_OUT[? k] == _key && ds_map_exists(PROJECT.nodeMap, k)) {
var node = PROJECT.nodeMap[? k];
if(node.group != group) continue;
draw_set_color(COLORS.node_blend_tunnel);
draw_set_alpha(0.35);
var frx = xx + w * _s / 2;
var fry = yy + h * _s / 2;
var tox = _x + (node.x + node.w / 2) * _s;
var toy = _y + (node.y + node.h / 2) * _s;
draw_line_dashed(frx, fry, tox, toy, 8 * _s, 16 * _s, current_time / 10);
draw_set_alpha(1);
}
k = ds_map_find_next(TUNNELS_OUT, k);
}
} #endregion
2023-10-27 13:55:31 +02:00
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { #region
draw_set_text(f_sdf, fa_center, fa_center, COLORS._main_text);
var str = string(getInputData(0));
2023-01-25 06:49:00 +01:00
var bbox = drawGetBbox(xx, yy, _s);
var ss = string_scale(str, bbox.w, bbox.h);
draw_text_transformed(bbox.xc, bbox.yc, str, ss, ss, 0);
2023-10-27 13:55:31 +02:00
} #endregion
2023-02-14 05:32:32 +01:00
2023-10-07 16:23:40 +02:00
static onClone = function() { onValueUpdate(0); }
static postConnect = function() { onValueUpdate(0); }
2023-02-14 05:32:32 +01:00
2023-10-27 13:55:31 +02:00
static onDestroy = function() { #region
2023-02-14 05:32:32 +01:00
if(error_notification != noone)
noti_remove(error_notification);
2023-10-27 13:55:31 +02:00
} #endregion
2023-01-25 06:49:00 +01:00
}