Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the previews in the chicken and botany encyclopedias #3324

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions code/__DEFINES/rust_g.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
21 changes: 21 additions & 0 deletions code/__HELPERS/~monkestation-helpers/icons.dm
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions monkestation/code/modules/asset_cache/assets/botanical_lexicon.dm
Original file line number Diff line number Diff line change
@@ -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)
22 changes: 22 additions & 0 deletions monkestation/code/modules/asset_cache/assets/chicken_book.dm
Original file line number Diff line number Diff line change
@@ -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)
27 changes: 12 additions & 15 deletions monkestation/code/modules/hydroponics/botanical_lexicon.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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]
Expand Down Expand Up @@ -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)

Expand Down
19 changes: 10 additions & 9 deletions monkestation/code/modules/ranching/chicken_book.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions tgstation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
15 changes: 6 additions & 9 deletions tgui/packages/tgui/interfaces/BotanicalLexicon.jsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -49,14 +49,11 @@ const PlantInfo = (props) => {
</Flex.Item>
<Flex.Item class="chicken-icon-container">
<Box
class="chicken_icon"
as="img"
src={resolveAsset(selectedPlant.plant_icon)}
height="96px"
style={{
'-ms-interpolation-mode': 'nearest-neighbor',
'image-rendering': 'pixelated',
}}
mb={-2}
className={classes([
'botanical_lexicon96x96',
selectedPlant.plant_icon,
])}
/>
</Flex.Item>

Expand Down
15 changes: 6 additions & 9 deletions tgui/packages/tgui/interfaces/RanchingEncyclopedia.jsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -49,14 +49,11 @@ const ChickenInfo = (props) => {
</Flex.Item>
<Flex.Item class="chicken-icon-container">
<Box
class="chicken_icon"
as="img"
src={resolveAsset(selectedChicken.chicken_icon)}
height="96px"
style={{
'-ms-interpolation-mode': 'nearest-neighbor',
'image-rendering': 'pixelated',
}}
mb={-2}
className={classes([
'chicken_book96x96',
selectedChicken.chicken_icon,
])}
/>
</Flex.Item>

Expand Down
Loading