From 2b8e7196d73b6caad54e5616367f37343c418438 Mon Sep 17 00:00:00 2001 From: Jeremiah <42397676+jlsnow301@users.noreply.github.com> Date: Mon, 13 Nov 2023 19:09:37 -0800 Subject: [PATCH] Fixes baseturf helpers (#79697) ## About The Pull Request Baseturf helpers do this: ![image](https://github.com/tgstation/tgstation/assets/42397676/f73887cc-10b1-4b24-b123-dc99c02ad45a) And they also do this (up to 3x): ![Screenshot 2023-11-12 164334](https://github.com/tgstation/tgstation/assets/42397676/ac555d9a-785b-4e02-b85d-e90ded3b08ad) When trying to debug `PlaceOnBottom` I couldn't help but notice it's trying to encompass use cases that simply aren't used anywhere. YAGNI - this makes it much more complex than it needs to be. ## Why It's Good For The Game Fixes weird baseturf handling FIxes #79172 ## Changelog N/A nothing player facing --------- Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com> --- code/game/turfs/baseturfs.dm | 27 ++++++------------------- code/modules/mapping/mapping_helpers.dm | 12 +++++++++-- code/modules/unit_tests/baseturfs.dm | 2 +- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/code/game/turfs/baseturfs.dm b/code/game/turfs/baseturfs.dm index 7eaac2f9ef0..91e66b1a4d0 100644 --- a/code/game/turfs/baseturfs.dm +++ b/code/game/turfs/baseturfs.dm @@ -20,27 +20,12 @@ return ChangeTurf(baseturfs, baseturfs, flags) // The bottom baseturf will never go away -// Take the input as baseturfs and put it underneath the current baseturfs -// If fake_turf_type is provided and new_baseturfs is not the baseturfs list will be created identical to the turf type's -// If both or just new_baseturfs is provided they will be inserted below the existing baseturfs -/turf/proc/PlaceOnBottom(list/new_baseturfs, turf/fake_turf_type) - if(fake_turf_type) - if(!new_baseturfs) - if(!length(baseturfs)) - baseturfs = list(baseturfs) - var/list/old_baseturfs = baseturfs.Copy() - assemble_baseturfs(fake_turf_type) - if(!length(baseturfs)) - baseturfs = list(baseturfs) - baseturfs = baseturfs_string_list((baseturfs - (baseturfs & GLOB.blacklisted_automated_baseturfs)) + old_baseturfs, src) - return - else if(!length(new_baseturfs)) - new_baseturfs = list(new_baseturfs, fake_turf_type) - else - new_baseturfs += fake_turf_type - if(!length(baseturfs)) - baseturfs = list(baseturfs) - baseturfs = baseturfs_string_list(new_baseturfs + baseturfs, src) +/// Places the given turf on the bottom of the turf stack. +/turf/proc/place_on_bottom(turf/bottom_turf) + baseturfs = baseturfs_string_list( + list(initial(bottom_turf.baseturfs), bottom_turf) + baseturfs, + src + ) // Make a new turf and put it on top // The args behave identical to PlaceOnBottom except they go on top diff --git a/code/modules/mapping/mapping_helpers.dm b/code/modules/mapping/mapping_helpers.dm index 92e67fc9082..605638679b4 100644 --- a/code/modules/mapping/mapping_helpers.dm +++ b/code/modules/mapping/mapping_helpers.dm @@ -6,8 +6,9 @@ name = "baseturf editor" icon = 'icons/effects/mapping_helpers.dmi' icon_state = "" - + /// Replacing a specific turf var/list/baseturf_to_replace + /// The desired bottom turf var/baseturf plane = POINT_PLANE @@ -33,9 +34,16 @@ qdel(src) +/// Replaces all the requested baseturfs (usually space/baseturfbottom) with the desired baseturf. Skips if its already there /obj/effect/baseturf_helper/proc/replace_baseturf(turf/thing) thing.remove_baseturfs_from_typecache(baseturf_to_replace) - thing.PlaceOnBottom(fake_turf_type = baseturf) + + if(length(thing.baseturfs)) + var/turf/tile = thing.baseturfs[1] + if(tile == baseturf) + return + + thing.place_on_bottom(baseturf) /obj/effect/baseturf_helper/space name = "space baseturf editor" diff --git a/code/modules/unit_tests/baseturfs.dm b/code/modules/unit_tests/baseturfs.dm index 2ac016f38b9..9bc561deeeb 100644 --- a/code/modules/unit_tests/baseturfs.dm +++ b/code/modules/unit_tests/baseturfs.dm @@ -53,7 +53,7 @@ // Do this instead of just ChangeTurf to guarantee that baseturfs is completely default on-init behavior RESET_TO_EXPECTED(run_loc_floor_bottom_left) - run_loc_floor_bottom_left.PlaceOnBottom(fake_turf_type = /turf/closed/wall/rock) + run_loc_floor_bottom_left.place_on_bottom(/turf/closed/wall/rock) TEST_ASSERT_EQUAL(run_loc_floor_bottom_left.type, EXPECTED_FLOOR_TYPE, "PlaceOnBottom shouldn't have changed turf") run_loc_floor_bottom_left.ScrapeAway()