Pixel-Composer/scripts/steam_ugc_collection/steam_ugc_collection.gml

88 lines
3.6 KiB
Text
Raw Normal View History

2023-11-14 14:29:11 +01:00
function steam_ugc_create_collection(file) { #region
2023-02-15 10:04:49 +01:00
if(STEAM_UGC_ITEM_UPLOADING) return;
2023-02-14 02:48:33 +01:00
2023-11-27 11:40:28 +01:00
STEAM_UGC_UPDATE = false;
2023-02-15 10:04:49 +01:00
STEAM_UGC_ITEM_UPLOADING = true;
2023-11-27 11:40:28 +01:00
STEAM_UGC_ITEM_FILE = file;
STEAM_UGC_TYPE = STEAM_UGC_FILE_TYPE.collection;
2023-02-14 02:48:33 +01:00
2023-02-15 10:04:49 +01:00
directory_destroy(DIRECTORY + "steamUGC");
directory_create(DIRECTORY + "steamUGC");
2023-11-26 13:16:38 +01:00
2023-02-15 10:04:49 +01:00
file_copy(file.path, DIRECTORY + "steamUGC/" + filename_name(file.path));
2023-08-04 13:12:32 +02:00
file_copy(file.meta_path, DIRECTORY + "steamUGC/" + filename_name(file.meta_path));
2023-11-26 13:16:38 +01:00
if(array_safe_get(file.spr_path, 0) != 0)
2023-02-17 11:31:33 +01:00
file_copy(file.spr_path[0], DIRECTORY + "steamUGC/" + filename_name(file.spr_path[0]));
2023-11-26 13:16:38 +01:00
steam_ugc_collection_generate(array_safe_get(file.spr_path, 0));
2023-02-14 02:48:33 +01:00
2023-02-15 10:04:49 +01:00
STEAM_UGC_ITEM_ID = steam_ugc_create_item(STEAM_APP_ID, ugc_filetype_community);
2023-11-14 14:29:11 +01:00
} #endregion
2023-02-15 10:04:49 +01:00
2023-11-14 14:29:11 +01:00
function steam_ugc_update_collection(file, update_preview = false, update_note = "Updated") { #region
2023-02-15 10:04:49 +01:00
if(STEAM_UGC_ITEM_UPLOADING) return;
2023-11-27 11:40:28 +01:00
STEAM_UGC_UPDATE = true;
2023-02-15 10:04:49 +01:00
STEAM_UGC_ITEM_UPLOADING = true;
2023-11-27 11:40:28 +01:00
STEAM_UGC_ITEM_FILE = file;
STEAM_UGC_TYPE = STEAM_UGC_FILE_TYPE.collection;
2023-02-15 10:04:49 +01:00
directory_destroy(DIRECTORY + "steamUGC");
directory_create(DIRECTORY + "steamUGC");
2023-11-26 13:16:38 +01:00
2023-02-15 10:04:49 +01:00
file_copy(file.path, DIRECTORY + "steamUGC/" + filename_name(file.path));
2023-08-04 13:12:32 +02:00
file_copy(file.meta_path, DIRECTORY + "steamUGC/" + filename_name(file.meta_path));
2023-02-17 11:31:33 +01:00
if(array_safe_get(file.spr_path, 0, 0) != 0)
file_copy(file.spr_path[0], DIRECTORY + "steamUGC/" + filename_name(file.spr_path[0]));
2023-02-15 10:04:49 +01:00
STEAM_UGC_PUBLISH_ID = file.meta.file_id;
STEAM_UGC_UPDATE_HANDLE = steam_ugc_start_item_update(STEAM_APP_ID, STEAM_UGC_PUBLISH_ID);
steam_ugc_set_item_title(STEAM_UGC_UPDATE_HANDLE, STEAM_UGC_ITEM_FILE.meta.name);
steam_ugc_set_item_description(STEAM_UGC_UPDATE_HANDLE, STEAM_UGC_ITEM_FILE.meta.description);
2023-11-14 14:29:11 +01:00
var tgs = STEAM_UGC_ITEM_FILE.meta.tags;
2023-11-27 11:40:28 +01:00
array_insert_unique(tgs, 0, "Collection");
array_push_unique(tgs, VERSION_STRING);
2023-11-14 14:29:11 +01:00
2023-11-26 13:16:38 +01:00
steam_ugc_collection_generate(array_safe_get(file.spr_path, 0));
2023-11-14 14:29:11 +01:00
steam_ugc_set_item_tags(STEAM_UGC_UPDATE_HANDLE, tgs);
2023-02-15 10:04:49 +01:00
steam_ugc_set_item_content(STEAM_UGC_UPDATE_HANDLE, DIRECTORY + "steamUGC");
2023-12-08 03:50:09 +01:00
if(file_exists_empty(TEMPDIR + "steamUGCthumbnail.png"))
2023-11-26 13:16:38 +01:00
steam_ugc_set_item_preview(STEAM_UGC_UPDATE_HANDLE, TEMPDIR + "steamUGCthumbnail.png");
2023-02-15 10:04:49 +01:00
2023-10-18 14:58:55 +02:00
STEAM_UGC_SUBMIT_ID = steam_ugc_submit_item_update(STEAM_UGC_UPDATE_HANDLE, update_note);
2023-11-14 14:29:11 +01:00
} #endregion
2023-02-14 02:48:33 +01:00
2023-11-14 14:29:11 +01:00
function steam_ugc_collection_generate(file, dest_path = TEMPDIR + "steamUGCthumbnail.png") { #region
2023-02-15 10:04:49 +01:00
file_delete(dest_path);
2023-11-26 13:16:38 +01:00
2023-02-15 10:04:49 +01:00
var prev_size = 512;
2023-11-26 13:16:38 +01:00
var spr = sprite_add(file, 0, false, false, 0, 0);
var _s = surface_create(prev_size, prev_size);
2023-02-15 10:04:49 +01:00
surface_set_target(_s);
draw_clear(COLORS._main_icon_dark);
draw_sprite_tiled(s_workshop_bg, 0, -64, -64);
draw_sprite_stretched(s_workshop_frame, 0, 0, 0, prev_size, prev_size);
2023-08-10 11:51:16 +02:00
if(spr == -1) spr = THEME.workshop_collection;
2023-02-15 10:04:49 +01:00
var ss = (prev_size - 160) / max(sprite_get_width(spr), sprite_get_height(spr));
var ox = (sprite_get_xoffset(spr) - sprite_get_width(spr) / 2) * ss;
var oy = (sprite_get_yoffset(spr) - sprite_get_height(spr) / 2) * ss;
draw_sprite_ext(spr, 0, prev_size / 2 + ox, prev_size / 2 + oy, ss, ss, 0, c_white, 1);
draw_sprite_stretched(s_workshop_badge, 0, 8, 8, 88, 88);
2023-08-10 11:51:16 +02:00
draw_sprite_ext(THEME.workshop_collection, 0, 40, 40, 1, 1, 0, COLORS._main_icon_dark, 1);
2023-11-14 14:29:11 +01:00
draw_set_text(f_h2, fa_right, fa_bottom, COLORS._main_icon_dark);
var _bw = 48 + string_width(VERSION_STRING);
2023-11-26 13:16:38 +01:00
var _bh = 80;
2023-11-14 14:29:11 +01:00
draw_sprite_stretched(s_workshop_badge_version, 0, prev_size - 8 - _bw, prev_size - 8 - _bh, _bw, _bh);
2023-11-26 13:16:38 +01:00
draw_text(prev_size - 16, prev_size - 8, VERSION_STRING);
2023-02-15 10:04:49 +01:00
surface_reset_target();
2023-03-19 09:17:39 +01:00
surface_save_safe(_s, dest_path);
2023-02-15 10:04:49 +01:00
surface_free(_s);
2023-11-14 14:29:11 +01:00
} #endregion