diff --git a/Containers/plate_controller.gd b/Containers/plate_controller.gd index b617482..20eaba3 100644 --- a/Containers/plate_controller.gd +++ b/Containers/plate_controller.gd @@ -13,6 +13,8 @@ extends Node ## the cosmetic result via the setter below. @export var contained_ids: Array[String] = []: set = _set_contained_ids +func get_food_items() -> Array[FoodItem]: + return container.contained_items func _ready() -> void: if not dirty_node: diff --git a/GameManager.gd b/GameManager.gd index 8065810..2316183 100644 --- a/GameManager.gd +++ b/GameManager.gd @@ -31,7 +31,7 @@ static func get_random_side() -> String: push_error("GameManager: get_random_side() called but sides_in_play is empty") return "" 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] diff --git a/Stations/table.gd b/Stations/table.gd index f65f354..393e4de 100644 --- a/Stations/table.gd +++ b/Stations/table.gd @@ -44,7 +44,7 @@ var _state: TableState = TableState.EMPTY var _state_time: float = 0.0 var _state_duration: float = 0.0 # set in _set_state_time var _unsatisfied_orders: Array[String] = [] - +var _players_count: int = 0 func _ready() -> void: if not label_3d: @@ -74,7 +74,6 @@ func _ready() -> void: for snap_zone_node in snap_zones: snap_zone_node.has_picked_up.connect(_on_object_picked_up) snap_zone_node.has_dropped.connect(_on_object_dropped) - player_detect_area_3d.body_entered.connect(_on_player_detected) set_process(true) _setState(TableState.EMPTY) @@ -90,15 +89,23 @@ func _on_object_dropped() -> void: print("Table: object dropped ") -# TODO: Use a on_stay signal or similar -func _on_player_detected(player): - print("Table _on_player_detected(), ", player) +# There is no on_stay signal, we have to track player with bool +func _on_player_enter(_body): + _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: return - - place_order() - _setState(TableState.WAITING_PRIMARY) - + if _players_count > 0: + place_order() + _setState(TableState.WAITING_PRIMARY) func _get_plate_from_item(_item: Node) -> 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) if food_item.id in _unsatisfied_orders: 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 - print("Table _unsatisfied_orders: ", _unsatisfied_orders) - if _unsatisfied_orders.size() > 0 and _state != TableState.EATING: - _setState(TableState.WAITING_FRIEND) + _unsatisfied_orders.erase(food_item.id) + _update_state_from_orders() - # 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: - print("Table: place_order()") + print("Table place_order()") var new_orders = _unsatisfied_orders.duplicate() 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: TableState.EMPTY: - _state_time = 5.0 - _state_duration = 5.0 + _state_time = randf_range(3, 7) + _state_duration = _state_time customers.visible = false _state = newState TableState.THINKING: @@ -200,7 +219,10 @@ func _setState(newState: TableState) -> void: TableState.EATING: _state_time = eating_duration _state_duration = eating_duration + _collect_money_from_plates() _set_snap_zones_enabled(false) + audio_player.stream = money_sound + audio_player.play() _state = newState @@ -240,7 +262,7 @@ func _refresh_display() -> void: match _state: TableState.EMPTY: progress_bar.set_bar_visible(false) - label_3d.text = "empty" + label_3d.text = "" TableState.THINKING: progress_bar.set_bar_visible(false) label_3d.text = lbl_thinking @@ -266,6 +288,8 @@ func _refresh_display() -> void: func _process(delta: float) -> void: _refresh_display() + _place_order_if_player() + # Wait for state to finish if _state_time > 0.0: _state_time = max(0.0, _state_time - delta) diff --git a/Stations/table.tscn b/Stations/table.tscn index c144632..194a656 100644 --- a/Stations/table.tscn +++ b/Stations/table.tscn @@ -187,7 +187,7 @@ vertical_alignment = 0 line_spacing = -15.0 [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 billboard = 2 text = "20.1s" @@ -207,3 +207,6 @@ collision_mask = 524288 [node name="CollisionShape3D" type="CollisionShape3D" parent="PlayerDetectArea3D" unique_id=1538221021] 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"] diff --git a/UI/progress_bar.tscn b/UI/progress_bar.tscn index 3e86b08..9be9811 100644 --- a/UI/progress_bar.tscn +++ b/UI/progress_bar.tscn @@ -17,6 +17,7 @@ transparent_bg = true size = Vector2i(320, 80) [node name="ProgressBar" type="ProgressBar" parent="Sprite3D/SubViewport" unique_id=727723524] +custom_minimum_size = Vector2(0, 400) anchors_preset = 8 anchor_left = 0.5 anchor_top = 0.5 @@ -30,3 +31,4 @@ grow_horizontal = 2 grow_vertical = 2 size_flags_horizontal = 4 size_flags_vertical = 4 +show_percentage = false