Files
Bubberstation/code/datums/components/connect_containers.dm
AnturK 4d6a8bc537 515 Compatibility (#71161)
Makes the code compatible with 515.1594+

Few simple changes and one very painful one.
Let's start with the easy:
* puts call behind `LIBCALL` define, so call_ext is properly used in 515
* Adds `NAMEOF_STATIC(_,X)` macro for nameof in static definitions since
src is now invalid there.
* Fixes tgui and devserver. From 515 onward the tmp3333{procid} cache
directory is not appened to base path in browser controls so we don't
check for it in base js and put the dev server dummy window file in
actual directory not the byond root.
* Renames the few things that had /final/ in typepath to ultimate since
final is a new keyword

And the very painful change:
`.proc/whatever` format is no longer valid, so we're replacing it with
new nameof() function. All this wrapped in three new macros.
`PROC_REF(X)`,`TYPE_PROC_REF(TYPE,X)`,`GLOBAL_PROC_REF(X)`. Global is
not actually necessary but if we get nameof that does not allow globals
it would be nice validation.
This is pretty unwieldy but there's no real alternative.
If you notice anything weird in the commits let me know because majority
was done with regex replace.

@tgstation/commit-access Since the .proc/stuff is pretty big change.

Co-authored-by: san7890 <the@san7890.com>
Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com>
2022-11-15 03:50:11 +00:00

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_REF(on_moved))
RegisterSignal(tracked, COMSIG_PARENT_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)