From 564785ddf6ffbd7b07dad263f06131a4e9f1ef51 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 31 Jul 2023 18:20:06 +0100 Subject: [PATCH] When any segment of the marker wall is punched, unmark the entire wall Fixes #102 --- CHANGELOG.md | 4 ++++ .../core/entities/pos_marker_wall.lua | 3 +++ worldeditadditions_core/core/pos.lua | 15 ++++++++++++--- .../core/pos_marker_manage.lua | 5 +++-- .../core/pos_marker_wall_manage.lua | 5 ++++- 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c60f871..66215f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ It's about time I started a changelog! This will serve from now on as the main c Note to self: See the bottom of this file for the release template text. +## v1.14.4: The multipoint update, hotfix 4 (unreleased) +- When any segment of the marker wall is punched, unmark the entire wall + + ## v1.14.3: The multipoint update, hotfix 3 (18th July 2023) - Fix regions not remembering their state and being unresettable diff --git a/worldeditadditions_core/core/entities/pos_marker_wall.lua b/worldeditadditions_core/core/entities/pos_marker_wall.lua index 85ba671..3ffa287 100644 --- a/worldeditadditions_core/core/entities/pos_marker_wall.lua +++ b/worldeditadditions_core/core/entities/pos_marker_wall.lua @@ -54,6 +54,9 @@ local WEAPositionMarkerWall = { end, on_punch = function(self, _) anchor.delete(self) + -- Only unmark the rest of the walls + -- Unmark for the player that created this wall.... NOT the player who punched it! + wea_c.pos.unmark(self.player_name, false, true) end, on_blast = function(self, damage) return false, false, {} -- Do not damage or knockback the player diff --git a/worldeditadditions_core/core/pos.lua b/worldeditadditions_core/core/pos.lua index 9fe7abe..6b968a2 100644 --- a/worldeditadditions_core/core/pos.lua +++ b/worldeditadditions_core/core/pos.lua @@ -33,7 +33,7 @@ local anchor = nil --- It is requested that all position/region marker UI elements be hidden for the given player. -- @event unmark --- @format { player_name: string } +-- @format { player_name: string, markers: bool, walls: bool } --- It is requested that all position/region marker UI elements be shown once more for the given player. -- @event mark @@ -268,15 +268,24 @@ end --- Hides the visual markers for the given player's positions and defined region, but does not clear the points. -- @param player_name string The name of the player to operate on. -local function unmark(player_name) +-- @param markers=true bool Whether to hide positional markers. +-- @param walls=true bool Whether to hide the marker walls. +-- @returns void +local function unmark(player_name, markers, walls) + if markers == nil then markers = true end + if walls == nil then walls = true end + anchor:emit("unmark", { - player_name = player_name + player_name = player_name, + markers = markers, + walls = walls }) end --- Shows the visual markers for the given player's positions and defined region once more. -- Often used some time after calling worldeditadditions_core.pos.unmark(). -- @param player_name string The name of the player to operate on. +-- @returns void local function mark(player_name) anchor:emit("mark", { player_name = player_name diff --git a/worldeditadditions_core/core/pos_marker_manage.lua b/worldeditadditions_core/core/pos_marker_manage.lua index b355e66..8668eca 100644 --- a/worldeditadditions_core/core/pos_marker_manage.lua +++ b/worldeditadditions_core/core/pos_marker_manage.lua @@ -92,8 +92,9 @@ end) wea_c.pos:addEventListener("unmark", function(event) ensure_player(event.player_name) - do_delete_all(event.player_name) - + if event.markers then + do_delete_all(event.player_name) + end -- Note that this function is NOT WorldEdit compatible, because it is only called through our override of WorldEdit's `//unmark`, and WorldEdit doesn't have an API function to call to unmark and everything is complicated. end) diff --git a/worldeditadditions_core/core/pos_marker_wall_manage.lua b/worldeditadditions_core/core/pos_marker_wall_manage.lua index 26041b1..996e499 100644 --- a/worldeditadditions_core/core/pos_marker_wall_manage.lua +++ b/worldeditadditions_core/core/pos_marker_wall_manage.lua @@ -85,13 +85,16 @@ local function handle_event(event) if needs_update(event) then do_update(event) end end +local function handle_unmark(event) + if event.walls then do_delete(event) end +end weac.pos:addEventListener("set", handle_event) weac.pos:addEventListener("pop", handle_event) weac.pos:addEventListener("push", handle_event) weac.pos:addEventListener("clear", do_delete) -weac.pos:addEventListener("unmark", do_delete) +weac.pos:addEventListener("unmark", handle_unmark) weac.pos:addEventListener("mark", do_update) weac.entities.pos_marker_wall:addEventListener("update_entity", update_entity) \ No newline at end of file