asd
This commit is contained in:
@@ -22,7 +22,6 @@ collision_layer = 65536
|
||||
collision_mask = 65536
|
||||
script = ExtResource("1_p30r1")
|
||||
snap_mode = 1
|
||||
initial_object = NodePath("../../BurgerBuns")
|
||||
metadata/_custom_type_script = "uid://cquqe4f1m1sw6"
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="XRToolsSnapZone" unique_id=1104626493]
|
||||
|
||||
@@ -8,6 +8,14 @@
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_vlqg6"]
|
||||
radius = 0.3
|
||||
|
||||
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_np_hob"]
|
||||
properties/0/path = NodePath(".:time_cooked")
|
||||
properties/0/spawn = true
|
||||
properties/0/replication_mode = 1
|
||||
properties/1/path = NodePath(".:cooking_result_time")
|
||||
properties/1/spawn = true
|
||||
properties/1/replication_mode = 1
|
||||
|
||||
[node name="Hob" type="StaticBody3D" unique_id=1687971542 groups=["station"]]
|
||||
script = ExtResource("1_7jc4g")
|
||||
|
||||
@@ -103,3 +111,7 @@ size = Vector3(0.9842529, 0.095687866, 0.14019775)
|
||||
transform = Transform3D(0.94465846, 0, 0, 0, 0.94465846, 0, 0, 0, 0.94465846, -0.003479004, -0.08253479, 0.5616675)
|
||||
operation = 2
|
||||
size = Vector3(0.9842529, 0.8349304, 0.072387695)
|
||||
|
||||
[node name="Sync" type="MultiplayerSynchronizer" parent="."]
|
||||
root_path = NodePath("..")
|
||||
replication_config = SubResource("SceneReplicationConfig_np_hob")
|
||||
|
||||
@@ -7,9 +7,13 @@ func _ready() -> void:
|
||||
snap_zone.has_picked_up.connect(_makeDirty)
|
||||
|
||||
func _makeDirty(item) -> void:
|
||||
if not NetworkManager.owns_world():
|
||||
return
|
||||
var plate: PlateController = item.get_node_or_null("PlateController") as PlateController
|
||||
if not plate:
|
||||
print("Dirt Station: held object is not a Plate")
|
||||
return
|
||||
if not plate.is_dirty:
|
||||
plate.is_dirty = true
|
||||
print("Dirt Station could not find Dirty in: ", item)
|
||||
|
||||
|
||||
|
||||
+9
-8
@@ -38,23 +38,24 @@ func _on_object_dropped() -> void:
|
||||
|
||||
|
||||
func convert_held_to_item(_item: PackedScene) -> void:
|
||||
if not NetworkManager.owns_world():
|
||||
return
|
||||
print("Hob converting ", _item)
|
||||
|
||||
|
||||
var old_pickable = snap_zone.picked_up_object
|
||||
if not old_pickable:
|
||||
push_warning("Hob finished cooking _item, but snap zone is missing its reference")
|
||||
return
|
||||
|
||||
# Create new item as child of root in the same position
|
||||
|
||||
# Spawn the new item through the server so it replicates to every peer
|
||||
# (including late joiners), in the old item's position.
|
||||
var original_transform = old_pickable.global_transform
|
||||
var new_scene_instance = _item.instantiate()
|
||||
get_tree().get_root().add_child(new_scene_instance)
|
||||
new_scene_instance.global_transform = original_transform
|
||||
var new_scene_instance = NetworkManager.spawn_item(_item.resource_path, original_transform)
|
||||
|
||||
# Drop and free the old item and pick up the new one
|
||||
print("Hob freeing old_pickable ", old_pickable)
|
||||
snap_zone.drop_object()
|
||||
old_pickable.queue_free()
|
||||
snap_zone.drop_object()
|
||||
NetworkManager.despawn_item(old_pickable)
|
||||
snap_zone.pick_up_object(new_scene_instance)
|
||||
|
||||
|
||||
|
||||
@@ -13,10 +13,8 @@ func _ready() -> void:
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
if not NetworkManager.owns_world():
|
||||
return
|
||||
if not snap_zone.picked_up_object:
|
||||
var new_item = item_scene.instantiate()
|
||||
|
||||
# Add the new item to the hob's parent (so it lives in the main world space)
|
||||
get_parent().add_child(new_item)
|
||||
new_item.global_transform = snap_zone.transform
|
||||
var new_item = NetworkManager.spawn_item(item_scene.resource_path, snap_zone.global_transform)
|
||||
snap_zone.pick_up_object(new_item)
|
||||
|
||||
@@ -9,6 +9,11 @@
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_dlkho"]
|
||||
radius = 0.3
|
||||
|
||||
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_np_sink"]
|
||||
properties/0/path = NodePath(".:progress")
|
||||
properties/0/spawn = true
|
||||
properties/0/replication_mode = 1
|
||||
|
||||
[node name="Sink" type="StaticBody3D" unique_id=2055277359 groups=["station"]]
|
||||
script = ExtResource("1_7hh4b")
|
||||
plate_scene = ExtResource("2_ai6d4")
|
||||
@@ -75,3 +80,7 @@ size = Vector3(1.4033203, 1.2053223, 0.352417)
|
||||
transform = Transform3D(1.3113414e-07, 0.12955962, 0.99157166, 8.8817837e-16, 0.9915716, -0.1295596, -0.9999999, 1.6989695e-08, 1.3002891e-07, 0.6035124, 0.019589934, -0.20879287)
|
||||
operation = 2
|
||||
size = Vector3(1.4033203, 1.2053223, 0.352417)
|
||||
|
||||
[node name="Sync" type="MultiplayerSynchronizer" parent="."]
|
||||
root_path = NodePath("..")
|
||||
replication_config = SubResource("SceneReplicationConfig_np_sink")
|
||||
|
||||
+70
-43
@@ -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)
|
||||
|
||||
|
||||
@@ -11,6 +11,17 @@ radius = 0.3
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_24d3s"]
|
||||
albedo_color = Color(0.31, 0.21576, 0.1333, 1)
|
||||
|
||||
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_np_table"]
|
||||
properties/0/path = NodePath(".:_state")
|
||||
properties/0/spawn = true
|
||||
properties/0/replication_mode = 1
|
||||
properties/1/path = NodePath(".:_state_time")
|
||||
properties/1/spawn = true
|
||||
properties/1/replication_mode = 1
|
||||
properties/2/path = NodePath(".:_unsatisfied_orders")
|
||||
properties/2/spawn = true
|
||||
properties/2/replication_mode = 1
|
||||
|
||||
[node name="Table" type="StaticBody3D" unique_id=1863572470 groups=["station"]]
|
||||
script = ExtResource("1_2vcpj")
|
||||
|
||||
@@ -155,3 +166,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.3306234, 0)
|
||||
pixel_size = 0.003
|
||||
billboard = 2
|
||||
text = "20.1s"
|
||||
|
||||
[node name="Sync" type="MultiplayerSynchronizer" parent="."]
|
||||
root_path = NodePath("..")
|
||||
replication_config = SubResource("SceneReplicationConfig_np_table")
|
||||
|
||||
Reference in New Issue
Block a user