Split Station into WorkStation abstract script

This commit is contained in:
JonShard
2026-08-13 20:00:37 +02:00
parent 5ced240c43
commit 9e0c3ed174
27 changed files with 441 additions and 429 deletions
-1
View File
@@ -68,7 +68,6 @@ func _exit_tree() -> void:
func _on_session_started(_is_server: bool) -> void:
NetworkManager.gate_existing_stations()
_populate_world_if_owner()
+2 -1
View File
@@ -116,7 +116,8 @@ func apply_held_state() -> void:
# Someone else owns it: stop simulating locally, just follow the sync.
if _pickable.is_picked_up():
if NetworkManager.is_online():
SweetLogger.debug("{0}: was held by {1} on this peer, but authority now says peer {2} owns it — force-dropping", [_pickable.name, _holder_desc(), net_held_by])
# Jon's note: When we get this warning, it usually mean a client-side snapzone is not disabled, and is fighting the server over the item.
SweetLogger.warning("{0}: was held by {1} on this peer, but authority now says peer {2} owns it — force-dropping", [_pickable.name, _holder_desc(), net_held_by])
_pickable.drop()
# Bail out when we're already in the follow-the-sync state. Without this the
# writes below (and the line logged with them) repeated every tick for every
-70
View File
@@ -163,62 +163,8 @@ func _spawn_item_from_data(data: Variant) -> Node:
inst.name = data["name"]
for key in data.get("props", {}):
inst.set(key, data["props"][key])
if not owns_world():
_gate_station(inst)
# ...and again once the node is in the tree. Gating before _ready() is what
# keeps a station from ever ticking on a client, but a station's own
# _ready() runs afterwards and can undo it (table.gd re-arms its state
# machine with set_process(true)). The deferred pass runs after every
# _ready() in this frame and re-asserts the gate.
_gate_station.call_deferred(inst)
return inst
# Stations run their own logic and auto-grab (XRToolsSnapZone with
# snap_mode=RANGE) identically on every peer by default, which would let each
# peer independently grab/simulate the same shared object. Disable both on
# every peer except the one that owns world logic; the server-authoritative
# item-authority RPCs are what let clients still grab a server-held item by
# hand. Runs before the node enters the tree, so its own _ready() sees the
# final (disabled) state.
#
# Group contract (see also _station_snap_zones): "station" marks the body that
# runs the station's script, "station_zone" marks its snap zones. Station scenes
# wrap that body in a Node3D (for StationMovement), and spawn_item hands us that
# wrapper, so accept either and recurse — a type check on the node we're handed
# silently gated nothing for stations whose root isn't the body itself.
func _gate_station(node: Node) -> void:
if not node.is_in_group("station"):
for child in node.find_children("*", "", true, false):
if child.is_in_group("station"):
_gate_station(child)
return
# Only report a gate that actually changed something: this runs a second time
# (deferred) for every spawned station, and on a re-gate that found nothing to
# do there is nothing worth logging.
var changed := node.is_processing()
for zone in node.find_children("*", "XRToolsSnapZone", true, false):
changed = changed or zone.enabled or zone.is_processing()
zone.enabled = false
zone.set_process(false)
node.set_process(false)
if changed:
log_line("gated station (non-owner peer): %s" % node.name)
## Gate every station already sitting in the scene tree, for peers that don't
## own world logic. Stations that arrive through spawn_item() are gated as they
## are built (see _spawn_item_from_data), but ones baked into a scene file never
## pass through there — leaving a client running its own snap zones, which then
## grab items straight out of the local hand and fight the server's
## authoritative placement. Idempotent, so it's safe on every session start.
func gate_existing_stations() -> void:
if owns_world():
return
for station in get_tree().get_nodes_in_group("station"):
_gate_station(station)
# --- Item grab-authority transfer -----------------------------------------
## Called by NetPickable when this peer grabs an item by hand. Godot rejects
@@ -420,22 +366,6 @@ func owns_world() -> bool:
return not is_online() or is_server()
# --- Station work-progress seam -------------------------------------------
## Reusable entry point for a client to contribute work to a station (e.g. a
## future chopping/gesture station). The client detects the gesture locally and
## calls this; the server validates and accumulates. Timer-driven stations like
## the Hob don't need it, but it is the drop-in seam for input-driven ones.
@rpc("any_peer", "reliable")
func submit_work(station_path: NodePath, amount: float) -> void:
if not is_server():
return
var station := get_node_or_null(station_path)
if station and station.has_method("add_work"):
log_line("submit_work: peer %d contributed %.2f to %s" % [multiplayer.get_remote_sender_id(), amount, station.name])
station.add_work(multiplayer.get_remote_sender_id(), amount)
## Called by the world scene once it's ready, passing its spawners. Must run
## before world_ready()/host()/join() on every peer so the custom spawn
## function is installed before any spawn packet can arrive.
+13 -13
View File
@@ -1,22 +1,22 @@
[gd_scene format=3 uid="uid://22shbqdvnwgo"]
[ext_resource type="Script" uid="uid://d1cefhe3yyyds" path="res://Net/multiplayer_world.gd" id="1_nlnup"]
[ext_resource type="PackedScene" uid="uid://j5s5wus7tuhb" path="res://Prefabs/XROrigin.tscn" id="2_8pfaf"]
[ext_resource type="Material" uid="uid://cmia50cfqxxo4" path="res://Textures/dev_material_3d.tres" id="3_gatbn"]
[ext_resource type="PackedScene" uid="uid://j7caslh27nor" path="res://Stations/Hob.tscn" id="4_3lufs"]
[ext_resource type="Sky" uid="uid://c1abtpwhdm2d5" path="res://Textures/sky/NightSkyHDRI009_16K.tres" id="5_kh26v"]
[ext_resource type="PackedScene" uid="uid://c6rift56ql3f8" path="res://Stations/BurgerBunsDispenser.tscn" id="7_tejmp"]
[ext_resource type="PackedScene" uid="uid://dpot5qie20vf6" path="res://Items/burger.tscn" id="9_rwx83"]
[ext_resource type="PackedScene" uid="uid://dvrk268s7gkxh" path="res://Stations/sink.tscn" id="12_ah4xa"]
[ext_resource type="PackedScene" uid="uid://cnjwtnhwh0i8q" path="res://Stations/dirt_station.tscn" id="13_46xi2"]
[ext_resource type="PackedScene" uid="uid://ck5tuftqmyiue" path="res://Stations/plate_dispenser.tscn" id="14_h88sx"]
[ext_resource type="PackedScene" uid="uid://cwnwo4i28upap" path="res://Stations/raw_burger_dispenser.tscn" id="15_m3h4l"]
[ext_resource type="PackedScene" uid="uid://efaec6ymgabo" path="res://Stations/Counter.tscn" id="15_tpcje"]
[ext_resource type="PackedScene" uid="uid://caf0xanmxbshy" path="res://Stations/table.tscn" id="16_g2k6a"]
[ext_resource type="PackedScene" uid="uid://j5s5wus7tuhb" path="res://prefabs/XROrigin.tscn" id="2_8pfaf"]
[ext_resource type="Material" uid="uid://cmia50cfqxxo4" path="res://textures/dev_material_3d.tres" id="3_gatbn"]
[ext_resource type="PackedScene" uid="uid://j7caslh27nor" path="res://stations/Hob_old.tscn" id="4_3lufs"]
[ext_resource type="Sky" uid="uid://c1abtpwhdm2d5" path="res://textures/sky/NightSkyHDRI009_16K.tres" id="5_kh26v"]
[ext_resource type="PackedScene" uid="uid://c6rift56ql3f8" path="res://stations/BurgerBunsDispenser.tscn" id="7_tejmp"]
[ext_resource type="PackedScene" uid="uid://dpot5qie20vf6" path="res://items/burger.tscn" id="9_rwx83"]
[ext_resource type="PackedScene" uid="uid://dvrk268s7gkxh" path="res://stations/sink.tscn" id="12_ah4xa"]
[ext_resource type="PackedScene" uid="uid://cnjwtnhwh0i8q" path="res://stations/dirt_station.tscn" id="13_46xi2"]
[ext_resource type="PackedScene" uid="uid://ck5tuftqmyiue" path="res://stations/plate_dispenser.tscn" id="14_h88sx"]
[ext_resource type="PackedScene" uid="uid://cwnwo4i28upap" path="res://stations/raw_burger_dispenser.tscn" id="15_m3h4l"]
[ext_resource type="PackedScene" uid="uid://efaec6ymgabo" path="res://stations/Counter.tscn" id="15_tpcje"]
[ext_resource type="PackedScene" uid="uid://caf0xanmxbshy" path="res://stations/table.tscn" id="16_g2k6a"]
[ext_resource type="Script" uid="uid://k8ywnvlhcic4" path="res://test/testworldLoad.gd" id="16_m3h4l"]
[ext_resource type="PackedScene" uid="uid://clujaf3u776a3" path="res://addons/godot-xr-tools/objects/viewport_2d_in_3d.tscn" id="17_gatbn"]
[ext_resource type="PackedScene" uid="uid://xtcei2uvd5li" path="res://UI/game_over_panel.tscn" id="18_3lufs"]
[ext_resource type="Script" uid="uid://cwijoksyou1ey" path="res://Prefabs/GameOvercontroler.gd" id="19_3lufs"]
[ext_resource type="Script" uid="uid://cwijoksyou1ey" path="res://prefabs/GameOvercontroler.gd" id="19_3lufs"]
[sub_resource type="BoxShape3D" id="BoxShape3D_vlqg6"]
size = Vector3(16, 0.1, 16)
+1 -1
View File
@@ -11,7 +11,7 @@
[ext_resource type="PackedScene" uid="uid://dlw5geheupgpt" path="res://stations/hatch.tscn" id="12_dpf3b"]
[ext_resource type="PackedScene" uid="uid://e4i6o5oriecx" path="res://items/PickupCube.tscn" id="13_1f3bw"]
[ext_resource type="PackedScene" uid="uid://caf0xanmxbshy" path="res://stations/table.tscn" id="13_yjosk"]
[ext_resource type="PackedScene" uid="uid://j7caslh27nor" path="res://stations/Hob.tscn" id="14_2ndvi"]
[ext_resource type="PackedScene" uid="uid://j7caslh27nor" path="res://stations/Hob_old.tscn" id="14_2ndvi"]
[ext_resource type="PackedScene" uid="uid://clujaf3u776a3" path="res://addons/godot-xr-tools/objects/viewport_2d_in_3d.tscn" id="14_di04w"]
[ext_resource type="PackedScene" uid="uid://efaec6ymgabo" path="res://stations/Counter.tscn" id="15_di04w"]
[ext_resource type="PackedScene" uid="uid://xtcei2uvd5li" path="res://UI/game_over_panel.tscn" id="15_eoxxy"]
-113
View File
@@ -3,18 +3,7 @@
[ext_resource type="Script" uid="uid://d1cefhe3yyyds" path="res://Net/multiplayer_world.gd" id="1_jfr2g"]
[ext_resource type="PackedScene" uid="uid://j5s5wus7tuhb" path="res://prefabs/XROrigin.tscn" id="2_8wkh3"]
[ext_resource type="Material" uid="uid://cmia50cfqxxo4" path="res://textures/dev_material_3d.tres" id="3_m56cs"]
[ext_resource type="PackedScene" uid="uid://j7caslh27nor" path="res://stations/Hob.tscn" id="4_5kvh0"]
[ext_resource type="Sky" uid="uid://c1abtpwhdm2d5" path="res://textures/sky/NightSkyHDRI009_16K.tres" id="5_l1qm6"]
[ext_resource type="PackedScene" uid="uid://c0lknik4noobs" path="res://items/BurgerBuns.tscn" id="6_bktvt"]
[ext_resource type="PackedScene" uid="uid://c6rift56ql3f8" path="res://stations/BurgerBunsDispenser.tscn" id="7_1nkd0"]
[ext_resource type="PackedScene" uid="uid://bp3v1jl8pctro" path="res://Containers/plate.tscn" id="8_l1owj"]
[ext_resource type="PackedScene" uid="uid://dpot5qie20vf6" path="res://items/burger.tscn" id="9_220hi"]
[ext_resource type="PackedScene" uid="uid://b3m2ag8g5rj4r" path="res://items/hamburger.tscn" id="10_qacki"]
[ext_resource type="PackedScene" uid="uid://e4i6o5oriecx" path="res://items/PickupCube.tscn" id="11_npf8s"]
[ext_resource type="PackedScene" uid="uid://dvrk268s7gkxh" path="res://stations/sink.tscn" id="12_8apyq"]
[ext_resource type="PackedScene" uid="uid://cnjwtnhwh0i8q" path="res://stations/dirt_station.tscn" id="13_jnwcx"]
[ext_resource type="PackedScene" uid="uid://cfc4ho67u4r5e" path="res://items/cooked_burger.tscn" id="14_1lg2m"]
[ext_resource type="PackedScene" uid="uid://efaec6ymgabo" path="res://stations/Counter.tscn" id="15_yy81s"]
[ext_resource type="PackedScene" uid="uid://clujaf3u776a3" path="res://addons/godot-xr-tools/objects/viewport_2d_in_3d.tscn" id="16_vp"]
[ext_resource type="PackedScene" path="res://UI/main_menu_panel.tscn" id="17_panel"]
@@ -61,111 +50,9 @@ shape = SubResource("BoxShape3D_vlqg6")
[node name="MeshInstance3D" type="MeshInstance3D" parent="Floor/CollisionShape3D" unique_id=1939997056]
mesh = SubResource("BoxMesh_24d3s")
[node name="Hob" parent="." unique_id=1687971542 instance=ExtResource("4_5kvh0")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.29336345, 0.015500337, -1.484)
[node name="WorldEnvironment" type="WorldEnvironment" parent="." unique_id=1177077250]
environment = SubResource("Environment_bvwq1")
[node name="BurgerBuns" parent="." unique_id=1088240294 instance=ExtResource("6_bktvt")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.5530176, 1.0505146, -1.3074328)
[node name="BurgerBunsDispenser" parent="." unique_id=1720683779 instance=ExtResource("7_1nkd0")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.568947, -0.018512607, -1.317366)
[node name="Plate" parent="." unique_id=190487773 instance=ExtResource("8_l1owj")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.5717233, 1.1548845, 1.5373346)
[node name="burger" parent="." unique_id=1417604760 instance=ExtResource("9_220hi")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.6888188, 1.0325116, -1.7110313)
[node name="burger2" parent="." unique_id=1584460510 instance=ExtResource("9_220hi")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.6931299, 1.1429771, -1.71225)
[node name="burger3" parent="." unique_id=1884095916 instance=ExtResource("9_220hi")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.69027674, 1.1099085, -1.7210286)
[node name="burger4" parent="." unique_id=1844818864 instance=ExtResource("9_220hi")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.69134104, 1.0672915, -1.7210286)
[node name="Hamburger" parent="." unique_id=761091445 instance=ExtResource("10_qacki")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.9352558, 1.2334514, 1.2447833)
[node name="PickableObject" parent="." unique_id=1675596942 instance=ExtResource("11_npf8s")]
transform = Transform3D(1, 0, -2.2351742e-08, -2.9802322e-08, 1.0000001, 0, -2.6077032e-08, 1.4901161e-08, 1, 0.6225724, 1.0654817, -1.0473135)
[node name="PickableObject2" parent="." unique_id=713087634 instance=ExtResource("11_npf8s")]
transform = Transform3D(1, 0, -2.2351742e-08, -2.9802322e-08, 1.0000001, -5.293956e-23, -2.6077032e-08, 1.4901161e-08, 1, 0.6359743, 1.0501236, -1.1673055)
[node name="PickableObject3" parent="." unique_id=879935619 instance=ExtResource("11_npf8s")]
transform = Transform3D(1, 0, -2.2351742e-08, -2.9802322e-08, 1.0000001, 0, -2.6077032e-08, 1.4901161e-08, 1, 0.5142721, 1.0654817, -1.0473135)
[node name="PickableObject4" parent="." unique_id=198541902 instance=ExtResource("11_npf8s")]
transform = Transform3D(1, 0, -2.2351742e-08, -2.9802322e-08, 1.0000001, -5.293956e-23, -2.6077032e-08, 1.4901161e-08, 1, 0.5276739, 1.0501236, -1.1673055)
[node name="Hamburger2" parent="." unique_id=1349934579 instance=ExtResource("10_qacki")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.9857153, 1.1424131, 0.9472374)
[node name="PickableObject5" parent="." unique_id=1021333509 instance=ExtResource("11_npf8s")]
transform = Transform3D(1, 0, -2.2351742e-08, -2.9802322e-08, 1.0000001, 0, -2.6077032e-08, 1.4901161e-08, 1, 0.73287535, 1.0922265, -1.0473135)
[node name="PickableObject6" parent="." unique_id=1268843669 instance=ExtResource("11_npf8s")]
transform = Transform3D(1, 0, -2.2351742e-08, -2.9802322e-08, 1.0000001, -5.293956e-23, -2.6077032e-08, 1.4901161e-08, 1, 0.7462772, 1.0768684, -1.1673055)
[node name="Sink" parent="." unique_id=2055277359 instance=ExtResource("12_8apyq")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.3147688, 0.015500337, -1.4940417)
[node name="DirtStation" parent="." unique_id=160842153 instance=ExtResource("13_jnwcx")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.0864775, 0.5, -1.244947)
[node name="Plate2" parent="." unique_id=356790445 instance=ExtResource("8_l1owj")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.5730225, 1.1085004, 0.59790254)
[node name="CookedBurger" parent="." unique_id=1127807542 instance=ExtResource("14_1lg2m")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.30782473, 1.1446649, -1.0928738)
[node name="CookedBurger2" parent="." unique_id=160088590 instance=ExtResource("14_1lg2m")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.30671906, 1.0522771, -1.0928738)
[node name="CookedBurger3" parent="." unique_id=992183367 instance=ExtResource("14_1lg2m")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.3344773, 1.0492828, -0.7096845)
[node name="CookedBurger4" parent="." unique_id=1837607086 instance=ExtResource("14_1lg2m")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.30671906, 1.098119, -1.0928738)
[node name="BurgerBuns2" parent="." unique_id=1210358958 instance=ExtResource("6_bktvt")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.3596323, 1.0205106, -0.22482127)
[node name="PickableObject7" parent="." unique_id=641653545 instance=ExtResource("11_npf8s")]
transform = Transform3D(1, 0, -2.2351742e-08, -2.9802322e-08, 1.0000001, 0, -2.6077032e-08, 1.4901161e-08, 1, -1.3556751, 1.0887735, 0.28881657)
[node name="PickableObject8" parent="." unique_id=1733819363 instance=ExtResource("11_npf8s")]
transform = Transform3D(1, 0, -2.2351742e-08, -2.9802322e-08, 1.0000001, -5.293956e-23, -2.6077032e-08, 1.4901161e-08, 1, -1.3422732, 1.0734154, 0.16882455)
[node name="PickableObject9" parent="." unique_id=12419746 instance=ExtResource("11_npf8s")]
transform = Transform3D(1, 0, -2.2351742e-08, -2.9802322e-08, 1.0000001, 0, -2.6077032e-08, 1.4901161e-08, 1, -1.4639754, 1.0887735, 0.28881657)
[node name="PickableObject10" parent="." unique_id=313160217 instance=ExtResource("11_npf8s")]
transform = Transform3D(1, 0, -2.2351742e-08, -2.9802322e-08, 1.0000001, -5.293956e-23, -2.6077032e-08, 1.4901161e-08, 1, -1.4505737, 1.0734154, 0.16882455)
[node name="Counter" parent="." unique_id=1487893288 instance=ExtResource("15_yy81s")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.7124918, 0.015500337, -1.4886917)
[node name="Counter2" parent="." unique_id=368890752 instance=ExtResource("15_yy81s")]
transform = Transform3D(-4.371139e-08, 0, 1, 0, 1, 0, -1, 0, -4.371139e-08, -1.7648025, 0.015500337, -0.4458799)
[node name="Counter3" parent="." unique_id=1498817646 instance=ExtResource("15_yy81s")]
transform = Transform3D(-4.371139e-08, 0, 1, 0, 1, 0, -1, 0, -4.371139e-08, -1.7648025, 0.015500337, 0.55367994)
[node name="Counter4" parent="." unique_id=906748771 instance=ExtResource("15_yy81s")]
transform = Transform3D(-4.371139e-08, 0, 1, 0, 1, 0, -1, 0, -4.371139e-08, -1.7648025, 0.015500337, 1.5539298)
[node name="Hamburger3" parent="." unique_id=369573848 instance=ExtResource("10_qacki")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.7201865, 1.142413, 0.14773655)
[node name="Plate3" parent="." unique_id=2004250522 instance=ExtResource("8_l1owj")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.5818124, 1.1085004, -0.4634577)
[node name="WorldContent" type="Node3D" parent="." unique_id=1660879286]
[node name="Players" type="Node3D" parent="." unique_id=494935131]
+8 -8
View File
@@ -1,15 +1,15 @@
[gd_scene format=3 uid="uid://c30i6h32w8p47"]
[ext_resource type="Script" uid="uid://d1cefhe3yyyds" path="res://Net/multiplayer_world.gd" id="1_kdan8"]
[ext_resource type="PackedScene" uid="uid://j5s5wus7tuhb" path="res://Prefabs/XROrigin.tscn" id="2_g30gi"]
[ext_resource type="Material" uid="uid://cmia50cfqxxo4" path="res://Textures/dev_material_3d.tres" id="3_75ecy"]
[ext_resource type="Sky" uid="uid://c1abtpwhdm2d5" path="res://Textures/sky/NightSkyHDRI009_16K.tres" id="5_c3xgf"]
[ext_resource type="Script" uid="uid://fyd2rjramhbb" path="res://Prefabs/kitchen_instantiator.gd" id="6_pw2j5"]
[ext_resource type="PackedScene" uid="uid://j5s5wus7tuhb" path="res://prefabs/XROrigin.tscn" id="2_g30gi"]
[ext_resource type="Material" uid="uid://cmia50cfqxxo4" path="res://textures/dev_material_3d.tres" id="3_75ecy"]
[ext_resource type="Sky" uid="uid://c1abtpwhdm2d5" path="res://textures/sky/NightSkyHDRI009_16K.tres" id="5_c3xgf"]
[ext_resource type="Script" uid="uid://fyd2rjramhbb" path="res://prefabs/kitchen_instantiator.gd" id="6_pw2j5"]
[ext_resource type="PackedScene" uid="uid://damrxtlt7uswf" path="res://content/station_layouts/small_line.tscn" id="7_0sjqq"]
[ext_resource type="PackedScene" uid="uid://j7caslh27nor" path="res://Stations/Hob.tscn" id="8_0sjqq"]
[ext_resource type="PackedScene" uid="uid://dm70ynyuw1a5u" path="res://Prefabs/day_controller.tscn" id="9_5wx0o"]
[ext_resource type="PackedScene" uid="uid://bnwb7imcotkod" path="res://Prefabs/build_mode_controller.tscn" id="10_464r1"]
[ext_resource type="PackedScene" uid="uid://dxe05wp60jg3l" path="res://Scenes/queue_controller.tscn" id="11_de1dy"]
[ext_resource type="PackedScene" uid="uid://j7caslh27nor" path="res://stations/Hob_old.tscn" id="8_0sjqq"]
[ext_resource type="PackedScene" uid="uid://dm70ynyuw1a5u" path="res://prefabs/day_controller.tscn" id="9_5wx0o"]
[ext_resource type="PackedScene" uid="uid://bnwb7imcotkod" path="res://prefabs/build_mode_controller.tscn" id="10_464r1"]
[ext_resource type="PackedScene" uid="uid://dxe05wp60jg3l" path="res://scenes/queue_controller.tscn" id="11_de1dy"]
[ext_resource type="Script" uid="uid://biu4qr3nr1eny" path="res://test/mp_test_driver.gd" id="99_mptst"]
[sub_resource type="BoxShape3D" id="BoxShape3D_vlqg6"]
+1 -1
View File
@@ -4,7 +4,7 @@
[ext_resource type="Sky" uid="uid://c1abtpwhdm2d5" path="res://textures/sky/NightSkyHDRI009_16K.tres" id="2_1jq86"]
[ext_resource type="PackedScene" uid="uid://j5s5wus7tuhb" path="res://prefabs/XROrigin.tscn" id="3_bryd6"]
[ext_resource type="Material" uid="uid://cmia50cfqxxo4" path="res://textures/dev_material_3d.tres" id="4_kpgm6"]
[ext_resource type="PackedScene" uid="uid://j7caslh27nor" path="res://stations/Hob.tscn" id="5_gfdi7"]
[ext_resource type="PackedScene" uid="uid://j7caslh27nor" path="res://stations/Hob_old.tscn" id="5_gfdi7"]
[ext_resource type="PackedScene" uid="uid://efaec6ymgabo" path="res://stations/Counter.tscn" id="7_jnxsa"]
[ext_resource type="PackedScene" uid="uid://bnwb7imcotkod" path="res://prefabs/build_mode_controller.tscn" id="9_hooyg"]
[ext_resource type="PackedScene" uid="uid://caf0xanmxbshy" path="res://stations/table.tscn" id="11_gaw43"]
+43 -79
View File
@@ -1,40 +1,14 @@
[gd_scene format=3 uid="uid://j7caslh27nor"]
[gd_scene format=3 uid="uid://b052o1fgwq5bw"]
[ext_resource type="PackedScene" uid="uid://cbs8jiqe8rcmn" path="res://abstract/station.tscn" id="1_2p1q6"]
[ext_resource type="Script" uid="uid://bsn8vhv5adxdo" path="res://stations/hob.gd" id="1_7jc4g"]
[ext_resource type="PackedScene" uid="uid://cvucwxibtol5f" path="res://stations/StationMovement.tscn" id="1_pydjp"]
[ext_resource type="Script" uid="uid://cquqe4f1m1sw6" path="res://addons/godot-xr-tools/objects/snap_zone.gd" id="2_er1dp"]
[ext_resource type="AudioStream" uid="uid://dmyuqe5058sv3" path="res://sounds/220197__gameaudio__click-basic.wav" id="3_6oyg1"]
[ext_resource type="PackedScene" uid="uid://bxbocxdaayvwx" path="res://UI/progress_bar.tscn" id="3_7uuqv"]
[ext_resource type="Material" uid="uid://d1djvskv4n4m3" path="res://textures/hob_off.tres" id="4_8qpxk"]
[ext_resource type="Material" uid="uid://db7c7w4apwti7" path="res://textures/hob_on.tres" id="6_m7l4u"]
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_np_hob"]
properties/0/path = NodePath("Hob:time_cooked")
properties/0/spawn = false
properties/0/replication_mode = 1
properties/1/path = NodePath("Hob:cooking_result")
properties/1/spawn = false
properties/1/replication_mode = 1
properties/2/path = NodePath("Hob:cooking_result_time")
properties/2/spawn = false
properties/2/replication_mode = 1
properties/3/path = NodePath("Hob:position")
properties/3/spawn = false
properties/3/replication_mode = 1
properties/4/path = NodePath("Hob:rotation")
properties/4/spawn = false
properties/4/replication_mode = 1
properties/5/path = NodePath("Hob:visible")
properties/5/spawn = false
properties/5/replication_mode = 1
[sub_resource type="BoxShape3D" id="BoxShape3D_kdxnr"]
[sub_resource type="BoxShape3D" id="BoxShape3D_l0sax"]
size = Vector3(0.6, 1, 0.6)
[sub_resource type="BoxShape3D" id="BoxShape3D_7uuqv"]
size = Vector3(0.6, 0.12802735, 0.6)
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_gkb3v"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_bmu77"]
[sub_resource type="Animation" id="Animation_7uuqv"]
length = 0.001
@@ -163,134 +137,124 @@ tracks/4/keys = {
"values": [1.0, 0.0, 1.0]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_ac5f3"]
[sub_resource type="AnimationLibrary" id="AnimationLibrary_pydjp"]
_data = {
&"RESET": SubResource("Animation_7uuqv"),
&"hob": SubResource("Animation_6oyg1")
}
[node name="Hob" type="Node3D" unique_id=172418174]
[node name="Hob" unique_id=707500902 instance=ExtResource("1_2p1q6")]
[node name="StationMovement" parent="." unique_id=946873975 node_paths=PackedStringArray("station") instance=ExtResource("1_pydjp")]
[node name="StationMovement" parent="." index="0" unique_id=946873975 node_paths=PackedStringArray("station")]
station = NodePath("../Hob")
[node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="." unique_id=768992259]
replication_config = SubResource("SceneReplicationConfig_np_hob")
[node name="ProgressBar3D" parent="." index="4" unique_id=654673176]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.2, -0.18)
[node name="Hob" type="StaticBody3D" parent="." unique_id=1332123047 groups=["station"]]
script = ExtResource("1_7jc4g")
[node name="CollisionShape3D" type="CollisionShape3D" parent="Hob" unique_id=1283846023]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.51483154, 0)
shape = SubResource("BoxShape3D_kdxnr")
[node name="XRToolsSnapZone" type="Area3D" parent="Hob" unique_id=538157739 groups=["station_zone"]]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.0418437, 0)
collision_layer = 65536
collision_mask = 65540
script = ExtResource("2_er1dp")
stash_sound = ExtResource("3_6oyg1")
[node name="SnapZone" parent="." index="5" unique_id=1315859105]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.048892, 0)
snap_mode = 1
metadata/_custom_type_script = "uid://cquqe4f1m1sw6"
[node name="CollisionShape3D2" type="CollisionShape3D" parent="Hob/XRToolsSnapZone" unique_id=370920392]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.000975132, 0)
shape = SubResource("BoxShape3D_7uuqv")
[node name="Hob" type="StaticBody3D" parent="." index="6" unique_id=732560156 node_paths=PackedStringArray("animation_player", "notification_audio", "ambient_audio", "progress_bar", "snap_zone", "synchronizer") groups=["station"]]
script = ExtResource("1_7jc4g")
animation_player = NodePath("AnimationPlayer")
notification_audio = NodePath("../AudioStreamPlayer3DPulse")
ambient_audio = NodePath("../AudioStreamPlayer3DContinous")
progress_bar = NodePath("../ProgressBar3D")
snap_zone = NodePath("../SnapZone")
synchronizer = NodePath("../MultiplayerSynchronizer")
[node name="AudioStreamPlayer3D" type="AudioStreamPlayer3D" parent="Hob/XRToolsSnapZone" unique_id=1991627595]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.022546828, -0.5270121, 0.36528283)
stream = ExtResource("3_6oyg1")
[node name="CollisionShape3D" type="CollisionShape3D" parent="Hob" index="0" unique_id=3886639]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.51483154, 0)
shape = SubResource("BoxShape3D_l0sax")
[node name="ProgressBar3D" parent="Hob" unique_id=654673176 instance=ExtResource("3_7uuqv")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.2621956, -0.09216304)
[node name="CSGCombiner3D" type="CSGCombiner3D" parent="Hob" unique_id=70901698]
[node name="CSGCombiner3D" type="CSGCombiner3D" parent="Hob" index="1" unique_id=1047451362]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.51483154, 0)
[node name="CSGBox3D" type="CSGBox3D" parent="Hob/CSGCombiner3D" unique_id=1111505172]
[node name="CSGBox3D" type="CSGBox3D" parent="Hob/CSGCombiner3D" index="0" unique_id=797498087]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00071543455, 3.7252903e-09, -0.008516133)
size = Vector3(0.6, 1, 0.5821045)
[node name="CSGCylinder3D" type="CSGCylinder3D" parent="Hob/CSGCombiner3D/CSGBox3D" unique_id=1338463939]
[node name="CSGCylinder3D" type="CSGCylinder3D" parent="Hob/CSGCombiner3D/CSGBox3D" index="0" unique_id=1788217430]
transform = Transform3D(0.8943019, 0, 0, 0, 0.8943019, 0, 0, 0, 0.8943019, 0, 0.5103538, -7.827557e-05)
operation = 2
radius = 0.25976563
height = 0.08898926
sides = 32
[node name="CSGTorus3D3" type="CSGTorus3D" parent="Hob/CSGCombiner3D" unique_id=666891341]
[node name="CSGTorus3D3" type="CSGTorus3D" parent="Hob/CSGCombiner3D" index="1" unique_id=1365654856]
transform = Transform3D(0.8943019, 0, 0, 0, 0.8943019, 0, 0, 0, 0.8943019, 0, 0.5003869, -7.827557e-05)
inner_radius = 0.09153879
outer_radius = 0.120084204
sides = 32
material = ExtResource("4_8qpxk")
[node name="CSGTorus3D2" type="CSGTorus3D" parent="Hob/CSGCombiner3D" unique_id=24541894]
[node name="CSGTorus3D2" type="CSGTorus3D" parent="Hob/CSGCombiner3D" index="2" unique_id=2113291709]
transform = Transform3D(0.8943019, 0, 0, 0, 0.8943019, 0, 0, 0, 0.8943019, 0, 0.5003869, -7.827557e-05)
inner_radius = 0.15036294
outer_radius = 0.17592031
sides = 32
material = ExtResource("4_8qpxk")
[node name="CSGTorus3D" type="CSGTorus3D" parent="Hob/CSGCombiner3D" unique_id=1901978664]
[node name="CSGTorus3D" type="CSGTorus3D" parent="Hob/CSGCombiner3D" index="3" unique_id=196825717]
transform = Transform3D(0.8943019, 0, 0, 0, 0.8943019, 0, 0, 0, 0.8943019, 0, 0.5003869, -7.827557e-05)
inner_radius = 0.20426142
outer_radius = 0.2321898
sides = 32
material = ExtResource("4_8qpxk")
[node name="CSGCylinder3D" type="CSGCylinder3D" parent="Hob/CSGCombiner3D" unique_id=1107239311]
[node name="CSGCylinder3D" type="CSGCylinder3D" parent="Hob/CSGCombiner3D" index="4" unique_id=893001662]
transform = Transform3D(0.8943019, 0, 0, 0, 0.8943019, 0, 0, 0, 0.8943019, 0, 0.4498226, -7.827557e-05)
radius = 0.071777344
height = 0.09637451
sides = 32
[node name="CSGCylinder3D2" type="CSGCylinder3D" parent="Hob/CSGCombiner3D" unique_id=435540815]
[node name="CSGCylinder3D2" type="CSGCylinder3D" parent="Hob/CSGCombiner3D" index="5" unique_id=1086831704]
transform = Transform3D(0.8943019, 0, 0, 0, -3.9091177e-08, 0.8943019, 0, -0.8943019, -3.9091177e-08, 0, 0.48668858, -0.0020651226)
radius = 0.008
height = 0.44487303
[node name="CSGCylinder3D3" type="CSGCylinder3D" parent="Hob/CSGCombiner3D" unique_id=878171801]
[node name="CSGCylinder3D3" type="CSGCylinder3D" parent="Hob/CSGCombiner3D" index="6" unique_id=145519146]
transform = Transform3D(-3.9091177e-08, -0.8943019, -3.9091177e-08, 0, -3.9091177e-08, 0.8943019, -0.8943019, 3.9091177e-08, 1.7087296e-15, 0, 0.48668858, -0.0020651226)
radius = 0.008
height = 0.44487303
[node name="CSGCylinder3D4" type="CSGCylinder3D" parent="Hob/CSGCombiner3D" unique_id=1619646436]
[node name="CSGCylinder3D4" type="CSGCylinder3D" parent="Hob/CSGCombiner3D" index="7" unique_id=905149123]
transform = Transform3D(1, 0, 0, 0, -4.371139e-08, 1, 0, -1, -4.371139e-08, -0.20412213, 0.42728558, 0.26171687)
radius = 0.044433594
height = 0.10932617
material = SubResource("StandardMaterial3D_gkb3v")
material = SubResource("StandardMaterial3D_bmu77")
[node name="CSGCylinder3D5" type="CSGCylinder3D" parent="Hob/CSGCombiner3D" unique_id=548846612]
[node name="CSGCylinder3D5" type="CSGCylinder3D" parent="Hob/CSGCombiner3D" index="8" unique_id=2028954364]
transform = Transform3D(1, 0, 0, 0, -4.371139e-08, 1, 0, -1, -4.371139e-08, 0.12531614, 0.42728558, 0.26171687)
radius = 0.044433594
height = 0.10932617
material = SubResource("StandardMaterial3D_gkb3v")
material = SubResource("StandardMaterial3D_bmu77")
[node name="CSGCylinder3D6" type="CSGCylinder3D" parent="Hob/CSGCombiner3D" unique_id=1208989647]
[node name="CSGCylinder3D6" type="CSGCylinder3D" parent="Hob/CSGCombiner3D" index="9" unique_id=1588021797]
transform = Transform3D(1, 0, 0, 0, -4.371139e-08, 1, 0, -1, -4.371139e-08, 0.22979808, 0.42728558, 0.26171687)
radius = 0.044433594
height = 0.10932617
material = SubResource("StandardMaterial3D_gkb3v")
material = SubResource("StandardMaterial3D_bmu77")
[node name="CSGBox3D2" type="CSGBox3D" parent="Hob/CSGCombiner3D" unique_id=465340362]
[node name="CSGBox3D2" type="CSGBox3D" parent="Hob/CSGCombiner3D" index="10" unique_id=1620789236]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.039733887, -0.07685089, 0.29250562)
operation = 2
size = Vector3(1.0999756, 0.8462982, 0.072387695)
[node name="CSGBox3D3" type="CSGBox3D" parent="Hob/CSGCombiner3D" unique_id=1813079759]
[node name="CSGBox3D3" type="CSGBox3D" parent="Hob/CSGCombiner3D" index="11" unique_id=1140499039]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.003479004, -0.08253479, 0.2656765)
size = Vector3(0.55, 0.835, 0.072)
[node name="CSGBox3D4" type="CSGBox3D" parent="Hob/CSGCombiner3D" unique_id=1978186019]
[node name="CSGBox3D4" type="CSGBox3D" parent="Hob/CSGCombiner3D" index="12" unique_id=923397574]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.003479004, -0.45215607, 0.24655426)
size = Vector3(0.55, 0.096, 0.14)
[node name="AnimationPlayer" type="AnimationPlayer" parent="Hob" unique_id=1525460719]
[node name="AnimationPlayer" type="AnimationPlayer" parent="Hob" index="2" unique_id=1592340772]
root_node = NodePath("../..")
libraries/ = SubResource("AnimationLibrary_ac5f3")
libraries/ = SubResource("AnimationLibrary_pydjp")
[node name="OmniLight3D" type="OmniLight3D" parent="Hob" unique_id=1618457623]
[node name="OmniLight3D" type="OmniLight3D" parent="Hob" index="3" unique_id=2050713654]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.0201802, 0)
light_color = Color(1, 0.13725491, 0, 1)
light_energy = 0.0
+52 -113
View File
@@ -1,127 +1,66 @@
extends StaticBody3D
class_name Hob
extends WorkStation
@export var cook_speed = 1
@onready var snap_zone: XRToolsSnapZone = $XRToolsSnapZone
@onready var progress_bar: ProgressBar3D = $ProgressBar3D
## Cooking state. All three are replicated (see Hob.tscn's Sync node) and each
## refreshes the display when it changes, which is what makes the hob look alive
## on a client: only the world owner runs the station's _process and its snap
## zone, so a client never reaches the code below by itself and would otherwise
## show a hob that never lights up.
@export var time_cooked: float = 0.0: set = _set_time_cooked
@export var cooking_result: String = "": set = _set_cooking_result
@export var cooking_result_time: float = 0.0: set = _set_cooking_result_time
func _set_time_cooked(value: float) -> void:
if is_equal_approx(time_cooked, value):
return
time_cooked = value
_refresh_display()
func _set_cooking_result(value: String) -> void:
if cooking_result == value:
return
cooking_result = value
_refresh_display()
# The flames follow whether we're cooking, on every peer.
_play_animation("hob" if not cooking_result.is_empty() else "RESET")
func _set_cooking_result_time(value: float) -> void:
if is_equal_approx(cooking_result_time, value):
return
cooking_result_time = value
_refresh_display()
@export var animation_player: AnimationPlayer
func _ready() -> void:
if not progress_bar or progress_bar is not ProgressBar3D:
push_error("Hob missing reference to progressbar, or wrong type:", progress_bar)
snap_zone.has_picked_up.connect(_on_object_picked_up)
snap_zone.has_dropped.connect(_on_object_dropped)
_refresh_display()
super.ready()
SweetLogger.debug("Hob {0} _ready", [name])
if not animation_player:
SweetLogger.warning("{0} missing animation_player reference", [name])
func _play_animation(name: String) -> void:
# Replicated setters can fire before the node is in the tree (spawn payload),
# when the @onready children don't exist yet.
var player := get_node_or_null("AnimationPlayer") as AnimationPlayer
if player:
player.play(name)
func _refresh_display() -> void:
# Guarded for the same reason as _play_animation.
if not progress_bar:
return
var progress := 0.0
if cooking_result and cooking_result_time > 0:
progress = clampf(float(time_cooked) / cooking_result_time, 0.0, 1.0)
progress_bar.set_progress(progress)
progress_bar.set_bar_visible(not cooking_result.is_empty())
progress_bar.override_fill_color(Color.RED if cooking_result == "charcoal" else Color.GREEN)
func _on_object_picked_up(_item) -> void:
SweetLogger.debug("object picked up: {0}", [_item])
# Find the CookableItem in held object
var _food_item = _item.get_node_or_null("FoodItem") as FoodItem
if not _food_item:
SweetLogger.debug("held object is not a FoodItem")
return
var result = RecipeManager.get_cooking_result(_food_item.id)
if not result:
SweetLogger.debug("held a FoodItem that is not cookable, id: {0} result: {1}", [_food_item.id, result])
func _start_cooking(id: String, work: float) -> void:
animation_player.play("hob")
if not enabled:
return
cooking_result = result
cooking_result_time = RecipeManager.get_cooking_time(_food_item.id)
SweetLogger.debug("set cooking_result {0}", [cooking_result])
# The setters above already refresh the display and start the flames.
result_id = id
max_work = work
SweetLogger.info("Start cooking - result_id: {0}, max_work: {1}", [result_id, max_work])
# The flames follow whether we're cooking, on every peer.
func _on_object_dropped(_item) -> void:
SweetLogger.debug("object drop")
time_cooked = 0
cooking_result = ""
cooking_result_time = 0
func convert_held_to_item(_item: String) -> void:
if not NetworkManager.owns_world():
return
SweetLogger.debug("converting {0}", [_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
# 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 = NetworkManager.spawn_item(RecipeManager.get_item_scene(_item).resource_path, original_transform)
# Drop and free the old item and pick up the new one
SweetLogger.debug("freeing old_pickable {0}", [old_pickable])
snap_zone.drop_object()
NetworkManager.despawn_item(old_pickable)
snap_zone.pick_up_object(new_scene_instance)
# If cooking something, progress cooking, when done, convert item
func _process(delta: float) -> void:
if cooking_result:
#print("Hob cooking_result: ", cooking_result)
time_cooked += cook_speed * delta
_refresh_display()
if time_cooked >= cooking_result_time:
time_cooked = 0
convert_held_to_item(cooking_result)
super.process(delta)
if not enabled:
return
if result_id:
add_work(cook_speed * delta)
# Called from Station base class
func refresh_display() -> void:
super.refresh_display()
progress_bar.override_fill_color(Color.RED if result_id == "charcoal" else Color.GREEN)
# Called from Station base class
func on_food_item_picked_up(food_item: FoodItem) -> void:
SweetLogger.debug("Object picked up: {0}", [food_item])
if not food_item:
SweetLogger.debug("Held object is not a FoodItem")
return
var result = RecipeManager.get_cooking_result(food_item.id)
if not result:
SweetLogger.debug("Held a FoodItem that is not cookable, id: {0} result: {1}", [food_item.id, result])
return
_start_cooking(result, RecipeManager.get_cooking_time(food_item.id))
# Called from Station base class
func on_food_item_dropped(_food_item: FoodItem):
SweetLogger.debug("->[]")
animation_player.play("RESET")
reset()
# Called from Station base class
func on_work_complete():
SweetLogger.debug("->[]")
animation_player.play("RESET")
convert_item()
+8 -8
View File
@@ -37,7 +37,7 @@ func _on_station_bought(_instance: Node3D):
set_move_handle_enabled(true)
func _ready() -> void:
SweetLogger.debug("enter")
SweetLogger.debug("->[]")
if not station:
push_error("StationMovement is missing referece to station")
if not move_handle:
@@ -105,7 +105,7 @@ func _apply_visibility_state(ghost_visible: bool, station_visible: bool) -> void
func _handle_pickup(_by: Node) -> void:
SweetLogger.info("handle pickup")
SweetLogger.debug("->[]")
if move_handle.get_picked_up_by() and move_handle.get_picked_up_by() is XRToolsSnapZone:
SweetLogger.info("handle pickup by snap zone, dropping and resetting position")
move_handle.drop()
@@ -186,7 +186,7 @@ func _is_move_position_valid() -> bool:
@rpc("any_peer", "call_local", "reliable")
func server_handle_drop(new_transform: Transform3D, client_thinks_valid: bool):
SweetLogger.debug("enter")
SweetLogger.debug("->[]")
if not multiplayer.is_server():
return
if not (client_thinks_valid):
@@ -213,33 +213,33 @@ func server_handle_drop(new_transform: Transform3D, client_thinks_valid: bool):
@rpc("any_peer", "call_local", "reliable") # Server updates clients
func server_artificial_pickup():
SweetLogger.debug("enter")
SweetLogger.debug("->[]")
_handle_pickup(self) # Arg is not used, but required of the signal.
@rpc("any_peer", "call_local", "reliable") # Server updates clients
func server_update_station_transform(new_transform: Transform3D) -> void:
SweetLogger.debug("entered")
SweetLogger.debug("->[]")
station.global_transform = new_transform
original_station_transform = new_transform
@rpc("any_peer", "call_local", "reliable") # Server updates clients
func server_update_handle_transform(new_transform: Transform3D) -> void:
SweetLogger.debug("entered")
SweetLogger.debug("->[]")
move_handle.global_transform = new_transform
@rpc("any_peer", "call_local", "reliable")
func server_update_visibility(ghost_visible: bool, station_visible: bool) -> void:
SweetLogger.debug("entered")
SweetLogger.debug("->[]")
move_ghost.visible = ghost_visible
station.visible = station_visible
@rpc("any_peer", "call_local", "unreliable")
func server_update_move_ghost_transform(new_transform: Transform3D, new_color: Color = GHOST_COLOR_VALID) -> void:
SweetLogger.debug("entered")
SweetLogger.debug("->[]")
move_ghost.global_transform = new_transform
_set_ghost_color(new_color)
+1 -1
View File
@@ -385,7 +385,7 @@ func _refresh_display() -> void:
func _process(delta: float) -> void:
_refresh_display()
_place_order_if_player()
SweetLogger.error("State {0} time: {1} duration: {2}", [TableState.keys()[_state], _state_time, _state_duration])
#SweetLogger.error("State {0} time: {1} duration: {2}", [TableState.keys()[_state], _state_time, _state_duration])
if not NetworkManager.owns_world():
SweetLogger.error("Is not server, return")
+1 -1
View File
@@ -1,6 +1,6 @@
[gd_resource type="StandardMaterial3D" format=3 uid="uid://cmia50cfqxxo4"]
[ext_resource type="Texture2D" uid="uid://di387qcr5vmsp" path="res://Textures/devTex.svg" id="1_3jxsn"]
[ext_resource type="Texture2D" uid="uid://di387qcr5vmsp" path="res://textures/devTex.svg" id="1_3jxsn"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_0gbf8"]
transparency = 1
+1 -1
View File
@@ -1,6 +1,6 @@
[gd_resource type="Sky" format=3 uid="uid://c1abtpwhdm2d5"]
[ext_resource type="Texture2D" uid="uid://bsuhedl8ltapa" path="res://Textures/sky/NightSkyHDRI009_16K_HDR.exr" id="acg_mft3ic9d"]
[ext_resource type="Texture2D" uid="uid://bsuhedl8ltapa" path="res://textures/sky/NightSkyHDRI009_16K_HDR.exr" id="acg_mft3ic9d"]
[sub_resource type="PanoramaSkyMaterial" id="acg_025sfqr4"]
panorama = ExtResource("acg_mft3ic9d")
+9 -9
View File
@@ -3,21 +3,21 @@
[ext_resource type="Script" uid="uid://xrfp03b32j1t" path="res://UI/shop_ui.gd" id="1_2k6ie"]
[ext_resource type="PackedScene" uid="uid://u7rpukx5ebqo" path="res://UI/shop_station_panel.tscn" id="1_pogqh"]
[ext_resource type="PackedScene" uid="uid://efaec6ymgabo" path="res://stations/Counter.tscn" id="2_35otv"]
[ext_resource type="Texture2D" uid="uid://c0nd4nh4vja73" path="res://textures/shop/counter.png" id="3_74fni"]
[ext_resource type="PackedScene" uid="uid://j7caslh27nor" path="res://stations/Hob.tscn" id="4_l3qkl"]
[ext_resource type="Texture2D" uid="uid://ejby14dl1svr" path="res://textures/shop/hob.png" id="5_2k6ie"]
[ext_resource type="Texture2D" uid="uid://dhja7i8tgb3ao" path="res://textures/shop/counter.png" id="3_74fni"]
[ext_resource type="PackedScene" uid="uid://j7caslh27nor" path="res://stations/Hob_old.tscn" id="4_l3qkl"]
[ext_resource type="Texture2D" uid="uid://br4ytiocwouqh" path="res://textures/shop/hob.png" id="5_2k6ie"]
[ext_resource type="PackedScene" uid="uid://dvrk268s7gkxh" path="res://stations/sink.tscn" id="6_rktus"]
[ext_resource type="Texture2D" uid="uid://ecdu0qqhib4" path="res://textures/shop/sink.png" id="7_4titf"]
[ext_resource type="Texture2D" uid="uid://gi6bksvs8ybx" path="res://textures/shop/sink.png" id="7_4titf"]
[ext_resource type="PackedScene" uid="uid://caf0xanmxbshy" path="res://stations/table.tscn" id="9_84wnh"]
[ext_resource type="PackedScene" uid="uid://cwnwo4i28upap" path="res://stations/raw_burger_dispenser.tscn" id="9_vl3v4"]
[ext_resource type="Texture2D" uid="uid://dpaqhbpmk7exf" path="res://textures/shop/raw_burger.png" id="10_rkek4"]
[ext_resource type="Texture2D" uid="uid://cv3grgonwlakt" path="res://textures/shop/table.png" id="10_sb5p3"]
[ext_resource type="Texture2D" uid="uid://b57nybt7her3k" path="res://textures/shop/raw_burger.png" id="10_rkek4"]
[ext_resource type="Texture2D" uid="uid://dp4ccvp2xgpqy" path="res://textures/shop/table.png" id="10_sb5p3"]
[ext_resource type="PackedScene" uid="uid://c6rift56ql3f8" path="res://stations/BurgerBunsDispenser.tscn" id="11_4m5wg"]
[ext_resource type="Texture2D" uid="uid://bmomecu0058xg" path="res://textures/shop/burger_buns.png" id="12_84wnh"]
[ext_resource type="Texture2D" uid="uid://4p7i3p3ox3qi" path="res://textures/shop/burger_buns.png" id="12_84wnh"]
[ext_resource type="PackedScene" uid="uid://ck5tuftqmyiue" path="res://stations/plate_dispenser.tscn" id="13_4m5wg"]
[ext_resource type="Texture2D" uid="uid://cjrwhtsjjhtu7" path="res://textures/shop/plates.png" id="14_84wnh"]
[ext_resource type="Texture2D" uid="uid://ouqlicmcjay3" path="res://textures/shop/plates.png" id="14_84wnh"]
[ext_resource type="PackedScene" uid="uid://sc6i0i1f0o48" path="res://stations/potato_dispenser.tscn" id="17_pdan6"]
[ext_resource type="Texture2D" uid="uid://blekcmdjkxs0q" path="res://textures/shop/potatoes.png" id="18_6lkkh"]
[ext_resource type="Texture2D" uid="uid://br4y6kq8w3usi" path="res://textures/shop/potatoes.png" id="18_6lkkh"]
[sub_resource type="LabelSettings" id="LabelSettings_vlqg6"]
font_size = 35
+115
View File
@@ -0,0 +1,115 @@
class_name Station
extends Node3D
### Abstract 'class', should never be instantiated ###
# - Keep all logic all stations share.
# - Contain as much of the networking code syncing stations as possible.
## Sounds
@export var pickup_sound: AudioStream
@export var drop_sound: AudioStream
## Node references. These are all required snd should be set in the inspector
@export var snap_zone: XRToolsSnapZone
@export var synchronizer: MultiplayerSynchronizer
var sync_config: SceneReplicationConfig
var enabled: bool: # When disabled the station only updated display and sounds.
get: return snap_zone.enabled
set(p_enabled):
SweetLogger.info("Set enabled {0} on station {1} on client {2}", [p_enabled, name, multiplayer.get_unique_id()])
snap_zone.enabled = p_enabled
snap_zone.set_process(p_enabled)
# The child station has to call super.ready() for this to be called
func ready() -> void:
SweetLogger.debug("Station {0} ready", [name])
if not snap_zone:
SweetLogger.warning("{0} missing snap_zone reference", [name])
if not synchronizer:
SweetLogger.warning("{0} missing synchronizer reference", [name])
# Disable if we're not the server.
if not NetworkManager.owns_world():
enabled = false
snap_zone.has_picked_up.connect(_on_object_picked_up_handler)
snap_zone.has_dropped.connect(_on_object_dropped_handler)
# Configure Multiplayer Syncronizer
# This overwrites any changes made in the inspector.
synchronizer.root_path = get_path()
synchronizer.replication_config = SceneReplicationConfig.new()
sync_config = synchronizer.replication_config
# The child station has to call super.process(delta) for this to be called
func process(_delta: float) -> void:
refresh_display()
## Signal handles ##
func _on_object_picked_up_handler(item: Node3D) -> void:
if not NetworkManager.owns_world():
return
_clients_on_object_picked_up_handler.rpc(item.get_path())
_apply_object_picked_up(item)
func _on_object_dropped_handler(item: Node3D) -> void:
if not NetworkManager.owns_world():
return
_clients_on_object_dropped_handler.rpc(item.get_path())
_apply_object_dropped(item)
func _apply_object_picked_up(item: Node3D) -> void:
SweetLogger.debug("Pickup: {0}", [item.name])
on_object_picked_up(item)
var food_item = Helper.find_food_item(item)
if food_item:
on_food_item_picked_up(food_item)
func _apply_object_dropped(item: Node3D) -> void:
SweetLogger.debug("Drop: {0}", [item.name])
on_object_dropped(item)
var food_item = Helper.find_food_item(item)
if food_item:
on_food_item_dropped(food_item)
# Propagate events to clients
@rpc("authority", "call_remote", "reliable")
func _clients_on_object_picked_up_handler(item_path: NodePath):
var item := Helper.get_node_from_path(self, item_path) as Node3D
if not item:
return
_apply_object_picked_up(item)
@rpc("authority", "call_remote", "reliable")
func _clients_on_object_dropped_handler(item_path: NodePath):
var item := Helper.get_node_from_path(self, item_path) as Node3D
if not item:
return
_apply_object_dropped(item)
## Virutal methods
# The child station implements these if it cares about them.
func on_object_picked_up(_item: Node3D) -> void:
SweetLogger.debug("Not implemented in {0}", [name])
func on_object_dropped(_item: Node3D) -> void:
SweetLogger.debug("Not implemented in {0}", [name])
func on_food_item_picked_up(_food_item: FoodItem) -> void:
SweetLogger.debug("Not implemented in {0}", [name])
func on_food_item_dropped(_food_item: FoodItem) -> void:
SweetLogger.debug("Not implemented in {0}", [name])
func refresh_display() -> void:
pass
+1
View File
@@ -0,0 +1 @@
uid://1ii5ov17p2p6
+23
View File
@@ -0,0 +1,23 @@
[gd_scene format=3 uid="uid://cbs8jiqe8rcmn"]
[ext_resource type="PackedScene" uid="uid://cvucwxibtol5f" path="res://stations/StationMovement.tscn" id="1_yuo1j"]
[ext_resource type="PackedScene" uid="uid://bxbocxdaayvwx" path="res://UI/progress_bar.tscn" id="2_be8yi"]
[ext_resource type="PackedScene" uid="uid://ce7vysyvondf8" path="res://addons/godot-xr-tools/objects/snap_zone.tscn" id="3_be8yi"]
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_0o2ds"]
[node name="Station" type="Node3D" unique_id=707500902]
[node name="StationMovement" parent="." unique_id=946873975 instance=ExtResource("1_yuo1j")]
[node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="." unique_id=1536666704]
replication_config = SubResource("SceneReplicationConfig_0o2ds")
[node name="AudioStreamPlayer3DPulse" type="AudioStreamPlayer3D" parent="." unique_id=1976975302]
[node name="AudioStreamPlayer3DContinous" type="AudioStreamPlayer3D" parent="." unique_id=925832848]
[node name="ProgressBar3D" parent="." unique_id=654673176 instance=ExtResource("2_be8yi")]
[node name="SnapZone" parent="." unique_id=1315859105 groups=["station_zone"] instance=ExtResource("3_be8yi")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
+128
View File
@@ -0,0 +1,128 @@
class_name WorkStation
extends Station
### Abstract 'class', should never be instantiated ###
# This script serves two main jobs:
# - Keep all logic all workstations (sink, hob...) share.
# - Contain as much of the networking code syncing stations as possible.
## Sounds
@export var process_sound: AudioStream
@export var complete_sound: AudioStream
## Node references. These are all required snd should be set in the inspector
@export var notification_audio: AudioStreamPlayer3D # Short sounds like pickup or complete
@export var ambient_audio: AudioStreamPlayer3D # Releating sounds like a cooking noise
@export var progress_bar: ProgressBar3D
## Synced by MultiplayerSyncronizer ##
var current_work: float # How far a FoodItem conversion is toward completion
var max_work: float # How much work has to be acheived to trigger conversion
var result_id: String # Station active if not empty. What FoodItem id the conversion turns the current FoodItem into.
# The child station has to call super.ready() for this to be called
func ready() -> void:
super.ready()
if not notification_audio:
SweetLogger.warning("{0} missing notification_audio reference", [name])
if not ambient_audio:
SweetLogger.warning("{0} missing ambient_audio reference", [name])
if not progress_bar:
SweetLogger.warning("{0} missing progress_bar reference", [name])
# Configure Multiplayer Syncronizer
# Base Station creates the config, here we append to it:
var properties: Array[NodePath] = [ ".:current_work", ".:max_work", ".:result_id"]
for property_path in properties:
sync_config.add_property(property_path)
sync_config.property_set_spawn(property_path, false)
sync_config.property_set_replication_mode(property_path, SceneReplicationConfig.REPLICATION_MODE_ON_CHANGE)
# The child station has to call super.process(delta) for this to be called
func process(delta: float) -> void:
super.process(delta)
#SweetLogger.debug("station process result_id: {0}, work: {1}, max_work: {2}", [result_id, current_work, max_work])
refresh_display()
# Propagate events to clients
@rpc("authority", "call_local", "reliable")
func _everyone_on_work_complete():
on_work_complete()
## Virutal methods ##
# The child station implements these if it cares about them.
func on_work_complete() -> void:
SweetLogger.debug("Not implemented in {0}", [name])
# The child station has to call super.refresh_display for this to be called
func refresh_display() -> void:
super.refresh_display()
var is_active: bool = not result_id.is_empty()
progress_bar.set_bar_visible(is_active)
progress_bar.set_progress((current_work / max_work) if is_active else 0.0)
## Public methods ##
# Will be called by clients to the server, and server to server
func add_work(work: float) -> void:
SweetLogger.debug("Add work: {0} current: {1} max_work: {2}", [snappedf(work, 0.01), snappedf(current_work, 0.01), snappedf(max_work, 0.01)])
if work <= 0:
SweetLogger.warning("Work to add must be positive, work: {0}", [work])
return
if not NetworkManager.owns_world:
server_add_work(work)
return
if not result_id or result_id.is_empty():
SweetLogger.warning("Work can not be added when result_id is empty")
return
current_work += work
if current_work >= max_work:
_everyone_on_work_complete()
@rpc("any_peer", "call_remote", "reliable")
func server_add_work(work: float) -> void:
add_work(work)
# Converts the currenly held item into result_id, by despawning it and instantiating a new item
func convert_item() -> Node3D:
if not NetworkManager.owns_world():
return
SweetLogger.info("Convert item, result_id: {0}", [result_id])
if not NetworkManager.owns_world:
SweetLogger.warning("Only the server should ever call this!")
return null
if not result_id or result_id.is_empty():
SweetLogger.warning("Station tried to convert item, but result_id is null or empty!")
return
var old_pickable = snap_zone.picked_up_object
if not old_pickable:
SweetLogger.warning("Station tried to convert item, but item is missing!")
return null
var target_id := result_id
var original_transform = old_pickable.global_transform
var new_scene_instance = NetworkManager.spawn_item(RecipeManager.get_item_scene(target_id).resource_path, original_transform)
reset()
# Drop and free the old item and pick up the new one
SweetLogger.debug("Freeing old_pickable {0}", [old_pickable])
snap_zone.drop_object()
NetworkManager.despawn_item(old_pickable)
snap_zone.pick_up_object(new_scene_instance)
SweetLogger.info("Convert item into id: {0}, node name: {1}", [target_id, new_scene_instance.name])
return new_scene_instance
func reset() -> void:
SweetLogger.debug("->[]")
current_work = 0
max_work = 0
result_id = ""
+1
View File
@@ -0,0 +1 @@
uid://b25s3bhslrlxc
Binary file not shown.
+1 -1
View File
@@ -1,7 +1,7 @@
[gd_scene format=3 uid="uid://bu6jt26pq2y0k"]
[ext_resource type="PackedScene" uid="uid://q37nqadkibbp" path="res://environment/door.tscn" id="1_hgrxd"]
[ext_resource type="PackedScene" uid="uid://j7caslh27nor" path="res://stations/Hob.tscn" id="1_p8umn"]
[ext_resource type="PackedScene" uid="uid://j7caslh27nor" path="res://stations/Hob_old.tscn" id="1_p8umn"]
[ext_resource type="PackedScene" uid="uid://caf0xanmxbshy" path="res://stations/table.tscn" id="2_d63j6"]
[ext_resource type="PackedScene" uid="uid://dlw5geheupgpt" path="res://stations/hatch.tscn" id="3_d63j6"]
[ext_resource type="PackedScene" uid="uid://da6yrsnxvsrif" path="res://environment/wall.tscn" id="4_41vpv"]
+3 -3
View File
@@ -1,6 +1,6 @@
[gd_scene format=3 uid="uid://damrxtlt7uswf"]
[ext_resource type="PackedScene" uid="uid://j7caslh27nor" path="res://stations/Hob.tscn" id="1_1wuvq"]
[ext_resource type="PackedScene" uid="uid://b052o1fgwq5bw" path="res://stations/Hob.tscn" id="1_1wuvq"]
[ext_resource type="PackedScene" uid="uid://efaec6ymgabo" path="res://stations/Counter.tscn" id="2_3qwcq"]
[ext_resource type="PackedScene" uid="uid://dvrk268s7gkxh" path="res://stations/sink.tscn" id="3_3qwcq"]
[ext_resource type="PackedScene" uid="uid://c6rift56ql3f8" path="res://stations/BurgerBunsDispenser.tscn" id="4_5eled"]
@@ -10,8 +10,6 @@
[node name="SmallLine" type="Node3D" unique_id=1844128818]
[node name="Hob" parent="." unique_id=1687971542 instance=ExtResource("1_1wuvq")]
[node name="Counter" parent="." unique_id=1487893288 instance=ExtResource("2_3qwcq")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.6, 0, 0)
@@ -29,3 +27,5 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.8000001, 0, 0)
[node name="Table" parent="." unique_id=987495548 instance=ExtResource("7_0342k")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -2.4, 0, 1.2)
[node name="Hob" parent="." unique_id=707500902 instance=ExtResource("1_1wuvq")]
+16
View File
@@ -1,4 +1,20 @@
### Station inheritence suggestion
Station
WorkStation (performs work on a food item to convert it)
Hob
Sink
Counter
StorageStation (one snap zone and list of positions, FILO item dispenser, like a gun magazine)
Shelf
PlateRak
Dishwasher
SharedInventoryStation (one snap zone, shares a list of connected stations with which items exist in each of them)
Table
Belt
Dispenser
### Multiplayer bugs
- despan flicker for clien broken
- client keep autorityu of thrown object until lands
- in build mode, snap zones off, stations disabled
+7
View File
@@ -46,3 +46,10 @@ static func get_snapped_transform(node: Node3D) -> Transform3D:
var target_yaw: float = snappedf(node.global_rotation_degrees.y, 90)
new_transform.basis = Basis(Vector3.UP, deg_to_rad(target_yaw))
return new_transform
static func get_node_from_path(from: Node, node_path: NodePath) -> Node3D:
var item := from.get_node_or_null(node_path) as Node3D
if not item:
SweetLogger.warning("Could not resolve node from node_path: {0}, are the trees in sync?", [node_path])
return null
return item
+1
View File
@@ -53,6 +53,7 @@ station="Hobs, Counters ..."
table="all nodes with table script"
chopping_tool="A pickable body that chops"
persistent_inventory="A station that keeps it's held items in build mode"
station_zone="The snap_zone node on stations should have this"
[input]
+1 -1
View File
@@ -4,7 +4,7 @@
[ext_resource type="PackedScene" uid="uid://j5s5wus7tuhb" path="res://prefabs/XROrigin.tscn" id="2_j7vd1"]
[ext_resource type="Material" uid="uid://cmia50cfqxxo4" path="res://textures/dev_material_3d.tres" id="3_ssbaf"]
[ext_resource type="Sky" uid="uid://c1abtpwhdm2d5" path="res://textures/sky/NightSkyHDRI009_16K.tres" id="4_081u3"]
[ext_resource type="PackedScene" uid="uid://j7caslh27nor" path="res://stations/Hob.tscn" id="5_t1fa7"]
[ext_resource type="PackedScene" uid="uid://j7caslh27nor" path="res://stations/Hob_old.tscn" id="5_t1fa7"]
[ext_resource type="PackedScene" uid="uid://dvrk268s7gkxh" path="res://stations/sink.tscn" id="6_6jhmh"]
[ext_resource type="PackedScene" uid="uid://bp3v1jl8pctro" path="res://Containers/plate.tscn" id="7_bowes"]
[ext_resource type="PackedScene" uid="uid://cnjwtnhwh0i8q" path="res://stations/dirt_station.tscn" id="8_pvl84"]