This commit is contained in:
2026-01-28 02:29:43 +08:00
parent d71f5d67e3
commit 6949e20a1f
13 changed files with 285 additions and 100 deletions
+15 -18
View File
@@ -212,20 +212,20 @@ func fill_floor(item_index: int, floor_index: int):
set_cell_item(cell_pos, item_index, current_orientation)
# Randomization functions
func randomize_grid(floor_index: int = -1):
func randomize_grid(floor_index: int = -1, custom_rng_callable: Callable = Callable()):
if floor_index == -1:
# Default auto-randomize behavior:
# Preserve Floor 0 (Ground)
# Shuffle Floor 1 (Objects/Items)
shuffle_floor_objects(1)
else:
randomize_floor(floor_index)
randomize_floor(floor_index, custom_rng_callable)
update_grid_data()
initialize_astar()
update_astar_costs()
func randomize_floor(floor_index: int):
func randomize_floor(floor_index: int, custom_rng_callable: Callable = Callable()):
if not mesh_library:
print("Error: No MeshLibrary assigned to GridMap")
return
@@ -235,10 +235,6 @@ func randomize_floor(floor_index: int):
var rng = RandomNumberGenerator.new()
rng.randomize()
var scarcity_mgr = null
if floor_index == 1:
scarcity_mgr = load("res://scripts/managers/scarcity_manager.gd")
for x in range(columns):
for z in range(rows):
# IMPORTANT: Only place items if Floor 0 has a walkable tile
@@ -249,9 +245,9 @@ func randomize_floor(floor_index: int):
set_cell_item(Vector3i(x, floor_index, z), -1) # Clear item if no ground
continue
# If Floor 1 and ScarcityManager exists, use it
if floor_index == 1 and scarcity_mgr:
var item_index = scarcity_mgr.get_random_tile_id()
# Use custom callable if provided
if custom_rng_callable.is_valid():
var item_index = custom_rng_callable.call()
set_cell_item(Vector3i(x, floor_index, z), item_index)
else:
# Default behavior
@@ -505,7 +501,7 @@ func initialize_astar():
update_astar_costs()
func find_path(start: Vector2, end: Vector2, floor_index: int = 0, clear_path_visual: bool = true) -> Array:
func find_path(start: Vector2, end: Vector2, floor_index: int = 0, clear_path_visual: bool = true, visualize: bool = true) -> Array:
var astar = astar_by_floor.get(floor_index)
if not astar:
return []
@@ -514,14 +510,15 @@ func find_path(start: Vector2, end: Vector2, floor_index: int = 0, clear_path_vi
var end_point = end.y * columns + end.x
path = astar.get_point_path(start_point, end_point)
if clear_path_visual:
clear_path_visualization(floor_index)
if visualize:
if clear_path_visual:
clear_path_visualization(floor_index)
set_cell_item(Vector3i(start.x, floor_index, start.y), start_item)
set_cell_item(Vector3i(end.x, floor_index, 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)
set_cell_item(Vector3i(start.x, floor_index, start.y), start_item)
set_cell_item(Vector3i(end.x, floor_index, 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)
return path