Pixel-Composer/scripts/collection_data/collection_data.gml

59 lines
1.4 KiB
Text
Raw Normal View History

2022-12-10 05:06:01 +01:00
function __initCollection() {
2022-01-13 05:24:03 +01:00
log_message("COLLECTION", "init");
globalvar COLLECTIONS;
COLLECTIONS = -1;
2022-01-13 05:24:03 +01:00
2022-09-27 06:37:28 +02:00
var root = DIRECTORY + "Collections";
if(!directory_exists(root))
directory_create(root);
2023-02-14 02:51:14 +01:00
var _l = root + "\\version";
if(file_exists(_l)) {
var res = json_load_struct(_l);
if(res.version < VERSION)
zip_unzip("data/Collections.zip", root);
} else
2022-12-10 05:06:01 +01:00
zip_unzip("data/Collections.zip", root);
2023-02-14 02:51:14 +01:00
json_save_struct(_l, { version: VERSION });
2022-01-13 05:24:03 +01:00
2022-01-25 10:58:11 +01:00
refreshCollections();
2022-01-13 05:24:03 +01:00
}
2022-01-25 10:58:11 +01:00
function refreshCollections() {
2022-01-13 05:24:03 +01:00
log_message("COLLECTION", "refreshing collection base folder.");
COLLECTIONS = new DirectoryObject("Collections", DIRECTORY + "Collections");
2022-09-27 06:37:28 +02:00
COLLECTIONS.scan([".json", ".pxcc"]);
COLLECTIONS.open = true;
2022-01-25 10:58:11 +01:00
}
2023-02-14 02:51:14 +01:00
function searchCollection(_list, _search_str, _clear_list = true) {
2023-02-14 11:40:24 +01:00
//if(_clear_list)
// ds_list_clear(_list);
2022-01-25 10:58:11 +01:00
if(_search_str == "") return;
var search_lower = string_lower(_search_str);
var st = ds_stack_create();
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 11:40:24 +01:00
var match = string_partial_match(string_lower(_nd.name), search_lower);
if(match == -9999) continue;
2023-01-01 02:06:02 +01:00
2023-02-14 11:40:24 +01:00
ds_priority_add(_list, _nd, match);
2022-01-25 10:58:11 +01:00
}
for( var i = 0; i < ds_list_size(_st.subDir); i++ ) {
ds_stack_push(st, _st.subDir[| i]);
}
}
2022-09-27 06:37:28 +02:00
2022-01-25 10:58:11 +01:00
ds_stack_destroy(st);
2022-01-13 05:24:03 +01:00
}