Files
Bubberstation/code/datums/components/onwear_mood.dm
LemonInTheDark ae5a4f955d Pulls apart the vestiges of components still hanging onto signals (#75914)
## About The Pull Request

Signals were initially only usable with component listeners, which while
no longer the case has lead to outdated documentation, names, and a
similar location in code.

This pr pulls the two apart. Partially because mso thinks we should, but
also because they really aren't directly linked anymore, and having them
in this midstate just confuses people.

[Renames comp_lookup to listen_lookup, since that's what it
does](102b79694f)

[Moves signal procs over to their own
file](33d07d01fd)

[Renames the PREQDELETING and QDELETING comsigs to drop the parent bit
since they can hook to more then just comps
now](335ea4ad08)

[Does something similar to the attackby comsigs (PARENT ->
ATOM)](210e57051d)

[And finally passes over the examine
signals](65917658fb)

## Why It's Good For The Game

Code makes more sense, things are better teased apart, s just good imo

## Changelog
🆑
refactor: Pulled apart the last vestiges of names/docs directly linking
signals to components
/🆑
2023-06-09 06:14:31 +00:00

55 lines
2.0 KiB
Plaintext

/// Add to clothing to give the wearer a mood buff and a unique examine text
/datum/component/onwear_mood
/// the event the wearer experiences
var/datum/mood_event/saved_event_type
/// examine string added to examine
var/examine_string
/// what slots it needs to be equipped to to work
var/slot_equip
/datum/component/onwear_mood/Initialize(datum/mood_event/saved_event_type, examine_string, slot_equip = ITEM_SLOT_ON_BODY)
if(!isitem(parent))
return COMPONENT_INCOMPATIBLE
src.saved_event_type = saved_event_type
src.examine_string = examine_string
if(!isnum(slot_equip))
stack_trace("Attempted to initialize onwear component with improper slot_equip [slot_equip]")
slot_equip = ITEM_SLOT_ON_BODY
src.slot_equip = slot_equip
/datum/component/onwear_mood/RegisterWithParent()
RegisterSignal(parent, COMSIG_ITEM_EQUIPPED, PROC_REF(affect_wearer))
RegisterSignal(parent, COMSIG_ATOM_EXAMINE, PROC_REF(on_examine))
/datum/component/onwear_mood/UnregisterFromParent()
UnregisterSignal(parent, list(COMSIG_ITEM_EQUIPPED, COMSIG_ATOM_EXAMINE))
clear_effects()
/datum/component/onwear_mood/proc/affect_wearer(datum/source, mob/living/target, slot)
SIGNAL_HANDLER
if(!(slot & slot_equip))
return // only affects "worn" slots by default
target.add_mood_event(REF(src), saved_event_type)
RegisterSignal(target, COMSIG_ATOM_EXAMINE, PROC_REF(on_examine))
RegisterSignal(target, COMSIG_MOB_UNEQUIPPED_ITEM, PROC_REF(clear_effects))
/datum/component/onwear_mood/proc/on_examine(datum/source, mob/user, list/examine_text)
SIGNAL_HANDLER
examine_text += span_notice(examine_string)
/// clears the effects on the wearer
/datum/component/onwear_mood/proc/clear_effects(mob/living/source, obj/item/dropped_item)
SIGNAL_HANDLER
var/obj/item/clothing = parent
// if called from a signal, check clothing
if(dropped_item && dropped_item != clothing)
return
source ||= clothing.loc
if(!istype(source))
return
UnregisterSignal(source, list(COMSIG_ATOM_EXAMINE, COMSIG_MOB_UNEQUIPPED_ITEM))
source.clear_mood_event(REF(src))