Files
Bubberstation/code/datums/elements/loomable.dm
T
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](https://github.com/tgstation/tgstation/commit/102b79694fa8eb57ecf7b36032616a9e368ccced)

[Moves signal procs over to their own
file](https://github.com/tgstation/tgstation/commit/33d07d01fd336726b4f6f6f1b61bb0b3f11a00dc)

[Renames the PREQDELETING and QDELETING comsigs to drop the parent bit
since they can hook to more then just comps
now](https://github.com/tgstation/tgstation/commit/335ea4ad081ec63c42cfa05856e582cca833af6e)

[Does something similar to the attackby comsigs (PARENT ->
ATOM)](https://github.com/tgstation/tgstation/commit/210e57051df63f88dac3dd83321236da825aae5e)

[And finally passes over the examine
signals](https://github.com/tgstation/tgstation/commit/65917658fb8a1e7d28ae23c9437a583d646f0302)

## 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

84 lines
3.3 KiB
Plaintext

/// Element that makes items turn into other items when you use them on a loom (or any other thing really if you change the var)
/datum/element/loomable
element_flags = ELEMENT_BESPOKE
argument_hash_start_idx = 2
/// What will spawn when the item is loomed
var/resulting_atom
/// How much of item do we need to loom, will be ignored if item isnt a stack
var/required_amount
/// What thing we look for triggering the loom process (usually a loom)
var/obj/target_type
/// What verb best fits the action of processing whatever the item is, for example "spun [thing]"
var/process_completion_verb
/// If the target needs to be anchored
var/target_needs_anchoring
/// How long it takes to loom the item
var/loom_time
/datum/element/loomable/Attach(
obj/item/target,
resulting_atom = /obj/item/stack/sheet/cloth,
required_amount = 4,
target_type = /obj/structure/loom,
process_completion_verb = "spun",
target_needs_anchoring = TRUE,
loom_time = 1 SECONDS
)
. = ..()
//currently this element only works for items as we need to call /obj/item/attack_atom()
if(!isitem(target))
return ELEMENT_INCOMPATIBLE
src.resulting_atom = resulting_atom
src.required_amount = required_amount
src.target_type = target_type
src.process_completion_verb = process_completion_verb
src.target_needs_anchoring = target_needs_anchoring
src.loom_time = loom_time
RegisterSignal(target, COMSIG_ITEM_ATTACK_OBJ, PROC_REF(try_and_loom_me))
RegisterSignal(target, COMSIG_ATOM_EXAMINE, PROC_REF(on_examine))
/datum/element/loomable/Detach(obj/item/source)
. = ..()
UnregisterSignal(source, list(COMSIG_ITEM_ATTACK_OBJ, COMSIG_ATOM_EXAMINE))
/// Adds an examine blurb to the description of any item that can be loomed
/datum/element/loomable/proc/on_examine(obj/item/source, mob/examiner, list/examine_list)
SIGNAL_HANDLER
examine_list += span_notice("You could probably process [source] at a <b>[initial(target_type.name)]</b>.")
/// Checks if the thing we clicked on can be used as a loom, and if we can actually loom the source at present (an example being does the stack have enough in it (if its a stack))
/datum/element/loomable/proc/try_and_loom_me(obj/item/source, atom/target, mob/living/user)
SIGNAL_HANDLER
if(!istype(target, target_type))
return
if(ismovable(target))
var/atom/movable/movable_target = target
if(target_needs_anchoring && !movable_target.anchored)
user.balloon_alert(user, "[movable_target] must be secured!")
return
if((required_amount > 1) && istype(source, /obj/item/stack))
var/obj/item/stack/source_stack = source
if(source_stack.amount < required_amount)
user.balloon_alert(user, "need [required_amount] of [source]!")
return
INVOKE_ASYNC(src, PROC_REF(loom_me), source, user, target)
return COMPONENT_CANCEL_ATTACK_CHAIN
/// If a do_after of the specified loom_time passes, will create a new one of resulting_atom and either delete the item, or .use the required amount if its a stack
/datum/element/loomable/proc/loom_me(obj/item/source, mob/living/user, atom/target)
if(!do_after(user, loom_time, target))
return
var/new_thing = new resulting_atom(target.drop_location())
user.balloon_alert_to_viewers("[process_completion_verb] [new_thing]")
if(isstack(source))
var/obj/item/stack/stack_we_use = source
stack_we_use.use(required_amount)
else
qdel(source)