World transision WIP

This commit is contained in:
cblech
2025-04-21 15:31:01 +02:00
parent 1782ff91b4
commit 71ca6c3305
22 changed files with 257 additions and 16 deletions
@@ -129,5 +129,11 @@ public partial class Player3D : CharacterBody3D
animatedSprite.Visible = false;
}
}
public void Teleport(Vector3 newPosition)
{
GlobalPosition = newPosition;
ResetPhysicsInterpolation();
GD.Print("Player Teleported");
}
}
@@ -15,6 +15,11 @@ public partial class VesnaBehaviour : Node
{
_farmingControls.FieldParent = _fieldParent;
}
public void TeleportTo(Vector3 newPosition)
{
GetNode<Player3D>("CharacterBody3D").Teleport(newPosition);
}
#region Farming
@@ -0,0 +1 @@
uid://bb4fc5y43ksfg
@@ -0,0 +1,8 @@
using Godot;
using System;
using Babushka.scripts.CSharp.Common.WorldManagement;
public partial class SpawnPointMarker : Node3D
{
[Export] public SpawnPointResource spawnPointResource;
}
@@ -0,0 +1 @@
uid://c7eaa0neniiss
@@ -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 = "";
}
}
@@ -0,0 +1 @@
uid://cjr2efpm660kr
@@ -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<SpawnPointResource, SpawnPointMarker> SpawnPoints;
public override void _EnterTree()
{
GD.Print("World Enter Tree");
// find all child nodes of type SpawnPoint
SpawnPoints = FindChildren("*")
.OfType<SpawnPointMarker>()
.Select(sp => new KeyValuePair<SpawnPointResource, SpawnPointMarker>(sp.spawnPointResource, sp))
.ToDictionary();
}
}
@@ -0,0 +1 @@
uid://6aq8mr0sofrs
@@ -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);
}
}
@@ -0,0 +1 @@
uid://cpbv0b3ahorep
@@ -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<World>();
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);
}
}
@@ -0,0 +1 @@
uid://g338f4yomfo3