From 5acf40c1223ffd8b07672da4c621aa0c388d1eab Mon Sep 17 00:00:00 2001 From: Yogi Wiguna Date: Wed, 25 Mar 2026 15:53:55 +0800 Subject: [PATCH] feat: Introduce `PlayerActionManager` for action point and grid highlighting, `SpecialTilesManager` for special tile effects, and a `tile_freeze` mesh resource. --- .../meshlibrary/tile_freeze.tres | 1 - scripts/managers/player_action_manager.gd | 9 +++-- scripts/managers/special_tiles_manager.gd | 35 +++++++++++-------- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/addons/enhanced_gridmap/meshlibrary/tile_freeze.tres b/addons/enhanced_gridmap/meshlibrary/tile_freeze.tres index 8722225..984b159 100644 --- a/addons/enhanced_gridmap/meshlibrary/tile_freeze.tres +++ b/addons/enhanced_gridmap/meshlibrary/tile_freeze.tres @@ -1,7 +1,6 @@ [gd_resource type="BoxMesh" format=3 uid="uid://b5cc3prem52r6"] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_e3p1j"] -transparency = 1 albedo_color = Color(0.38039216, 1, 0.9607843, 0.5) [resource] diff --git a/scripts/managers/player_action_manager.gd b/scripts/managers/player_action_manager.gd index 0ae1770..2b45d23 100644 --- a/scripts/managers/player_action_manager.gd +++ b/scripts/managers/player_action_manager.gd @@ -4,7 +4,8 @@ extends Node var player: Node3D var enhanced_gridmap: Node -var highlighted_cells = [] +var highlighted_cells = [] # List of positions +# highlight_restore_items no longer needed for Layer 2 func initialize(p_player: Node3D, p_gridmap: Node): player = p_player @@ -76,7 +77,7 @@ func highlight_cells_if_authorized(cells_to_highlight: Array, item_id: int = -1) for cell in cells_to_highlight: highlighted_cells.append(cell) - # Use Layer 2 for overlay highlights + # Use Layer 2 for overlay highlights (prevents overwriting Execution on Layer 0) enhanced_gridmap.set_cell_item( Vector3i(cell.x, 2, cell.y), highlight_item @@ -96,6 +97,7 @@ func highlight_empty_adjacent_cells(): var current_cell = Vector3i(player.current_position.x, 1, player.current_position.y) if enhanced_gridmap.get_cell_item(current_cell) == -1: highlighted_cells.append(player.current_position) + # Set on Layer 2 (Overlay) enhanced_gridmap.set_cell_item(Vector3i(player.current_position.x, 2, player.current_position.y), enhanced_gridmap.hover_item) print("Highlighted current position: ", player.current_position) @@ -108,6 +110,7 @@ func highlight_empty_adjacent_cells(): var cell = Vector3i(cell_pos.x, 1, cell_pos.y) if enhanced_gridmap.get_cell_item(cell) == -1: # Check if cell is empty highlighted_cells.append(cell_pos) + # Set on Layer 2 (Overlay) enhanced_gridmap.set_cell_item(Vector3i(cell_pos.x, 2, cell_pos.y), enhanced_gridmap.hover_item) print("Highlighted adjacent cell: ", cell_pos) @@ -123,6 +126,7 @@ func highlight_random_valid_cells(): var current_item = enhanced_gridmap.get_cell_item(current_cell) if current_item != -1: highlighted_cells.append(player.current_position) + # Set on Layer 2 (Overlay) enhanced_gridmap.set_cell_item(Vector3i(player.current_position.x, 2, player.current_position.y), enhanced_gridmap.hover_item) @@ -134,6 +138,7 @@ func highlight_random_valid_cells(): var cell = Vector3i(cell_pos.x, 1, cell_pos.y) if enhanced_gridmap.get_cell_item(cell) != -1: # Only highlight cells with items highlighted_cells.append(cell_pos) + # Set on Layer 2 (Overlay) enhanced_gridmap.set_cell_item(Vector3i(cell_pos.x, 2, cell_pos.y), enhanced_gridmap.hover_item) diff --git a/scripts/managers/special_tiles_manager.gd b/scripts/managers/special_tiles_manager.gd index bdb0d9a..31bf58c 100644 --- a/scripts/managers/special_tiles_manager.gd +++ b/scripts/managers/special_tiles_manager.gd @@ -400,34 +400,41 @@ func _execute_area_freeze(target_pos: Vector2i = Vector2i(-9999, -9999)): else: NotificationManager.send_message(player, "Hit %d Players!" % hit_count, NotificationManager.MessageType.GOAL) - # Visual Feedback (Layer 2 - Overlay Level) + # Visual Feedback (Layer 0 - Ground Level, matching Wall logic) if player.is_multiplayer_authority(): var main_node = get_node_or_null("/root/Main") if main_node and main_node.has_method("sync_grid_items_batch"): var batch_data = [] + var restoration_data = [] # Stores {pos, item} to restore later + for rx in range(-radius, radius + 1): for rz in range(-radius, radius + 1): - var cell_x = center_pos.x + rx - var cell_z = center_pos.y + rz - # Put back on Layer 2 (Overlay) as requested - batch_data.append({"x": cell_x, "y": 2, "z": cell_z, "item": 5}) + var cx = center_pos.x + rx + var cz = center_pos.y + rz + var pos = Vector3i(cx, 0, cz) + + # Get original ground item to restore later + var original_ground = enhanced_gridmap.get_cell_item(pos) + + # Ignore if it is an immutable tile (Safe Zone 2, Wall 4, etc) + if original_ground in [1, 2, 3, 4, 15, 16]: continue + + restoration_data.append({"pos": pos, "item": original_ground}) + batch_data.append({"x": cx, "y": 0, "z": cz, "item": 5}) if not batch_data.is_empty(): main_node.rpc("sync_grid_items_batch", batch_data) - # Removal timer + # Removal timer with accurate restoration get_tree().create_timer(FREEZE_SLOW_DURATION).timeout.connect(func(): var cl_node = get_node_or_null("/root/Main") if not cl_node: return var clear_batch = [] - for rx in range(-radius, radius + 1): - for rz in range(-radius, radius + 1): - var cx = center_pos.x + rx - var cz = center_pos.y + rz - # Check if it is STILL Freeze Overlay on Layer 2 - if enhanced_gridmap.get_cell_item(Vector3i(cx, 2, cz)) == 5: - # Remove Item (back to -1) - clear_batch.append({"x": cx, "y": 2, "z": cz, "item": -1}) + for entry in restoration_data: + var p = entry.pos + # Only restore if it is STILL our Freeze tile + if enhanced_gridmap.get_cell_item(p) == 5: + clear_batch.append({"x": p.x, "y": 0, "z": p.z, "item": entry.item}) if not clear_batch.is_empty(): cl_node.rpc("sync_grid_items_batch", clear_batch) )