Files
Bubberstation/code/datums/elements/digitalcamo.dm
SmArtKar dfb12f91d6 HUD traits now apply their corresponding hud automatically. Most clothing/item/etc sources of HUDs now only use traits (#84984)
## About The Pull Request

Currently if you want to apply a HUD you usually add both its trait and
the HUD itself. Only exceptions are things like simplemobs where you
should avoid adding the hud trait since it adds security/med DB access
and such, but there is no cases where you'd want to apply the trait and
not apply the hud.

Requested by Melbert about a week ago.

![image](https://github.com/user-attachments/assets/8af3e9cc-ea22-4cee-86ec-54c397291727)

## Why It's Good For The Game

This makes working with HUDs significantly easier, as you no longer have
to bother with manually adding/removing them. Also potentially removes
an edge case where if your hud could get removed while keeping the
trait.

## Changelog
🆑
refactor: HUD traits now apply their corresponding hud automatically
/🆑
2024-07-19 01:24:07 +02:00

54 lines
1.8 KiB
Plaintext

/datum/element/digitalcamo
element_flags = ELEMENT_DETACH_ON_HOST_DESTROY
var/list/attached_mobs = list()
/datum/element/digitalcamo/New()
. = ..()
START_PROCESSING(SSdcs, src)
/datum/element/digitalcamo/Attach(datum/target)
. = ..()
if(!isliving(target) || (target in attached_mobs))
return ELEMENT_INCOMPATIBLE
RegisterSignal(target, COMSIG_ATOM_EXAMINE, PROC_REF(on_examine))
RegisterSignal(target, COMSIG_LIVING_CAN_TRACK, PROC_REF(can_track))
var/image/img = image(loc = target)
img.override = TRUE
attached_mobs[target] = img
HideFromAIHuds(target)
/datum/element/digitalcamo/Detach(datum/target)
. = ..()
UnregisterSignal(target, list(COMSIG_ATOM_EXAMINE, COMSIG_LIVING_CAN_TRACK))
for(var/mob/living/silicon/ai/AI in GLOB.player_list)
AI.client.images -= attached_mobs[target]
attached_mobs -= target
UnhideFromAIHuds(target)
/datum/element/digitalcamo/proc/HideFromAIHuds(mob/living/target)
for(var/mob/living/silicon/ai/AI in GLOB.ai_list)
for (var/hud_type in AI.silicon_huds)
var/datum/atom_hud/silicon_hud = GLOB.huds[hud_type]
silicon_hud.hide_single_atomhud_from(AI,target)
/datum/element/digitalcamo/proc/UnhideFromAIHuds(mob/living/target)
for(var/mob/living/silicon/ai/AI in GLOB.ai_list)
for (var/hud_type in AI.silicon_huds)
var/datum/atom_hud/silicon_hud = GLOB.huds[hud_type]
silicon_hud.unhide_single_atomhud_from(AI,target)
/datum/element/digitalcamo/proc/on_examine(datum/source, mob/M)
SIGNAL_HANDLER
to_chat(M, span_warning("[source.p_their()] skin seems to be shifting like something is moving below it."))
/datum/element/digitalcamo/proc/can_track(datum/source, mob/user)
SIGNAL_HANDLER
return COMPONENT_CANT_TRACK
/datum/element/digitalcamo/process()
for(var/mob/living/silicon/ai/AI in GLOB.player_list)
for(var/mob in attached_mobs)
AI.client.images |= attached_mobs[mob]