mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-02-08 15:28:40 +00:00
## 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>
98 lines
3.2 KiB
Plaintext
98 lines
3.2 KiB
Plaintext
/**
|
|
* # mobs that can wear hats!
|
|
*/
|
|
/datum/element/hat_wearer
|
|
element_flags = ELEMENT_DETACH_ON_HOST_DESTROY|ELEMENT_BESPOKE
|
|
argument_hash_start_idx = 2
|
|
///offsets of hats we will wear
|
|
var/list/offsets
|
|
///signals to remove the hat on
|
|
var/list/remove_hat_signals
|
|
///traits we check before adding the hat
|
|
var/traits_prevent_checks
|
|
|
|
/datum/element/hat_wearer/Attach(datum/target, offsets = list(), remove_hat_signals = list(), traits_prevent_checks = list())
|
|
. = ..()
|
|
if (!isliving(target))
|
|
return ELEMENT_INCOMPATIBLE
|
|
src.offsets = offsets
|
|
src.traits_prevent_checks = traits_prevent_checks
|
|
RegisterSignal(target, COMSIG_ATOM_UPDATE_OVERLAYS, PROC_REF(on_overlays_updated))
|
|
RegisterSignal(target, COMSIG_ATOM_EXITED, PROC_REF(exited))
|
|
RegisterSignal(target, COMSIG_ATOM_ENTERED, PROC_REF(on_entered))
|
|
RegisterSignal(target, COMSIG_ATOM_ATTACKBY, PROC_REF(on_attack_by))
|
|
if(!length(remove_hat_signals))
|
|
return
|
|
RegisterSignals(target, remove_hat_signals, PROC_REF(remove_hat))
|
|
|
|
/datum/element/hat_wearer/Detach(datum/target)
|
|
var/obj/item/hat = (locate(/obj/item/clothing/head) in target)
|
|
if(hat)
|
|
hat.forceMove(get_turf(target))
|
|
UnregisterSignal(target, list(
|
|
COMSIG_ATOM_UPDATE_OVERLAYS,
|
|
COMSIG_ATOM_EXITED,
|
|
COMSIG_ATOM_ENTERED,
|
|
COMSIG_ATOM_ATTACKBY,
|
|
))
|
|
if(length(remove_hat_signals))
|
|
UnregisterSignal(target, remove_hat_signals)
|
|
return ..()
|
|
|
|
/datum/element/hat_wearer/proc/on_overlays_updated(atom/source, list/overlays)
|
|
SIGNAL_HANDLER
|
|
|
|
var/obj/item/hat = (locate(/obj/item/clothing/head) in source)
|
|
if(isnull(hat))
|
|
return
|
|
var/mutable_appearance/hat_overlay = mutable_appearance(hat.worn_icon, hat.icon_state)
|
|
hat_overlay.pixel_w = offsets[1]
|
|
hat_overlay.pixel_z = offsets[2]
|
|
overlays += hat_overlay
|
|
|
|
/datum/element/hat_wearer/proc/exited(atom/movable/source, atom/movable/exited)
|
|
SIGNAL_HANDLER
|
|
|
|
if(!istype(exited, /obj/item/clothing/head))
|
|
return
|
|
source.update_appearance(UPDATE_OVERLAYS)
|
|
|
|
/datum/element/hat_wearer/proc/on_entered(atom/movable/source, atom/movable/arrived, atom/old_loc, list/atom/old_locs)
|
|
SIGNAL_HANDLER
|
|
|
|
if(!istype(arrived, /obj/item/clothing/head))
|
|
return
|
|
for(var/obj/item/clothing/head/already_worn in source)
|
|
if(already_worn == arrived)
|
|
continue
|
|
already_worn.forceMove(get_turf(source))
|
|
source.update_appearance(UPDATE_OVERLAYS)
|
|
|
|
/datum/element/hat_wearer/proc/on_attack_by(atom/movable/source, obj/item/item, mob/living/attacker)
|
|
SIGNAL_HANDLER
|
|
|
|
if(!istype(item, /obj/item/clothing/head))
|
|
return
|
|
|
|
for(var/trait_check in traits_prevent_checks)
|
|
if(HAS_TRAIT(source, trait_check))
|
|
source.balloon_alert(attacker, "not possible right now!")
|
|
return COMPONENT_NO_AFTERATTACK
|
|
|
|
INVOKE_ASYNC(src, PROC_REF(place_hat), source, item, attacker)
|
|
return COMPONENT_NO_AFTERATTACK
|
|
|
|
/datum/element/hat_wearer/proc/place_hat(atom/movable/source, obj/item/item, mob/living/attacker)
|
|
if(!do_after(attacker, delay = 3 SECONDS, target = source))
|
|
source.balloon_alert(attacker, "must stay still!")
|
|
return
|
|
item.forceMove(source)
|
|
|
|
/datum/element/hat_wearer/proc/remove_hat(atom/movable/source)
|
|
SIGNAL_HANDLER
|
|
|
|
var/obj/our_hat = locate(/obj/item/clothing/head) in source
|
|
if(isnull(our_hat))
|
|
return
|
|
our_hat.forceMove(source.drop_location())
|