Pixel-Composer/scripts/load_function/load_function.gml

204 lines
5.0 KiB
Plaintext
Raw Normal View History

2023-02-14 02:51:14 +01:00
function LOAD() {
if(DEMO) return false;
2022-12-16 09:18:09 +01:00
var path = get_open_filename("Pixel Composer project (.pxc)|*.pxc", "");
2023-02-28 09:43:01 +01:00
key_release();
2022-01-18 05:44:05 +01:00
if(path == "") return;
if(filename_ext(path) != ".json" && filename_ext(path) != ".pxc") return;
2022-11-01 03:06:03 +01:00
gc_collect();
2022-01-18 05:44:05 +01:00
LOAD_PATH(path);
2022-11-03 11:44:49 +01:00
ds_list_clear(STATUSES);
ds_list_clear(WARNING);
ds_list_clear(ERRORS);
2022-01-18 05:44:05 +01:00
}
2023-02-14 02:51:14 +01:00
function LOAD_PATH(path, readonly = false, safe_mode = false) {
2023-02-23 07:02:19 +01:00
if(MODIFIED && !READONLY) {
var dia = dialogCall(o_dialog_load);
dia.path = path;
dia.readonly = readonly;
dia.safe_mode = safe_mode;
} else
__LOAD_PATH(path, readonly, safe_mode);
}
function __LOAD_PATH(path, readonly = false, safe_mode = false) {
2023-02-14 02:51:14 +01:00
SAFE_MODE = safe_mode;
if(DEMO) return false;
2022-01-18 05:44:05 +01:00
if(!file_exists(path)) {
2022-11-14 03:16:15 +01:00
log_warning("LOAD", "File not found");
2022-01-18 05:44:05 +01:00
return false;
}
if(filename_ext(path) != ".json" && filename_ext(path) != ".pxc") {
2022-11-14 03:16:15 +01:00
log_warning("LOAD", "File not a valid project");
2022-01-18 05:44:05 +01:00
return false;
}
2023-02-23 07:02:19 +01:00
LOADING = true;
2023-04-14 12:23:25 +02:00
2022-12-10 05:06:01 +01:00
nodeCleanUp();
clearPanel();
setPanel();
2023-02-14 13:44:46 +01:00
instance_destroy(_p_dialog);
2023-02-23 07:02:19 +01:00
//room_restart();
2023-04-14 12:23:25 +02:00
ds_list_clear(ERRORS);
2022-12-10 05:06:01 +01:00
var temp_path = DIRECTORY + "_temp";
2022-01-18 05:44:05 +01:00
if(file_exists(temp_path)) file_delete(temp_path);
file_copy(path, temp_path);
2022-12-13 09:20:36 +01:00
ALWAYS_FULL = false;
2022-01-18 05:44:05 +01:00
READONLY = readonly;
SET_PATH(path);
2023-06-13 14:42:06 +02:00
var _load_content = json_load_struct(temp_path);
2022-01-18 05:44:05 +01:00
2023-06-13 14:42:06 +02:00
if(struct_has(_load_content, "version")) {
var _v = _load_content.version;
2022-12-23 04:45:52 +01:00
LOADING_VERSION = _v;
2022-01-18 05:44:05 +01:00
if(_v != SAVEFILE_VERSION) {
var warn = "File version mismatch : loading file verion " + string(_v) + " to Pixel Composer " + string(SAVEFILE_VERSION);
2022-11-14 03:16:15 +01:00
log_warning("LOAD", warn);
2022-01-18 05:44:05 +01:00
}
} else {
var warn = "File version mismatch : loading old format to Pixel Composer " + string(SAVEFILE_VERSION);
2022-11-14 03:16:15 +01:00
log_warning("LOAD", warn);
2022-01-18 05:44:05 +01:00
}
2022-01-19 06:11:17 +01:00
nodeCleanUp();
2022-01-18 05:44:05 +01:00
var create_list = ds_list_create();
2023-06-13 14:42:06 +02:00
if(struct_has(_load_content, "nodes")) {
try {
2023-06-13 14:42:06 +02:00
var _node_list = _load_content.nodes;
for(var i = 0; i < array_length(_node_list); i++) {
var _node = nodeLoad(_node_list[i]);
if(_node) ds_list_add(create_list, _node);
}
} catch(e) {
2022-12-22 03:09:55 +01:00
log_warning("LOAD", exception_print(e));
2022-01-18 05:44:05 +01:00
}
}
try {
2023-06-13 14:42:06 +02:00
if(struct_has(_load_content, "animator")) {
var _anim_map = _load_content.animator;
ANIMATOR.frames_total = _anim_map.frames_total;
ANIMATOR.framerate = _anim_map.framerate;
}
} catch(e) {
2022-12-22 03:09:55 +01:00
log_warning("LOAD, animator", exception_print(e));
2022-01-18 05:44:05 +01:00
}
2022-12-10 05:06:01 +01:00
try {
2023-06-13 14:42:06 +02:00
if(struct_has(_load_content, "metadata"))
METADATA.deserialize(_load_content.metadata);
2022-12-10 05:06:01 +01:00
} catch(e) {
2023-02-14 02:51:14 +01:00
log_warning("LOAD, metadata", exception_print(e));
2022-12-10 05:06:01 +01:00
}
2023-03-07 14:29:47 +01:00
GLOBAL = new Node_Global();
try {
2023-06-13 14:42:06 +02:00
if(struct_has(_load_content, "global"))
GLOBAL.deserialize(_load_content.global);
2023-03-07 14:29:47 +01:00
} catch(e) {
log_warning("LOAD, global", exception_print(e));
}
2023-05-16 21:28:16 +02:00
try {
2023-06-13 14:42:06 +02:00
if(struct_has(_load_content, "addon")) {
var _addon = _load_content.addon;
2023-06-17 14:30:49 +02:00
LOAD_ADDON = _addon;
struct_foreach(_addon, function(_name, _value) { addonLoad(_name, false); });
} else
LOAD_ADDON = {};
2023-05-16 21:28:16 +02:00
} catch(e) {
log_warning("LOAD, addon", exception_print(e));
}
2022-01-18 05:44:05 +01:00
ds_queue_clear(CONNECTION_CONFLICT);
try {
for(var i = 0; i < ds_list_size(create_list); i++)
create_list[| i].loadGroup();
} catch(e) {
2022-12-22 03:09:55 +01:00
log_warning("LOAD, group", exception_print(e));
2022-01-18 05:44:05 +01:00
}
try {
for(var i = 0; i < ds_list_size(create_list); i++)
create_list[| i].postDeserialize();
} catch(e) {
2022-12-22 03:09:55 +01:00
log_warning("LOAD, deserialize", exception_print(e));
2022-01-18 05:44:05 +01:00
}
2022-12-21 02:30:23 +01:00
try {
for(var i = 0; i < ds_list_size(create_list); i++)
create_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(create_list); i++)
create_list[| i].preConnect();
for(var i = 0; i < ds_list_size(create_list); i++)
create_list[| i].connect();
} catch(e) {
2022-12-22 03:09:55 +01:00
log_warning("LOAD, connect", exception_print(e));
2022-01-18 05:44:05 +01:00
}
try {
for(var i = 0; i < ds_list_size(create_list); i++)
create_list[| i].doUpdate();
} catch(e) {
2022-12-22 03:09:55 +01:00
log_warning("LOAD, update", exception_print(e));
2022-01-18 05:44:05 +01:00
}
2023-03-02 07:59:14 +01:00
Render(, true);
2022-01-18 05:44:05 +01:00
if(!ds_queue_empty(CONNECTION_CONFLICT)) {
var pass = 0;
try {
while(++pass < 4 && !ds_queue_empty(CONNECTION_CONFLICT)) {
var size = ds_queue_size(CONNECTION_CONFLICT);
2023-06-13 14:42:06 +02:00
log_message("LOAD", $"[Connect] {size} Connection conflict(s) detected (pass: {pass})");
2022-12-23 04:45:52 +01:00
repeat(size)
ds_queue_dequeue(CONNECTION_CONFLICT).connect();
2022-12-10 05:06:01 +01:00
Render();
2022-01-18 05:44:05 +01:00
}
2022-12-23 04:45:52 +01:00
if(!ds_queue_empty(CONNECTION_CONFLICT))
2022-11-14 03:16:15 +01:00
log_warning("LOAD", "Some connection(s) is unsolved. 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("LOAD, connect solver", exception_print(e));
}
2022-01-18 05:44:05 +01:00
}
2023-01-09 03:14:20 +01:00
try {
for(var i = 0; i < ds_list_size(create_list); i++)
create_list[| i].postConnect();
} catch(e) {
log_warning("LOAD, connect", exception_print(e));
}
2023-06-17 14:30:49 +02:00
Render();
2022-12-27 13:30:02 +01:00
2022-01-18 05:44:05 +01:00
LOADING = false;
2022-09-27 06:37:28 +02:00
MODIFIED = false;
2022-01-18 05:44:05 +01:00
PANEL_ANIMATION.updatePropertyList();
2022-11-18 03:20:31 +01:00
log_message("FILE", "load " + path, THEME.noti_icon_file_load);
2022-12-10 05:06:01 +01:00
PANEL_MENU.setNotiIcon(THEME.noti_icon_file_load);
2022-01-29 14:25:18 +01:00
2023-04-15 14:48:29 +02:00
refreshNodeMap();
2022-01-18 05:44:05 +01:00
return true;
2023-03-05 07:16:44 +01:00
}