From 6933e17f3a256ff106a96d5683c00978f42af780 Mon Sep 17 00:00:00 2001 From: JonShard Date: Wed, 29 Jul 2026 13:41:16 +0200 Subject: [PATCH] Simplified Network manager WIP --- Scenes/main.tscn | 96 ---------- Scenes/main_menu.tscn | 3 +- Scenes/multiPlayer.tscn | 55 +++--- Stations/csg_box_3d.tscn | 3 - UI/main_menu_panel.gd | 20 +-- UI/main_menu_panel.tscn | 77 ++++---- .../objects/viewport_2d_in_3d.tscn | 23 +-- content/kitchen_layouts/small_line.tscn | 27 +++ project.godot | 2 + recipes.yaml.uid | 1 - scripts/add_spawnables.gd | 10 -- scripts/add_spawnables.gd.uid | 1 - scripts/main.gd | 6 +- scripts/network_manager.gd | 169 ++++++++++++++++++ scripts/network_manager.gd.uid | 1 + 15 files changed, 299 insertions(+), 195 deletions(-) delete mode 100644 Scenes/main.tscn delete mode 100644 Stations/csg_box_3d.tscn create mode 100644 content/kitchen_layouts/small_line.tscn delete mode 100644 recipes.yaml.uid delete mode 100644 scripts/add_spawnables.gd delete mode 100644 scripts/add_spawnables.gd.uid create mode 100644 scripts/network_manager.gd create mode 100644 scripts/network_manager.gd.uid diff --git a/Scenes/main.tscn b/Scenes/main.tscn deleted file mode 100644 index 6d06a80..0000000 --- a/Scenes/main.tscn +++ /dev/null @@ -1,96 +0,0 @@ -[gd_scene format=3 uid="uid://clw8ai6kngqxb"] - -[ext_resource type="Script" uid="uid://b4ldkd3ngs0vp" path="res://scripts/main.gd" id="1_0xm2m"] -[ext_resource type="PackedScene" uid="uid://j5s5wus7tuhb" path="res://prefabs/xr_origin.tscn" id="2_h2yge"] -[ext_resource type="Material" uid="uid://cmia50cfqxxo4" path="res://textures/dev_material_3d.tres" id="3_272bh"] -[ext_resource type="PackedScene" uid="uid://e4i6o5oriecx" path="res://items/pickupcube.tscn" id="3_h2yge"] -[ext_resource type="PackedScene" uid="uid://j7caslh27nor" path="res://stations/Hob.tscn" id="3_lquwl"] -[ext_resource type="PackedScene" uid="uid://efaec6ymgabo" path="res://stations/Counter.tscn" id="4_7mycd"] -[ext_resource type="Sky" uid="uid://c1abtpwhdm2d5" path="res://textures/sky/NightSkyHDRI009_16K.tres" id="6_7mycd"] -[ext_resource type="PackedScene" uid="uid://dpot5qie20vf6" path="res://items/burger.tscn" id="8_5vw27"] -[ext_resource type="PackedScene" uid="uid://bp3v1jl8pctro" path="res://containers/plate.tscn" id="9_kek77"] - -[sub_resource type="BoxShape3D" id="BoxShape3D_vlqg6"] -size = Vector3(5, 0.1, 5) - -[sub_resource type="BoxMesh" id="BoxMesh_24d3s"] -material = ExtResource("3_272bh") -size = Vector3(5, 0.1, 5) - -[sub_resource type="Environment" id="Environment_bvwq1"] -background_mode = 2 -sky = ExtResource("6_7mycd") -reflected_light_source = 2 -tonemap_mode = 3 -ssr_enabled = true -ssao_enabled = true -ssil_enabled = true -sdfgi_enabled = true - -[sub_resource type="BoxShape3D" id="BoxShape3D_kek77"] -size = Vector3(5.1, 10, 0.1) - -[node name="Main" type="Node3D" unique_id=1312265607] -script = ExtResource("1_0xm2m") - -[node name="XROrigin3D" parent="." unique_id=2055526621 instance=ExtResource("2_h2yge")] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.8820953, 0) - -[node name="DirectionalLight3D" type="DirectionalLight3D" parent="." unique_id=1376644384] -transform = Transform3D(-0.8660254, -0.43301278, 0.24999999, 0.3022632, -0.05510214, 0.9516306, -0.39829266, 0.8997021, 0.17860365, 0, 0, 0) - -[node name="Floor" type="StaticBody3D" parent="." unique_id=122279514] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.05, 0) - -[node name="CollisionShape3D" type="CollisionShape3D" parent="Floor" unique_id=958841648] -shape = SubResource("BoxShape3D_vlqg6") - -[node name="MeshInstance3D" type="MeshInstance3D" parent="Floor/CollisionShape3D" unique_id=1939997056] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00018164515, 0.0006352663, -0.002532661) -mesh = SubResource("BoxMesh_24d3s") - -[node name="Hob" parent="." unique_id=1687971542 instance=ExtResource("3_lquwl")] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.29336345, 0.8981018, -1.484) - -[node name="Counter" parent="." unique_id=1487893288 instance=ExtResource("4_7mycd")] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.73186195, 0.8981018, -1.484) - -[node name="PickableObject" parent="." unique_id=1675596942 instance=ExtResource("3_h2yge")] -transform = Transform3D(1, 0, -2.2351742e-08, -2.9802322e-08, 1.0000001, 0, -2.6077032e-08, 1.4901161e-08, 1, -0.70505303, 1.5761534, -1.0317149) - -[node name="PickableObject2" parent="." unique_id=713087634 instance=ExtResource("3_h2yge")] -transform = Transform3D(1, 0, -2.2351742e-08, -2.9802322e-08, 1.0000001, 0, -2.6077032e-08, 1.4901161e-08, 1, 0.28315204, 1.5607953, -1.0657519) - -[node name="WorldEnvironment" type="WorldEnvironment" parent="." unique_id=1177077250] -environment = SubResource("Environment_bvwq1") - -[node name="OmniLight3D" type="OmniLight3D" parent="." unique_id=812168256] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.2856425, 1.4939771, -1.4959787) -visible = false -light_color = Color(1, 0.38431373, 0, 1) -light_energy = 1.784 -shadow_enabled = true - -[node name="burger" parent="." unique_id=1554047278 instance=ExtResource("8_5vw27")] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.482068, -1.2252241) - -[node name="Plate" parent="." unique_id=190487773 instance=ExtResource("9_kek77")] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.22971058, 1.699144, -1.8499806) - -[node name="StaticBody3D" type="StaticBody3D" parent="." unique_id=82945083] - -[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D" unique_id=1909896160] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 4.688614, 2.5070028) -shape = SubResource("BoxShape3D_kek77") - -[node name="CollisionShape3D2" type="CollisionShape3D" parent="StaticBody3D" unique_id=39538720] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 4.688614, -2.5446289) -shape = SubResource("BoxShape3D_kek77") - -[node name="CollisionShape3D3" type="CollisionShape3D" parent="StaticBody3D" unique_id=1984048740] -transform = Transform3D(-4.371139e-08, 0, -1, 0, 1, 0, 1, 0, -4.371139e-08, -2.525816, 4.688614, -0.018813243) -shape = SubResource("BoxShape3D_kek77") - -[node name="CollisionShape3D4" type="CollisionShape3D" parent="StaticBody3D" unique_id=1484088721] -transform = Transform3D(-4.371139e-08, 0, -1, 0, 1, 0, 1, 0, -4.371139e-08, 2.525816, 4.688614, -0.018813023) -shape = SubResource("BoxShape3D_kek77") diff --git a/Scenes/main_menu.tscn b/Scenes/main_menu.tscn index d211d06..0ad570d 100644 --- a/Scenes/main_menu.tscn +++ b/Scenes/main_menu.tscn @@ -4,7 +4,7 @@ [ext_resource type="Sky" uid="uid://c1abtpwhdm2d5" path="res://textures/sky/NightSkyHDRI009_16K.tres" id="2_rtw2f"] [ext_resource type="PackedScene" uid="uid://j5s5wus7tuhb" path="res://prefabs/xr_origin.tscn" id="3_tbmy8"] [ext_resource type="PackedScene" uid="uid://clujaf3u776a3" path="res://addons/godot-xr-tools/objects/viewport_2d_in_3d.tscn" id="4_jk1qb"] -[ext_resource type="PackedScene" path="res://ui/main_menu_panel.tscn" id="5_rtw2f"] +[ext_resource type="PackedScene" uid="uid://jispfagyh1di" path="res://ui/main_menu_panel.tscn" id="5_rtw2f"] [ext_resource type="Material" uid="uid://cmia50cfqxxo4" path="res://textures/dev_material_3d.tres" id="6_oa1go"] [sub_resource type="Environment" id="Environment_bvwq1"] @@ -37,7 +37,6 @@ transform = Transform3D(5, 0, 0, 0, 5, 0, 0, 0, 5, 0.36171648, 2.0238447, -1.975 screen_size = Vector2(0.6, 0.4) scene = ExtResource("5_rtw2f") viewport_size = Vector2(600, 400) -transparent = 1 scene_properties_keys = PackedStringArray("main_menu_panel.gd") [node name="DirectionalLight3D" type="DirectionalLight3D" parent="." unique_id=1376644384] diff --git a/Scenes/multiPlayer.tscn b/Scenes/multiPlayer.tscn index 128383c..5cf3e39 100644 --- a/Scenes/multiPlayer.tscn +++ b/Scenes/multiPlayer.tscn @@ -1,5 +1,6 @@ [gd_scene format=3 uid="uid://c30i6h32w8p47"] +[ext_resource type="Script" uid="uid://b4ldkd3ngs0vp" path="res://scripts/main.gd" id="1_4vwpp"] [ext_resource type="PackedScene" uid="uid://j5s5wus7tuhb" path="res://prefabs/xr_origin.tscn" id="1_pjkx2"] [ext_resource type="Material" uid="uid://cmia50cfqxxo4" path="res://textures/dev_material_3d.tres" id="2_pjkx2"] [ext_resource type="Sky" uid="uid://c1abtpwhdm2d5" path="res://textures/sky/NightSkyHDRI009_16K.tres" id="3_4vwpp"] @@ -11,6 +12,9 @@ size = Vector3(15, 0.1, 15) material = ExtResource("2_pjkx2") size = Vector3(15, 0.1, 15) +[sub_resource type="BoxShape3D" id="BoxShape3D_arao0"] +size = Vector3(15, 20, 0.1) + [sub_resource type="Environment" id="Environment_bvwq1"] background_mode = 2 sky = ExtResource("3_4vwpp") @@ -20,10 +24,8 @@ ssao_enabled = true ssil_enabled = true sdfgi_enabled = true -[sub_resource type="BoxShape3D" id="BoxShape3D_arao0"] -size = Vector3(15, 20, 0.1) - [node name="Main" type="Node3D" unique_id=1312265607] +script = ExtResource("1_4vwpp") [node name="XROrigin3D" parent="." unique_id=2055526621 groups=["local_xr_origin"] instance=ExtResource("1_pjkx2")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.36171648, 0, 0.81835127) @@ -41,34 +43,41 @@ shape = SubResource("BoxShape3D_vlqg6") transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00018164515, 0.0006352663, -0.002532661) mesh = SubResource("BoxMesh_24d3s") +[node name="InvisibleWalls" type="StaticBody3D" parent="." unique_id=4404969] + +[node name="CollisionShape3D" type="CollisionShape3D" parent="InvisibleWalls" unique_id=998476672] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 9.197384, 7.589958) +shape = SubResource("BoxShape3D_arao0") + +[node name="CollisionShape3D2" type="CollisionShape3D" parent="InvisibleWalls" unique_id=340303902] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 9.197384, -7.509142) +shape = SubResource("BoxShape3D_arao0") + +[node name="CollisionShape3D3" type="CollisionShape3D" parent="InvisibleWalls" unique_id=1193703037] +transform = Transform3D(-4.371139e-08, 0, -1, 0, 1, 0, 1, 0, -4.371139e-08, -7.438612, 9.197384, -0.018813243) +shape = SubResource("BoxShape3D_arao0") + +[node name="CollisionShape3D4" type="CollisionShape3D" parent="InvisibleWalls" unique_id=1431367494] +transform = Transform3D(-4.371139e-08, 0, -1, 0, 1, 0, 1, 0, -4.371139e-08, 7.502467, 9.197384, -0.018813023) +shape = SubResource("BoxShape3D_arao0") + [node name="WorldEnvironment" type="WorldEnvironment" parent="." unique_id=1177077250] environment = SubResource("Environment_bvwq1") -[node name="WorldContent" type="Node3D" parent="." unique_id=291550153] - -[node name="Players" type="Node3D" parent="." unique_id=1595463693] - -[node name="ItemsSpawner" type="MultiplayerSpawner" parent="." unique_id=627119248] -spawn_path = NodePath("../WorldContent") - [node name="PlayersSpawner" type="MultiplayerSpawner" parent="." unique_id=106645565] _spawnable_scenes = PackedStringArray("res://Player/net_player.tscn") spawn_path = NodePath("../Players") -[node name="StaticBody3D" type="StaticBody3D" parent="." unique_id=4404969] +[node name="Players" type="Node3D" parent="." unique_id=1595463693] -[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D" unique_id=998476672] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 9.197384, 7.589958) -shape = SubResource("BoxShape3D_arao0") +[node name="ItemsSpawner" type="MultiplayerSpawner" parent="." unique_id=627119248] +_spawnable_scenes = PackedStringArray("uid://dpot5qie20vf6", "uid://b3m2ag8g5rj4r", "uid://c0lknik4noobs", "uid://b3m2ag8g5rj4r", "uid://cfc4ho67u4r5e", "uid://e4i6o5oriecx") +spawn_path = NodePath("../Items") -[node name="CollisionShape3D2" type="CollisionShape3D" parent="StaticBody3D" unique_id=340303902] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 9.197384, -7.509142) -shape = SubResource("BoxShape3D_arao0") +[node name="Items" type="Node3D" parent="." unique_id=291550153] -[node name="CollisionShape3D3" type="CollisionShape3D" parent="StaticBody3D" unique_id=1193703037] -transform = Transform3D(-4.371139e-08, 0, -1, 0, 1, 0, 1, 0, -4.371139e-08, -7.438612, 9.197384, -0.018813243) -shape = SubResource("BoxShape3D_arao0") +[node name="StationsSpawner" type="MultiplayerSpawner" parent="." unique_id=240083159] +_spawnable_scenes = PackedStringArray("uid://c6rift56ql3f8", "uid://efaec6ymgabo", "uid://bbg7dwsbxxh1t", "uid://cnjwtnhwh0i8q", "uid://j7caslh27nor", "uid://ck5tuftqmyiue", "uid://cwnwo4i28upap", "uid://dvrk268s7gkxh", "uid://caf0xanmxbshy") +spawn_path = NodePath("../Stations") -[node name="CollisionShape3D4" type="CollisionShape3D" parent="StaticBody3D" unique_id=1431367494] -transform = Transform3D(-4.371139e-08, 0, -1, 0, 1, 0, 1, 0, -4.371139e-08, 7.502467, 9.197384, -0.018813023) -shape = SubResource("BoxShape3D_arao0") +[node name="Stations" type="Node3D" parent="." unique_id=1991170324] diff --git a/Stations/csg_box_3d.tscn b/Stations/csg_box_3d.tscn deleted file mode 100644 index 3c17705..0000000 --- a/Stations/csg_box_3d.tscn +++ /dev/null @@ -1,3 +0,0 @@ -[gd_scene format=3 uid="uid://cwwnbx5uat3fw"] - -[node name="CSGBox3D" type="CSGBox3D" unique_id=725518829] diff --git a/UI/main_menu_panel.gd b/UI/main_menu_panel.gd index 6616f3a..42a6172 100644 --- a/UI/main_menu_panel.gd +++ b/UI/main_menu_panel.gd @@ -5,8 +5,8 @@ extends Control ## multiplayer game, or join one by IP, driving scene switches + NetworkManager ## directly. -const JON_SCENE := "res://Scenes/JonScene.tscn" -const MULTIPLAYER_SCENE := "res://Scenes/multiPlayer.tscn" +const JON_SCENE := "res://Scenes/jon_scene.tscn" +const MULTIPLAYER_SCENE := "res://Scenes/multiplayer.tscn" const SETTINGS_PATH := "user://vryhungry_settings.cfg" var _ip := "127.0.0.1" @@ -24,6 +24,7 @@ var _ip := "127.0.0.1" func _ready() -> void: + print("Menu Panel _ready") if _bypass_menu_for_cmdline(): return for child in _keypad.get_children(): @@ -37,12 +38,6 @@ func _ready() -> void: _load_ip() _show_root_view() _refresh_ip() - # Show why we're back here, if the last session ended unexpectedly - # (dropped connection, failed join). Pulled rather than pushed, since - # NetworkManager may have set this before this panel even existed. - var status := NetworkManager.take_status() - if not status.is_empty(): - set_status(status) ## --server / --join on the command line skip straight to the multiplayer @@ -65,11 +60,13 @@ func _bypass_menu_for_cmdline() -> bool: func _show_root_view() -> void: + print("Menu Panel show root view") _root_view.visible = true _join_view.visible = false func _show_join_view() -> void: + print("Menu Panel show join view") _root_view.visible = false _join_view.visible = true set_status("Enter host IP, then Join") @@ -90,16 +87,19 @@ func _refresh_ip() -> void: func _on_john_pressed() -> void: + print("Menu Panel press jon_scene") NetworkManager.leave() get_tree().change_scene_to_file.call_deferred(JON_SCENE) func _on_host_pressed() -> void: - NetworkManager.request_host() - get_tree().change_scene_to_file.call_deferred("res://Scenes/JonScene.tscn") + print("Menu Panel press host") + NetworkManager.host() + get_tree().change_scene_to_file.call_deferred(MULTIPLAYER_SCENE) func _on_join_pressed() -> void: + print("Menu Panel press host") if _ip.is_empty(): set_status("Enter an IP first") return diff --git a/UI/main_menu_panel.tscn b/UI/main_menu_panel.tscn index 91e4d9f..60eafc3 100644 --- a/UI/main_menu_panel.tscn +++ b/UI/main_menu_panel.tscn @@ -1,97 +1,102 @@ -[gd_scene format=3] +[gd_scene format=3 uid="uid://jispfagyh1di"] [ext_resource type="Script" uid="uid://crs47shds8bm4" path="res://ui/main_menu_panel.gd" id="1_panel"] -[node name="MainMenuPanel" type="Control"] +[node name="MainMenuPanel" type="Control" unique_id=1716965055] layout_mode = 3 anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 script = ExtResource("1_panel") -[node name="Background" type="ColorRect" parent="."] +[node name="Background" type="ColorRect" parent="." unique_id=417297929] layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 color = Color(0.09, 0.1, 0.13, 1) -[node name="Margin" type="MarginContainer" parent="."] +[node name="Margin" type="MarginContainer" parent="." unique_id=122841427] layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 theme_override_constants/margin_left = 24 theme_override_constants/margin_top = 16 theme_override_constants/margin_right = 24 theme_override_constants/margin_bottom = 16 -[node name="Title" type="Label" parent="Margin"] +[node name="Title" type="Label" parent="Margin" unique_id=1426156127] layout_mode = 2 size_flags_vertical = 0 theme_override_font_sizes/font_size = 26 text = "VRyHungry" horizontal_alignment = 1 -[node name="Status" type="Label" parent="Margin"] +[node name="Status" type="Label" parent="Margin" unique_id=672946938] unique_name_in_owner = true layout_mode = 2 size_flags_vertical = 0 theme_override_colors/font_color = Color(0.8, 0.8, 0.5, 1) theme_override_font_sizes/font_size = 16 -text = "" horizontal_alignment = 1 -[node name="RootView" type="VBoxContainer" parent="Margin"] +[node name="RootView" type="VBoxContainer" parent="Margin" unique_id=1020931014] unique_name_in_owner = true layout_mode = 2 theme_override_constants/separation = 14 -[node name="Spacer" type="Control" parent="Margin/RootView"] +[node name="Spacer" type="Control" parent="Margin/RootView" unique_id=1907673970] custom_minimum_size = Vector2(0, 36) layout_mode = 2 -[node name="JohnButton" type="Button" parent="Margin/RootView"] +[node name="JohnButton" type="Button" parent="Margin/RootView" unique_id=593797044] unique_name_in_owner = true -layout_mode = 2 custom_minimum_size = Vector2(0, 64) +layout_mode = 2 theme_override_font_sizes/font_size = 26 text = "Play John's Scene" -[node name="HostButton" type="Button" parent="Margin/RootView"] +[node name="HostButton" type="Button" parent="Margin/RootView" unique_id=2142523398] unique_name_in_owner = true -layout_mode = 2 custom_minimum_size = Vector2(0, 64) +layout_mode = 2 theme_override_font_sizes/font_size = 26 text = "Host Multiplayer" -[node name="JoinMenuButton" type="Button" parent="Margin/RootView"] +[node name="JoinMenuButton" type="Button" parent="Margin/RootView" unique_id=1379606559] unique_name_in_owner = true -layout_mode = 2 custom_minimum_size = Vector2(0, 64) +layout_mode = 2 theme_override_font_sizes/font_size = 26 text = "Join Multiplayer" -[node name="JoinView" type="VBoxContainer" parent="Margin"] +[node name="JoinView" type="VBoxContainer" parent="Margin" unique_id=1763078998] unique_name_in_owner = true visible = false layout_mode = 2 theme_override_constants/separation = 10 -[node name="Title" type="Label" parent="Margin/JoinView"] +[node name="Title" type="Label" parent="Margin/JoinView" unique_id=309630334] layout_mode = 2 theme_override_font_sizes/font_size = 22 text = "Join Multiplayer" horizontal_alignment = 1 -[node name="IPLabel" type="Label" parent="Margin/JoinView"] +[node name="IPLabel" type="Label" parent="Margin/JoinView" unique_id=108493382] unique_name_in_owner = true layout_mode = 2 theme_override_font_sizes/font_size = 34 text = "127.0.0.1" horizontal_alignment = 1 -[node name="Keypad" type="GridContainer" parent="Margin/JoinView"] +[node name="Keypad" type="GridContainer" parent="Margin/JoinView" unique_id=1454498030] unique_name_in_owner = true layout_mode = 2 size_flags_vertical = 3 @@ -99,106 +104,106 @@ theme_override_constants/h_separation = 8 theme_override_constants/v_separation = 8 columns = 3 -[node name="B1" type="Button" parent="Margin/JoinView/Keypad"] +[node name="B1" type="Button" parent="Margin/JoinView/Keypad" unique_id=535729591] layout_mode = 2 size_flags_horizontal = 3 size_flags_vertical = 3 theme_override_font_sizes/font_size = 26 text = "1" -[node name="B2" type="Button" parent="Margin/JoinView/Keypad"] +[node name="B2" type="Button" parent="Margin/JoinView/Keypad" unique_id=439142035] layout_mode = 2 size_flags_horizontal = 3 size_flags_vertical = 3 theme_override_font_sizes/font_size = 26 text = "2" -[node name="B3" type="Button" parent="Margin/JoinView/Keypad"] +[node name="B3" type="Button" parent="Margin/JoinView/Keypad" unique_id=20138366] layout_mode = 2 size_flags_horizontal = 3 size_flags_vertical = 3 theme_override_font_sizes/font_size = 26 text = "3" -[node name="B4" type="Button" parent="Margin/JoinView/Keypad"] +[node name="B4" type="Button" parent="Margin/JoinView/Keypad" unique_id=1142576108] layout_mode = 2 size_flags_horizontal = 3 size_flags_vertical = 3 theme_override_font_sizes/font_size = 26 text = "4" -[node name="B5" type="Button" parent="Margin/JoinView/Keypad"] +[node name="B5" type="Button" parent="Margin/JoinView/Keypad" unique_id=422202098] layout_mode = 2 size_flags_horizontal = 3 size_flags_vertical = 3 theme_override_font_sizes/font_size = 26 text = "5" -[node name="B6" type="Button" parent="Margin/JoinView/Keypad"] +[node name="B6" type="Button" parent="Margin/JoinView/Keypad" unique_id=652822802] layout_mode = 2 size_flags_horizontal = 3 size_flags_vertical = 3 theme_override_font_sizes/font_size = 26 text = "6" -[node name="B7" type="Button" parent="Margin/JoinView/Keypad"] +[node name="B7" type="Button" parent="Margin/JoinView/Keypad" unique_id=1644038518] layout_mode = 2 size_flags_horizontal = 3 size_flags_vertical = 3 theme_override_font_sizes/font_size = 26 text = "7" -[node name="B8" type="Button" parent="Margin/JoinView/Keypad"] +[node name="B8" type="Button" parent="Margin/JoinView/Keypad" unique_id=2009764487] layout_mode = 2 size_flags_horizontal = 3 size_flags_vertical = 3 theme_override_font_sizes/font_size = 26 text = "8" -[node name="B9" type="Button" parent="Margin/JoinView/Keypad"] +[node name="B9" type="Button" parent="Margin/JoinView/Keypad" unique_id=809575757] layout_mode = 2 size_flags_horizontal = 3 size_flags_vertical = 3 theme_override_font_sizes/font_size = 26 text = "9" -[node name="BDot" type="Button" parent="Margin/JoinView/Keypad"] +[node name="BDot" type="Button" parent="Margin/JoinView/Keypad" unique_id=2136562018] layout_mode = 2 size_flags_horizontal = 3 size_flags_vertical = 3 theme_override_font_sizes/font_size = 26 text = "." -[node name="B0" type="Button" parent="Margin/JoinView/Keypad"] +[node name="B0" type="Button" parent="Margin/JoinView/Keypad" unique_id=2008425599] layout_mode = 2 size_flags_horizontal = 3 size_flags_vertical = 3 theme_override_font_sizes/font_size = 26 text = "0" -[node name="BDel" type="Button" parent="Margin/JoinView/Keypad"] +[node name="BDel" type="Button" parent="Margin/JoinView/Keypad" unique_id=413462771] layout_mode = 2 size_flags_horizontal = 3 size_flags_vertical = 3 theme_override_font_sizes/font_size = 22 text = "DEL" -[node name="Buttons" type="HBoxContainer" parent="Margin/JoinView"] +[node name="Buttons" type="HBoxContainer" parent="Margin/JoinView" unique_id=2121996996] layout_mode = 2 theme_override_constants/separation = 10 -[node name="JoinButton" type="Button" parent="Margin/JoinView/Buttons"] +[node name="JoinButton" type="Button" parent="Margin/JoinView/Buttons" unique_id=1797756998] unique_name_in_owner = true +custom_minimum_size = Vector2(0, 56) layout_mode = 2 size_flags_horizontal = 3 -custom_minimum_size = Vector2(0, 56) theme_override_font_sizes/font_size = 24 text = "JOIN" -[node name="BackButton" type="Button" parent="Margin/JoinView/Buttons"] +[node name="BackButton" type="Button" parent="Margin/JoinView/Buttons" unique_id=704422546] unique_name_in_owner = true +custom_minimum_size = Vector2(0, 56) layout_mode = 2 size_flags_horizontal = 3 -custom_minimum_size = Vector2(0, 56) theme_override_font_sizes/font_size = 24 text = "BACK" diff --git a/addons/godot-xr-tools/objects/viewport_2d_in_3d.tscn b/addons/godot-xr-tools/objects/viewport_2d_in_3d.tscn index 71e2269..f74ce76 100644 --- a/addons/godot-xr-tools/objects/viewport_2d_in_3d.tscn +++ b/addons/godot-xr-tools/objects/viewport_2d_in_3d.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=7 format=3 uid="uid://clujaf3u776a3"] +[gd_scene format=3 uid="uid://clujaf3u776a3"] [ext_resource type="Script" uid="uid://eavk7267igp7" path="res://addons/godot-xr-tools/objects/viewport_2d_in_3d.gd" id="1"] [ext_resource type="Script" uid="uid://cpl5yiyf1ypft" path="res://addons/godot-xr-tools/objects/viewport_2d_in_3d_body.gd" id="2"] @@ -7,41 +7,44 @@ resource_local_to_scene = true size = Vector2(3, 2) -[sub_resource type="ViewportTexture" id="ViewportTexture_ufe4n"] +[sub_resource type="ViewportTexture" id="ViewportTexture_gvc48"] +viewport_path = NodePath("Viewport") -[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_fvml0"] +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_4gj7x"] transparency = 1 cull_mode = 2 -albedo_texture = SubResource("ViewportTexture_ufe4n") +albedo_texture = SubResource("ViewportTexture_gvc48") texture_filter = 1 [sub_resource type="BoxShape3D" id="4"] resource_local_to_scene = true size = Vector3(3, 2, 0.02) -[node name="Viewport2Din3D" type="Node3D"] +[node name="Viewport2Din3D" type="Node3D" unique_id=1136024888] script = ExtResource("1") +transparent = 1 alpha_scissor_threshold = 0.25 unshaded = false filter = true +scene_properties_keys = PackedStringArray() -[node name="Viewport" type="SubViewport" parent="."] +[node name="Viewport" type="SubViewport" parent="." unique_id=1205536037] disable_3d = true transparent_bg = true gui_embed_subwindows = true size = Vector2i(300, 200) render_target_update_mode = 1 -[node name="Screen" type="MeshInstance3D" parent="."] +[node name="Screen" type="MeshInstance3D" parent="." unique_id=1799394652] mesh = SubResource("1") -surface_material_override/0 = SubResource("StandardMaterial3D_fvml0") +surface_material_override/0 = SubResource("StandardMaterial3D_4gj7x") -[node name="StaticBody3D" type="StaticBody3D" parent="."] +[node name="StaticBody3D" type="StaticBody3D" parent="." unique_id=959647424] collision_layer = 5242881 collision_mask = 0 script = ExtResource("2") viewport_size = Vector2(300, 200) -[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D"] +[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D" unique_id=1695382741] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.01) shape = SubResource("4") diff --git a/content/kitchen_layouts/small_line.tscn b/content/kitchen_layouts/small_line.tscn new file mode 100644 index 0000000..4bad21a --- /dev/null +++ b/content/kitchen_layouts/small_line.tscn @@ -0,0 +1,27 @@ +[gd_scene format=3 uid="uid://cey1s10v2xufq"] + +[ext_resource type="PackedScene" uid="uid://j7caslh27nor" path="res://stations/Hob.tscn" id="1_iwheq"] +[ext_resource type="PackedScene" uid="uid://dvrk268s7gkxh" path="res://stations/sink.tscn" id="2_ad3hj"] +[ext_resource type="PackedScene" uid="uid://efaec6ymgabo" path="res://stations/Counter.tscn" id="3_rsv28"] +[ext_resource type="PackedScene" uid="uid://cwnwo4i28upap" path="res://stations/raw_burger_dispenser.tscn" id="4_drmjc"] +[ext_resource type="PackedScene" uid="uid://c6rift56ql3f8" path="res://stations/BurgerBunsDispenser.tscn" id="5_ad3hj"] +[ext_resource type="PackedScene" uid="uid://ck5tuftqmyiue" path="res://stations/plate_dispenser.tscn" id="6_rsv28"] + +[node name="SmallLine" type="Node3D" unique_id=50655734] + +[node name="Hob" parent="." unique_id=1687971542 instance=ExtResource("1_iwheq")] + +[node name="Sink" parent="." unique_id=2055277359 instance=ExtResource("2_ad3hj")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.2, 0, 0) + +[node name="Counter" parent="." unique_id=1487893288 instance=ExtResource("3_rsv28")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.6, 0, 0) + +[node name="RawBurgerDispenser" parent="." unique_id=235630131 instance=ExtResource("4_drmjc")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.2, -0.48000002, 0) + +[node name="BurgerBunsDispenser" parent="." unique_id=1720683779 instance=ExtResource("5_ad3hj")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.6, -0.48000002, 0) + +[node name="PlateDispenser" parent="." unique_id=710538846 instance=ExtResource("6_rsv28")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.8000001, -0.48000002, 0) diff --git a/project.godot b/project.godot index cb8b9c2..f11d5ae 100644 --- a/project.godot +++ b/project.godot @@ -21,6 +21,8 @@ XRToolsUserSettings="*uid://bqgb8i74tm0t" XRToolsRumbleManager="*uid://by853dk86g1qw" GlobalKeyEvents="*uid://c60unagog5oi1" Signals="*uid://fuux6cxfjwdc" +NetworkManager="*uid://da1xwj5tyeii6" +Main="uid://b4ldkd3ngs0vp" [debug] diff --git a/recipes.yaml.uid b/recipes.yaml.uid deleted file mode 100644 index 3785c41..0000000 --- a/recipes.yaml.uid +++ /dev/null @@ -1 +0,0 @@ -uid://b5y4a58f517wi diff --git a/scripts/add_spawnables.gd b/scripts/add_spawnables.gd deleted file mode 100644 index d20cab4..0000000 --- a/scripts/add_spawnables.gd +++ /dev/null @@ -1,10 +0,0 @@ -extends MultiplayerSpawner - - -func _ready() -> void: - add_spawnable_scene("res://Stations/csg_box_3d.tscn") - - - -func _process(delta: float) -> void: - pass diff --git a/scripts/add_spawnables.gd.uid b/scripts/add_spawnables.gd.uid deleted file mode 100644 index 341408f..0000000 --- a/scripts/add_spawnables.gd.uid +++ /dev/null @@ -1 +0,0 @@ -uid://ctsqvhicswj8m diff --git a/scripts/main.gd b/scripts/main.gd index fe40149..bc5ec36 100644 --- a/scripts/main.gd +++ b/scripts/main.gd @@ -6,15 +6,15 @@ const GAME_MANAGER = preload("res://scripts/game_manager.gd") var xr_interface :XRInterface func _ready(): - print("main: _ready") + print("Main _ready") RECIPE_MANAGER.print_all_recipes() GAME_MANAGER.meals_in_play = ["hamburger"] xr_interface = XRServer.find_interface("OpenXR") if xr_interface and xr_interface.is_initialized(): - print("OpenXR started :)") + print("Main OpenXR started :)") DisplayServer.window_set_vsync_mode(DisplayServer.VSYNC_DISABLED) get_viewport().use_xr = true else: - print("OpenXR failed to start. Check your headset...") + print("Main OpenXR failed to start. Check your headset...") diff --git a/scripts/network_manager.gd b/scripts/network_manager.gd new file mode 100644 index 0000000..4899129 --- /dev/null +++ b/scripts/network_manager.gd @@ -0,0 +1,169 @@ +extends Node + +const DEFAULT_PORT := 24565 +const MAX_CLIENTS := 7 + + +signal player_joined(peer_id: int) +signal player_left(peer_id: int) +signal session_started(is_server: bool) +signal session_ended() +signal connection_failed() + +# World hooks, registered by main.gd once the scene tree exists. +var _world: Node = null +var _players_spawner: MultiplayerSpawner = null +var _items_spawner: MultiplayerSpawner = null +var _content_root: Node = null + + +func _ready() -> void: + multiplayer.peer_connected.connect(_on_peer_connected) + multiplayer.peer_disconnected.connect(_on_peer_disconnected) + multiplayer.connected_to_server.connect(_on_connected_to_server) + multiplayer.connection_failed.connect(_on_connection_failed) + multiplayer.server_disconnected.connect(_on_server_disconnected) + _handle_cmdline() + +# --- Public API ------------------------------------------------------------ + +## Start hosting. The host is peer 1 and also plays (listen server). +func host(port: int = DEFAULT_PORT) -> Error: + var peer := ENetMultiplayerPeer.new() + var err := peer.create_server(port, MAX_CLIENTS) + if err != OK: + print("NetworkManager HOST failed to create_server on port %d: %s" % [port, error_string(err)]) + return err + multiplayer.multiplayer_peer = peer + print("NetworkManager HOST started on port %d (peer id %d)" % [port, multiplayer.get_unique_id()]) + session_started.emit(true) + return OK + + +## Join an existing host. +func join(address: String = "127.0.0.1", port: int = DEFAULT_PORT) -> Error: + var peer := ENetMultiplayerPeer.new() + var err := peer.create_client(address, port) + if err != OK: + print("NetworkManager JOIN failed to create_client %s:%d: %s" % [address, port, error_string(err)]) + return err + multiplayer.multiplayer_peer = peer + print("NetworkManager JOIN connecting to %s:%d ..." % [address, port]) + return OK + + +## Leave the session and tear down transport. +func leave() -> void: + _go_offline() + print("NetworkManager Session ended") + session_ended.emit() + + +# Restore Godot's default OfflineMultiplayerPeer (rather than leaving the peer +# null), so is_multiplayer_authority()/get_unique_id() keep working while we are +# back in single-player / menu state. +func _go_offline() -> void: + if multiplayer.multiplayer_peer: + multiplayer.multiplayer_peer.close() + multiplayer.multiplayer_peer = OfflineMultiplayerPeer.new() + unregister_world() + + +func is_server() -> bool: + return is_online() and multiplayer.is_server() + + +## True only when a real ENet session is active. Godot installs a default +## OfflineMultiplayerPeer, so a non-null peer alone does not mean "online". +func is_online() -> bool: + var p := multiplayer.multiplayer_peer + return p != null and not (p is OfflineMultiplayerPeer) + + +## True on the machine that owns authoritative world logic: the server when +## online, or the single player when offline. Station logic and spawning should +## only run where this is true, so state has one source of truth. +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"): + print("NetworkManager 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. +func register_world(world: Node, players_spawner: MultiplayerSpawner, items_spawner: MultiplayerSpawner) -> void: + _world = world + _players_spawner = players_spawner + _items_spawner = items_spawner + _content_root = items_spawner.get_node(items_spawner.spawn_path) if items_spawner else world + print("NetworkManager World registered (players_spawner=%s items_spawner=%s)" % [str(players_spawner != null), str(items_spawner != null)]) + + +## Called when the world scene goes away (disconnect, leaving the session) so +## the autoload doesn't hold stale/freed references across a scene reload. +func unregister_world() -> void: + _world = null + _content_root = null + _players_spawner = null + _items_spawner = null + + + +# --- Session signal handlers ---------------------------------------------- + +func _on_peer_connected(peer_id: int) -> void: + print("NetworkManager peer_connected: %d" % peer_id) + # Only the server reacts by materialising that peer's player. + if is_server(): + print("NetworkManager player_present: %d" % peer_id) + player_joined.emit(peer_id) + +func _on_peer_disconnected(peer_id: int) -> void: + print("NetworkManager peer_disconnected: %d" % peer_id) + if is_server(): + print("NetworkManager player_absent: %d" % peer_id) + player_left.emit(peer_id) + +func _on_connected_to_server() -> void: + print("NetworkManager connected_to_server (my id=%d)" % multiplayer.get_unique_id()) + session_started.emit(false) + +func _on_connection_failed() -> void: + print("NetworkManager connection_failed") + _go_offline() + connection_failed.emit() + +func _on_server_disconnected() -> void: + print("NetworkManager server_disconnected") + _go_offline() + session_ended.emit() + + +# --- Command-line driven test bootstrap ----------------------------------- +func _handle_cmdline() -> void: + var args := OS.get_cmdline_user_args() + if args.has("--server"): + print("NetworkManager cmdline: --server") + host() + elif args.has("--join"): + var idx := args.find("--join") + var addr := "127.0.0.1" + if idx + 1 < args.size(): + addr = args[idx + 1] + print("NetworkManager cmdline: --join %s" % addr) + join(addr) diff --git a/scripts/network_manager.gd.uid b/scripts/network_manager.gd.uid new file mode 100644 index 0000000..6038bb5 --- /dev/null +++ b/scripts/network_manager.gd.uid @@ -0,0 +1 @@ +uid://da1xwj5tyeii6