separate save, load file

This commit is contained in:
MakhamDev 2022-01-18 11:44:05 +07:00
parent 1971cb7660
commit 51d23ef006
5 changed files with 136 additions and 124 deletions

View file

@ -282,7 +282,7 @@
{"id":{"name":"s_dialog_active","path":"sprites/s_dialog_active/s_dialog_active.yy",},"order":0,},
{"id":{"name":"obj_reader","path":"scripts/obj_reader/obj_reader.yy",},"order":2,},
{"id":{"name":"sh_invert","path":"shaders/sh_invert/sh_invert.yy",},"order":30,},
{"id":{"name":"save_load","path":"scripts/save_load/save_load.yy",},"order":0,},
{"id":{"name":"save","path":"scripts/save/save.yy",},"order":0,},
{"id":{"name":"node_perlin_smear","path":"scripts/node_perlin_smear/node_perlin_smear.yy",},"order":10,},
{"id":{"name":"node_alpha_cutoff","path":"scripts/node_alpha_cutoff/node_alpha_cutoff.yy",},"order":37,},
{"id":{"name":"sh_channel_R","path":"shaders/sh_channel_R/sh_channel_R.yy",},"order":12,},
@ -520,6 +520,7 @@
{"id":{"name":"sample_projects","path":"scripts/sample_projects/sample_projects.yy",},"order":6,},
{"id":{"name":"s_path_tools_add","path":"sprites/s_path_tools_add/s_path_tools_add.yy",},"order":4,},
{"id":{"name":"s_ui_scrollbar","path":"sprites/s_ui_scrollbar/s_ui_scrollbar.yy",},"order":3,},
{"id":{"name":"load","path":"scripts/load/load.yy",},"order":2,},
{"id":{"name":"ds_map","path":"scripts/ds_map/ds_map.yy",},"order":0,},
{"id":{"name":"sh_atlas","path":"shaders/sh_atlas/sh_atlas.yy",},"order":31,},
{"id":{"name":"node_scale","path":"scripts/node_scale/node_scale.yy",},"order":9,},

121
scripts/load/load.gml Normal file
View file

@ -0,0 +1,121 @@
function LOAD() {
var path = get_open_filename("*.pxc;*.json", "");
if(path == "") return;
if(filename_ext(path) != ".json" && filename_ext(path) != ".pxc") return;
LOAD_PATH(path);
}
function LOAD_PATH(path, readonly = false) {
if(!file_exists(path)) {
PANEL_MENU.showNoti("File not found", s_noti_icon_warning);
return false;
}
if(filename_ext(path) != ".json" && filename_ext(path) != ".pxc") {
PANEL_MENU.showNoti("File not a valid project", s_noti_icon_warning);
return false;
}
var temp_path = DIRECTORY + "\_temp";
if(file_exists(temp_path)) file_delete(temp_path);
file_copy(path, temp_path);
APPEND_ID = 0;
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"];
if(_v != SAVEFILE_VERSION) {
var warn = "File version mismatch : loading file verion " + string(_v) + " to Pixel Composer " + string(SAVEFILE_VERSION);
log_warning("FILE", warn)
PANEL_MENU.addNotiExtra(warn);
}
} else {
var warn = "File version mismatch : loading old format to Pixel Composer " + string(SAVEFILE_VERSION);
log_warning("FILE", warn)
PANEL_MENU.addNotiExtra(warn);
}
clearNodes();
var create_list = ds_list_create();
if(ds_map_exists(_map, "nodes")) {
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);
}
}
if(ds_map_exists(_map, "animator")) {
var _anim_map = _map[? "animator"];
ANIMATOR.frames_total = _anim_map[? "frames_total"];
ANIMATOR.framerate = _anim_map[? "framerate"];
}
ds_map_destroy(_map);
ds_queue_clear(CONNECTION_CONFLICT);
for(var i = 0; i < ds_list_size(create_list); i++) {
create_list[| i].loadGroup();
}
for(var i = 0; i < ds_list_size(create_list); i++) {
create_list[| i].postDeserialize();
}
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();
}
for(var i = 0; i < ds_list_size(create_list); i++) {
create_list[| i].postConnect();
}
for(var i = 0; i < ds_list_size(create_list); i++) {
create_list[| i].doUpdate();
}
renderAll();
if(!ds_queue_empty(CONNECTION_CONFLICT)) {
var pass = 0;
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) + " )");
repeat(size) {
ds_queue_dequeue(CONNECTION_CONFLICT).connect();
}
renderAll();
}
if(!ds_queue_empty(CONNECTION_CONFLICT))
PANEL_MENU.addNotiExtra("Some connection(s) is unsolved. This may caused by render node not being update properly, or image path is broken.");
}
LOADING = false;
PANEL_GRAPH.fullView();
PANEL_ANIMATION.updatePropertyList();
log_message("FILE", "load at " + path);
PANEL_MENU.showNoti("File loaded", s_noti_icon_file);
return true;
}

