Pixel-Composer/scripts/append_function/append_function.gml

135 lines
3.8 KiB
Plaintext
Raw Normal View History

2022-01-18 05:31:19 +01:00
function APPEND(_path) {
APPENDING = true;
2022-12-12 09:08:03 +01:00
var log = false;
2022-01-18 05:31:19 +01:00
if(_path == "") return;
2022-12-12 09:08:03 +01:00
var _map = json_load(_path);
2022-01-18 05:31:19 +01:00
2022-12-12 09:08:03 +01:00
if(_map == -1) {
printlog("Decode error");
return
2022-01-18 05:31:19 +01:00
}
if(ds_map_exists(_map, "version")) {
var _v = _map[? "version"];
2022-12-23 04:45:52 +01:00
LOADING_VERSION = _v;
2022-01-18 05:31:19 +01:00
if(_v != SAVEFILE_VERSION) {
var warn = "File version mismatch : loading file verion " + string(_v) + " to Pixel Composer " + string(SAVEFILE_VERSION);
log_warning("FILE", warn)
}
} else {
var warn = "File version mismatch : loading old format to Pixel Composer " + string(SAVEFILE_VERSION);
log_warning("FILE", warn)
}
var _node_list = _map[? "nodes"];
var appended_list = ds_list_create();
var node_create = ds_list_create();
ds_queue_clear(CONNECTION_CONFLICT);
2022-01-19 03:05:13 +01:00
ds_map_clear(APPEND_MAP);
2022-12-12 09:08:03 +01:00
var t = current_time;
2022-01-18 05:31:19 +01:00
for(var i = 0; i < ds_list_size(_node_list); i++) {
var _node = nodeLoad(_node_list[| i], true);
if(_node) ds_list_add(appended_list, _node);
}
2022-12-12 09:08:03 +01:00
printlog("Load time: " + string(current_time - t));
t = current_time;
2022-01-18 05:31:19 +01:00
try {
for(var i = 0; i < ds_list_size(appended_list); i++) {
var _node = appended_list[| i];
_node.loadGroup();
2022-01-18 05:31:19 +01:00
if(_node.group == PANEL_GRAPH.getCurrentContext())
ds_list_add(node_create, _node);
}
} catch(e) {
2022-12-22 03:09:55 +01:00
log_warning("APPEND, node", exception_print(e));
2022-01-18 05:31:19 +01:00
}
2022-12-12 09:08:03 +01:00
printlog("Load group time: " + string(current_time - t));
t = current_time;
2022-01-18 05:31:19 +01:00
try {
for(var i = 0; i < ds_list_size(appended_list); i++)
appended_list[| i].postDeserialize();
} catch(e) {
2022-12-22 03:09:55 +01:00
log_warning("APPEND, deserialize", exception_print(e));
2022-01-18 05:31:19 +01:00
}
2022-12-12 09:08:03 +01:00
printlog("Deserialize time: " + string(current_time - t));
t = current_time;
2022-12-10 05:06:01 +01:00
2022-12-21 02:30:23 +01:00
try {
for(var i = 0; i < ds_list_size(appended_list); i++)
appended_list[| i].applyDeserialize();
} catch(e) {
2022-12-22 03:09:55 +01:00
log_warning("LOAD, apply deserialize", exception_print(e));
2022-12-21 02:30:23 +01:00
}
try {
for(var i = 0; i < ds_list_size(appended_list); i++)
appended_list[| i].preConnect();
for(var i = 0; i < ds_list_size(appended_list); i++)
appended_list[| i].connect();
for(var i = 0; i < ds_list_size(appended_list); i++)
appended_list[| i].postConnect();
} catch(e) {
2022-12-22 03:09:55 +01:00
log_warning("APPEND, connect", exception_print(e));
2022-01-18 05:31:19 +01:00
}
2022-12-12 09:08:03 +01:00
printlog("Connect time: " + string(current_time - t));
t = current_time;
2022-01-18 05:31:19 +01:00
try {
for(var i = 0; i < ds_list_size(appended_list); i++)
appended_list[| i].doUpdate();
} catch(e) {
2022-12-22 03:09:55 +01:00
log_warning("APPEND, update", exception_print(e));
2022-01-23 04:08:16 +01:00
}
2022-12-12 09:08:03 +01:00
printlog("Update time: " + string(current_time - t));
t = current_time;
2022-01-18 05:31:19 +01:00
ds_list_destroy(appended_list);
2022-12-10 05:06:01 +01:00
Render(true);
2022-01-18 05:31:19 +01:00
2022-01-23 04:08:16 +01:00
if(!ds_queue_empty(CONNECTION_CONFLICT)) {
var pass = 0;
2022-01-18 05:31:19 +01:00
try {
2022-09-21 06:09:40 +02:00
while(++pass < 3 && !ds_queue_empty(CONNECTION_CONFLICT)) {
var size = ds_queue_size(CONNECTION_CONFLICT);
log_message("APPEND", "[Connect] " + string(size) + " Connection conflict(s) detected ( pass: " + string(pass) + " )");
repeat(size) {
2022-09-21 06:09:40 +02:00
var junc = ds_queue_dequeue(CONNECTION_CONFLICT);
var res = junc.connect(true);
log_message("APPEND", "[Connect] Reconnecting " + string(junc.name) + " " + (res? "SUCCESS" : "FAILED"));
}
2022-12-10 05:06:01 +01:00
Render(true);
2022-01-23 04:08:16 +01:00
}
2022-01-18 05:31:19 +01:00
if(!ds_queue_empty(CONNECTION_CONFLICT))
2022-12-12 09:08:03 +01:00
log_warning("APPEND", "Some connection(s) is unresolved. This may caused by render node not being update properly, or image path is broken.");
} catch(e) {
2022-12-22 03:09:55 +01:00
log_warning("APPEND, Conflict solver error : ", exception_print(e));
}
2022-01-23 04:08:16 +01:00
}
2022-12-12 09:08:03 +01:00
printlog("Conflict time: " + string(current_time - t));
t = current_time;
2022-01-18 05:31:19 +01:00
APPENDING = false;
PANEL_ANIMATION.updatePropertyList();
2022-11-18 03:20:31 +01:00
log_message("FILE", "append file " + _path, THEME.noti_icon_file_load);
2022-01-29 14:25:18 +01:00
ds_map_destroy(_map);
2022-01-18 05:31:19 +01:00
return node_create;
2022-01-19 03:05:13 +01:00
}
function GetAppendID(old_id) {
if(ds_map_exists(APPEND_MAP, old_id))
return APPEND_MAP[? old_id];
2022-12-21 02:30:23 +01:00
print("Get append ID error: " + string(old_id));
2022-01-19 03:05:13 +01:00
return -1;
2022-01-18 05:31:19 +01:00
}