This commit is contained in:
algodoogle
2026-07-25 19:26:43 +01:00
parent f7024db98d
commit 596d777fae
32 changed files with 832 additions and 257 deletions
+70 -43
View File
@@ -25,9 +25,16 @@ enum TableState {
WAITING_FRIEND, # Waiting for friends food to arrive
EATING
}
var _state = TableState.EMPTY # use _setState(), never set directly
var _state_time: float = 0.0
var _unsatisfied_orders: Array[String]
## State is server-authoritative and synced (see table.tscn's Sync node);
## state transitions only ever run where NetworkManager.owns_world() is true
## (the whole station's _process is gated off elsewhere for non-owners, see
## NetworkManager._gate_station). The setters below just refresh the display,
## so both the server (via _setState) and clients (via incoming sync) show
## the same text. Use _setState(), never assign _state directly.
var _state: TableState = TableState.EMPTY: set = _set_state
var _state_time: float = 0.0: set = _set_state_time
var _unsatisfied_orders: Array[String] = []: set = _set_unsatisfied_orders
func _ready() -> void:
if not label_3d:
@@ -59,8 +66,8 @@ func _on_object_picked_up(_item) -> void:
func _on_object_dropped() -> void:
print("Table: object dropped ")
func _get_plate_from_item(_item: Node) -> PlateController:
return _item.get_children().filter(func(c): return c is PlateController).front() as PlateController
@@ -70,9 +77,9 @@ func _absorb_item_if_correct(_item: Node) -> void:
var plate = _get_plate_from_item(_item)
if not plate:
print("Table: held object is not a Plate")
return
return
print("Table: held a Plate!")
# Absorm items from the plate we want
for food_item in plate.container.contained_items:
print("Table: held a plate with FoodItem: ", food_item.id)
@@ -81,12 +88,11 @@ func _absorb_item_if_correct(_item: Node) -> void:
_unsatisfied_orders.erase(food_item.id)
GAME_MANAGER.money += food_item.sell_value
_setState(TableState.WAITING_FRIEND)
_update_order_text()
# Table has everything it wants. Start eating
if _unsatisfied_orders.is_empty():
_setState(TableState.EATING)
func place_order() -> void:
print("Table: place_order()")
@@ -94,56 +100,78 @@ func place_order() -> void:
_unsatisfied_orders.append(GAME_MANAGER.get_random_meal())
func _update_order_text() -> void:
label_3d.text = "%s\n%s" % [TableState.keys()[_state], "\n".join(_unsatisfied_orders)]
## Server-only state transition: sets the new state's timer and assigns
## _state (whose setter refreshes the display on every peer).
func _setState(newState: TableState) -> void:
print("Table set _state: ", TableState.keys()[newState])
if newState == TableState.EMPTY:
label_3d.text = "empty"
if newState == TableState.THINKING:
_state_time = initial_eating_time
label_3d.text = lbl_thinking
if newState == TableState.WAITING_PRIMARY:
_state_time = initial_primary_time
_update_order_text()
if newState == TableState.WAITING_FRIEND:
_state_time = initial_friend_time
_update_order_text()
if newState == TableState.EATING:
_state_time = initial_eating_time
label_3d.text = lbl_eating
match newState:
TableState.EMPTY:
_state_time = 0.0
TableState.THINKING:
_state_time = initial_eating_time
TableState.WAITING_PRIMARY:
_state_time = initial_primary_time
TableState.WAITING_FRIEND:
_state_time = initial_friend_time
TableState.EATING:
_state_time = initial_eating_time
_state = newState
## Pure presentation, driven off the current (locally authoritative or
## synced-from-server) state. Runs on every peer.
func _refresh_display() -> void:
if not label_3d:
return
match _state:
TableState.EMPTY:
label_3d.text = "empty"
TableState.THINKING:
label_3d.text = lbl_thinking
TableState.WAITING_PRIMARY, TableState.WAITING_FRIEND:
label_3d.text = "%s\n%s" % [TableState.keys()[_state], "\n".join(_unsatisfied_orders)]
TableState.EATING:
label_3d.text = lbl_eating
if label_3d_time:
label_3d_time.text = "%.1f" % _state_time
func _set_state(value: TableState) -> void:
_state = value
_refresh_display()
func _set_state_time(value: float) -> void:
_state_time = value
_refresh_display()
func _set_unsatisfied_orders(value: Array[String]) -> void:
_unsatisfied_orders = value
_refresh_display()
func _process(delta: float) -> void:
# Wait for state to finish
if _state_time > 0:
_state_time -= delta
label_3d_time.text = "%.1f" % _state_time
return
# When state timer is finished, do this stuff before moving to next state
match _state:
TableState.EMPTY:
_setState(TableState.THINKING)
TableState.THINKING:
_setState(TableState.WAITING_PRIMARY)
place_order()
_update_order_text()
TableState.THINKING:
place_order()
_setState(TableState.WAITING_PRIMARY)
TableState.WAITING_PRIMARY:
label_3d.text = lbl_gameover
TableState.WAITING_FRIEND:
label_3d.text = lbl_gameover
@@ -158,4 +186,3 @@ func _process(delta: float) -> void:
plate.container.clear()
plate.is_dirty = true
_setState(TableState.EMPTY)