View file

@ -6,7 +6,7 @@
"path": "folders/functions/save load.yy",
},
"resourceVersion": "1.0",
"name": "save_load",
"name": "load",
"tags": [],
"resourceType": "GMScript",
}

View file

@ -98,128 +98,6 @@ function SAVE_AT(path) {
PANEL_MENU.showNoti("File saved", s_noti_icon_save);
}
function LOAD() {
var path = get_open_filename("*.pxc;*.json", "");
if(path == "") return;
if(filename_ext(path) != ".json" && filename_ext(path) != ".pxc") return;
LOAD_PATH(path);
}
function LOAD_PATH(path, readonly = false) {
if(!file_exists(path)) {
PANEL_MENU.showNoti("File not found", s_noti_icon_warning);
return false;
}
if(filename_ext(path) != ".json" && filename_ext(path) != ".pxc") {
PANEL_MENU.showNoti("File not a valid project", s_noti_icon_warning);
return false;
}
var temp_path = DIRECTORY + "\_temp";
if(file_exists(temp_path)) file_delete(temp_path);
file_copy(path, temp_path);
APPEND_ID = 0;
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"];
if(_v != SAVEFILE_VERSION) {
var warn = "File version mismatch : loading file verion " + string(_v) + " to Pixel Composer " + string(SAVEFILE_VERSION);
log_warning("FILE", warn)
PANEL_MENU.addNotiExtra(warn);
}
} else {
var warn = "File version mismatch : loading old format to Pixel Composer " + string(SAVEFILE_VERSION);
log_warning("FILE", warn)
PANEL_MENU.addNotiExtra(warn);
}
clearNodes();
var create_list = ds_list_create();
if(ds_map_exists(_map, "nodes")) {
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);
}
}
if(ds_map_exists(_map, "animator")) {
var _anim_map = _map[? "animator"];
ANIMATOR.frames_total = _anim_map[? "frames_total"];
ANIMATOR.framerate = _anim_map[? "framerate"];
}
ds_map_destroy(_map);
ds_queue_clear(CONNECTION_CONFLICT);
for(var i = 0; i < ds_list_size(create_list); i++) {
create_list[| i].loadGroup();
}
for(var i = 0; i < ds_list_size(create_list); i++) {
create_list[| i].postDeserialize();
}
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();
}
for(var i = 0; i < ds_list_size(create_list); i++) {
create_list[| i].postConnect();
}
for(var i = 0; i < ds_list_size(create_list); i++) {
create_list[| i].doUpdate();
}
renderAll();
if(!ds_queue_empty(CONNECTION_CONFLICT)) {
var pass = 0;
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) + " )");
repeat(size) {
ds_queue_dequeue(CONNECTION_CONFLICT).connect();
}
renderAll();
}
if(!ds_queue_empty(CONNECTION_CONFLICT))
PANEL_MENU.addNotiExtra("Some connection(s) is unsolved. This may caused by render node not being update properly, or image path is broken.");
}
LOADING = false;
PANEL_GRAPH.fullView();
PANEL_ANIMATION.updatePropertyList();
log_message("FILE", "load at " + path);
PANEL_MENU.showNoti("File loaded", s_noti_icon_file);
return true;
}
function SAVE_COLLECTIONS(_list, _path, save_surface = true) {
var file = file_text_open_write(_path);
var _map = ds_map_create();

12
scripts/save/save.yy Normal file
View file

@ -0,0 +1,12 @@
{
"isDnD": false,
"isCompatibility": false,
"parent": {
"name": "save load",
"path": "folders/functions/save load.yy",
},
"resourceVersion": "1.0",
"name": "save",
"tags": [],
"resourceType": "GMScript",
}