mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-11 18:22:14 +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 /🆑
69 lines
2.5 KiB
Plaintext
69 lines
2.5 KiB
Plaintext
/// This component behaves similar to connect_loc_behalf, but it's nested and hooks a signal onto all MOVABLES containing this atom.
|
|
/datum/component/connect_containers
|
|
dupe_mode = COMPONENT_DUPE_UNIQUE_PASSARGS
|
|
|
|
/// An assoc list of signal -> procpath to register to the loc this object is on.
|
|
var/list/connections
|
|
/**
|
|
* The atom the component is tracking. The component will delete itself if the tracked is deleted.
|
|
* Signals will also be updated whenever it moves.
|
|
*/
|
|
var/atom/movable/tracked
|
|
|
|
/datum/component/connect_containers/Initialize(atom/movable/tracked, list/connections)
|
|
. = ..()
|
|
if (!ismovable(tracked))
|
|
return COMPONENT_INCOMPATIBLE
|
|
|
|
src.connections = connections
|
|
set_tracked(tracked)
|
|
|
|
/datum/component/connect_containers/Destroy()
|
|
set_tracked(null)
|
|
return ..()
|
|
|
|
/datum/component/connect_containers/InheritComponent(datum/component/component, original, atom/movable/tracked, list/connections)
|
|
// Not equivalent. Checks if they are not the same list via shallow comparison.
|
|
if(!compare_list(src.connections, connections))
|
|
stack_trace("connect_containers component attached to [parent] tried to inherit another connect_containers component with different connections")
|
|
return
|
|
if(src.tracked != tracked)
|
|
set_tracked(tracked)
|
|
|
|
/datum/component/connect_containers/proc/set_tracked(atom/movable/new_tracked)
|
|
if(tracked)
|
|
UnregisterSignal(tracked, list(COMSIG_MOVABLE_MOVED, COMSIG_QDELETING))
|
|
unregister_signals(tracked.loc)
|
|
tracked = new_tracked
|
|
if(!tracked)
|
|
return
|
|
RegisterSignal(tracked, COMSIG_MOVABLE_MOVED, PROC_REF(on_moved))
|
|
RegisterSignal(tracked, COMSIG_QDELETING, PROC_REF(handle_tracked_qdel))
|
|
update_signals(tracked)
|
|
|
|
/datum/component/connect_containers/proc/handle_tracked_qdel()
|
|
SIGNAL_HANDLER
|
|
qdel(src)
|
|
|
|
/datum/component/connect_containers/proc/update_signals(atom/movable/listener)
|
|
if(!ismovable(listener.loc))
|
|
return
|
|
|
|
for(var/atom/movable/container as anything in get_nested_locs(listener))
|
|
RegisterSignal(container, COMSIG_MOVABLE_MOVED, PROC_REF(on_moved))
|
|
for(var/signal in connections)
|
|
parent.RegisterSignal(container, signal, connections[signal])
|
|
|
|
/datum/component/connect_containers/proc/unregister_signals(atom/movable/location)
|
|
if(!ismovable(location))
|
|
return
|
|
|
|
for(var/atom/movable/target as anything in (get_nested_locs(location) + location))
|
|
UnregisterSignal(target, COMSIG_MOVABLE_MOVED)
|
|
parent.UnregisterSignal(target, connections)
|
|
|
|
/datum/component/connect_containers/proc/on_moved(atom/movable/listener, atom/old_loc)
|
|
SIGNAL_HANDLER
|
|
unregister_signals(old_loc)
|
|
update_signals(listener)
|