Pixel-Composer/scripts/steam_ugc_functions/steam_ugc_functions.gml

112 lines
3.1 KiB
Plaintext
Raw Normal View History

2024-02-03 13:11:50 +01:00
function __initSteamUGC() { #region
2024-07-03 12:52:51 +02:00
globalvar STEAM_SUBS, STEAM_COLLECTION, STEAM_PROJECTS, STEAM_TAGS;
2024-04-08 07:13:46 +02:00
STEAM_SUBS = ds_list_create();
STEAM_COLLECTION = ds_list_create();
STEAM_PROJECTS = ds_list_create();
2024-07-03 12:52:51 +02:00
STEAM_TAGS = [];
2023-02-15 10:43:24 +01:00
2023-02-16 02:51:51 +01:00
if(DEMO) return;
2023-02-15 10:43:24 +01:00
if(!STEAM_ENABLED) return;
2023-11-27 11:40:28 +01:00
directory_verify(DIRECTORY + "steamUGC");
2024-02-03 13:11:50 +01:00
try { steamUCGload(); } catch(e) { log_message("SESSION", $"> init SteamUGC | error {e}"); }
} #endregion
2023-02-17 11:31:33 +01:00
2024-02-03 13:11:50 +01:00
function steamUCGload() { #region
2023-02-17 11:31:33 +01:00
ds_list_clear(STEAM_SUBS);
ds_list_clear(STEAM_COLLECTION);
ds_list_clear(STEAM_PROJECTS);
2024-07-03 12:52:51 +02:00
STEAM_TAGS = [];
2023-02-17 11:31:33 +01:00
2023-02-15 10:43:24 +01:00
steam_ugc_get_subscribed_items(STEAM_SUBS);
for( var i = 0; i < ds_list_size(STEAM_SUBS); i++ ) {
var item_map = ds_map_create();
if (steam_ugc_get_item_install_info(STEAM_SUBS[| i], item_map)) {
var info_map = ds_map_create();
var _update = false;
if (steam_ugc_get_item_update_info(STEAM_SUBS[| i], info_map))
_update = info_map[? "needs_update"];
ds_map_destroy(info_map);
2023-11-27 11:40:28 +01:00
if(_update) steam_ugc_subscribe_item(STEAM_SUBS[| i]);
else __loadSteamUGC(STEAM_SUBS[| i], item_map);
} else
2023-02-15 10:43:24 +01:00
steam_ugc_subscribe_item(STEAM_SUBS[| i]);
ds_map_destroy(item_map);
}
2024-02-03 13:11:50 +01:00
} #endregion
2023-02-15 10:43:24 +01:00
2024-02-03 13:11:50 +01:00
function __loadSteamUGC(file_id, item_map) { #region
2023-02-15 10:43:24 +01:00
var _path = item_map[? "folder"];
2024-02-03 13:11:50 +01:00
var f = file_find_first(_path + "/*.pxcc", 0); file_find_close();
2023-02-15 10:43:24 +01:00
if(f != "") {
__loadSteamUGCCollection(file_id, f, _path);
return;
}
2024-02-03 13:11:50 +01:00
var p = file_find_first(_path + "/*.pxc", 0); file_find_close();
2023-02-15 10:43:24 +01:00
if(p != "") {
__loadSteamUGCProject(file_id, p, _path);
return;
}
2024-02-03 13:11:50 +01:00
} #endregion
2023-02-15 10:43:24 +01:00
2024-02-03 13:11:50 +01:00
function __loadSteamUGCCollection(file_id, f, path) { #region
2024-06-03 09:34:59 +02:00
if(filename_ext_raw(f) != "pxcc") return;
2024-02-03 13:11:50 +01:00
var fullPath = $"{path}/{f}";
var name = filename_name_only(f);
var file = new FileObject(name, fullPath);
var icon_path = string_replace(fullPath, ".pxcc", ".png");
2023-12-08 03:50:09 +01:00
if(file_exists_empty(icon_path)) {
2023-02-15 10:43:24 +01:00
var _temp = sprite_add(icon_path, 0, false, false, 0, 0);
2024-02-03 13:11:50 +01:00
var ww = sprite_get_width(_temp);
var hh = sprite_get_height(_temp);
var amo = safe_mod(ww, hh) == 0? ww / hh : 1;
2023-02-15 10:43:24 +01:00
sprite_delete(_temp);
2024-02-03 13:11:50 +01:00
2023-11-27 11:40:28 +01:00
file.spr_path = [ icon_path, amo, false ];
2023-02-15 10:43:24 +01:00
}
ds_list_add(STEAM_COLLECTION, file);
2024-01-10 06:36:33 +01:00
var meta = file.getMetadata(true);
2023-11-27 14:50:20 +01:00
meta.steam = FILE_STEAM_TYPE.steamOpen;
2023-02-15 10:43:24 +01:00
meta.file_id = file_id;
2024-02-03 13:11:50 +01:00
} #endregion
2023-02-15 10:43:24 +01:00
2024-02-03 13:11:50 +01:00
function __loadSteamUGCProject(file_id, f, path) { #region
2024-06-03 09:34:59 +02:00
if(!path_is_project(f, false)) return;
2024-02-03 13:11:50 +01:00
var fullPath = $"{path}/{f}";
var name = filename_name_only(f);
var file = new FileObject(name, fullPath);
2023-03-08 12:14:01 +01:00
var icon_path = path + "/thumbnail.png";
2024-02-03 13:11:50 +01:00
if(file_exists_empty(icon_path)) {
var _temp = sprite_add(icon_path, 0, false, false, 0, 0);
var ww = sprite_get_width(_temp);
var hh = sprite_get_height(_temp);
var amo = safe_mod(ww, hh) == 0? ww / hh : 1;
sprite_delete(_temp);
file.spr_path = [ icon_path, amo, false ];
}
2023-02-15 10:43:24 +01:00
ds_list_add(STEAM_PROJECTS, file);
2024-02-03 13:11:50 +01:00
var meta = file.getMetadata(true);
2023-11-27 14:50:20 +01:00
meta.steam = FILE_STEAM_TYPE.steamOpen;
2023-02-15 10:43:24 +01:00
meta.file_id = file_id;
2024-07-03 12:52:51 +02:00
for (var i = 0, n = array_length(meta.tags); i < n; i++)
array_push_unique(STEAM_TAGS, meta.tags[i]);
2024-02-03 13:11:50 +01:00
} #endregion