Files
Bubberstation/code/datums/elements/wall_engraver.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

77 lines
2.9 KiB
Plaintext

/// An element that lets you engrave walls when right click is used
/datum/element/wall_engraver
/datum/element/wall_engraver/Attach(datum/target)
. = ..()
if (!isitem(target))
return ELEMENT_INCOMPATIBLE
RegisterSignal(target, COMSIG_ATOM_EXAMINE, PROC_REF(on_examine))
RegisterSignal(target, COMSIG_ITEM_PRE_ATTACK_SECONDARY, PROC_REF(on_item_pre_attack_secondary))
/datum/element/wall_engraver/Detach(datum/source)
. = ..()
UnregisterSignal(source, COMSIG_ATOM_EXAMINE)
UnregisterSignal(source, COMSIG_ITEM_PRE_ATTACK_SECONDARY)
///signal called on parent being examined
/datum/element/wall_engraver/proc/on_examine(datum/source, mob/user, list/examine_list)
SIGNAL_HANDLER
examine_list += span_notice("You can engrave some walls with your secondary attack if you can think of something interesting to engrave.")
///signal called on parent being used to right click attack something
/datum/element/wall_engraver/proc/on_item_pre_attack_secondary(datum/source, atom/target, mob/living/user)
SIGNAL_HANDLER
INVOKE_ASYNC(src, PROC_REF(try_chisel), source, target, user)
return COMPONENT_CANCEL_ATTACK_CHAIN
/datum/element/wall_engraver/proc/try_chisel(obj/item/item, turf/closed/wall, mob/living/user)
if(!istype(wall) || !user.mind)
return
if(HAS_TRAIT_FROM(wall, TRAIT_NOT_ENGRAVABLE, INNATE_TRAIT))
user.balloon_alert(user, "wall cannot be engraved!")
return
if(HAS_TRAIT_FROM(wall, TRAIT_NOT_ENGRAVABLE, TRAIT_GENERIC))
user.balloon_alert(user, "wall has already been engraved!")
return
if(!length(user.mind?.memories))
user.balloon_alert(user, "nothing memorable to engrave!")
return
var/datum/memory/memory_to_engrave = user.mind.select_memory("engrave")
if(!memory_to_engrave)
return
if(!user.Adjacent(wall))
return
item.add_fingerprint(user)
playsound(item, item.hitsound, 30, TRUE, -1)
user.do_attack_animation(wall)
user.balloon_alert(user, "engraving wall...")
if(!do_after(user, 5 SECONDS, target = wall))
return
user.balloon_alert(user, "wall engraved")
user.do_attack_animation(wall)
var/do_persistent_save = !(memory_to_engrave.memory_flags & MEMORY_FLAG_NOPERSISTENCE)
var/engraved_story = memory_to_engrave.generate_story(STORY_ENGRAVING, STORY_FLAG_DATED)
if(!engraved_story)
CRASH("Tried to submit a memory with an invalid story [memory_to_engrave]")
wall.AddComponent(/datum/component/engraved, engraved_story, persistent_save = do_persistent_save, story_value = memory_to_engrave.story_value)
memory_to_engrave.memory_flags |= MEMORY_FLAG_ALREADY_USED
//while someone just engraved a story "worth engraving" we should add this to SSpersistence for a possible prison tattoo
if(do_persistent_save)
var/list/tattoo_entry = list()
var/tattoo_story = memory_to_engrave.generate_story(STORY_TATTOO)
if(!tattoo_story)
CRASH("Tried to submit a memory with an invalid story [memory_to_engrave]")
tattoo_entry["story"] = tattoo_story
SSpersistence.prison_tattoos_to_save += list(tattoo_entry)