From f928cc2b12609ee0caa712a8f6d2864c69fc0d6d Mon Sep 17 00:00:00 2001 From: Mothblocks <35135081+Mothblocks@users.noreply.github.com> Date: Mon, 19 Apr 2021 23:43:53 -0700 Subject: [PATCH] Fixes connect_loc not reconnecting turf changes (#58507) --- code/datums/elements/connect_loc.dm | 10 ++++++++-- code/modules/unit_tests/connect_loc.dm | 5 ++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/code/datums/elements/connect_loc.dm b/code/datums/elements/connect_loc.dm index adfcf87233d2..537aebdee0fa 100644 --- a/code/datums/elements/connect_loc.dm +++ b/code/datums/elements/connect_loc.dm @@ -88,6 +88,12 @@ post_change_callbacks += changeturf_callback /datum/element/connect_loc/proc/post_turf_change(turf/new_turf) - for (var/atom/movable/tracked as anything in targets[new_turf]) - var/datum/listener = targets[new_turf][tracked] + // If we don't cut the targets list before iterating, + // then we won't re-register the change turf signal. + var/list/turf_targets = targets[new_turf] + var/list/targets_copy = turf_targets.Copy() + turf_targets.Cut() + + for (var/atom/movable/tracked as anything in targets_copy) + var/datum/listener = targets_copy[tracked] update_signals(listener, tracked) diff --git a/code/modules/unit_tests/connect_loc.dm b/code/modules/unit_tests/connect_loc.dm index 84dc7222fc01..7569ba25e036 100644 --- a/code/modules/unit_tests/connect_loc.dm +++ b/code/modules/unit_tests/connect_loc.dm @@ -35,10 +35,13 @@ current_turf.ChangeTurf(/turf/closed/wall) - current_turf = get_turf(watcher) SEND_SIGNAL(current_turf, COMSIG_MOCK_SIGNAL) TEST_ASSERT_EQUAL(watcher.times_called, 2, "After changing turf, connect_loc didn't reconnect it") + current_turf.ChangeTurf(/turf/open/floor/carpet) + SEND_SIGNAL(current_turf, COMSIG_MOCK_SIGNAL) + TEST_ASSERT_EQUAL(watcher.times_called, 3, "After changing turf a second time, connect_loc didn't reconnect it") + /datum/unit_test/connect_loc_change_turf/Destroy() run_loc_floor_bottom_left.ChangeTurf(old_turf_type) return ..()