Pixel-Composer/scripts/assets_data/assets_data.gml

55 lines
1.3 KiB
Plaintext
Raw Normal View History

2022-09-27 06:37:28 +02:00
#region assets
global.ASSET_MAP = ds_map_create();
global.ASSET_CACHE = ds_map_create();
function __initAssets() {
ds_map_clear(global.ASSET_MAP);
var root = DIRECTORY + "Assets";
directory_verify(root);
2022-09-27 06:37:28 +02:00
if(check_version($"{root}/version"))
2022-12-10 05:06:01 +01:00
zip_unzip("data/Assets.zip", root);
2023-02-14 02:51:14 +01:00
2022-09-27 06:37:28 +02:00
global.ASSETS = new DirectoryObject("Assets", root);
global.ASSETS.scan([".png"]);
var st = ds_stack_create();
ds_stack_push(st, global.ASSETS);
while(!ds_stack_empty(st)) {
var _st = ds_stack_pop(st);
for( var i = 0; i < ds_list_size(_st.content); i++ ) {
var _f = _st.content[| i];
2023-01-17 08:11:55 +01:00
global.ASSET_MAP[? _f.path] = _f;
2022-09-27 06:37:28 +02:00
}
for( var i = 0; i < ds_list_size(_st.subDir); i++ ) {
ds_stack_push(st, _st.subDir[| i]);
}
}
ds_stack_destroy(st);
}
function get_asset(key) {
if(!ds_map_exists(global.ASSET_MAP, key)) return noone;
2023-07-17 19:58:33 +02:00
2022-09-27 06:37:28 +02:00
if(ds_map_exists(global.ASSET_CACHE, key)) {
var s = global.ASSET_CACHE[? key];
var valid = true;
if(is_array(s)) {
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(s); i < n; i++ )
2022-09-27 06:37:28 +02:00
valid &= is_surface(s[i]);
} else
valid = is_surface(s);
if(valid) return s;
}
2023-01-17 08:11:55 +01:00
var spr = global.ASSET_MAP[? key].getSpr();
2022-09-27 06:37:28 +02:00
global.ASSET_CACHE[? key] = surface_create_from_sprite(spr);
return global.ASSET_CACHE[? key];
}
#endregion