Compress pixel composer project file

This commit is contained in:
Tanasart 2024-04-01 18:32:13 +07:00
parent 5d3a1f7835
commit e82a50e5e3
7 changed files with 32 additions and 25 deletions

View file

@ -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

View file

@ -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)); }

View file

@ -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

View file

@ -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

View file

@ -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();

View file

@ -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);
}

View file

@ -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;