mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-15 12:11:45 +00:00
I'm refactoring proximity monitors and fields, removing lots of bloat from both that's hardly even used. Proximity monitors no longer generate effect objects to track the surrounding area, should be less cpu expensive and easier to maintain (or phase out), read and use. This PR also adds a couple components which may be needed for future stuff (for starters, the mirror reflection PR #62638 could use the connect_range comp) Improving old old, ugly old code and adding some useful backend components. Tested and working.
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_PARENT_QDELETING))
|
|
unregister_signals(tracked.loc)
|
|
tracked = new_tracked
|
|
if(!tracked)
|
|
return
|
|
RegisterSignal(tracked, COMSIG_MOVABLE_MOVED, .proc/on_moved)
|
|
RegisterSignal(tracked, COMSIG_PARENT_QDELETING, .proc/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/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)
|