From bcd36f46c04cef5f2c6547fee2e52af75342930b Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Mon, 14 Aug 2023 14:14:40 +0200 Subject: [PATCH] [MIRROR] Fixes a bug with the immerse element [MDB IGNORE] (#23073) * Fixes a bug with the immerse element (#77585) ## About The Pull Request What it says on the tin. This runtime was caught downstream in an away mission unit test where a mob is placed in a water turf. ![image](https://github.com/tgstation/tgstation/assets/13398309/8123321d-8bf4-4186-a63d-944080ad9f8a) Basically the immerse overlay wasn't being added the very first time it was created, because it wasn't being returned by `generate_vis_overlay()`. Derp. It went unnoticed because the overlays are cached and so every subsequent `add_immerse_overlay()` works fine. And I guess upstream doesn't have any mobs that spawn in water during tests so it was never caught. Also stops `on_init_or_entered()` from needlessly being called twice in the case of a movable atom in water being initialized before the water turf. The signal `COMSIG_ATOM_AFTER_SUCCESSFUL_INITIALIZED_ON` already sees to that. ## Why It's Good For The Game Fixes a bug ## Changelog :cl: fix: fixes immerse overlays not being added the first time a mob enters a water turf /:cl: * Fixes a bug with the immerse element --------- Co-authored-by: Bloop <13398309+vinylspiders@users.noreply.github.com> --- code/datums/elements/immerse.dm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/code/datums/elements/immerse.dm b/code/datums/elements/immerse.dm index 4eae1ebaa0b..d6af04cd0c8 100644 --- a/code/datums/elements/immerse.dm +++ b/code/datums/elements/immerse.dm @@ -88,6 +88,8 @@ RegisterSignal(source, COMSIG_ATOM_ABSTRACT_EXITED, PROC_REF(on_atom_exited)) attached_turfs_and_movables += source for(var/atom/movable/movable as anything in source) + if(!(movable.flags_1 & INITIALIZED_1)) + continue on_init_or_entered(source, movable) ///Stops the element from affecting on the turf and its contents. Called on Detach() or when TRAIT_IMMERSE_STOPPED is added. @@ -206,6 +208,7 @@ vis_overlay.overlay_appearance = overlay_appearance generated_visual_overlays["[is_below_water][width]x[height]"] = vis_overlay + return vis_overlay ///This proc removes the vis_overlay, the keep together trait and some signals from the movable. /datum/element/immerse/proc/remove_immerse_overlay(atom/movable/movable)