Pixel-Composer/scripts/steam_ugc_functions/steam_ugc_functions.gml

98 lines
2.5 KiB
Plaintext
Raw Normal View History

2023-02-15 10:43:24 +01:00
function __initSteamUGC() {
globalvar STEAM_SUBS, STEAM_COLLECTION, STEAM_PROJECTS;
2023-02-17 11:31:33 +01:00
STEAM_SUBS = ds_list_create();
2023-02-15 10:43:24 +01:00
STEAM_COLLECTION = ds_list_create();
STEAM_PROJECTS = ds_list_create();
2023-02-16 02:51:51 +01:00
if(DEMO) return;
2023-02-15 10:43:24 +01:00
if(!STEAM_ENABLED) return;
2023-02-17 11:31:33 +01:00
steamUCGload();
}
function steamUCGload() {
ds_list_clear(STEAM_SUBS);
ds_list_clear(STEAM_COLLECTION);
ds_list_clear(STEAM_PROJECTS);
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();
//print("Querying item ID " + string(STEAM_SUBS[| i]));
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);
if(_update) {
steam_ugc_subscribe_item(STEAM_SUBS[| i]);
//print("Item need update");
} else {
__loadSteamUGC(STEAM_SUBS[| i], item_map);
}
} else {
steam_ugc_subscribe_item(STEAM_SUBS[| i]);
//print("Item not downloaded");
}
ds_map_destroy(item_map);
}
}
function __loadSteamUGC(file_id, item_map) {
var _path = item_map[? "folder"];
2023-03-08 12:14:01 +01:00
var f = file_find_first(_path + "/*.pxcc", 0);
2023-02-15 10:43:24 +01:00
file_find_close();
if(f != "") {
__loadSteamUGCCollection(file_id, f, _path);
return;
}
2023-03-08 12:14:01 +01:00
var p = file_find_first(_path + "/*.pxc", 0);
2023-02-15 10:43:24 +01:00
file_find_close();
if(p != "") {
__loadSteamUGCProject(file_id, p, _path);
return;
}
}
2023-05-07 20:55:13 +02:00
function __loadSteamUGCCollection(file_id, f, path) {
2023-02-17 11:31:33 +01:00
var name = string_replace(filename_name(f), ".pxcc", "");
2023-03-08 12:14:01 +01:00
var file = new FileObject(name, path + "/" + f);
var icon_path = string_replace(path + "/" + f, ".pxcc", ".png");
2023-02-15 10:43:24 +01:00
if(file_exists(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);
2023-02-20 10:16:31 +01:00
var amo = safe_mod(ww, hh) == 0? ww / hh : 1;
2023-02-15 10:43:24 +01:00
sprite_delete(_temp);
file.spr_path = [icon_path, amo, false];
}
ds_list_add(STEAM_COLLECTION, file);
var meta = file.getMetadata();
meta.steam = true;
meta.file_id = file_id;
}
2023-05-07 20:55:13 +02:00
function __loadSteamUGCProject(file_id, f, path) {
2023-02-15 10:43:24 +01:00
var name = string_replace(filename_name(f), ".pxc", "");
2023-03-08 12:14:01 +01:00
var file = new FileObject(name, path + "/" + f);
var icon_path = path + "/thumbnail.png";
2023-02-15 10:43:24 +01:00
file.spr_path = [icon_path, 1, false];
ds_list_add(STEAM_PROJECTS, file);
var meta = file.getMetadata();
meta.steam = true;
meta.file_id = file_id;
}