Pixel-Composer/scripts/node_collection/node_collection.gml

183 lines
4.1 KiB
Plaintext
Raw Normal View History

2022-01-24 02:21:25 +01:00
enum COLLECTION_TAG {
group = 1,
loop = 2
}
2022-01-13 05:24:03 +01:00
function Node_Collection(_x, _y) : Node(_x, _y) constructor {
nodes = ds_list_create();
2022-01-23 04:08:16 +01:00
custom_input_index = 0;
custom_output_index = 0;
2022-01-13 05:24:03 +01:00
function add(_node) {
ds_list_add(nodes, _node);
var list = _node.group == -1? PANEL_GRAPH.nodes_list : _node.group.nodes;
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) {
var _pos = ds_list_find_index(nodes, _node);
ds_list_delete(nodes, _pos);
var list = group == -1? PANEL_GRAPH.nodes_list : group.nodes;
ds_list_add(list, _node);
recordAction(ACTION_TYPE.group_removed, self, _node);
2022-01-29 14:25:18 +01:00
switch(instanceof(_node)) {
case "Node_Group_Input" :
case "Node_Group_Output" :
case "Node_Iterator_Input" :
case "Node_Iterator_Output" :
case "Node_Iterator_Index" :
nodeDelete(_node);
break;
default :
_node.group = group;
}
2022-01-13 05:24:03 +01:00
}
2022-12-10 05:06:01 +01:00
static clearCache = function() {
for(var i = 0; i < ds_list_size(nodes); i++) {
nodes[| i].clearCache();
}
}
2022-01-23 04:08:16 +01:00
static stepBegin = function() {
2022-12-10 05:06:01 +01:00
use_cache = false;
auto_update = true;
cache_result[ANIMATOR.current_frame] = true;
2022-01-13 05:24:03 +01:00
for(var i = 0; i < ds_list_size(nodes); i++) {
2022-12-10 05:06:01 +01:00
var n = nodes[| i];
n.stepBegin();
auto_update &= n.auto_update;
if(!n.use_cache) continue;
use_cache = true;
cache_result[ANIMATOR.current_frame] &= n.cache_result[ANIMATOR.current_frame];
2022-01-13 05:24:03 +01:00
}
var out_surf = false;
2022-01-29 14:25:18 +01:00
for( var i = 0; i < ds_list_size(outputs); i++) {
if(outputs[| i].type == VALUE_TYPE.surface)
out_surf = true;
}
if(out_surf) {
w = 128;
min_h = 128;
} else {
w = 96;
min_h = 0;
}
setHeight();
2022-01-13 05:24:03 +01:00
}
2022-12-10 05:06:01 +01:00
static doUpdate = function() {
for(var i = 0; i < ds_list_size(nodes); i++) {
nodes[| i].doUpdate();
}
}
2022-01-18 05:31:19 +01:00
static step = function() {
render_time = 0;
2022-01-13 05:24:03 +01:00
for(var i = 0; i < ds_list_size(nodes); i++) {
nodes[| i].step();
render_time += nodes[| 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-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();
deserialize(keyframe_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
static onDestroy = function() {
for( var i = 0; i < ds_list_size(nodes); i++ ) {
nodes[| i].destroy();
}
}
static resetRenderStatus = function() {
for( var i = 0; i < ds_list_size(nodes); i++ ) {
nodes[| i].setRenderStatus(false);
if(variable_struct_exists(nodes[| i], "nodes"))
nodes[| i].resetRenderStatus();
}
}
2022-12-10 05:06:01 +01:00
static collectionDeserialize = function(scale = false) {
sortIO();
var _inputs = load_map[? "inputs"];
if(!ds_list_empty(_inputs) && !ds_list_empty(inputs)) {
var _siz = min(ds_list_size(_inputs), ds_list_size(inputs));
for(var i = 0; i < _siz; i++) {
inputs[| i].deserialize(_inputs[| i], scale);
}
}
}
2022-01-13 05:24:03 +01:00
}