2022-12-10 11:06:01 +07:00
|
|
|
function __initCollection() {
|
2022-01-13 11:24:03 +07:00
|
|
|
log_message("COLLECTION", "init");
|
|
|
|
|
|
|
|
globalvar COLLECTIONS;
|
2022-01-25 10:05:30 +07:00
|
|
|
COLLECTIONS = -1;
|
2022-01-13 11:24:03 +07:00
|
|
|
|
2024-09-16 14:29:37 +07:00
|
|
|
var root = DIRECTORY + "Collections"; directory_verify(root);
|
|
|
|
var rootz = DIRECTORY + "Collections_cache"; directory_verify(rootz);
|
2023-02-14 08:51:14 +07:00
|
|
|
|
2023-11-18 09:47:11 +07:00
|
|
|
if(check_version($"{root}/version"))
|
2022-12-10 11:06:01 +07:00
|
|
|
zip_unzip("data/Collections.zip", root);
|
2022-01-13 11:24:03 +07:00
|
|
|
|
2023-12-11 15:59:58 +07:00
|
|
|
COLLECTIONS = new DirectoryObject("Collections", DIRECTORY + "Collections");
|
2024-01-26 20:38:50 +07:00
|
|
|
refreshCollections();
|
2022-01-13 11:24:03 +07:00
|
|
|
}
|
|
|
|
|
2022-01-25 16:58:11 +07:00
|
|
|
function refreshCollections() {
|
2022-01-13 11:24:03 +07:00
|
|
|
log_message("COLLECTION", "refreshing collection base folder.");
|
|
|
|
|
2022-01-25 10:05:30 +07:00
|
|
|
COLLECTIONS = new DirectoryObject("Collections", DIRECTORY + "Collections");
|
2022-09-27 11:37:28 +07:00
|
|
|
COLLECTIONS.scan([".json", ".pxcc"]);
|
2022-01-25 10:05:30 +07:00
|
|
|
COLLECTIONS.open = true;
|
2022-01-25 16:58:11 +07:00
|
|
|
}
|
|
|
|
|
2024-09-26 09:27:52 +07:00
|
|
|
function searchCollection(_list, _search_str, _toList = true) {
|
2022-01-25 16:58:11 +07:00
|
|
|
if(_search_str == "") return;
|
|
|
|
var search_lower = string_lower(_search_str);
|
2024-09-25 12:34:40 +07:00
|
|
|
|
2022-01-25 16:58:11 +07:00
|
|
|
var st = ds_stack_create();
|
2024-09-26 09:27:52 +07:00
|
|
|
var ll = _toList? ds_priority_create() : _list;
|
2024-09-25 12:34:40 +07:00
|
|
|
|
2022-01-25 16:58:11 +07:00
|
|
|
ds_stack_push(st, COLLECTIONS);
|
|
|
|
|
|
|
|
while(!ds_stack_empty(st)) {
|
|
|
|
var _st = ds_stack_pop(st);
|
|
|
|
for( var i = 0; i < ds_list_size(_st.content); i++ ) {
|
|
|
|
var _nd = _st.content[| i];
|
|
|
|
|
2023-02-14 17:40:24 +07:00
|
|
|
var match = string_partial_match(string_lower(_nd.name), search_lower);
|
|
|
|
if(match == -9999) continue;
|
2023-01-01 08:06:02 +07:00
|
|
|
|
2024-09-25 12:34:40 +07:00
|
|
|
ds_priority_add(ll, _nd, match);
|
2022-01-25 16:58:11 +07:00
|
|
|
}
|
|
|
|
|
2024-09-25 12:34:40 +07:00
|
|
|
for( var i = 0; i < ds_list_size(_st.subDir); i++ )
|
2022-01-25 16:58:11 +07:00
|
|
|
ds_stack_push(st, _st.subDir[| i]);
|
|
|
|
}
|
2022-09-27 11:37:28 +07:00
|
|
|
|
2024-09-26 09:27:52 +07:00
|
|
|
if(_toList) {
|
|
|
|
repeat(ds_priority_size(ll))
|
|
|
|
ds_list_add(_list, ds_priority_delete_max(ll));
|
|
|
|
|
|
|
|
ds_priority_destroy(ll);
|
|
|
|
}
|
2024-09-25 12:34:40 +07:00
|
|
|
|
2022-01-25 16:58:11 +07:00
|
|
|
ds_stack_destroy(st);
|
2023-04-21 19:08:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function saveCollection(_node, _path, _name, save_surface = true, metadata = noone) {
|
|
|
|
if(_node == noone) return;
|
|
|
|
|
2024-09-16 14:29:37 +07:00
|
|
|
var _pxz = false;
|
|
|
|
var _file = _path + "/" + filename_name_only(_name);
|
|
|
|
|
|
|
|
if(_pxz) {
|
|
|
|
_path = _file + ".pxz";
|
|
|
|
SAVE_PXZ_COLLECTION(_node, _path, PANEL_PREVIEW.getNodePreviewSurface(), metadata, _node.group);
|
2023-04-21 19:08:10 +02:00
|
|
|
|
2024-09-16 14:29:37 +07:00
|
|
|
} else {
|
|
|
|
_path = _file + ".pxcc";
|
|
|
|
SAVE_COLLECTION(_node, _path, save_surface, metadata, _node.group);
|
2023-04-21 19:08:10 +02:00
|
|
|
|
2024-09-16 14:29:37 +07:00
|
|
|
}
|
|
|
|
|
2023-04-21 19:08:10 +02:00
|
|
|
PANEL_COLLECTION.updated_path = _path;
|
|
|
|
PANEL_COLLECTION.updated_prog = 1;
|
|
|
|
PANEL_COLLECTION.refreshContext();
|
2022-01-13 11:24:03 +07:00
|
|
|
}
|