77 lines
2.3 KiB
GDScript
77 lines
2.3 KiB
GDScript
extends StaticBody3D
|
|
|
|
@onready var seat_container: Node3D = $SeatContainer
|
|
|
|
# Preload the new seat models
|
|
var SEAT_1 = load("res://scenes/tekton_stand/tekton_seat.tscn")
|
|
var SEAT_2 = load("res://scenes/tekton_stand/tekton_seat_2.tscn")
|
|
|
|
# Sync the chosen shape so all clients see the same one
|
|
@export var shape_index: int = -1:
|
|
set(value):
|
|
shape_index = value
|
|
if is_inside_tree():
|
|
_update_mesh_from_index()
|
|
|
|
func _ready():
|
|
add_to_group("StaticTektonStands")
|
|
print("Static Stand Ready: ", name)
|
|
|
|
# Clear 3x3 local GridMap void for late joiners
|
|
call_deferred("_clear_local_gridmap_area")
|
|
|
|
if multiplayer.is_server():
|
|
# Only randomize if not already set (Main.gd sets it now)
|
|
if shape_index == -1:
|
|
shape_index = randi() % 2 # Randomize between seat 1 and 2
|
|
_update_mesh_from_index()
|
|
else:
|
|
# Client side:
|
|
if shape_index != -1:
|
|
_update_mesh_from_index()
|
|
|
|
func _clear_local_gridmap_area():
|
|
var main = get_tree().get_root().get_node_or_null("Main")
|
|
if not main: return
|
|
var gridmap = main.get_node_or_null("EnhancedGridMap")
|
|
if not gridmap or not "cell_size" in gridmap: return
|
|
|
|
var grid_x = int(round((global_position.x - gridmap.cell_size.x / 2.0) / gridmap.cell_size.x))
|
|
var grid_z = int(round((global_position.z - gridmap.cell_size.z / 2.0) / gridmap.cell_size.z))
|
|
|
|
var floor_count = 3
|
|
if "floors" in gridmap: floor_count = gridmap.floors
|
|
|
|
for dx in range(-1, 2):
|
|
for dy in range(-1, 2):
|
|
for f in range(floor_count):
|
|
gridmap.set_cell_item(Vector3i(grid_x + dx, f, grid_z + dy), -1)
|
|
|
|
# Force pathfinding update if methods exist
|
|
if gridmap.has_method("update_grid_data"):
|
|
gridmap.update_grid_data()
|
|
if gridmap.has_method("update_astar_costs"):
|
|
gridmap.update_astar_costs()
|
|
|
|
func _update_mesh_from_index():
|
|
if not is_inside_tree() or not seat_container: return
|
|
|
|
# Clear existing models
|
|
for child in seat_container.get_children():
|
|
child.queue_free()
|
|
|
|
var seats = [SEAT_1, SEAT_2]
|
|
var idx = shape_index % seats.size()
|
|
var selected_scene = seats[idx]
|
|
|
|
if not selected_scene:
|
|
push_error("[StaticStand] Failed to load seat model at index %d. Path may be incorrect." % idx)
|
|
return
|
|
|
|
var seat_instance = selected_scene.instantiate()
|
|
seat_container.add_child(seat_instance)
|
|
|
|
# Ensure the model is centered
|
|
seat_instance.position = Vector3.ZERO
|
|
print("[StaticStand] Instantiated Seat Model %d" % idx)
|