2022-01-24 02:21:25 +01:00
|
|
|
enum COLLECTION_TAG {
|
|
|
|
group = 1,
|
|
|
|
loop = 2
|
|
|
|
}
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
function groupNodes(nodeArray, _group = noone, record = true, check_connect = true) {
|
|
|
|
UNDO_HOLDING = true;
|
|
|
|
|
|
|
|
if(_group == noone) {
|
|
|
|
var cx = 0;
|
|
|
|
var cy = 0;
|
|
|
|
for(var i = 0; i < array_length(nodeArray); i++) {
|
|
|
|
var _node = nodeArray[i];
|
|
|
|
cx += _node.x;
|
|
|
|
cy += _node.y;
|
|
|
|
}
|
|
|
|
cx = round(cx / array_length(nodeArray) / 32) * 32;
|
|
|
|
cy = round(cy / array_length(nodeArray) / 32) * 32;
|
|
|
|
|
|
|
|
_group = new Node_Group(cx, cy, PANEL_GRAPH.getCurrentContext());
|
|
|
|
}
|
|
|
|
|
|
|
|
var _content = [];
|
|
|
|
|
|
|
|
for(var i = 0; i < array_length(nodeArray); i++) {
|
|
|
|
_group.add(nodeArray[i]);
|
|
|
|
_content[i] = nodeArray[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
var _io = [];
|
|
|
|
if(check_connect)
|
|
|
|
for(var i = 0; i < array_length(nodeArray); i++)
|
|
|
|
array_append(_io, nodeArray[i].checkConnectGroup());
|
|
|
|
|
|
|
|
UNDO_HOLDING = false;
|
|
|
|
if(record) recordAction(ACTION_TYPE.group, _group, { io: _io, content: _content });
|
|
|
|
|
|
|
|
return _group;
|
|
|
|
}
|
|
|
|
|
|
|
|
function upgroupNode(collection, record = true) {
|
|
|
|
UNDO_HOLDING = true;
|
|
|
|
var _content = [];
|
|
|
|
var _io = [];
|
2023-02-28 09:43:01 +01:00
|
|
|
var node_list = collection.getNodeList();
|
|
|
|
while(!ds_list_empty(node_list)) {
|
|
|
|
var remNode = node_list[| 0];
|
2023-02-14 05:32:32 +01:00
|
|
|
if(remNode.destroy_when_upgroup)
|
|
|
|
array_push(_io, remNode);
|
|
|
|
else
|
|
|
|
array_push(_content, remNode);
|
|
|
|
|
|
|
|
collection.remove(remNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
nodeDelete(collection);
|
|
|
|
UNDO_HOLDING = false;
|
|
|
|
|
|
|
|
if(record) recordAction(ACTION_TYPE.ungroup, collection, { io: _io, content: _content });
|
|
|
|
}
|
|
|
|
|
2023-02-28 09:43:01 +01:00
|
|
|
function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
2022-01-13 05:24:03 +01:00
|
|
|
nodes = ds_list_create();
|
2022-12-13 09:20:36 +01:00
|
|
|
ungroupable = true;
|
2023-02-19 13:49:20 +01:00
|
|
|
auto_render_time = false;
|
|
|
|
combine_render_time = true;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-02-28 09:43:01 +01:00
|
|
|
isInstancer = false;
|
|
|
|
instanceBase = noone;
|
|
|
|
|
2022-01-23 04:08:16 +01:00
|
|
|
custom_input_index = 0;
|
|
|
|
custom_output_index = 0;
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
metadata = new MetaDataManager();
|
|
|
|
|
2023-03-02 07:59:14 +01:00
|
|
|
inspUpdateTooltip = get_text("panel_inspector_execute", "Execute node contents");
|
|
|
|
inspUpdateIcon = [ THEME.sequence_control, 1, COLORS._main_value_positive ];
|
|
|
|
|
|
|
|
static inspectorUpdate = function() {
|
|
|
|
onInspectorUpdate();
|
|
|
|
}
|
|
|
|
static onInspectorUpdate = function() {
|
|
|
|
RenderListAction(nodes, group);
|
|
|
|
}
|
|
|
|
|
|
|
|
static hasInspectorUpdate = function(group = false) {
|
|
|
|
if(!group) return false;
|
|
|
|
|
|
|
|
for( var i = 0; i < ds_list_size(nodes); i++ ) {
|
|
|
|
if(nodes[| i].hasInspectorUpdate())
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-02-28 09:43:01 +01:00
|
|
|
static getNodeBase = function() {
|
|
|
|
if(instanceBase == noone) return self;
|
|
|
|
return instanceBase.getNodeBase();
|
|
|
|
}
|
|
|
|
|
|
|
|
static getNodeList = function() {
|
|
|
|
if(instanceBase == noone) return nodes;
|
|
|
|
return instanceBase.getNodeList();
|
|
|
|
}
|
|
|
|
|
2023-01-01 02:06:02 +01:00
|
|
|
static drawOverlay = function(active, _x, _y, _s, _mx, _my, _snx, _sny) {
|
|
|
|
for(var i = custom_input_index; i < ds_list_size(inputs); i++) {
|
|
|
|
var _in = inputs[| i];
|
|
|
|
var _show = _in.from.inputs[| 6].getValue();
|
|
|
|
|
|
|
|
if(!_show) continue;
|
|
|
|
_in.drawOverlay(active, _x, _y, _s, _mx, _my, _snx, _sny);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-16 09:18:09 +01:00
|
|
|
static getNextNodes = function() {
|
|
|
|
for(var i = custom_input_index; i < ds_list_size(inputs); i++) {
|
|
|
|
var _in = inputs[| i].from;
|
2023-02-19 13:49:20 +01:00
|
|
|
if(!_in.renderActive) continue;
|
2022-12-16 09:18:09 +01:00
|
|
|
|
2023-01-25 06:49:00 +01:00
|
|
|
ds_queue_enqueue(RENDER_QUEUE, _in);
|
2022-12-16 09:18:09 +01:00
|
|
|
printIf(global.RENDER_LOG, "Push group input " + _in.name + " to stack");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
static setRenderStatus = function(result) {
|
|
|
|
rendered = result;
|
|
|
|
|
|
|
|
if(result) {
|
|
|
|
var siz = ds_list_size(outputs);
|
|
|
|
for( var i = custom_output_index; i < siz; i++ ) {
|
|
|
|
var _o = outputs[| i];
|
|
|
|
if(_o.node.rendered) continue;
|
2022-12-16 09:18:09 +01:00
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
rendered = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-28 09:43:01 +01:00
|
|
|
if(!result && group != noone)
|
2022-12-12 09:08:03 +01:00
|
|
|
group.setRenderStatus(result);
|
|
|
|
}
|
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
function add(_node) {
|
2023-02-28 09:43:01 +01:00
|
|
|
ds_list_add(getNodeList(), _node);
|
|
|
|
var list = _node.group == noone? PANEL_GRAPH.nodes_list : _node.group.getNodeList();
|
2022-01-13 05:24:03 +01:00
|
|
|
var _pos = ds_list_find_index(list, _node);
|
|
|
|
ds_list_delete(list, _pos);
|
|
|
|
|
|
|
|
recordAction(ACTION_TYPE.group_added, self, _node);
|
|
|
|
_node.group = self;
|
|
|
|
}
|
|
|
|
|
|
|
|
function remove(_node) {
|
2023-02-28 09:43:01 +01:00
|
|
|
var node_list = getNodeList();
|
|
|
|
var _pos = ds_list_find_index(node_list, _node);
|
|
|
|
ds_list_delete(node_list, _pos);
|
|
|
|
var list = group == noone? PANEL_GRAPH.nodes_list : group.getNodeList();
|
2022-01-13 05:24:03 +01:00
|
|
|
ds_list_add(list, _node);
|
|
|
|
|
|
|
|
recordAction(ACTION_TYPE.group_removed, self, _node);
|
2022-01-29 14:25:18 +01:00
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
if(struct_has(_node, "ungroup"))
|
|
|
|
_node.ungroup();
|
|
|
|
|
|
|
|
if(_node.destroy_when_upgroup)
|
|
|
|
nodeDelete(_node);
|
|
|
|
else
|
|
|
|
_node.group = group;
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
2022-12-10 05:06:01 +01:00
|
|
|
static clearCache = function() {
|
2023-02-28 09:43:01 +01:00
|
|
|
var node_list = getNodeList();
|
|
|
|
for(var i = 0; i < ds_list_size(node_list); i++) {
|
|
|
|
node_list[| i].clearCache();
|
2022-12-10 05:06:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-23 04:08:16 +01:00
|
|
|
static stepBegin = function() {
|
2022-12-10 05:06:01 +01:00
|
|
|
use_cache = false;
|
2022-12-23 04:45:52 +01:00
|
|
|
|
2022-12-21 02:30:23 +01:00
|
|
|
array_safe_set(cache_result, ANIMATOR.current_frame, true);
|
2022-12-10 05:06:01 +01:00
|
|
|
|
2023-02-28 09:43:01 +01:00
|
|
|
var node_list = getNodeList();
|
|
|
|
for(var i = 0; i < ds_list_size(node_list); i++) {
|
|
|
|
var n = node_list[| i];
|
2022-12-10 05:06:01 +01:00
|
|
|
n.stepBegin();
|
|
|
|
if(!n.use_cache) continue;
|
|
|
|
|
|
|
|
use_cache = true;
|
2022-12-21 02:30:23 +01:00
|
|
|
if(!array_safe_get(n.cache_result, ANIMATOR.current_frame))
|
|
|
|
array_safe_set(cache_result, ANIMATOR.current_frame, false);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2022-01-25 04:05:30 +01:00
|
|
|
|
|
|
|
var out_surf = false;
|
|
|
|
|
2022-01-29 14:25:18 +01:00
|
|
|
for( var i = 0; i < ds_list_size(outputs); i++) {
|
2022-01-25 04:05:30 +01:00
|
|
|
if(outputs[| i].type == VALUE_TYPE.surface)
|
|
|
|
out_surf = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(out_surf) {
|
|
|
|
w = 128;
|
|
|
|
min_h = 128;
|
|
|
|
} else {
|
|
|
|
w = 96;
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2022-01-25 04:05:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
setHeight();
|
2022-12-16 09:18:09 +01:00
|
|
|
doStepBegin();
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
2022-01-18 05:31:19 +01:00
|
|
|
static step = function() {
|
2023-02-19 13:49:20 +01:00
|
|
|
if(combine_render_time) render_time = 0;
|
|
|
|
|
2023-02-28 09:43:01 +01:00
|
|
|
var node_list = getNodeList();
|
|
|
|
for(var i = 0; i < ds_list_size(node_list); i++) {
|
|
|
|
node_list[| i].step();
|
2023-02-19 13:49:20 +01:00
|
|
|
if(combine_render_time)
|
2023-02-28 09:43:01 +01:00
|
|
|
render_time += node_list[| i].render_time;
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
2022-11-14 03:16:15 +01:00
|
|
|
if(PANEL_GRAPH.node_focus == self && panelFocus(PANEL_GRAPH) && DOUBLE_CLICK) {
|
2022-01-13 05:24:03 +01:00
|
|
|
PANEL_GRAPH.addContext(self);
|
|
|
|
DOUBLE_CLICK = false;
|
|
|
|
}
|
2022-12-16 09:18:09 +01:00
|
|
|
|
|
|
|
onStep();
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
2022-12-16 09:18:09 +01:00
|
|
|
static onStep = function() {}
|
|
|
|
|
2022-12-10 05:06:01 +01:00
|
|
|
static triggerRender = function() {
|
2022-01-23 04:08:16 +01:00
|
|
|
for(var i = custom_input_index; i < ds_list_size(inputs); i++) {
|
|
|
|
var jun_node = inputs[| i].from;
|
2022-12-10 05:06:01 +01:00
|
|
|
jun_node.triggerRender();
|
2022-01-23 04:08:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-18 05:31:19 +01:00
|
|
|
static preConnect = function() {
|
|
|
|
sortIO();
|
2022-12-12 09:08:03 +01:00
|
|
|
deserialize(load_map, load_scale);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
2022-01-18 05:31:19 +01:00
|
|
|
static sortIO = function() {
|
|
|
|
var siz = ds_list_size(inputs);
|
|
|
|
var ar = ds_priority_create();
|
|
|
|
|
2022-01-23 04:08:16 +01:00
|
|
|
for( var i = custom_input_index; i < siz; i++ ) {
|
2022-01-18 05:31:19 +01:00
|
|
|
var _in = inputs[| i];
|
|
|
|
var _or = _in.from.inputs[| 5].getValue();
|
|
|
|
|
|
|
|
ds_priority_add(ar, _in, _or);
|
|
|
|
}
|
|
|
|
|
2022-01-23 04:08:16 +01:00
|
|
|
for( var i = siz - 1; i >= custom_input_index; i-- ) {
|
|
|
|
ds_list_delete(inputs, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
for( var i = custom_input_index; i < siz; i++ ) {
|
2022-01-18 05:31:19 +01:00
|
|
|
var _jin = ds_priority_delete_min(ar);
|
|
|
|
_jin.index = i;
|
|
|
|
ds_list_add(inputs, _jin);
|
|
|
|
}
|
|
|
|
|
|
|
|
ds_priority_destroy(ar);
|
|
|
|
|
|
|
|
var siz = ds_list_size(outputs);
|
|
|
|
var ar = ds_priority_create();
|
|
|
|
|
2022-01-23 04:08:16 +01:00
|
|
|
for( var i = custom_output_index; i < siz; i++ ) {
|
2022-01-18 05:31:19 +01:00
|
|
|
var _out = outputs[| i];
|
|
|
|
var _or = _out.from.inputs[| 1].getValue();
|
|
|
|
|
|
|
|
ds_priority_add(ar, _out, _or);
|
|
|
|
}
|
|
|
|
|
2022-01-23 04:08:16 +01:00
|
|
|
for( var i = siz - 1; i >= custom_output_index; i-- ) {
|
|
|
|
ds_list_delete(outputs, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
for( var i = custom_output_index; i < siz; i++ ) {
|
2022-01-18 05:31:19 +01:00
|
|
|
var _jout = ds_priority_delete_min(ar);
|
|
|
|
_jout.index = i;
|
|
|
|
ds_list_add(outputs, _jout);
|
|
|
|
}
|
|
|
|
|
|
|
|
ds_priority_destroy(ar);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2022-01-19 03:51:53 +01:00
|
|
|
|
2023-02-28 09:43:01 +01:00
|
|
|
static onClone = function(_newNode, target = PANEL_GRAPH.getCurrentContext()) {
|
|
|
|
if(instanceBase != noone) {
|
|
|
|
_newNode.instanceBase = instanceBase;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
var dups = ds_list_create();
|
|
|
|
|
|
|
|
for(var i = 0; i < ds_list_size(nodes); i++) {
|
|
|
|
var _node = nodes[| i];
|
|
|
|
var _cnode = _node.clone(target);
|
|
|
|
ds_list_add(dups, _cnode);
|
|
|
|
|
|
|
|
APPEND_MAP[? _node.node_id] = _cnode.node_id;
|
2022-01-19 03:51:53 +01:00
|
|
|
}
|
2023-02-14 05:32:32 +01:00
|
|
|
|
|
|
|
APPENDING = true;
|
|
|
|
for(var i = 0; i < ds_list_size(dups); i++) {
|
|
|
|
var _node = dups[| i];
|
|
|
|
_node.connect();
|
|
|
|
}
|
|
|
|
APPENDING = false;
|
|
|
|
|
|
|
|
ds_list_destroy(dups);
|
|
|
|
}
|
|
|
|
|
|
|
|
static enable = function() {
|
|
|
|
active = true;
|
2023-02-28 09:43:01 +01:00
|
|
|
var node_list = getNodeList();
|
|
|
|
for( var i = 0; i < ds_list_size(node_list); i++ )
|
|
|
|
node_list[| i].enable();
|
2023-02-14 05:32:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static disable = function() {
|
|
|
|
active = false;
|
2023-02-28 09:43:01 +01:00
|
|
|
var node_list = getNodeList();
|
|
|
|
for( var i = 0; i < ds_list_size(node_list); i++ )
|
|
|
|
node_list[| i].disable();
|
2022-01-19 03:51:53 +01:00
|
|
|
}
|
2022-01-25 04:05:30 +01:00
|
|
|
|
2022-12-13 09:20:36 +01:00
|
|
|
static resetAllRenderStatus = function() {
|
2023-02-28 09:43:01 +01:00
|
|
|
var node_list = getNodeList();
|
|
|
|
for( var i = 0; i < ds_list_size(node_list); i++ ) {
|
|
|
|
node_list[| i].setRenderStatus(false);
|
|
|
|
if(variable_struct_exists(node_list[| i], "nodes"))
|
|
|
|
node_list[| i].resetAllRenderStatus();
|
2022-01-25 04:05:30 +01:00
|
|
|
}
|
|
|
|
}
|
2022-12-21 02:30:23 +01:00
|
|
|
|
2023-02-28 09:43:01 +01:00
|
|
|
static setInstance = function(node) {
|
|
|
|
instanceBase = node;
|
|
|
|
}
|
|
|
|
|
|
|
|
static resetInstance = function() {
|
|
|
|
instanceBase = noone;
|
|
|
|
}
|
|
|
|
|
|
|
|
static processSerialize = function(_map) {
|
|
|
|
_map[? "instance_base"] = instanceBase? instanceBase.node_id : noone;
|
|
|
|
}
|
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
static preConnect = function() {
|
2023-02-28 09:43:01 +01:00
|
|
|
instanceBase = GetAppendID(ds_map_try_get(load_map, "instance_base", noone));
|
|
|
|
|
2022-12-21 02:30:23 +01:00
|
|
|
sortIO();
|
2023-01-17 08:11:55 +01:00
|
|
|
applyDeserialize();
|
2022-12-21 02:30:23 +01:00
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|