From e82a50e5e39fe01734af89a4492ce5dd4392ca79 Mon Sep 17 00:00:00 2001 From: Tanasart Date: Mon, 1 Apr 2024 18:32:13 +0700 Subject: [PATCH] Compress pixel composer project file --- objects/o_main/Create_0.gml | 4 +++- objects/o_main/Step_1.gml | 2 +- scripts/buffer_functions/buffer_functions.gml | 8 ++++++++ scripts/directory_object/directory_object.gml | 1 + scripts/load_function/load_function.gml | 19 ++++++++++++++----- scripts/node_wrap_area/node_wrap_area.gml | 15 --------------- scripts/save_function/save_function.gml | 8 +++++--- 7 files changed, 32 insertions(+), 25 deletions(-) diff --git a/objects/o_main/Create_0.gml b/objects/o_main/Create_0.gml index 14fa5a5e7..897594471 100644 --- a/objects/o_main/Create_0.gml +++ b/objects/o_main/Create_0.gml @@ -196,6 +196,7 @@ node = Node_create_WAV_File_Read_path(PANEL_GRAPH.mouse_grid_x, PANEL_GRAPH.mouse_grid_y, p); break; case ".pxc" : + case ".cpxc" : LOAD_PATH(p); break; case ".pxcc" : @@ -219,6 +220,7 @@ #region version version_check = -1; version_latest = 0; + //if(os_is_network_connected()) { // var version = "https://gist.githubusercontent.com/Ttanasart-pt/d9eefbda84a78863c122b8b155bc0cda/raw/version.txt"; // version_check = http_get(version); @@ -401,7 +403,7 @@ path = string_replace_all(path, "\n", ""); path = string_replace_all(path, "\"", ""); - if(file_exists_empty(path) && filename_ext(path) == ".pxc") + if(file_exists_empty(path) && (filename_ext(path) == ".pxc" || filename_ext(path) == ".cpxc")) PROGRAM_ARGUMENTS._path = path; } else diff --git a/objects/o_main/Step_1.gml b/objects/o_main/Step_1.gml index cd0879223..05389b45e 100644 --- a/objects/o_main/Step_1.gml +++ b/objects/o_main/Step_1.gml @@ -100,7 +100,7 @@ _HOVERING_ELEMENT = noone; string_lead_zero(current_day, 2) + "T" + string_lead_zero(current_hour, 2) + string_lead_zero(current_minute, 2) + - string_lead_zero(current_second, 2) + ".pxc"; + string_lead_zero(current_second, 2) + filename_ext(PROJECT.path); try { SAVE_AT(PROJECT, loc + fname, "Autosaved "); } catch(e) { print(exception_print(e)); } diff --git a/scripts/buffer_functions/buffer_functions.gml b/scripts/buffer_functions/buffer_functions.gml index b77016a32..fd8e62213 100644 --- a/scripts/buffer_functions/buffer_functions.gml +++ b/scripts/buffer_functions/buffer_functions.gml @@ -88,4 +88,12 @@ function buffer_setPixel(buffer, _w, _h, _x, _y, _c) { #region buffer_seek(buffer, buffer_seek_start, (_w * _y + _x) * 4); buffer_write(buffer, buffer_u32, _c); +} #endregion + +function buffer_compress_string(str) { #region + var _len = string_length(str); + var buffer = buffer_create(1, buffer_grow, 1); + + buffer_write(buffer, buffer_string, str); + return buffer_compress(buffer, 0, buffer_get_size(buffer)); } #endregion \ No newline at end of file diff --git a/scripts/directory_object/directory_object.gml b/scripts/directory_object/directory_object.gml index 3e2990677..caad3a9fa 100644 --- a/scripts/directory_object/directory_object.gml +++ b/scripts/directory_object/directory_object.gml @@ -23,6 +23,7 @@ function FileObject(_name, _path) constructor { #region type = FILE_TYPE.assets; break; case ".pxc" : + case ".cpxc" : type = FILE_TYPE.project; break; } #endregion diff --git a/scripts/load_function/load_function.gml b/scripts/load_function/load_function.gml index 53bf3a1b3..34bb46ca6 100644 --- a/scripts/load_function/load_function.gml +++ b/scripts/load_function/load_function.gml @@ -1,7 +1,7 @@ function LOAD(safe = false) { #region if(DEMO) return false; - var path = get_open_filename("Pixel Composer PROJECT (.pxc)|*.pxc", ""); + var path = get_open_filename("Pixel Composer project (.pxc)|*.pxc;*.cpxc", ""); key_release(); if(path == "") return; if(filename_ext(path) != ".json" && filename_ext(path) != ".pxc") return; @@ -71,7 +71,7 @@ function LOAD_AT(path, readonly = false, override = false) { #region return false; } - if(filename_ext(path) != ".json" && filename_ext(path) != ".pxc") { + if(filename_ext(path) != ".json" && filename_ext(path) != ".pxc" && filename_ext(path) != ".cpxc") { log_warning("LOAD", "File not a valid PROJECT"); return false; } @@ -102,10 +102,19 @@ function LOAD_AT(path, readonly = false, override = false) { #region printIf(log, $" > Create temp : {(get_timer() - t1) / 1000} ms"); t1 = get_timer(); var _load_content; + var _ext = filename_ext(path); + var s; + + if(_ext == ".pxc") { + var f = file_text_open_read(path); + s = file_text_read_all(f); + file_text_close(f); + + } else if(_ext == ".cpxc") { + var b = buffer_decompress(buffer_load(path)); + s = buffer_read(b, buffer_string); + } - var f = file_text_open_read(path); - var s = file_text_read_all(f); - file_text_close(f); _load_content = json_parse(s); printIf(log, $" > Load struct : {(get_timer() - t1) / 1000} ms"); t1 = get_timer(); diff --git a/scripts/node_wrap_area/node_wrap_area.gml b/scripts/node_wrap_area/node_wrap_area.gml index db7926561..f857bec1e 100644 --- a/scripts/node_wrap_area/node_wrap_area.gml +++ b/scripts/node_wrap_area/node_wrap_area.gml @@ -21,21 +21,6 @@ function Node_Wrap_Area(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) attribute_surface_depth(); attribute_interpolation(); - attributes[? "initalset"] = false; - - static onValueFromUpdate = function(index) { #region - if(index == 0 && attributes[? "initalset"] == false) { - var _surf = getInputData(0); - if(!is_surface(_surf)) return; - - var _sw = surface_get_width_safe(_surf); - var _sh = surface_get_height_safe(_surf); - - inputs[| 1].setValue([ _sw / 2, _sh / 2, _sw / 2, _sh / 2, AREA_SHAPE.rectangle ]); - attributes[? "initalset"] = true; - } - } if(!LOADING && !APPENDING) run_in(1, function() { onValueFromUpdate(0); }) #endregion - static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { inputs[| 1].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); } diff --git a/scripts/save_function/save_function.gml b/scripts/save_function/save_function.gml index f1163235b..d3edcb683 100644 --- a/scripts/save_function/save_function.gml +++ b/scripts/save_function/save_function.gml @@ -94,11 +94,11 @@ function SAVE(project = PROJECT) { #region function SAVE_AS(project = PROJECT) { #region if(DEMO) return false; - var path = get_save_filename("Pixel Composer project (.pxc)|*.pxc", ""); + var path = get_save_filename("Pixel Composer project (.pxc)|*.pxc|Compressed Pixel Composer project (.cpxc)|*.cpxc", ""); key_release(); if(path == "") return false; - if(filename_ext(path) != ".pxc") + if(filename_ext(path) != ".pxc" && filename_ext(path) != ".cpxc") path += ".pxc"; if(file_exists_empty(path)) @@ -119,7 +119,9 @@ function SAVE_AT(project = PROJECT, path = "", log = "save at ") { #region // path = $"{filename_dir(path)}/[{VERSION_STRING}] {filename_name(path)}"; if(file_exists_empty(path)) file_delete(path); - file_text_write_all(path, save_serialize(project)); + var _ext = filename_ext(path); + if(_ext == ".pxc") file_text_write_all(path, save_serialize(project)); + else if(_ext == ".cpxc") buffer_save(buffer_compress_string(save_serialize(project)), path); SAVING = false; project.readonly = false;