Fix table doesn't detect player that were present before order state

This commit is contained in:
JonShard
2026-07-31 09:19:14 +02:00
parent 89e72c161b
commit 3d616bf4a5
5 changed files with 56 additions and 25 deletions
+2
View File
@@ -13,6 +13,8 @@ extends Node
## the cosmetic result via the setter below. ## the cosmetic result via the setter below.
@export var contained_ids: Array[String] = []: set = _set_contained_ids @export var contained_ids: Array[String] = []: set = _set_contained_ids
func get_food_items() -> Array[FoodItem]:
return container.contained_items
func _ready() -> void: func _ready() -> void:
if not dirty_node: if not dirty_node:
+1 -1
View File
@@ -31,7 +31,7 @@ static func get_random_side() -> String:
push_error("GameManager: get_random_side() called but sides_in_play is empty") push_error("GameManager: get_random_side() called but sides_in_play is empty")
return "" return ""
var rand_index = randi() % sides_in_play.size() var rand_index = randi() % sides_in_play.size()
print("GameManager: get_random_side() returning ", sides_in_play[rand_index]) print("GameManager: get_random_side() list=%s returning %s" % [sides_in_play, sides_in_play[rand_index]])
return sides_in_play[rand_index] return sides_in_play[rand_index]
+47 -23
View File
@@ -44,7 +44,7 @@ var _state: TableState = TableState.EMPTY
var _state_time: float = 0.0 var _state_time: float = 0.0
var _state_duration: float = 0.0 # set in _set_state_time var _state_duration: float = 0.0 # set in _set_state_time
var _unsatisfied_orders: Array[String] = [] var _unsatisfied_orders: Array[String] = []
var _players_count: int = 0
func _ready() -> void: func _ready() -> void:
if not label_3d: if not label_3d:
@@ -74,7 +74,6 @@ func _ready() -> void:
for snap_zone_node in snap_zones: for snap_zone_node in snap_zones:
snap_zone_node.has_picked_up.connect(_on_object_picked_up) snap_zone_node.has_picked_up.connect(_on_object_picked_up)
snap_zone_node.has_dropped.connect(_on_object_dropped) snap_zone_node.has_dropped.connect(_on_object_dropped)
player_detect_area_3d.body_entered.connect(_on_player_detected)
set_process(true) set_process(true)
_setState(TableState.EMPTY) _setState(TableState.EMPTY)
@@ -90,15 +89,23 @@ func _on_object_dropped() -> void:
print("Table: object dropped ") print("Table: object dropped ")
# TODO: Use a on_stay signal or similar # There is no on_stay signal, we have to track player with bool
func _on_player_detected(player): func _on_player_enter(_body):
print("Table _on_player_detected(), ", player) _players_count += 1
print("Table _on_player_enter() pleryers_count: ", _players_count)
func _on_player_exit(_body):
_players_count -= 1
print("Table _on_player_exit() pleryers_count: ", _players_count)
func _place_order_if_player():
if _state != TableState.ORDERING: if _state != TableState.ORDERING:
return return
if _players_count > 0:
place_order() place_order()
_setState(TableState.WAITING_PRIMARY) _setState(TableState.WAITING_PRIMARY)
func _get_plate_from_item(_item: Node) -> PlateController: func _get_plate_from_item(_item: Node) -> PlateController:
return _item.get_children().filter(func(c): return c is PlateController).front() as PlateController return _item.get_children().filter(func(c): return c is PlateController).front() as PlateController
@@ -120,22 +127,34 @@ func _absorb_item_if_correct(_item: Node) -> void:
#print("Table: held a plate with FoodItem: ", food_item.id) #print("Table: held a plate with FoodItem: ", food_item.id)
if food_item.id in _unsatisfied_orders: if food_item.id in _unsatisfied_orders:
print("Table: held a plate with FoodItem that is in unsatisfied orders, removing it") print("Table: held a plate with FoodItem that is in unsatisfied orders, removing it")
_unsatisfied_orders.erase(food_item.id)
(plate_controller.get_parent() as XRToolsPickable).get_picked_up_by().enabled = false # Lock meal that is deliverd (plate_controller.get_parent() as XRToolsPickable).get_picked_up_by().enabled = false # Lock meal that is deliverd
print("Table _unsatisfied_orders: ", _unsatisfied_orders) _unsatisfied_orders.erase(food_item.id)
if _unsatisfied_orders.size() > 0 and _state != TableState.EATING: _update_state_from_orders()
_setState(TableState.WAITING_FRIEND)
# Table has everything it wants. Start eating
elif _unsatisfied_orders.is_empty() and _state != TableState.EATING:
GAME_MANAGER.money += food_item.sell_value
audio_player.stream = money_sound
audio_player.play()
_setState(TableState.EATING)
func _update_state_from_orders():
print("Table _update_state_from_orders: ", _unsatisfied_orders)
if _unsatisfied_orders.size() > 0 and _state != TableState.EATING:
_setState(TableState.WAITING_FRIEND)
# Table has everything it wants. Start eating
elif _unsatisfied_orders.is_empty() and _state != TableState.EATING:
_setState(TableState.EATING)
func _collect_money_from_plates():
for snap_zone_node in snap_zones:
var held_object = snap_zone_node.picked_up_object
if not held_object:
continue
var plate: PlateController = _get_plate_from_item(held_object)
for fi: FoodItem in plate.get_food_items():
GAME_MANAGER.money += fi.sell_value
print("Table _collect_money_from_plates(), money: ", GAME_MANAGER.money)
func place_order() -> void: func place_order() -> void:
print("Table: place_order()") print("Table place_order()")
var new_orders = _unsatisfied_orders.duplicate() var new_orders = _unsatisfied_orders.duplicate()
new_orders.append(GAME_MANAGER.get_random_meal()) new_orders.append(GAME_MANAGER.get_random_meal())
new_orders.append(GAME_MANAGER.get_random_meal()) new_orders.append(GAME_MANAGER.get_random_meal())
@@ -174,8 +193,8 @@ func _setState(newState: TableState) -> void:
match newState: match newState:
TableState.EMPTY: TableState.EMPTY:
_state_time = 5.0 _state_time = randf_range(3, 7)
_state_duration = 5.0 _state_duration = _state_time
customers.visible = false customers.visible = false
_state = newState _state = newState
TableState.THINKING: TableState.THINKING:
@@ -200,7 +219,10 @@ func _setState(newState: TableState) -> void:
TableState.EATING: TableState.EATING:
_state_time = eating_duration _state_time = eating_duration
_state_duration = eating_duration _state_duration = eating_duration
_collect_money_from_plates()
_set_snap_zones_enabled(false) _set_snap_zones_enabled(false)
audio_player.stream = money_sound
audio_player.play()
_state = newState _state = newState
@@ -240,7 +262,7 @@ func _refresh_display() -> void:
match _state: match _state:
TableState.EMPTY: TableState.EMPTY:
progress_bar.set_bar_visible(false) progress_bar.set_bar_visible(false)
label_3d.text = "empty" label_3d.text = ""
TableState.THINKING: TableState.THINKING:
progress_bar.set_bar_visible(false) progress_bar.set_bar_visible(false)
label_3d.text = lbl_thinking label_3d.text = lbl_thinking
@@ -266,6 +288,8 @@ func _refresh_display() -> void:
func _process(delta: float) -> void: func _process(delta: float) -> void:
_refresh_display() _refresh_display()
_place_order_if_player()
# Wait for state to finish # Wait for state to finish
if _state_time > 0.0: if _state_time > 0.0:
_state_time = max(0.0, _state_time - delta) _state_time = max(0.0, _state_time - delta)
+4 -1
View File
@@ -187,7 +187,7 @@ vertical_alignment = 0
line_spacing = -15.0 line_spacing = -15.0
[node name="Label3DTime" type="Label3D" parent="." unique_id=1534849507] [node name="Label3DTime" type="Label3D" parent="." unique_id=1534849507]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.4532461, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.513246, 0)
pixel_size = 0.003 pixel_size = 0.003
billboard = 2 billboard = 2
text = "20.1s" text = "20.1s"
@@ -207,3 +207,6 @@ collision_mask = 524288
[node name="CollisionShape3D" type="CollisionShape3D" parent="PlayerDetectArea3D" unique_id=1538221021] [node name="CollisionShape3D" type="CollisionShape3D" parent="PlayerDetectArea3D" unique_id=1538221021]
shape = SubResource("BoxShape3D_vlqg6") shape = SubResource("BoxShape3D_vlqg6")
[connection signal="body_entered" from="PlayerDetectArea3D" to="." method="_on_player_enter"]
[connection signal="body_exited" from="PlayerDetectArea3D" to="." method="_on_player_exit"]
+2
View File
@@ -17,6 +17,7 @@ transparent_bg = true
size = Vector2i(320, 80) size = Vector2i(320, 80)
[node name="ProgressBar" type="ProgressBar" parent="Sprite3D/SubViewport" unique_id=727723524] [node name="ProgressBar" type="ProgressBar" parent="Sprite3D/SubViewport" unique_id=727723524]
custom_minimum_size = Vector2(0, 400)
anchors_preset = 8 anchors_preset = 8
anchor_left = 0.5 anchor_left = 0.5
anchor_top = 0.5 anchor_top = 0.5
@@ -30,3 +31,4 @@ grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
size_flags_horizontal = 4 size_flags_horizontal = 4
size_flags_vertical = 4 size_flags_vertical = 4
show_percentage = false