Pixel-Composer/scripts/node_guide/node_guide.gml

168 lines
4.0 KiB
Plaintext
Raw Normal View History

2023-06-05 18:27:53 +02:00
globalvar NODE_EXTRACT;
NODE_EXTRACT = false;
function __generate_node_data() { #region
2023-02-14 02:48:33 +01:00
var amo = ds_map_size(ALL_NODES);
var k = ds_map_find_first(ALL_NODES);
CLONING = true;
2023-06-05 18:27:53 +02:00
NODE_EXTRACT = true;
2023-02-14 02:48:33 +01:00
2023-06-05 18:27:53 +02:00
var dir = DIRECTORY + "Nodes/";
directory_verify(dir);
2023-06-05 18:27:53 +02:00
var data = {};
2023-06-17 14:30:49 +02:00
var junc = {};
2023-06-05 18:27:53 +02:00
var locale = {};
2023-03-05 07:16:44 +01:00
2023-02-14 02:48:33 +01:00
repeat(amo) {
var _n = ALL_NODES[? k];
var _b = _n.build(0, 0);
2023-03-05 07:16:44 +01:00
k = ds_map_find_next(ALL_NODES, k);
if(_b.name == "") continue;
2023-06-17 14:30:49 +02:00
var _data = variable_clone(_n, 1);
var _junc = {};
_junc.node = _n.node;
2023-06-05 18:27:53 +02:00
var _loca = {};
_loca.name = _n.name;
_loca.tooltip = _n.tooltip;
2023-02-14 02:48:33 +01:00
2023-06-17 14:30:49 +02:00
var _jin = [], _jot = [];
2023-06-05 18:27:53 +02:00
var _lin = [], _lot = [];
2023-06-17 14:30:49 +02:00
var _din = [], _dot = [];
2023-02-14 02:48:33 +01:00
2023-03-05 07:16:44 +01:00
for( var i = 0; i < ds_list_size(_b.inputs); i++ ) {
2023-06-17 14:30:49 +02:00
_din[i] = variable_clone(_b.inputs[| i], 1);
_jin[i] = {
2023-06-05 18:27:53 +02:00
type: _b.inputs[| i].type,
visible: _b.inputs[| i].visible? 1 : 0,
};
_lin[i] = {
2023-06-13 14:42:06 +02:00
name: _b.inputs[| i]._initName,
2023-03-05 07:16:44 +01:00
tooltip: _b.inputs[| i].tooltip,
};
2023-02-14 02:48:33 +01:00
}
2023-03-05 07:16:44 +01:00
for( var i = 0; i < ds_list_size(_b.outputs); i++ ) {
2023-06-17 14:30:49 +02:00
_dot[i] = variable_clone(_b.outputs[| i], 1);
_jot[i] = {
2023-06-05 18:27:53 +02:00
type: _b.outputs[| i].type,
visible: _b.outputs[| i].visible? 1 : 0,
};
_lot[i] = {
2023-06-13 14:42:06 +02:00
name: _b.outputs[| i]._initName,
2023-03-05 07:16:44 +01:00
tooltip: _b.outputs[| i].tooltip,
};
}
2023-06-17 14:30:49 +02:00
_junc.inputs = _jin;
_junc.outputs = _jot;
junc[$ _n.name] = _junc;
2023-06-05 18:27:53 +02:00
_loca.inputs = _lin;
_loca.outputs = _lot;
locale[$ _n.node] = _loca;
2023-06-17 14:30:49 +02:00
_data.inputs = _din;
_data.outputs = _dot;
data[$ _n.name] = _data;
2023-02-14 02:48:33 +01:00
}
2023-06-17 14:30:49 +02:00
json_save_struct(dir + "node_data.json", data, true);
json_save_struct(dir + "node_junctions.json", junc, false);
json_save_struct(dir + "node_locale.json", locale, true);
shellOpenExplorer(dir);
2023-06-05 18:27:53 +02:00
2023-02-14 02:48:33 +01:00
CLONING = false;
game_end();
} #endregion
#region node suggestion
function __loadNodeReleated(path) {
var _json = json_load_struct(path);
var _keys = variable_struct_get_names(_json);
var _rel = global.NODE_RELATION;
for( var i = 0, n = array_length(_keys); i < n; i++ ) {
var _group = _json[$ _keys[i]];
2023-10-09 16:07:33 +02:00
if(!struct_has(_rel, _keys[i]))
_rel[$ _keys[i]] = { relations : {} };
var _Vgroup = _rel[$ _keys[i]].relations;
switch(_group.key) {
case "connectionType" :
var _types = variable_struct_get_names(_group.relations);
for( var j = 0, m = array_length(_types); j < m; j++ ) {
var _k = value_type_from_string(_types[j]);
if(!struct_has(_Vgroup, _k)) _Vgroup[$ _k] = [];
array_append(_Vgroup[$ _k], _group.relations[$ _types[j]]);
}
break;
2023-10-09 16:07:33 +02:00
case "contextNode" :
var _nodes = variable_struct_get_names(_group.relations);
for( var j = 0, m = array_length(_nodes); j < m; j++ ) {
if(!struct_has(_Vgroup, _nodes[j])) _Vgroup[$ _nodes[j]] = [];
array_append(_Vgroup[$ _nodes[j]], _group.relations[$ _nodes[j]]);
}
break;
}
}
}
function __initNodeReleated() {
global.NODE_RELATION = {};
var _dir = DIRECTORY + "Nodes/Related";
directory_verify(_dir);
var f = file_find_first(_dir + "/*.json", fa_none);
while (f != "") {
__loadNodeReleated(_dir + "/" + f);
f = file_find_next();
}
file_find_close();
}
function nodeReleatedQuery(type, key) {
if(!struct_has(global.NODE_RELATION, type)) return [];
var _sugs = global.NODE_RELATION[$ type];
if(!struct_has(_sugs.relations, key)) return [];
return _sugs.relations[$ key];
}
#endregion
2023-02-14 02:48:33 +01:00
2023-03-21 03:01:53 +01:00
function __initNodeData() {
2023-02-14 02:48:33 +01:00
global.NODE_GUIDE = {};
2023-03-28 06:58:28 +02:00
var nodeDir = DIRECTORY + "Nodes/";
if(file_exists("data/tooltip.zip"))
2023-03-28 06:58:28 +02:00
zip_unzip("data/tooltip.zip", nodeDir);
2023-06-05 18:27:53 +02:00
if(file_exists("data/nodes.json")) {
file_delete(nodeDir + "nodes.json");
file_copy_override("data/nodes.json", nodeDir + "nodes.json");
2023-06-05 18:27:53 +02:00
}
var _relFrom = $"data/related_node.json";
var _relTo = nodeDir + "Related/default.json";
directory_verify(nodeDir + "Related");
file_copy_override(_relFrom, _relTo);
//print($"Copying related nodes from {_relFrom} to {_relTo}\n\t{file_exists(_relFrom)}, {file_exists(_relTo)}");
__initNodeReleated();
2023-02-14 02:48:33 +01:00
}