Pixel-Composer/scripts/load_function/load_function.gml

197 lines
4.9 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", "");
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) {
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;
}
2022-12-10 05:06:01 +01:00
nodeCleanUp();
clearPanel();
setPanel();
2023-02-14 13:44:46 +01:00
instance_destroy(_p_dialog);
2022-12-10 05:06:01 +01:00
room_restart();
2022-01-18 05:44:05 +01:00
var temp_path = DIRECTORY + "\_temp";
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
LOADING = true;
READONLY = readonly;
SET_PATH(path);
var file = file_text_open_read(temp_path);
var load_str = "";
while(!file_text_eof(file)) {
load_str += file_text_readln(file);
}
file_text_close(file);
var _map = json_decode(load_str);
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: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();
if(ds_map_exists(_map, "nodes")) {
try {
var _node_list = _map[? "nodes"];
for(var i = 0; i < ds_list_size(_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 {
if(ds_map_exists(_map, "animator")) {
var _anim_map = _map[? "animator"];
ANIMATOR.frames_total = ds_map_try_get(_anim_map, "frames_total");
ANIMATOR.framerate = ds_map_try_get(_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-02-14 02:51:14 +01:00
if(ds_map_exists(_map, "metadata"))
METADATA.deserialize(_map[? "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-02-14 02:51:14 +01:00
//try {
// if(ds_map_exists(_map, "graph")) {
// PANEL_GRAPH.graph_x = ds_map_try_get(_map[? "graph"], "graph_x");
// PANEL_GRAPH.graph_y = ds_map_try_get(_map[? "graph"], "graph_y");
// }
//} catch(e) {
// log_warning("LOAD, graph", 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-01-17 08:11:55 +01:00
try {
for(var i = 0; i < ds_list_size(create_list); i++) {
2023-02-14 02:51:14 +01:00
if(create_list[| i].hasInspectorUpdate())
2023-01-17 08:11:55 +01:00
create_list[| i].inspectorUpdate();
}
} catch(e) {
log_warning("LOAD, update", exception_print(e));
}
2022-12-10 05:06:01 +01:00
Render();
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);
log_message("LOAD", "[Connect] " + string(size) + " Connection conflict(s) detected ( pass: " + string(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));
}
2022-12-27 13:30:02 +01:00
UPDATE = RENDER_TYPE.full;
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
ds_map_destroy(_map);
2022-01-18 05:44:05 +01:00
return true;
}