diff --git a/code/controllers/configuration/entries/general.dm b/code/controllers/configuration/entries/general.dm index e79fd0f6fc1..6fec8758aae 100644 --- a/code/controllers/configuration/entries/general.dm +++ b/code/controllers/configuration/entries/general.dm @@ -653,6 +653,9 @@ /datum/config_entry/flag/cache_assets default = TRUE +/datum/config_entry/flag/save_spritesheets + default = FALSE + /datum/config_entry/flag/station_name_in_hub_entry default = FALSE diff --git a/code/modules/asset_cache/asset_list.dm b/code/modules/asset_cache/asset_list.dm index 0f34c964f05..222b5b06655 100644 --- a/code/modules/asset_cache/asset_list.dm +++ b/code/modules/asset_cache/asset_list.dm @@ -62,6 +62,13 @@ GLOBAL_LIST_EMPTY(asset_datums) /datum/asset/proc/should_refresh() return !cross_round_cachable || !CONFIG_GET(flag/cache_assets) +/// Simply takes any generated file and saves it to the round-specific /logs folder. Useful for debugging potential issues with spritesheet generation/display. +/// Only called when the SAVE_SPRITESHEETS config option is uncommented. +/datum/asset/proc/save_to_logs(file_name, file_location) + var/asset_path = "[GLOB.log_directory]/generated_assets/[file_name]" + fdel(asset_path) // just in case, sadly we can't use rust_g stuff here. + fcopy(file_location, asset_path) + /// If you don't need anything complicated. /datum/asset/simple _abstract = /datum/asset/simple @@ -194,12 +201,16 @@ GLOBAL_LIST_EMPTY(asset_datums) for(var/size_id in sizes) var/size = sizes[size_id] SSassets.transport.register_asset("[name]_[size_id].png", size[SPRSZ_STRIPPED]) - var/res_name = "spritesheet_[name].css" - var/fname = "data/spritesheets/[res_name]" - fdel(fname) - text2file(generate_css(), fname) - SSassets.transport.register_asset(res_name, fcopy_rsc(fname)) - fdel(fname) + var/css_name = "spritesheet_[name].css" + var/file_directory = "data/spritesheets/[css_name]" + fdel(file_directory) + text2file(generate_css(), file_directory) + SSassets.transport.register_asset(css_name, fcopy_rsc(file_directory)) + + if(CONFIG_GET(flag/save_spritesheets)) + save_to_logs(file_name = css_name, file_location = file_directory) + + fdel(file_directory) if (CONFIG_GET(flag/cache_assets) && cross_round_cachable) write_to_cache() @@ -245,13 +256,19 @@ GLOBAL_LIST_EMPTY(asset_datums) continue // save flattened version - var/fname = "data/spritesheets/[name]_[size_id].png" - fcopy(size[SPRSZ_ICON], fname) - var/error = rustg_dmi_strip_metadata(fname) + var/png_name = "[name]_[size_id].png" + var/file_directory = "data/spritesheets/[png_name]" + fcopy(size[SPRSZ_ICON], file_directory) + var/error = rustg_dmi_strip_metadata(file_directory) if(length(error)) - stack_trace("Failed to strip [name]_[size_id].png: [error]") - size[SPRSZ_STRIPPED] = icon(fname) - fdel(fname) + stack_trace("Failed to strip [png_name]: [error]") + size[SPRSZ_STRIPPED] = icon(file_directory) + + // this is useful here for determining if weird sprite issues (like having a white background) are a cause of what we're doing DM-side or not since we can see the full flattened thing at-a-glance. + if(CONFIG_GET(flag/save_spritesheets)) + save_to_logs(file_name = png_name, file_location = file_directory) + + fdel(file_directory) /datum/asset/spritesheet/proc/generate_css() var/list/out = list() @@ -288,9 +305,13 @@ GLOBAL_LIST_EMPTY(asset_datums) replaced_css = replacetext(replaced_css, find_background_urls.match, "background:url('[asset_url]')") LAZYADD(cached_spritesheets_needed, asset_id) - var/replaced_css_filename = "data/spritesheets/spritesheet_[name].css" + var/finalized_name = "spritesheet_[name].css" + var/replaced_css_filename = "data/spritesheets/[finalized_name]" rustg_file_write(replaced_css, replaced_css_filename) - SSassets.transport.register_asset("spritesheet_[name].css", replaced_css_filename) + SSassets.transport.register_asset(finalized_name, replaced_css_filename) + + if(CONFIG_GET(flag/save_spritesheets)) + save_to_logs(file_name = finalized_name, file_location = replaced_css_filename) fdel(replaced_css_filename) diff --git a/config/config.txt b/config/config.txt index d66eaf0942e..08483946c64 100644 --- a/config/config.txt +++ b/config/config.txt @@ -623,6 +623,11 @@ MOTD motd.txt ## but enabled on production (the default). CACHE_ASSETS 0 +## If this is uncommented, we will save all associated spritesheet PNGs and CSS files to a folder in the round-specific logs folder. +## Useful for developers to debug potential spritesheet issues to determine where the issue is cropping up (either in DM-side sprite generation or in the TGUI-side display of said spritesheet). +## Will only seek to waste disk space if ran on production. +#SAVE_SPRITESHEETS + ## Uncomment to allow the station name to be in the hub entry. ## You should only enable this if you can guarantee a station name doesn't break BYOND's TOS. ## BYOND staff have gotten upset at us in the past for inappropriate station names.