mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-31 20:11:56 +00:00
## 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 /🆑
87 lines
2.3 KiB
Plaintext
87 lines
2.3 KiB
Plaintext
/**
|
|
* # Vacuum Component
|
|
*
|
|
* Adds a vacuum functionality to an atom, requires a trashbag to be linked
|
|
* using signals
|
|
*
|
|
*/
|
|
/datum/component/vacuum
|
|
/// The linked trash bag to vacuum trash into
|
|
var/obj/item/storage/bag/trash/vacuum_bag
|
|
|
|
/datum/component/vacuum/Initialize(obj/item/storage/bag/trash/connected_bag = null)
|
|
. = ..()
|
|
if(!ismovable(parent))
|
|
return COMPONENT_INCOMPATIBLE
|
|
if (connected_bag)
|
|
attach_bag(null, connected_bag)
|
|
RegisterSignal(parent, COMSIG_MOVABLE_MOVED, PROC_REF(suck))
|
|
RegisterSignal(parent, COMSIG_VACUUM_BAG_ATTACH, PROC_REF(attach_bag))
|
|
RegisterSignal(parent, COMSIG_VACUUM_BAG_DETACH, PROC_REF(detach_bag))
|
|
|
|
/**
|
|
* Called when parent moves, deligates vacuuming functionality
|
|
*
|
|
* Arguments:
|
|
* * suckee - The source of the signal
|
|
*/
|
|
/datum/component/vacuum/proc/suck(datum/suckee)
|
|
SIGNAL_HANDLER
|
|
|
|
// get tile to suck on
|
|
var/atom/movable/AM = suckee
|
|
var/turf/tile = AM.loc
|
|
if (!isturf(tile))
|
|
return
|
|
|
|
// no bag attached, don't bother
|
|
if (!vacuum_bag)
|
|
return
|
|
|
|
// suck the things
|
|
INVOKE_ASYNC(src, PROC_REF(suck_items), tile)
|
|
|
|
/**
|
|
* Sucks up items as possible from a provided turf into the connected trash bag
|
|
*
|
|
* Arguments:
|
|
* * tile - The tile upon which to vacuum up items
|
|
*/
|
|
/datum/component/vacuum/proc/suck_items(turf/tile)
|
|
var/sucked = FALSE
|
|
for (var/potential_item in tile)
|
|
if (!isitem(potential_item))
|
|
continue
|
|
var/obj/item/item = potential_item
|
|
if (vacuum_bag?.attackby(item))
|
|
sucked = TRUE // track that we successfully sucked up something
|
|
|
|
// if we did indeed suck up something, play a funny noise
|
|
if (sucked)
|
|
playsound(parent, SFX_RUSTLE, 50, TRUE, -5)
|
|
|
|
/**
|
|
* Handler for when a new trash bag is attached
|
|
*
|
|
* Arguments:
|
|
* * source - The source of the signal
|
|
* * new_bag - The new bag being installed
|
|
*/
|
|
/datum/component/vacuum/proc/attach_bag(datum/source, obj/item/storage/bag/trash/new_bag)
|
|
SIGNAL_HANDLER
|
|
|
|
vacuum_bag = new_bag
|
|
RegisterSignal(new_bag, COMSIG_QDELETING, PROC_REF(detach_bag))
|
|
|
|
/**
|
|
* Handler for when a trash bag is detached
|
|
*
|
|
* Arguments:
|
|
* * source - The source of the signal
|
|
*/
|
|
/datum/component/vacuum/proc/detach_bag(datum/source)
|
|
SIGNAL_HANDLER
|
|
if (vacuum_bag) // null check to avoid runtime on bag being deleted then sending detach as a result from parent
|
|
UnregisterSignal(vacuum_bag, COMSIG_QDELETING)
|
|
vacuum_bag = null
|