Pixel-Composer/scripts/append_function/append_function.gml

166 lines
4.7 KiB
Text
Raw Normal View History

2023-11-23 02:32:26 +01:00
function APPEND(_path, context = PANEL_GRAPH.getCurrentContext()) { #region
2024-02-06 13:53:08 +01:00
CALL("append");
2024-02-04 07:33:42 +01:00
2023-01-01 02:06:02 +01:00
if(_path == "") return noone;
2023-06-13 14:42:06 +02:00
var _map = json_load_struct(_path);
2022-01-18 05:31:19 +01:00
2022-12-12 09:08:03 +01:00
if(_map == -1) {
2023-08-04 13:12:32 +02:00
printIf(log, "Decode error");
2023-01-01 02:06:02 +01:00
return noone;
2022-01-18 05:31:19 +01:00
}
2023-03-25 12:53:29 +01:00
var node_create = __APPEND_MAP(_map, context);
recordAction(ACTION_TYPE.collection_loaded, array_clone(node_create), _path);
2023-02-28 09:43:01 +01:00
log_message("FILE", "append file " + _path, THEME.noti_icon_file_load);
return node_create;
2023-11-23 02:32:26 +01:00
} #endregion
2023-02-28 09:43:01 +01:00
function __APPEND_MAP(_map, context = PANEL_GRAPH.getCurrentContext(), appended_list = []) { #region
2023-03-25 12:27:04 +01:00
static log = false;
2023-02-14 02:51:14 +01:00
UNDO_HOLDING = true;
2023-06-13 14:42:06 +02:00
if(struct_has(_map, "version")) {
var _v = _map.version;
2024-03-27 11:51:14 +01:00
LOADING_VERSION = _v;
2024-02-04 07:33:42 +01:00
if(PREFERENCES.notify_load_version && floor(_v) != floor(SAVE_VERSION)) {
2023-12-05 04:28:49 +01:00
var warn = $"File version mismatch : loading file version {_v} to Pixel Composer {SAVE_VERSION}";
2022-01-18 05:31:19 +01:00
log_warning("FILE", warn)
}
}
2023-06-13 14:42:06 +02:00
if(!struct_has(_map, "nodes")) return noone;
var _node_list = _map.nodes;
var node_create = [];
2022-01-18 05:31:19 +01:00
2024-03-22 09:44:11 +01:00
APPENDING = true;
2023-07-25 20:12:40 +02:00
2022-01-18 05:31:19 +01:00
ds_queue_clear(CONNECTION_CONFLICT);
2024-04-11 05:51:13 +02:00
if(!CLONING) 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
2023-06-13 14:42:06 +02:00
for(var i = 0; i < array_length(_node_list); i++) {
2024-04-11 05:51:13 +02:00
var ex = ds_map_exists(APPEND_MAP, _node_list[i].id);
2023-06-13 14:42:06 +02:00
var _node = nodeLoad(_node_list[i], true, context);
if(_node && !ex) array_push(appended_list, _node);
2022-01-18 05:31:19 +01:00
}
2023-08-04 13:12:32 +02:00
printIf(log, "Load time: " + string(current_time - t)); t = current_time;
2022-01-18 05:31:19 +01:00
try {
for(var i = 0; i < array_length(appended_list); i++) {
var _node = appended_list[i];
2023-03-26 07:13:36 +02:00
_node.loadGroup(context);
2022-01-18 05:31:19 +01:00
2023-03-25 12:53:29 +01:00
if(_node.group == context)
array_push(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
}
2023-08-04 13:12:32 +02:00
printIf(log, "Load group time: " + string(current_time - t)); t = current_time;
2022-01-18 05:31:19 +01:00
try {
for(var i = 0; i < array_length(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
}
2023-08-04 13:12:32 +02:00
printIf(log, "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 < array_length(appended_list); i++)
appended_list[i].applyDeserialize();
2022-12-21 02:30:23 +01:00
} 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
}
2023-08-04 13:12:32 +02:00
printIf(log, "Apply deserialize time: " + string(current_time - t)); t = current_time;
2022-12-21 02:30:23 +01:00
try {
for(var i = 0; i < array_length(appended_list); i++)
appended_list[i].preConnect();
2024-04-11 05:51:13 +02:00
for(var i = 0; i < array_length(appended_list); i++)
appended_list[i].connect();
2024-04-11 05:51:13 +02:00
for(var i = 0; i < array_length(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
}
2023-08-04 13:12:32 +02:00
printIf(log, "Connect time: " + string(current_time - t)); t = current_time;
2022-01-18 05:31:19 +01:00
try {
for(var i = 0; i < array_length(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
}
2023-08-04 13:12:32 +02:00
printIf(log, "Update time: " + string(current_time - t)); t = current_time;
2022-01-18 05:31:19 +01:00
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);
2023-06-13 14:42:06 +02:00
log_message("APPEND", $"[Connect] {size} Connection conflict(s) detected (pass: {pass})");
repeat(size) {
2022-09-21 06:09:40 +02:00
var junc = ds_queue_dequeue(CONNECTION_CONFLICT);
var res = junc.connect(true);
2023-06-13 14:42:06 +02:00
log_message("APPEND", $"[Connect] Reconnecting {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
}
2023-08-04 13:12:32 +02:00
printIf(log, "Conflict time: " + string(current_time - t)); t = current_time;
2022-01-18 05:31:19 +01:00
2023-01-09 03:14:20 +01:00
try {
for(var i = 0; i < array_length(appended_list); i++)
appended_list[i].postLoad();
2023-01-09 03:14:20 +01:00
} catch(e) {
log_warning("APPEND, connect", exception_print(e));
}
2023-02-14 02:51:14 +01:00
UNDO_HOLDING = false;
APPENDING = false;
2023-10-02 10:45:30 +02:00
2023-06-13 14:42:06 +02:00
if(struct_has(_map, "metadata")) {
var meta = _map.metadata;
for( var i = 0; i < array_length(node_create); i++ ) {
var _node = node_create[i];
2023-02-14 02:51:14 +01:00
if(!struct_has(_node, "metadata")) continue;
_node.metadata.deserialize(meta, true);
}
}
2023-04-15 14:48:29 +02:00
refreshNodeMap();
2023-11-07 06:01:38 +01:00
RENDER_ALL_REORDER
2023-04-15 14:48:29 +02:00
2023-10-12 07:07:24 +02:00
if(struct_has(_map, "timelines")) {
var _time = new timelineItemGroup().deserialize(_map.timelines);
array_append(PROJECT.timelines.contents, _time.contents);
}
2022-01-18 05:31:19 +01:00
return node_create;
2023-11-23 02:32:26 +01:00
} #endregion
2022-01-19 03:05:13 +01:00
2023-11-23 02:32:26 +01:00
function GetAppendID(old_id) { #region
2023-02-28 09:43:01 +01:00
if(old_id == noone) return noone;
2022-01-19 03:05:13 +01:00
if(ds_map_exists(APPEND_MAP, old_id))
return APPEND_MAP[? old_id];
2024-05-08 07:27:29 +02:00
// print("Get append ID error: " + string(old_id));
2023-02-28 09:43:01 +01:00
return noone;
2023-11-23 02:32:26 +01:00
} #endregion