Files
Bubberstation/code/datums/components/basic_inhands.dm
Waterpig d3d3a12540 The big fix for pixel_x and pixel_y use cases. (#90124)
## About The Pull Request

516 requires float layered overlays to be using pixel_w and pixel_z
instead of pixel_x and pixel_y respectively, unless we want
visual/layering errors. This makes sense, as w,z are for visual effects
only. Sadly seems we were not entirely consistent in this, and many
things seem to have been using x,y incorrectly.

This hopefully fixes that, and thus also fixes layering issues. Complete
1:1 compatibility not guaranteed.

I did the lazy way suggested to me by SmArtKar to speed it up (Runtiming
inside apply_overlays), and this is still included in the PR to flash
out possible issues in a TM (Plus I will need someone to grep the
runtimes for me after the TM period to make sure nothing was missed).
After this is done I'll remove all these extra checks.

Lints will probably be failing for a bit, got to wait for [this
update](4b77cd487d)
to them to make it into release. Or just unlint the lines, though that's
probably gonna produce code debt

## Why It's Good For The Game

Fixes this massive 516 mess, hopefully.

closes #90281

## Changelog
🆑
refactor: Changed many of our use cases for pixel_x and pixel_y
correctly into pixel_w and pixel_z, fixing layering issues in the
process.
/🆑

---------

Co-authored-by: SmArtKar <44720187+SmArtKar@users.noreply.github.com>
Co-authored-by: SmArtKar <master.of.bagets@gmail.com>
2025-03-28 14:18:45 +00:00

51 lines
1.9 KiB
Plaintext

/**
* Basic handling for showing held items in a mob's hands
*/
/datum/component/basic_inhands
/// Layer index we show our inhands upon
var/display_layer
/// Y offset to apply to inhands
var/y_offset
/// X offset to apply to inhands, is inverted for the left hand
var/x_offset
/// What overlays are we currently showing?
var/list/cached_overlays
/datum/component/basic_inhands/Initialize(display_layer = 1, y_offset = 0, x_offset = 0)
. = ..()
if (!isliving(parent))
return COMPONENT_INCOMPATIBLE
src.display_layer = display_layer
src.y_offset = y_offset
src.x_offset = x_offset
cached_overlays = list()
/datum/component/basic_inhands/RegisterWithParent()
. = ..()
RegisterSignal(parent, COMSIG_ATOM_UPDATE_OVERLAYS, PROC_REF(on_updated_overlays))
RegisterSignal(parent, COMSIG_MOB_UPDATE_HELD_ITEMS, PROC_REF(on_updated_held_items))
/datum/component/basic_inhands/UnregisterFromParent()
. = ..()
UnregisterSignal(parent, list(COMSIG_ATOM_UPDATE_OVERLAYS, COMSIG_MOB_UPDATE_HELD_ITEMS))
/// When your overlays update, add your held overlays
/datum/component/basic_inhands/proc/on_updated_overlays(atom/parent_atom, list/overlays)
SIGNAL_HANDLER
overlays += cached_overlays
/// When your number of held items changes, regenerate held icons
/datum/component/basic_inhands/proc/on_updated_held_items(mob/living/holding_mob)
SIGNAL_HANDLER
var/list/held_overlays = list()
for(var/obj/item/held in holding_mob.held_items)
var/is_right = IS_RIGHT_INDEX(holding_mob.get_held_index_of_item(held))
var/icon_file = is_right ? held.righthand_file : held.lefthand_file
var/mutable_appearance/held_overlay = held.build_worn_icon(default_layer = HANDS_LAYER, default_icon_file = icon_file, isinhands = TRUE)
held_overlay.pixel_z += y_offset
held_overlay.pixel_w += x_offset * (is_right ? 1 : -1)
held_overlays += held_overlay
cached_overlays = held_overlays
holding_mob.update_appearance(UPDATE_OVERLAYS)