feat: Introduce an enhanced gridmap addon with procedural generation, pathfinding, and initial core game scripts and assets.

This commit is contained in:
Yogi Wiguna
2026-02-23 12:31:42 +08:00
parent f72f641332
commit 92fd76f4b8
7 changed files with 67 additions and 39 deletions
+20 -12
View File
@@ -52,7 +52,11 @@ func _ready():
if auto_generate:
generate_grid()
if auto_randomize:
randomize_grid()
# Safety check: Don't auto-randomize if game mode manages its own arena
if not (ResourceLoader.exists("res://scripts/managers/lobby_manager.gd") \
and get_node_or_null("/root/LobbyManager") \
and get_node("/root/LobbyManager").game_mode == "Stop n Go"):
randomize_grid()
validate_item_indices()
# Core grid management functions
@@ -276,9 +280,9 @@ func randomize_floor(floor_index: int, custom_rng_callable: Callable = Callable(
if current_item_on_floor in immutable_items:
continue
# IMPORTANT: Only place items if Floor 0 has a walkable tile
# IMPORTANT: Only place items if Floor 0 has a valid ground tile (Walkable, Safe Zone, etc)
var floor_0_item = get_cell_item(Vector3i(x, 0, z))
var is_ground = (floor_0_item == normal_items[0]) # Assuming 0 is ground
var is_ground = (floor_0_item != -1) # All tiles on Layer 0 are valid ground
if not is_ground:
set_cell_item(Vector3i(x, floor_index, z), -1) # Clear item if no ground
@@ -564,25 +568,29 @@ func find_path(start: Vector2, end: Vector2, floor_index: int = 0, clear_path_vi
path = astar.get_point_path(start_point, end_point)
# TEMPORARY PATH VISUALIZATION - Moved to Layer 2 (Overlay) to protect Floor 0 and Floor 1
if visualize:
if clear_path_visual:
clear_path_visualization(floor_index)
clear_path_visualization()
set_cell_item(Vector3i(start.x, floor_index, start.y), start_item)
set_cell_item(Vector3i(end.x, floor_index, end.y), end_item)
# Always use Layer 2 for these temporary markers
set_cell_item(Vector3i(start.x, 2, start.y), start_item)
set_cell_item(Vector3i(end.x, 2, end.y), end_item)
for point in path:
if point != start and point != end:
set_cell_item(Vector3i(point.x, floor_index, point.y), hover_item)
if Vector2(point.x, point.y) != start and Vector2(point.x, point.y) != end:
set_cell_item(Vector3i(point.x, 2, point.y), hover_item)
return path
# Path visualization
func clear_path_visualization(floor_index: int = 0):
# Path visualization - Standardized to Layer 2
func clear_path_visualization(unused_floor_idx: int = 0):
# We strictly clear Layer 2 (Overlay) and reset to -1 (Empty)
# This ensures we never overwrite Layer 0 (Floor) or Layer 1 (Items)
for x in range(columns):
for z in range(rows):
var cell_item = get_cell_item(Vector3i(x, floor_index, z))
var cell_item = get_cell_item(Vector3i(x, 2, z))
if cell_item == hover_item or cell_item == start_item or cell_item == end_item:
set_cell_item(Vector3i(x, floor_index, z), normal_items[0])
set_cell_item(Vector3i(x, 2, z), -1)
# Cost calculation and updates
func get_cell_cost(x: int, z: int, floor_index: int = 0) -> float: