Pixel-Composer/scripts/sample_projects/sample_projects.gml

60 lines
1.6 KiB
Plaintext
Raw Normal View History

2022-01-13 05:24:03 +01:00
#region samples
globalvar SAMPLE_PROJECTS;
SAMPLE_PROJECTS = ds_list_create();
#endregion
function LOAD_FOLDER(list, folder) {
2023-12-05 13:49:18 +01:00
var path = $"{DIRECTORY}Welcome files/{folder}";
if(!directory_exists(path)) return;
2022-01-29 14:25:18 +01:00
var file = file_find_first(path + "/*", fa_directory);
2023-02-15 10:43:24 +01:00
2023-03-08 12:14:01 +01:00
while(file != "") {
2024-06-03 09:34:59 +02:00
var f = file;
var full_path = path + "/" + file;
file = file_find_next();
if(!path_is_project(full_path)) continue;
var f = new FileObject(filename_name_only(f), full_path);
var icon_path = string_replace(full_path, filename_ext(full_path), ".png");
2022-01-29 14:25:18 +01:00
2024-06-03 09:34:59 +02:00
if(file_exists_empty(icon_path)) {
f.spr = sprite_add(icon_path, 0, false, false, 0, 0);
sprite_set_offset(f.spr, sprite_get_width(f.spr) / 2, sprite_get_height(f.spr) / 2);
2022-01-13 05:24:03 +01:00
}
2024-06-03 09:34:59 +02:00
f.tag = folder;
ds_list_add(list, f);
2022-01-13 05:24:03 +01:00
}
file_find_close();
}
2022-01-29 14:25:18 +01:00
function LOAD_SAMPLE() {
2022-01-29 14:25:18 +01:00
ds_list_clear(SAMPLE_PROJECTS);
var zzip = "Welcome files/Welcome files.zip";
2023-12-05 13:49:18 +01:00
var targ = $"{DIRECTORY}Welcome files";
2022-01-29 14:25:18 +01:00
2023-12-05 13:49:18 +01:00
directory_verify(targ);
zip_unzip(zzip, targ);
2023-03-08 12:14:01 +01:00
2024-06-29 05:22:20 +02:00
var _dir = [];
var path = $"{DIRECTORY}Welcome files/";
var file = file_find_first(path + "/*", fa_directory);
while(file != "") {
if(directory_exists(path + "/" + file))
array_push(_dir, file);
file = file_find_next();
}
file_find_close();
for (var i = 0, n = array_length(PREFERENCES.welcome_file_order); i < n; i++) {
LOAD_FOLDER(SAMPLE_PROJECTS, PREFERENCES.welcome_file_order[i]);
array_remove(_dir, PREFERENCES.welcome_file_order[i]);
}
2024-06-29 05:22:20 +02:00
for (var i = 0, n = array_length(_dir); i < n; i++)
LOAD_FOLDER(SAMPLE_PROJECTS, _dir[i]);
}