mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-07-20 04:26:03 +01:00
Config Flag to Save Generated Spritesheets to Logs (#74884)
## About The Pull Request I was helping someone debug some weird bug with spritesheets a bit ago, and I didn't like having to manually comment out all of the `fdel()` stuff in order to help visualize what the potential issue might have been with the spritesheets on either their DM-side generation or their TGUI-level display. I decided to add a compile-time level flag that will automatically copy over any generated spritesheet assets (css and pngs) to the round-specific `data/logs` folder for analysis when a developer should need it. I also had to switch around some vars and make a few new ones to reduce how copy-pasta it might get and ensure standardization/readability while also being 0.001 times faster since we benefit from the string cache (unprovable fact). ## Why It's Good For The Game It's incredibly useful to see the actual flattened spritesheet itself sometimes when you're doing this type of work and you keep getting odd bugs here and there. Also saves headache from having to clear out the temp `/data/spritesheets` folder every time you comment shit out, as well as having an effective paper trail for A/B testing whatever bullshit you've got going on.  ## Changelog Doesn't affect players.
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user