feat: Introduce an EnhancedGridMap with advanced grid generation, randomization, and data serialization features, along with a default MeshLibrary and a new main scene script.
This commit is contained in:
@@ -182,6 +182,38 @@ func clear_grid(floor_index: int = -1):
|
||||
clear_floor(floor_index)
|
||||
update_grid_data()
|
||||
|
||||
# =============================================================================
|
||||
# Data Serialization Helpers (For Networking)
|
||||
# =============================================================================
|
||||
|
||||
func get_floor_data(floor_index: int) -> PackedInt32Array:
|
||||
# Returns a flat PackedInt32Array [x, z, item_id, ...] for the specified floor.
|
||||
var data = PackedInt32Array()
|
||||
# Use get_used_cells() as the source of truth from the GridMap itself
|
||||
for cell in get_used_cells():
|
||||
if cell.y == floor_index:
|
||||
data.append(cell.x)
|
||||
data.append(cell.z)
|
||||
data.append(get_cell_item(cell))
|
||||
return data
|
||||
|
||||
func set_floor_data(floor_index: int, data: PackedInt32Array):
|
||||
# Sets the floor items from a flat PackedInt32Array. Clears existing items on that floor first.
|
||||
clear_floor(floor_index)
|
||||
# Iterate by triplets [x, z, item]
|
||||
var count = data.size()
|
||||
if count % 3 != 0:
|
||||
print("[EnhancedGridMap] Error: Malformed grid data array (size %d not divisible by 3)" % count)
|
||||
return
|
||||
|
||||
for i in range(0, count, 3):
|
||||
var x = data[i]
|
||||
var z = data[i+1]
|
||||
var item = data[i+2]
|
||||
set_cell_item(Vector3i(x, floor_index, z), item)
|
||||
|
||||
update_grid_data()
|
||||
|
||||
func fill_grid(item_index: int, floor_index: int = -1):
|
||||
if not mesh_library:
|
||||
print("No MeshLibrary assigned to GridMap")
|
||||
|
||||
Reference in New Issue
Block a user