Skip to content

Commit

Permalink
Cache sprite data alongside spritesheets, fixing emotes and a whole l…
Browse files Browse the repository at this point in the history
…otta other missing images (#140)

* Cache sprite data alongside spritesheets, fixing emotes and a whole lotta other missing images (#80601)

* Cache sprite data alongside spritesheets, fixing emotes and a whole lotta other missing images

* Update cleanbot_ai.dm

---------

Co-authored-by: Mothblocks <[email protected]>
Co-authored-by: NovaBot <[email protected]>
Co-authored-by: Giz <[email protected]>
  • Loading branch information
4 people authored and Iajret committed Dec 28, 2023
1 parent e8f9847 commit 1d918ce
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
32 changes: 29 additions & 3 deletions code/modules/asset_cache/asset_list.dm
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ GLOBAL_LIST_EMPTY(asset_datums)

if (isnull(should_refresh))
// `fexists` seems to always fail on static-time
should_refresh = !fexists("[ASSET_CROSS_ROUND_CACHE_DIRECTORY]/spritesheet.[name].css")
should_refresh = !fexists(css_cache_filename()) || !fexists(data_cache_filename())

return should_refresh

Expand Down Expand Up @@ -296,8 +296,17 @@ GLOBAL_LIST_EMPTY(asset_datums)

return out.Join("\n")

/datum/asset/spritesheet/proc/css_cache_filename()
return "[ASSET_CROSS_ROUND_CACHE_DIRECTORY]/spritesheet.[name].css"

/datum/asset/spritesheet/proc/data_cache_filename()
return "[ASSET_CROSS_ROUND_CACHE_DIRECTORY]/spritesheet.[name].json"

/datum/asset/spritesheet/proc/read_from_cache()
var/replaced_css = file2text("[ASSET_CROSS_ROUND_CACHE_DIRECTORY]/spritesheet.[name].css")
return read_css_from_cache() && read_data_from_cache()

/datum/asset/spritesheet/proc/read_css_from_cache()
var/replaced_css = file2text(css_cache_filename())

var/regex/find_background_urls = regex(@"background:url\('%(.+?)%'\)", "g")
while (find_background_urls.Find(replaced_css))
Expand All @@ -319,6 +328,14 @@ GLOBAL_LIST_EMPTY(asset_datums)

return TRUE

/datum/asset/spritesheet/proc/read_data_from_cache()
var/json = json_decode(file2text(data_cache_filename()))

if (islist(json["sprites"]))
sprites = json["sprites"]

return TRUE

/datum/asset/spritesheet/proc/send_from_cache(client/client)
if (isnull(cached_spritesheets_needed))
stack_trace("cached_spritesheets_needed was null when sending assets from [type] from cache")
Expand All @@ -334,14 +351,23 @@ GLOBAL_LIST_EMPTY(asset_datums)
return SSassets.transport.get_asset_url(asset)

/datum/asset/spritesheet/proc/write_to_cache()
write_css_to_cache()
write_data_to_cache()

/datum/asset/spritesheet/proc/write_css_to_cache()
for (var/size_id in sizes)
fcopy(SSassets.cache["[name]_[size_id].png"].resource, "[ASSET_CROSS_ROUND_CACHE_DIRECTORY]/spritesheet.[name]_[size_id].png")

generating_cache = TRUE
var/mock_css = generate_css()
generating_cache = FALSE

rustg_file_write(mock_css, "[ASSET_CROSS_ROUND_CACHE_DIRECTORY]/spritesheet.[name].css")
rustg_file_write(mock_css, css_cache_filename())

/datum/asset/spritesheet/proc/write_data_to_cache()
rustg_file_write(json_encode(list(
"sprites" = sprites,
)), data_cache_filename())

/datum/asset/spritesheet/proc/get_cached_url_mappings()
var/list/mappings = list()
Expand Down
4 changes: 4 additions & 0 deletions code/modules/mob/living/basic/bots/cleanbot/cleanbot_ai.dm
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
var/list/flag_list = controller.clean_flags
var/mob/living/basic/bot/cleanbot/bot_pawn = controller.pawn
for(var/list_key in flag_list)
// NOVA EDIT ADDITION START - TODO - Remove when cleanbot AI runtimes are fixed
if(QDELETED(bot_pawn))
return SUBTREE_RETURN_FINISH_PLANNING
// NOVA EDIT ADDITION END
if(!(bot_pawn.janitor_mode_flags & flag_list[list_key]))
continue
final_hunt_list += controller.blackboard[list_key]
Expand Down

0 comments on commit 1d918ce

Please sign in to comment.