Pixel-Composer/scripts/__node_module/__node_module.gml

74 lines
1.7 KiB
Plaintext
Raw Normal View History

2023-10-18 14:58:55 +02:00
function NodeModule(parent) constructor {
self.parent = parent;
2024-08-08 06:57:51 +02:00
inputs = [];
2023-10-18 14:58:55 +02:00
load_map = -1;
load_scale = false;
2024-08-08 06:57:51 +02:00
static isLeaf = function() {
for( var i = 0, n = array_length(inputs); i < n; i++ ) {
var _inp = inputs[i];
if(_inp.value_from != noone) return false;
2023-10-27 13:55:31 +02:00
}
return true;
2024-08-08 06:57:51 +02:00
}
2023-10-27 13:55:31 +02:00
2024-08-08 06:57:51 +02:00
static drawConnections = function(params = {}, _inputs = []) {
for(var i = 0; i < array_length(inputs); i++) {
var jun = inputs[i];
2023-10-27 13:55:31 +02:00
if(jun.value_from == noone) continue;
2023-10-27 13:55:31 +02:00
if(!jun.value_from.node.active) continue;
if(!jun.isVisible()) continue;
if(i >= 0) array_push(_inputs, jun);
}
2024-08-08 06:57:51 +02:00
}
2023-10-27 13:55:31 +02:00
2024-08-08 06:57:51 +02:00
static isRendered = function() { //Check if every input is ready (updated)
for(var j = 0; j < array_length(inputs); j++)
if(!inputs[j].isRendered()) return false;
2023-10-27 13:55:31 +02:00
return true;
2024-08-08 06:57:51 +02:00
}
2023-10-27 13:55:31 +02:00
2024-08-08 06:57:51 +02:00
static resetCache = function() {
for( var i = 0; i < array_length(inputs); i++ ) {
if(!is_instanceof(inputs[i], NodeValue)) continue;
inputs[i].resetCache();
2023-10-18 14:58:55 +02:00
}
2024-08-08 06:57:51 +02:00
}
2023-10-18 14:58:55 +02:00
2024-08-08 06:57:51 +02:00
static serialize = function(scale = false, preset = false) {
2023-10-18 14:58:55 +02:00
var _map = {};
var _inputs = [];
2024-08-08 06:57:51 +02:00
for(var i = 0; i < array_length(inputs); i++)
array_push(_inputs, inputs[i].serialize(scale, preset));
2023-10-18 14:58:55 +02:00
_map.inputs = _inputs;
_map.outputs = [];
return _map;
2024-08-08 06:57:51 +02:00
}
2023-10-18 14:58:55 +02:00
2024-08-08 06:57:51 +02:00
static deserialize = function(_map, scale = false, preset = false) {
2023-10-18 14:58:55 +02:00
load_map = _map;
load_scale = scale;
2024-08-08 06:57:51 +02:00
}
2023-10-18 14:58:55 +02:00
2024-08-08 06:57:51 +02:00
static applyDeserialize = function(preset = false) {
2023-10-18 14:58:55 +02:00
var _inputs = load_map.inputs;
2024-08-08 06:57:51 +02:00
var amo = min(array_length(inputs), array_length(_inputs));
2023-10-18 14:58:55 +02:00
for(var i = 0; i < amo; i++)
2024-08-08 06:57:51 +02:00
inputs[i].applyDeserialize(_inputs[i], load_scale, preset);
}
2023-10-18 14:58:55 +02:00
2024-08-08 06:57:51 +02:00
static connect = function() {
for(var i = 0; i < array_length(inputs); i++)
inputs[i].connect(false);
}
2023-10-18 14:58:55 +02:00
}