feat: Introduce an EnhancedGridMap with advanced generation, randomization, pathfinding, and data serialization, along with new player, powerup, and portal managers.

This commit is contained in:
Yogi Wiguna
2026-03-04 17:40:10 +08:00
parent 8f03cc15c5
commit cd7881bc3f
12 changed files with 128 additions and 107 deletions
+16 -13
View File
@@ -1581,12 +1581,15 @@ func request_randomize_item(grid_position: Vector2i):
func sync_grid_item(x: int, y: int, z: int, item: int):
var enhanced_gridmap = $EnhancedGridMap
if enhanced_gridmap:
# WALL-SAFETY CHECK: Block tiles (7-20) from being placed on walls (4) or void (-1)
# PROTECTED FLOOR CHECK: Block tiles (7-20) from being placed on walls (4) or void (-1)
# Note: We allow spawning on Safe Zones, Start, and Finish as it's on Layer 1.
if y == 1 and item >= 7 and item <= 20:
var f0 = enhanced_gridmap.get_cell_item(Vector3i(x, 0, z))
if f0 == 4 or f0 == -1:
# Log and block illegal placement
print("[Main] Blocked illegal tile (%d) placement on wall/void at (%d, %d)" % [item, x, z])
var f1 = enhanced_gridmap.get_cell_item(Vector3i(x, 1, z))
# Block if Layer 0 is Wall (4) or Void (-1)
# OR Layer 1 is already a wall (4 or 13)
if f0 in [4, -1] or f1 == 4 or f1 == 13:
return
enhanced_gridmap.set_cell_item(Vector3i(x, y, z), item)
@@ -1607,10 +1610,11 @@ func sync_grid_items_batch(data: Array):
var z = entry.get("z", 0)
var item = entry.get("item", -1)
# WALL-SAFETY CHECK
# PROTECTED FLOOR CHECK
if y == 1 and item >= 7 and item <= 20:
var f0 = enhanced_gridmap.get_cell_item(Vector3i(x, 0, z))
if f0 == 4 or f0 == -1:
var f1 = enhanced_gridmap.get_cell_item(Vector3i(x, 1, z))
if f0 in [4, -1] or f1 == 4 or f1 == 13:
continue
enhanced_gridmap.set_cell_item(Vector3i(x, y, z), item)
@@ -1625,13 +1629,12 @@ func randomize_game_grid():
var enhanced_gridmap = $EnhancedGridMap
if enhanced_gridmap:
# Randomize Floor 1 using ScarcityController
enhanced_gridmap.randomize_floor(1, ScarcityController.get_random_tile_id)
# Sync to clients if needed (usually handled by initial state sync or explicit item syncs)
# Since Main.gd doesn't have a "Sync Floor" RPC, we rely on clients running the same seed or syncing individual cells.
# For now, let's assume server authority + sync on connect handles it, or add sync loop if critical.
pass
# Use density-aware callable: 60% chance for a real tile, 40% for none
var density_callable = func():
if randf() > 0.6: return -1
return ScarcityController.get_random_tile_id()
enhanced_gridmap.randomize_floor(1, density_callable)
@rpc("authority", "call_local", "reliable")
func sync_full_grid_data_stop_n_go(floor0: PackedInt32Array, floor1: PackedInt32Array, cols: int, rows: int):