mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2024-12-23 21:46:17 +01:00
- Add preference option to save and load project layout.
This commit is contained in:
parent
11de0da99f
commit
f8c7dab28a
11 changed files with 83 additions and 38 deletions
|
@ -179,6 +179,15 @@ event_inherited();
|
|||
|
||||
ds_list_add(pref_global, __txt("Save/Load"));
|
||||
|
||||
ds_list_add(pref_global, new __Panel_Linear_Setting_Item_Preference(
|
||||
__txtx("pref_save_layout", "Save layout"),
|
||||
"save_layout",
|
||||
new checkBox(function() {
|
||||
PREFERENCES.save_layout = !PREFERENCES.save_layout;
|
||||
PREF_SAVE();
|
||||
})
|
||||
));
|
||||
|
||||
ds_list_add(pref_global, new __Panel_Linear_Setting_Item_Preference(
|
||||
__txtx("pref_save_file_minify", "Minify save file"),
|
||||
"save_file_minify",
|
||||
|
|
|
@ -15,7 +15,7 @@ function exportPortable(project = PROJECT) {
|
|||
|
||||
var raw_name = filename_name_only(path);
|
||||
var raw_path = filename_path(path) + raw_name;
|
||||
var _proj = save_serialize(project, true);
|
||||
var _proj = project.serialize();
|
||||
|
||||
var zip = zip_create();
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
"Extrude": new hotkeySimple("E", MOD_KEY.alt),
|
||||
"Inset": new hotkeySimple("I", MOD_KEY.alt),
|
||||
"Skew": new hotkeySimple("S", MOD_KEY.alt),
|
||||
"Corner": new hotkeySimple("C", MOD_KEY.alt),
|
||||
},
|
||||
|
||||
"Node_Mesh_Warp": {
|
||||
|
|
|
@ -253,6 +253,9 @@ function LOAD_AT(path, readonly = false, override = false) { #region
|
|||
|
||||
printIf(log, $"========== Load {array_length(PROJECT.allNodes)} nodes completed in {(get_timer() - t0) / 1000} ms ==========");
|
||||
|
||||
if(PREFERENCES.save_layout && struct_has(_load_content, "layout"))
|
||||
LoadPanelStruct(_load_content.layout.panel);
|
||||
|
||||
return true;
|
||||
} #endregion
|
||||
|
||||
|
|
|
@ -141,6 +141,9 @@
|
|||
#endregion
|
||||
|
||||
#region node function
|
||||
function node_get_id(node) { return node? node.node_id : noone; }
|
||||
function node_from_id(nid) { return nid && ds_map_exists(PROJECT.nodeMap, nid)? PROJECT.nodeMap[? nid] : noone; }
|
||||
|
||||
function nodeLoad(_data, scale = false, _group = noone) {
|
||||
INLINE
|
||||
if(!is_struct(_data)) return;
|
||||
|
|
|
@ -77,6 +77,8 @@
|
|||
return noone;
|
||||
} #endregion
|
||||
|
||||
function LoadPanelStruct(struct) { loadPanelStruct(PANEL_MAIN, struct); }
|
||||
|
||||
function loadPanelStruct(panel, str) { #region
|
||||
var cont = str.content;
|
||||
|
||||
|
@ -108,10 +110,10 @@
|
|||
}
|
||||
} #endregion
|
||||
|
||||
function loadPanel(path, panel) { #region
|
||||
function loadPanel(path) {
|
||||
CURRENT_PANEL = json_load_struct(path);
|
||||
loadPanelStruct(panel, CURRENT_PANEL.panel);
|
||||
} #endregion
|
||||
LoadPanelStruct(CURRENT_PANEL.panel);
|
||||
}
|
||||
|
||||
function checkPanelValid() { #region
|
||||
var val = true;
|
||||
|
@ -180,7 +182,7 @@
|
|||
var file = $"{DIRECTORY}layouts/{PREFERENCES.panel_layout_file}.json";
|
||||
if(!file_exists_empty(file))
|
||||
file = DIRECTORY + "layouts/Horizontal.json";
|
||||
loadPanel(file, PANEL_MAIN);
|
||||
loadPanel(file);
|
||||
|
||||
PANEL_MAIN.refresh();
|
||||
PANEL_MAIN.refreshSize();
|
||||
|
|
|
@ -2590,11 +2590,24 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor {
|
|||
return {
|
||||
name: instanceof(self),
|
||||
project,
|
||||
|
||||
graph_x,
|
||||
graph_y,
|
||||
|
||||
graph_s,
|
||||
graph_s_to,
|
||||
};
|
||||
}
|
||||
|
||||
static deserialize = function(data) {
|
||||
setProject(data.project);
|
||||
|
||||
graph_x = struct_try_get(data, "graph_x", graph_x);
|
||||
graph_y = struct_try_get(data, "graph_x", graph_y);
|
||||
|
||||
graph_s = struct_try_get(data, "graph_x", graph_s);
|
||||
graph_s_to = struct_try_get(data, "graph_x", graph_s_to);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
|
|
@ -1120,14 +1120,14 @@ function Panel_Inspector() : PanelContent() constructor {
|
|||
static serialize = function() {
|
||||
return {
|
||||
name: instanceof(self),
|
||||
inspecting,
|
||||
inspectings,
|
||||
inspecting : node_get_id(inspecting),
|
||||
inspectings : array_map(inspectings, function(n) { return node_get_id(n) }),
|
||||
};
|
||||
}
|
||||
|
||||
static deserialize = function(data) {
|
||||
inspecting = data.inspecting;
|
||||
inspectings = data.inspectings;
|
||||
inspecting = node_from_id(data.inspecting);
|
||||
inspectings = array_map(data.inspectings, function(n) { return node_from_id(n); });
|
||||
|
||||
return self;
|
||||
}
|
||||
|
|
|
@ -2155,13 +2155,22 @@ function Panel_Preview() : PanelContent() constructor {
|
|||
|
||||
static serialize = function() {
|
||||
return {
|
||||
name: instanceof(self),
|
||||
preview_node,
|
||||
name: instanceof(self),
|
||||
preview_node : [ node_get_id(preview_node[0]), node_get_id(preview_node[1]) ],
|
||||
|
||||
canvas_x,
|
||||
canvas_y,
|
||||
canvas_s,
|
||||
};
|
||||
}
|
||||
|
||||
static deserialize = function(data) {
|
||||
preview_node = data.preview_node;
|
||||
if(struct_has(data, "preview_node"))
|
||||
preview_node = [ node_from_id(data.preview_node[0]), node_from_id(data.preview_node[1]) ];
|
||||
|
||||
canvas_x = struct_try_get(data, "canvas_x", canvas_x);
|
||||
canvas_y = struct_try_get(data, "canvas_y", canvas_y);
|
||||
canvas_s = struct_try_get(data, "canvas_s", canvas_s);
|
||||
|
||||
run_in(1, fullView)
|
||||
return self;
|
||||
|
|
|
@ -124,10 +124,16 @@
|
|||
|
||||
#endregion
|
||||
|
||||
#region //////////////////////////////////////////////////////////////////////// MISC //////////////////////////////////////////////////////////////////////////
|
||||
#region //////////////////////////////////////////////////////////////////////// SAVE //////////////////////////////////////////////////////////////////////////
|
||||
|
||||
PREFERENCES.save_file_minify = true;
|
||||
PREFERENCES.save_backup = 1;
|
||||
PREFERENCES.save_layout = false;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region //////////////////////////////////////////////////////////////////////// MISC //////////////////////////////////////////////////////////////////////////
|
||||
|
||||
PREFERENCES.render_all_export = true;
|
||||
PREFERENCES.clear_temp_on_close = true;
|
||||
|
|
|
@ -2,7 +2,7 @@ globalvar SAVING, IS_SAVING;
|
|||
SAVING = false;
|
||||
IS_SAVING = false;
|
||||
|
||||
function NEW() { #region
|
||||
function NEW() {
|
||||
CALL("new");
|
||||
|
||||
PROJECT = new Project();
|
||||
|
@ -11,16 +11,16 @@ function NEW() { #region
|
|||
var graph = new Panel_Graph(PROJECT);
|
||||
PANEL_GRAPH.panel.setContent(graph, true);
|
||||
PANEL_GRAPH = graph;
|
||||
} #endregion
|
||||
}
|
||||
|
||||
function save_serialize(project = PROJECT, _outMap = false) { #region
|
||||
function SERIALIZE_PROJECT(project = PROJECT) {
|
||||
var _map = project.serialize();
|
||||
_map.layout = panelSerialize();
|
||||
|
||||
if(_outMap) return _map;
|
||||
return PREFERENCES.save_file_minify? json_stringify_minify(_map) : json_stringify(_map, true);
|
||||
} #endregion
|
||||
}
|
||||
|
||||
function SET_PATH(project, path) { #region
|
||||
function SET_PATH(project, path) {
|
||||
if(path == "") {
|
||||
project.readonly = false;
|
||||
} else if(!project.readonly) {
|
||||
|
@ -34,23 +34,23 @@ function SET_PATH(project, path) { #region
|
|||
}
|
||||
|
||||
project.path = path;
|
||||
} #endregion
|
||||
}
|
||||
|
||||
function SAVE_ALL() { #region
|
||||
function SAVE_ALL() {
|
||||
for( var i = 0, n = array_length(PROJECTS); i < n; i++ )
|
||||
SAVE(PROJECTS[i]);
|
||||
} #endregion
|
||||
}
|
||||
|
||||
function SAVE(project = PROJECT) { #region
|
||||
function SAVE(project = PROJECT) {
|
||||
if(DEMO) return false;
|
||||
|
||||
if(project.path == "" || project.readonly || path_is_backup(project.path))
|
||||
return SAVE_AS(project);
|
||||
|
||||
return SAVE_AT(project, project.path);
|
||||
} #endregion
|
||||
}
|
||||
|
||||
function SAVE_AS(project = PROJECT) { #region
|
||||
function SAVE_AS(project = PROJECT) {
|
||||
if(DEMO) return false;
|
||||
|
||||
var path = get_save_filename_pxc("Pixel Composer project (.pxc)|*.pxc|Compressed Pixel Composer project (.cpxc)|*.cpxc", "");
|
||||
|
@ -66,17 +66,15 @@ function SAVE_AS(project = PROJECT) { #region
|
|||
SET_PATH(project, path);
|
||||
|
||||
return true;
|
||||
} #endregion
|
||||
}
|
||||
|
||||
function SAVE_AT(project = PROJECT, path = "", log = "save at ") { #region
|
||||
function SAVE_AT(project = PROJECT, path = "", log = "save at ") {
|
||||
CALL("save");
|
||||
|
||||
if(DEMO) return false;
|
||||
|
||||
IS_SAVING = true;
|
||||
SAVING = true;
|
||||
//if(TESTING && string_char_at(filename_name(path), 1) != "[")
|
||||
// path = $"{filename_dir(path)}/[{VERSION_STRING}] {filename_name(path)}";
|
||||
|
||||
if(PREFERENCES.save_backup) {
|
||||
for(var i = PREFERENCES.save_backup - 1; i >= 0; i--) {
|
||||
|
@ -90,9 +88,10 @@ function SAVE_AT(project = PROJECT, path = "", log = "save at ") { #region
|
|||
|
||||
if(file_exists_empty(path)) file_delete(path);
|
||||
var _ext = filename_ext_raw(path);
|
||||
var _prj = SERIALIZE_PROJECT(project);
|
||||
|
||||
if(_ext == "pxc") file_text_write_all(path, save_serialize(project));
|
||||
else if(_ext == "cpxc") buffer_save(buffer_compress_string(save_serialize(project)), path);
|
||||
if(_ext == "pxc") file_text_write_all(path, _prj);
|
||||
else if(_ext == "cpxc") buffer_save(buffer_compress_string(_prj), path);
|
||||
|
||||
SAVING = false;
|
||||
project.readonly = false;
|
||||
|
@ -102,11 +101,11 @@ function SAVE_AT(project = PROJECT, path = "", log = "save at ") { #region
|
|||
PANEL_MENU.setNotiIcon(THEME.noti_icon_file_save);
|
||||
|
||||
return true;
|
||||
} #endregion
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////// COLLECTION ///////////////////////////////////////////////////////
|
||||
|
||||
function SAVE_COLLECTIONS(_list, _path, save_surface = true, metadata = noone, context = PANEL_GRAPH.getCurrentContext()) { #region
|
||||
function SAVE_COLLECTIONS(_list, _path, save_surface = true, metadata = noone, context = PANEL_GRAPH.getCurrentContext()) {
|
||||
var _content = {};
|
||||
_content.version = SAVE_VERSION;
|
||||
|
||||
|
@ -151,9 +150,9 @@ function SAVE_COLLECTIONS(_list, _path, save_surface = true, metadata = noone, c
|
|||
|
||||
log_message("COLLECTION", "save collection at " + _path, THEME.noti_icon_file_save);
|
||||
PANEL_MENU.setNotiIcon(THEME.noti_icon_file_save);
|
||||
} #endregion
|
||||
}
|
||||
|
||||
function SAVE_COLLECTION(_node, _path, save_surface = true, metadata = noone, context = PANEL_GRAPH.getCurrentContext()) { #region
|
||||
function SAVE_COLLECTION(_node, _path, save_surface = true, metadata = noone, context = PANEL_GRAPH.getCurrentContext()) {
|
||||
if(save_surface) {
|
||||
var preview_surface = PANEL_PREVIEW.getNodePreviewSurface();
|
||||
if(is_surface(preview_surface)) {
|
||||
|
@ -186,9 +185,9 @@ function SAVE_COLLECTION(_node, _path, save_surface = true, metadata = noone, co
|
|||
|
||||
log_message("COLLECTION", "save collection at " + _path, THEME.noti_icon_file_save);
|
||||
PANEL_MENU.setNotiIcon(THEME.noti_icon_file_save);
|
||||
} #endregion
|
||||
}
|
||||
|
||||
function SAVE_NODE(_arr, _node, dx = 0, dy = 0, scale = false, context = PANEL_GRAPH.getCurrentContext()) { #region
|
||||
function SAVE_NODE(_arr, _node, dx = 0, dy = 0, scale = false, context = PANEL_GRAPH.getCurrentContext()) {
|
||||
if(struct_has(_node, "nodes")) {
|
||||
for(var i = 0; i < array_length(_node.nodes); i++)
|
||||
SAVE_NODE(_arr, _node.nodes[i], dx, dy, scale, context);
|
||||
|
@ -202,4 +201,4 @@ function SAVE_NODE(_arr, _node, dx = 0, dy = 0, scale = false, context = PANEL_G
|
|||
if(m.group == c) m.group = noone;
|
||||
|
||||
array_push(_arr, m);
|
||||
} #endregion
|
||||
}
|
Loading…
Reference in a new issue