From 57cb6a68093f5764890120c34cac745cc3666cd7 Mon Sep 17 00:00:00 2001 From: Lucy Date: Wed, 11 Sep 2024 05:45:21 -0400 Subject: [PATCH] Fix the previews in the chicken and botany encyclopedias --- code/__DEFINES/rust_g.dm | 7 +++++ code/__HELPERS/~monkestation-helpers/icons.dm | 21 +++++++++++++++ .../asset_cache/assets/botanical_lexicon.dm | 25 +++++++++++++++++ .../asset_cache/assets/chicken_book.dm | 22 +++++++++++++++ .../modules/hydroponics/botanical_lexicon.dm | 27 +++++++++---------- .../code/modules/ranching/chicken_book.dm | 19 ++++++------- tgstation.dme | 3 +++ .../tgui/interfaces/BotanicalLexicon.jsx | 15 +++++------ .../tgui/interfaces/RanchingEncyclopedia.jsx | 15 +++++------ 9 files changed, 112 insertions(+), 42 deletions(-) create mode 100644 code/__HELPERS/~monkestation-helpers/icons.dm create mode 100644 monkestation/code/modules/asset_cache/assets/botanical_lexicon.dm create mode 100644 monkestation/code/modules/asset_cache/assets/chicken_book.dm diff --git a/code/__DEFINES/rust_g.dm b/code/__DEFINES/rust_g.dm index db6114a05fb1..810991dafa49 100644 --- a/code/__DEFINES/rust_g.dm +++ b/code/__DEFINES/rust_g.dm @@ -124,6 +124,13 @@ #define rustg_dmi_strip_metadata(fname) RUSTG_CALL(RUST_G, "dmi_strip_metadata")(fname) #define rustg_dmi_create_png(path, width, height, data) RUSTG_CALL(RUST_G, "dmi_create_png")(path, width, height, data) #define rustg_dmi_resize_png(path, width, height, resizetype) RUSTG_CALL(RUST_G, "dmi_resize_png")(path, width, height, resizetype) + +#define RUSTG_RESIZE_NEAREST "nearest" +#define RUSTG_RESIZE_CATMULL "catmull" +#define RUSTG_RESIZE_GAUSSIAN "gaussian" +#define RUSTG_RESIZE_LANCZOS3 "lanczos3" +#define RUSTG_RESIZE_TRIANGLE "triangle" + /** * input: must be a path, not an /icon; you have to do your own handling if it is one, as icon objects can't be directly passed to rustg. * diff --git a/code/__HELPERS/~monkestation-helpers/icons.dm b/code/__HELPERS/~monkestation-helpers/icons.dm new file mode 100644 index 000000000000..73b6900edc93 --- /dev/null +++ b/code/__HELPERS/~monkestation-helpers/icons.dm @@ -0,0 +1,21 @@ +#define TMP_UPSCALE_PATH "tmp/resize_icon.png" + +/// Upscales an icon using rust-g. +/// You really shouldn't use this TOO often, as it has to copy the icon to a temporary png file, +/// resize it, fcopy_rsc the resized png, and then create a new /icon from said png. +/// Cache the output where possible. +/proc/resize_icon(icon/icon, width, height, resize_type = RUSTG_RESIZE_NEAREST) as /icon + RETURN_TYPE(/icon) + SHOULD_BE_PURE(TRUE) + + if(!istype(icon)) + CRASH("Attempted to upscale non-icon") + if(!IS_SAFE_NUM(width) || !IS_SAFE_NUM(height)) + CRASH("Attempted to upscale icon to non-number width/height") + if(!fcopy(icon, TMP_UPSCALE_PATH)) + CRASH("Failed to create temporary png file to upscale") + UNLINT(rustg_dmi_resize_png(TMP_UPSCALE_PATH, "[width]", "[height]", resize_type)) // technically impure but in practice its not + . = icon(fcopy_rsc(TMP_UPSCALE_PATH)) + fdel(TMP_UPSCALE_PATH) + +#undef TMP_UPSCALE_PATH diff --git a/monkestation/code/modules/asset_cache/assets/botanical_lexicon.dm b/monkestation/code/modules/asset_cache/assets/botanical_lexicon.dm new file mode 100644 index 000000000000..0594936e9270 --- /dev/null +++ b/monkestation/code/modules/asset_cache/assets/botanical_lexicon.dm @@ -0,0 +1,25 @@ +/datum/asset/spritesheet/botanical_lexicon + name = "botanical_lexicon" + +/datum/asset/spritesheet/botanical_lexicon/create_spritesheets() + var/list/id_list = list() + var/list/seeds = (subtypesof(/datum/hydroponics/plant_mutation) - /datum/hydroponics/plant_mutation/spliced_mutation - /datum/hydroponics/plant_mutation/infusion) + for(var/datum/hydroponics/plant_mutation/mutation as anything in seeds) + var/obj/item/seed_type = mutation::created_seed + if(!ispath(seed_type, /obj/item)) + continue + var/seed_icon_file = seed_type::icon + var/seed_icon_state = seed_type::icon_state + if(!seed_icon_file || !seed_icon_state) + continue + var/id = sanitize_css_class_name("[seed_icon_file]_[seed_icon_state]") + if(id_list[id]) + continue + var/icon/seed_icon = icon(seed_icon_file, seed_icon_state) + var/icon/resized_icon = resize_icon(seed_icon, 96, 96) + if(!resized_icon) + stack_trace("Failed to upscale icon for \"[seed_icon_state]\" @ '[seed_icon]', upscaling using BYOND!") + seed_icon.Scale(96, 96) + resized_icon = seed_icon + id_list[id] = TRUE + Insert(id, resized_icon) diff --git a/monkestation/code/modules/asset_cache/assets/chicken_book.dm b/monkestation/code/modules/asset_cache/assets/chicken_book.dm new file mode 100644 index 000000000000..c2a19ed73b66 --- /dev/null +++ b/monkestation/code/modules/asset_cache/assets/chicken_book.dm @@ -0,0 +1,22 @@ +/datum/asset/spritesheet/chicken_book + name = "chicken_book" + +/datum/asset/spritesheet/chicken_book/create_spritesheets() + var/list/id_list = list() + for(var/datum/mutation/ranching/chicken/chicken_mutation as anything in subtypesof(/datum/mutation/ranching/chicken)) + var/chicken_type = chicken_mutation::chicken_type + if(!ispath(chicken_type, /mob/living/basic/chicken)) + continue + var/id = sanitize_css_class_name("[chicken_type]") + if(id_list[id]) + continue + var/mob/living/basic/chicken/chicken = new chicken_type + var/icon/chicken_icon = getFlatIcon(chicken, EAST, no_anim = TRUE) + var/icon/resized_icon = resize_icon(chicken_icon, 96, 96) + if(!resized_icon) + stack_trace("Failed to upscale icon for [chicken_type], upscaling using BYOND!") + chicken_icon.Scale(96, 96) + resized_icon = chicken_icon + id_list[id] = TRUE + Insert(id, resized_icon) + QDEL_NULL(chicken) diff --git a/monkestation/code/modules/hydroponics/botanical_lexicon.dm b/monkestation/code/modules/hydroponics/botanical_lexicon.dm index 653b042df625..c81ee38a940e 100644 --- a/monkestation/code/modules/hydroponics/botanical_lexicon.dm +++ b/monkestation/code/modules/hydroponics/botanical_lexicon.dm @@ -5,15 +5,20 @@ icon_state = "chicken_book" /obj/item/botanical_lexicon/ui_interact(mob/user, datum/tgui/ui) - ui = SStgui.try_update_ui(user,src,ui) + ui = SStgui.try_update_ui(user, src, ui) if(!ui) - ui = new(user,src,"BotanicalLexicon") + ui = new(user, src, "BotanicalLexicon") + ui.set_autoupdate(FALSE) ui.open() -/obj/item/botanical_lexicon/ui_act(action,list/params) +/obj/item/botanical_lexicon/ui_act(action, list/params) if(..()) return +/obj/item/botanical_lexicon/ui_assets(mob/user) + return list( + get_asset_datum(/datum/asset/spritesheet/botanical_lexicon), + ) /obj/item/botanical_lexicon/ui_static_data(mob/user) var/list/data = list() @@ -24,10 +29,10 @@ if(!listed_mutation.created_seed) continue - var/obj/item/seeds/created_seed = new listed_mutation.created_seed + var/obj/item/seeds/created_seed = listed_mutation.created_seed - details["name"] = created_seed.name - details["desc"] = created_seed.desc + details["name"] = created_seed::name + details["desc"] = created_seed::desc if(listed_mutation.required_potency.len) details["potency_low"] = listed_mutation.required_potency[1] @@ -60,15 +65,7 @@ reagent_names += initial(listed_reagent.name) details["required_reagents"] = reagent_names.Join(",") - - var/icon/plant_icon = getFlatIcon(created_seed) - var/md5 = md5(fcopy_rsc(plant_icon)) - if(!SSassets.cache["photo_[md5]_[created_seed.name]_icon.png"]) - SSassets.transport.register_asset("photo_[md5]_[created_seed.name]_icon.png", plant_icon) - SSassets.transport.send_assets(user, list("photo_[md5]_[created_seed.name]_icon.png" = plant_icon)) - details["plant_icon"] = SSassets.transport.get_asset_url("photo_[md5]_[created_seed.name]_icon.png") - - qdel(created_seed) + details["plant_icon"] = sanitize_css_class_name("[created_seed::icon]_[created_seed::icon_state]") plant_list += list(details) qdel(listed_mutation) diff --git a/monkestation/code/modules/ranching/chicken_book.dm b/monkestation/code/modules/ranching/chicken_book.dm index c56f7d3e24fb..f4643491f8b3 100644 --- a/monkestation/code/modules/ranching/chicken_book.dm +++ b/monkestation/code/modules/ranching/chicken_book.dm @@ -5,15 +5,21 @@ icon_state = "chicken_book" /obj/item/chicken_book/ui_interact(mob/user, datum/tgui/ui) - ui = SStgui.try_update_ui(user,src,ui) + ui = SStgui.try_update_ui(user, src, ui) if(!ui) - ui = new(user,src,"RanchingEncyclopedia") + ui = new(user, src, "RanchingEncyclopedia") + ui.set_autoupdate(FALSE) ui.open() -/obj/item/chicken_book/ui_act(action,list/params) +/obj/item/chicken_book/ui_act(action, list/params) if(..()) return +/obj/item/chicken_book/ui_assets(mob/user) + return list( + get_asset_datum(/datum/asset/spritesheet/chicken_book), + ) + /obj/item/chicken_book/ui_static_data(mob/user) var/list/data = list() var/list/chicken_list = list() @@ -79,12 +85,7 @@ details["nearby_items"] = obj_names.Join(",") details["comes_from"] = created_mutation.can_come_from_string - var/icon/chicken_icon = getFlatIcon(F) - var/md5 = md5(fcopy_rsc(chicken_icon)) - if(!SSassets.cache["photo_[md5]_[F.breed_name]_icon.png"]) - SSassets.transport.register_asset("photo_[md5]_[F.breed_name]_icon.png", chicken_icon) - SSassets.transport.send_assets(user, list("photo_[md5]_[F.breed_name]_icon.png" = chicken_icon)) - details["chicken_icon"] = SSassets.transport.get_asset_url("photo_[md5]_[F.breed_name]_icon.png") + details["chicken_icon"] = sanitize_css_class_name("[created_mutation.chicken_type]") chicken_list += list(details) qdel(F) qdel(created_mutation) diff --git a/tgstation.dme b/tgstation.dme index e44b368f0025..68c49aaa5310 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -588,6 +588,7 @@ #include "code\__HELPERS\~monkestation-helpers\clients.dm" #include "code\__HELPERS\~monkestation-helpers\cmp.dm" #include "code\__HELPERS\~monkestation-helpers\icon_smoothing.dm" +#include "code\__HELPERS\~monkestation-helpers\icons.dm" #include "code\__HELPERS\~monkestation-helpers\mapping.dm" #include "code\__HELPERS\~monkestation-helpers\mobs.dm" #include "code\__HELPERS\~monkestation-helpers\roundend.dm" @@ -6279,6 +6280,8 @@ #include "monkestation\code\modules\assault_ops\code\armaments\mod_modules.dm" #include "monkestation\code\modules\assault_ops\code\armaments\utility.dm" #include "monkestation\code\modules\assembly\flash.dm" +#include "monkestation\code\modules\asset_cache\assets\botanical_lexicon.dm" +#include "monkestation\code\modules\asset_cache\assets\chicken_book.dm" #include "monkestation\code\modules\atmospherics\machinery\air_alarm\air_alarm_ac.dm" #include "monkestation\code\modules\balloon_alert\balloon_alert.dm" #include "monkestation\code\modules\ballpit\ballbit_sink.dm" diff --git a/tgui/packages/tgui/interfaces/BotanicalLexicon.jsx b/tgui/packages/tgui/interfaces/BotanicalLexicon.jsx index e950e2196e96..17a1c1a184b0 100644 --- a/tgui/packages/tgui/interfaces/BotanicalLexicon.jsx +++ b/tgui/packages/tgui/interfaces/BotanicalLexicon.jsx @@ -1,5 +1,5 @@ import { toTitleCase } from 'common/string'; -import { resolveAsset } from '../assets'; +import { classes } from 'common/react'; import { useBackend, useLocalState } from '../backend'; import { Flex, Box, Tabs, Stack } from '../components'; import { Window } from '../layouts'; @@ -49,14 +49,11 @@ const PlantInfo = (props) => { diff --git a/tgui/packages/tgui/interfaces/RanchingEncyclopedia.jsx b/tgui/packages/tgui/interfaces/RanchingEncyclopedia.jsx index 846c91b5d6ab..7c50ce8007a7 100644 --- a/tgui/packages/tgui/interfaces/RanchingEncyclopedia.jsx +++ b/tgui/packages/tgui/interfaces/RanchingEncyclopedia.jsx @@ -1,5 +1,5 @@ import { toTitleCase } from 'common/string'; -import { resolveAsset } from '../assets'; +import { classes } from 'common/react'; import { useBackend, useLocalState } from '../backend'; import { Flex, Box, Tabs, Stack } from '../components'; import { Window } from '../layouts'; @@ -49,14 +49,11 @@ const ChickenInfo = (props) => {