From 71ca6c33056ad7d7898be8225d898e592b290920 Mon Sep 17 00:00:00 2001 From: cblech Date: Mon, 21 Apr 2025 15:31:01 +0200 Subject: [PATCH] World transision WIP --- prefabs/Player3D.tscn | 4 +- .../world_elements/world_change_trigger.tscn | 6 ++ project.godot | 4 -- resources/spawnpoints/from_test_scene.tres | 8 +++ .../spawnpoints/spawnpoint_game_start.tres | 8 +++ resources/spawnpoints/tmp1.tres | 8 +++ scenes/babushka_scene_main.tscn | 16 ++++-- .../Babushka_world_item_pickup_testing.tscn | 34 ++++++++++- .../babushka_world_level_change_test.tscn | 56 +++++++++++++++++++ .../Common/CharacterControls/Player3D.cs | 8 ++- .../CharacterControls/VesnaBehaviour.cs | 5 ++ .../Common/WorldManagement/SpawnPoint.cs.uid | 1 + .../WorldManagement/SpawnPointMarker.cs | 8 +++ .../WorldManagement/SpawnPointMarker.cs.uid | 1 + .../WorldManagement/SpawnPointResource.cs | 14 +++++ .../WorldManagement/SpawnPointResource.cs.uid | 1 + .../CSharp/Common/WorldManagement/World.cs | 21 +++++++ .../Common/WorldManagement/World.cs.uid | 1 + .../WorldManagement/WorldChangeTrigger.cs | 26 +++++++++ .../WorldManagement/WorldChangeTrigger.cs.uid | 1 + .../Common/WorldManagement/WorldContainer.cs | 41 ++++++++++++++ .../WorldManagement/WorldContainer.cs.uid | 1 + 22 files changed, 257 insertions(+), 16 deletions(-) create mode 100644 prefabs/world_elements/world_change_trigger.tscn create mode 100644 resources/spawnpoints/from_test_scene.tres create mode 100644 resources/spawnpoints/spawnpoint_game_start.tres create mode 100644 resources/spawnpoints/tmp1.tres create mode 100644 scenes/worlds/babushka_world_level_change_test.tscn create mode 100644 scripts/CSharp/Common/WorldManagement/SpawnPoint.cs.uid create mode 100644 scripts/CSharp/Common/WorldManagement/SpawnPointMarker.cs create mode 100644 scripts/CSharp/Common/WorldManagement/SpawnPointMarker.cs.uid create mode 100644 scripts/CSharp/Common/WorldManagement/SpawnPointResource.cs create mode 100644 scripts/CSharp/Common/WorldManagement/SpawnPointResource.cs.uid create mode 100644 scripts/CSharp/Common/WorldManagement/World.cs create mode 100644 scripts/CSharp/Common/WorldManagement/World.cs.uid create mode 100644 scripts/CSharp/Common/WorldManagement/WorldChangeTrigger.cs create mode 100644 scripts/CSharp/Common/WorldManagement/WorldChangeTrigger.cs.uid create mode 100644 scripts/CSharp/Common/WorldManagement/WorldContainer.cs create mode 100644 scripts/CSharp/Common/WorldManagement/WorldContainer.cs.uid diff --git a/prefabs/Player3D.tscn b/prefabs/Player3D.tscn index 73507af..8d0be65 100644 --- a/prefabs/Player3D.tscn +++ b/prefabs/Player3D.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=303 format=3 uid="uid://dbd1niu3tp8y5"] [ext_resource type="Script" uid="uid://b4ugrget2x6lb" path="res://scripts/CSharp/Common/CharacterControls/Player3D.cs" id="1_3trg2"] -[ext_resource type="Script" uid="uid://bblprbhnbyv77" path="res://scripts/CSharp/Common/CharacterControls/VesnaBehaviour.cs" id="1_pkl5l"] +[ext_resource type="Script" uid="uid://xm0um640aes7" path="res://scripts/CSharp/Common/CharacterControls/VesnaBehaviour.cs" id="1_pkl5l"] [ext_resource type="Texture2D" uid="uid://duaideiajsu8r" path="res://art/characters/Vesna/babushka concept art vesna.png" id="2_3trg2"] [ext_resource type="PackedScene" uid="uid://biwd3jj65qrlh" path="res://prefabs/farming/base_field.tscn" id="2_oq5hi"] [ext_resource type="Texture2D" uid="uid://c4ggew55w0icj" path="res://art/farm/farming/farmobjekte/harke.png" id="4_kngqo"] @@ -1344,5 +1344,3 @@ _wateringCanSprite = NodePath("../CharacterBody3D/Farming/Watering can") _fieldPrefab = ExtResource("2_oq5hi") _movingPlayer = NodePath("../CharacterBody3D") metadata/_custom_type_script = "uid://b1sscdr4ptec8" - -[connection signal="WaterField" from="FarmingControls" to="." method="UseWateringCan"] diff --git a/prefabs/world_elements/world_change_trigger.tscn b/prefabs/world_elements/world_change_trigger.tscn new file mode 100644 index 0000000..433556e --- /dev/null +++ b/prefabs/world_elements/world_change_trigger.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://bs3vs05wp5a20"] + +[ext_resource type="Script" uid="uid://cpbv0b3ahorep" path="res://scripts/CSharp/Common/WorldManagement/WorldChangeTrigger.cs" id="1_wqqyh"] + +[node name="WorldChangeTrigger" type="Area3D"] +script = ExtResource("1_wqqyh") diff --git a/project.godot b/project.godot index b6e7500..ff7a7a2 100644 --- a/project.godot +++ b/project.godot @@ -66,10 +66,6 @@ translation/id_counter=22 translation/locales=["de", "en"] text/autopauses={} -[display] - -window/size/always_on_top=true - [dotnet] project/assembly_name="Babushka" diff --git a/resources/spawnpoints/from_test_scene.tres b/resources/spawnpoints/from_test_scene.tres new file mode 100644 index 0000000..60b0431 --- /dev/null +++ b/resources/spawnpoints/from_test_scene.tres @@ -0,0 +1,8 @@ +[gd_resource type="Resource" script_class="SpawnPointResource" load_steps=2 format=3 uid="uid://cipetn2hmnew4"] + +[ext_resource type="Script" uid="uid://cjr2efpm660kr" path="res://scripts/CSharp/Common/WorldManagement/SpawnPointResource.cs" id="1_ymkjy"] + +[resource] +script = ExtResource("1_ymkjy") +name = "" +metadata/_custom_type_script = "uid://cjr2efpm660kr" diff --git a/resources/spawnpoints/spawnpoint_game_start.tres b/resources/spawnpoints/spawnpoint_game_start.tres new file mode 100644 index 0000000..099b149 --- /dev/null +++ b/resources/spawnpoints/spawnpoint_game_start.tres @@ -0,0 +1,8 @@ +[gd_resource type="Resource" script_class="SpawnPointResource" load_steps=2 format=3 uid="uid://daow8nx85vuc8"] + +[ext_resource type="Script" uid="uid://cjr2efpm660kr" path="res://scripts/CSharp/Common/WorldManagement/SpawnPointResource.cs" id="1_kdbco"] + +[resource] +script = ExtResource("1_kdbco") +name = "GameStart" +metadata/_custom_type_script = "uid://cjr2efpm660kr" diff --git a/resources/spawnpoints/tmp1.tres b/resources/spawnpoints/tmp1.tres new file mode 100644 index 0000000..18cb9e0 --- /dev/null +++ b/resources/spawnpoints/tmp1.tres @@ -0,0 +1,8 @@ +[gd_resource type="Resource" script_class="SpawnPointResource" load_steps=2 format=3 uid="uid://dissbtj4nflu5"] + +[ext_resource type="Script" uid="uid://cjr2efpm660kr" path="res://scripts/CSharp/Common/WorldManagement/SpawnPointResource.cs" id="1_vyl4c"] + +[resource] +script = ExtResource("1_vyl4c") +name = "tmp1" +metadata/_custom_type_script = "uid://cjr2efpm660kr" diff --git a/scenes/babushka_scene_main.tscn b/scenes/babushka_scene_main.tscn index 1ec9734..069ba24 100644 --- a/scenes/babushka_scene_main.tscn +++ b/scenes/babushka_scene_main.tscn @@ -1,17 +1,21 @@ -[gd_scene load_steps=4 format=3 uid="uid://dbgkbil1ultks"] +[gd_scene load_steps=6 format=3 uid="uid://dbgkbil1ultks"] -[ext_resource type="PackedScene" uid="uid://dbxy2y85r1d8x" path="res://scenes/worlds/Babushka_world_item_pickup_testing.tscn" id="1_l112d"] +[ext_resource type="Script" uid="uid://g338f4yomfo3" path="res://scripts/CSharp/Common/WorldManagement/WorldContainer.cs" id="1_l112d"] +[ext_resource type="PackedScene" uid="uid://dbxy2y85r1d8x" path="res://scenes/worlds/Babushka_world_item_pickup_testing.tscn" id="2_akoq3"] [ext_resource type="PackedScene" uid="uid://dbd1niu3tp8y5" path="res://prefabs/Player3D.tscn" id="2_l45op"] +[ext_resource type="Resource" uid="uid://daow8nx85vuc8" path="res://resources/spawnpoints/spawnpoint_game_start.tres" id="3_4ix36"] [ext_resource type="PackedScene" uid="uid://cgjc4wurbgimy" path="res://prefabs/UI/Inventory/Inventory.tscn" id="3_akoq3"] [node name="BabushkaSceneMain" type="Node"] [node name="WorldContainer" type="Node" parent="."] +script = ExtResource("1_l112d") +startingWorld = ExtResource("2_akoq3") +startingSpawnPoint = ExtResource("3_4ix36") -[node name="WorldItemPickupTest" parent="WorldContainer" instance=ExtResource("1_l112d")] - -[node name="Player3d" parent="." node_paths=PackedStringArray("_fieldParent") instance=ExtResource("2_l45op")] +[node name="Player3d" parent="." instance=ExtResource("2_l45op")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -5.51633, 0.725631, 3.57249) -_fieldParent = NodePath("") [node name="Inventory" parent="." instance=ExtResource("3_akoq3")] + +[connection signal="WorldChanged" from="WorldContainer" to="Player3d" method="TeleportTo"] diff --git a/scenes/worlds/Babushka_world_item_pickup_testing.tscn b/scenes/worlds/Babushka_world_item_pickup_testing.tscn index a678057..b4780f2 100644 --- a/scenes/worlds/Babushka_world_item_pickup_testing.tscn +++ b/scenes/worlds/Babushka_world_item_pickup_testing.tscn @@ -1,11 +1,17 @@ -[gd_scene load_steps=10 format=3 uid="uid://dbxy2y85r1d8x"] +[gd_scene load_steps=17 format=3 uid="uid://dbxy2y85r1d8x"] +[ext_resource type="Script" uid="uid://6aq8mr0sofrs" path="res://scripts/CSharp/Common/WorldManagement/World.cs" id="1_jnel3"] [ext_resource type="PackedScene" uid="uid://biwd3jj65qrlh" path="res://prefabs/farming/base_field.tscn" id="2_741gk"] [ext_resource type="PackedScene" uid="uid://5hltxpdxmqcq" path="res://prefabs/interactions/generic_item_on_ground.tscn" id="5_sjt6k"] [ext_resource type="Resource" uid="uid://cndd64batns31" path="res://resources/items/bucket.tres" id="6_nvnpb"] -[ext_resource type="Script" uid="uid://d17si23dtlg72" path="res://scripts/CSharp/Common/Farming/FieldService.cs" id="7_3rkjv"] +[ext_resource type="Script" uid="uid://12hleqx8amr8" path="res://scripts/CSharp/Common/Farming/FieldService.cs" id="7_3rkjv"] [ext_resource type="Resource" uid="uid://c5yg3lx756v4v" path="res://resources/items/hoe.tres" id="7_hv2km"] [ext_resource type="Resource" uid="uid://d1uuxp1lp4aro" path="res://resources/items/tomato_seed.tres" id="8_hv2km"] +[ext_resource type="Script" uid="uid://c7eaa0neniiss" path="res://scripts/CSharp/Common/WorldManagement/SpawnPointMarker.cs" id="8_w0pbi"] +[ext_resource type="Resource" uid="uid://daow8nx85vuc8" path="res://resources/spawnpoints/spawnpoint_game_start.tres" id="9_sal3e"] +[ext_resource type="Resource" uid="uid://cipetn2hmnew4" path="res://resources/spawnpoints/from_test_scene.tres" id="10_sal3e"] +[ext_resource type="PackedScene" uid="uid://bs3vs05wp5a20" path="res://prefabs/world_elements/world_change_trigger.tscn" id="11_43jow"] +[ext_resource type="PackedScene" uid="uid://cidjhvp38n4b4" path="res://scenes/worlds/babushka_world_level_change_test.tscn" id="12_oux87"] [sub_resource type="PlaneMesh" id="PlaneMesh_8yprl"] @@ -15,7 +21,11 @@ albedo_color = Color(0.505882, 0.588235, 0.494118, 1) [sub_resource type="BoxShape3D" id="BoxShape3D_t58di"] size = Vector3(2.01563, 0.160522, 2.00824) +[sub_resource type="BoxShape3D" id="BoxShape3D_oux87"] +size = Vector3(1, 1, 2.94604) + [node name="WorldItemPickupTest" type="Node3D"] +script = ExtResource("1_jnel3") [node name="MeshInstance3D" type="MeshInstance3D" parent="."] transform = Transform3D(10, 0, 0, 0, 10, 0, 0, 0, 10, 0, 0, 0) @@ -62,6 +72,26 @@ _infiniteSupply = true _blueprint = ExtResource("8_hv2km") [node name="Spawnpoint" type="Node3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.87715, 0, 1.54015) +script = ExtResource("8_w0pbi") +spawnPointResource = ExtResource("9_sal3e") + +[node name="Spawnpoint tmp" type="Node3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -8.3672, 0, 0.113484) +script = ExtResource("8_w0pbi") +spawnPointResource = ExtResource("10_sal3e") + +[node name="WorldChangeTrigger" parent="." instance=ExtResource("11_43jow")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -9.78829, 0.546566, -0.241783) +collision_mask = 17 +switchToWorld = ExtResource("12_oux87") +switchToSpawnPoint = ExtResource("10_sal3e") + +[node name="CollisionShape3D" type="CollisionShape3D" parent="WorldChangeTrigger"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.193655, 0, 0.233521) +shape = SubResource("BoxShape3D_oux87") + +[connection signal="area_entered" from="WorldChangeTrigger" to="WorldChangeTrigger" method="AreaEnteredHandler"] [editable path="GenericItemOnGround"] [editable path="GenericItemOnGround2"] diff --git a/scenes/worlds/babushka_world_level_change_test.tscn b/scenes/worlds/babushka_world_level_change_test.tscn new file mode 100644 index 0000000..fae37e6 --- /dev/null +++ b/scenes/worlds/babushka_world_level_change_test.tscn @@ -0,0 +1,56 @@ +[gd_scene load_steps=11 format=3 uid="uid://cidjhvp38n4b4"] + +[ext_resource type="Script" uid="uid://6aq8mr0sofrs" path="res://scripts/CSharp/Common/WorldManagement/World.cs" id="1_nat7a"] +[ext_resource type="PackedScene" uid="uid://bs3vs05wp5a20" path="res://prefabs/world_elements/world_change_trigger.tscn" id="5_tb7xe"] +[ext_resource type="PackedScene" uid="uid://dbxy2y85r1d8x" path="res://scenes/worlds/Babushka_world_item_pickup_testing.tscn" id="6_evakd"] +[ext_resource type="Script" uid="uid://c7eaa0neniiss" path="res://scripts/CSharp/Common/WorldManagement/SpawnPointMarker.cs" id="8_pl6uc"] +[ext_resource type="Resource" uid="uid://daow8nx85vuc8" path="res://resources/spawnpoints/spawnpoint_game_start.tres" id="9_rutwt"] +[ext_resource type="Resource" uid="uid://cipetn2hmnew4" path="res://resources/spawnpoints/from_test_scene.tres" id="10_s5gm8"] + +[sub_resource type="PlaneMesh" id="PlaneMesh_8yprl"] + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_8tgff"] +albedo_color = Color(0.505882, 0.588235, 0.494118, 1) + +[sub_resource type="BoxShape3D" id="BoxShape3D_t58di"] +size = Vector3(2.01563, 0.160522, 2.00824) + +[sub_resource type="BoxShape3D" id="BoxShape3D_tydq3"] +size = Vector3(1, 1, 6.21814) + +[node name="WorldItemPickupTest" type="Node3D"] +script = ExtResource("1_nat7a") + +[node name="MeshInstance3D" type="MeshInstance3D" parent="."] +transform = Transform3D(10, 0, 0, 0, 10, 0, 0, 0, 10, 0, 0, 0) +mesh = SubResource("PlaneMesh_8yprl") +skeleton = NodePath("") +surface_material_override/0 = SubResource("StandardMaterial3D_8tgff") + +[node name="StaticBody3D" type="StaticBody3D" parent="MeshInstance3D"] + +[node name="CollisionShape3D" type="CollisionShape3D" parent="MeshInstance3D/StaticBody3D"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.000976563, -0.0739136, -0.00112915) +shape = SubResource("BoxShape3D_t58di") + +[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 0.618408, 0.785857, 0, -0.785857, 0.618408, -0.802612, 0, 4.73262) + +[node name="Spawnpoint" type="Node3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.87715, 0, 1.54015) +script = ExtResource("8_pl6uc") +spawnPointResource = ExtResource("9_rutwt") + +[node name="Spawnpoint tmp" type="Node3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 8.00564, 0, 0.0870138) +script = ExtResource("8_pl6uc") +spawnPointResource = ExtResource("10_s5gm8") + +[node name="WorldChangeTrigger" parent="." instance=ExtResource("5_tb7xe")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 9.82414, 0, 0) +switchToWorld = ExtResource("6_evakd") +switchToSpawnPoint = ExtResource("10_s5gm8") + +[node name="CollisionShape3D" type="CollisionShape3D" parent="WorldChangeTrigger"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.235657) +shape = SubResource("BoxShape3D_tydq3") diff --git a/scripts/CSharp/Common/CharacterControls/Player3D.cs b/scripts/CSharp/Common/CharacterControls/Player3D.cs index 03e2d3a..7454750 100644 --- a/scripts/CSharp/Common/CharacterControls/Player3D.cs +++ b/scripts/CSharp/Common/CharacterControls/Player3D.cs @@ -129,5 +129,11 @@ public partial class Player3D : CharacterBody3D animatedSprite.Visible = false; } } - + + public void Teleport(Vector3 newPosition) + { + GlobalPosition = newPosition; + ResetPhysicsInterpolation(); + GD.Print("Player Teleported"); + } } diff --git a/scripts/CSharp/Common/CharacterControls/VesnaBehaviour.cs b/scripts/CSharp/Common/CharacterControls/VesnaBehaviour.cs index b8ba6a8..1ce3071 100644 --- a/scripts/CSharp/Common/CharacterControls/VesnaBehaviour.cs +++ b/scripts/CSharp/Common/CharacterControls/VesnaBehaviour.cs @@ -15,6 +15,11 @@ public partial class VesnaBehaviour : Node { _farmingControls.FieldParent = _fieldParent; } + + public void TeleportTo(Vector3 newPosition) + { + GetNode("CharacterBody3D").Teleport(newPosition); + } #region Farming diff --git a/scripts/CSharp/Common/WorldManagement/SpawnPoint.cs.uid b/scripts/CSharp/Common/WorldManagement/SpawnPoint.cs.uid new file mode 100644 index 0000000..ba834c7 --- /dev/null +++ b/scripts/CSharp/Common/WorldManagement/SpawnPoint.cs.uid @@ -0,0 +1 @@ +uid://bb4fc5y43ksfg diff --git a/scripts/CSharp/Common/WorldManagement/SpawnPointMarker.cs b/scripts/CSharp/Common/WorldManagement/SpawnPointMarker.cs new file mode 100644 index 0000000..5348d62 --- /dev/null +++ b/scripts/CSharp/Common/WorldManagement/SpawnPointMarker.cs @@ -0,0 +1,8 @@ +using Godot; +using System; +using Babushka.scripts.CSharp.Common.WorldManagement; + +public partial class SpawnPointMarker : Node3D +{ + [Export] public SpawnPointResource spawnPointResource; +} diff --git a/scripts/CSharp/Common/WorldManagement/SpawnPointMarker.cs.uid b/scripts/CSharp/Common/WorldManagement/SpawnPointMarker.cs.uid new file mode 100644 index 0000000..87b34be --- /dev/null +++ b/scripts/CSharp/Common/WorldManagement/SpawnPointMarker.cs.uid @@ -0,0 +1 @@ +uid://c7eaa0neniiss diff --git a/scripts/CSharp/Common/WorldManagement/SpawnPointResource.cs b/scripts/CSharp/Common/WorldManagement/SpawnPointResource.cs new file mode 100644 index 0000000..dfc206d --- /dev/null +++ b/scripts/CSharp/Common/WorldManagement/SpawnPointResource.cs @@ -0,0 +1,14 @@ +using Godot; + +namespace Babushka.scripts.CSharp.Common.WorldManagement; + +[GlobalClass] +public partial class SpawnPointResource : Resource +{ + [Export] public string name; + + public SpawnPointResource() + { + name = ""; + } +} \ No newline at end of file diff --git a/scripts/CSharp/Common/WorldManagement/SpawnPointResource.cs.uid b/scripts/CSharp/Common/WorldManagement/SpawnPointResource.cs.uid new file mode 100644 index 0000000..9f83d70 --- /dev/null +++ b/scripts/CSharp/Common/WorldManagement/SpawnPointResource.cs.uid @@ -0,0 +1 @@ +uid://cjr2efpm660kr diff --git a/scripts/CSharp/Common/WorldManagement/World.cs b/scripts/CSharp/Common/WorldManagement/World.cs new file mode 100644 index 0000000..30302ca --- /dev/null +++ b/scripts/CSharp/Common/WorldManagement/World.cs @@ -0,0 +1,21 @@ +using Godot; +using System; +using System.Collections.Generic; +using System.Linq; +using Babushka.scripts.CSharp.Common.WorldManagement; + +public partial class World : Node +{ + public IReadOnlyDictionary SpawnPoints; + + public override void _EnterTree() + { + GD.Print("World Enter Tree"); + + // find all child nodes of type SpawnPoint + SpawnPoints = FindChildren("*") + .OfType() + .Select(sp => new KeyValuePair(sp.spawnPointResource, sp)) + .ToDictionary(); + } +} \ No newline at end of file diff --git a/scripts/CSharp/Common/WorldManagement/World.cs.uid b/scripts/CSharp/Common/WorldManagement/World.cs.uid new file mode 100644 index 0000000..3eaa8b1 --- /dev/null +++ b/scripts/CSharp/Common/WorldManagement/World.cs.uid @@ -0,0 +1 @@ +uid://6aq8mr0sofrs diff --git a/scripts/CSharp/Common/WorldManagement/WorldChangeTrigger.cs b/scripts/CSharp/Common/WorldManagement/WorldChangeTrigger.cs new file mode 100644 index 0000000..6629722 --- /dev/null +++ b/scripts/CSharp/Common/WorldManagement/WorldChangeTrigger.cs @@ -0,0 +1,26 @@ +using Godot; +using System; +using Babushka.scripts.CSharp.Common.WorldManagement; + +public partial class WorldChangeTrigger : Area3D +{ + [Export] private PackedScene switchToWorld; + [Export] private SpawnPointResource switchToSpawnPoint; + + public override void _EnterTree() + { + //AreaEntered += AreaEnteredHandler; + } + + public override void _ExitTree() + { + //AreaEntered -= AreaEnteredHandler; + } + + public void AreaEnteredHandler(Area3D area) + { + GD.Print("Area Entered"); + var worldContainer = (WorldContainer)FindParent("WorldContainer"); + worldContainer.SwitchWorld(switchToWorld, switchToSpawnPoint); + } +} \ No newline at end of file diff --git a/scripts/CSharp/Common/WorldManagement/WorldChangeTrigger.cs.uid b/scripts/CSharp/Common/WorldManagement/WorldChangeTrigger.cs.uid new file mode 100644 index 0000000..9e9e705 --- /dev/null +++ b/scripts/CSharp/Common/WorldManagement/WorldChangeTrigger.cs.uid @@ -0,0 +1 @@ +uid://cpbv0b3ahorep diff --git a/scripts/CSharp/Common/WorldManagement/WorldContainer.cs b/scripts/CSharp/Common/WorldManagement/WorldContainer.cs new file mode 100644 index 0000000..b1aad67 --- /dev/null +++ b/scripts/CSharp/Common/WorldManagement/WorldContainer.cs @@ -0,0 +1,41 @@ +using Godot; +using System; +using System.Linq; +using Babushka.scripts.CSharp.Common.WorldManagement; + +public partial class WorldContainer : Node +{ + [Export] private PackedScene startingWorld; + [Export] private SpawnPointResource startingSpawnPoint; + + [Signal] public delegate void WorldChangedEventHandler(Vector3 spawnPointPosition); + + public void SwitchWorld(PackedScene newWorldScene, SpawnPointResource spawnPoint) + { + // Unload the current world + if (GetChildCount() > 0) + { + GetChild(0).QueueFree(); + } + + // Load the new world + var newWorld = newWorldScene.Instantiate(); + AddChild(newWorld); + + // Switch to the new spawn point + if (newWorld.SpawnPoints.TryGetValue(spawnPoint, out var spawnPointMarker)) + { + EmitSignalWorldChanged(spawnPointMarker.GlobalPosition); + } + else + { + GD.PrintErr("Selected spawn point not found in the new world."); + EmitSignalWorldChanged(newWorld.SpawnPoints.First().Value.GlobalPosition); + } + } + + public override void _Ready() + { + SwitchWorld(startingWorld,startingSpawnPoint); + } +} diff --git a/scripts/CSharp/Common/WorldManagement/WorldContainer.cs.uid b/scripts/CSharp/Common/WorldManagement/WorldContainer.cs.uid new file mode 100644 index 0000000..1069a4e --- /dev/null +++ b/scripts/CSharp/Common/WorldManagement/WorldContainer.cs.uid @@ -0,0 +1 @@ +uid://g338f4yomfo3