Files

63 lines
2.0 KiB
C#
Raw Permalink Normal View History

2025-09-12 13:20:27 +02:00
using System;
using System.Diagnostics;
2025-10-07 15:29:39 +02:00
using System.Threading.Tasks;
2025-09-12 13:20:27 +02:00
using Babushka.scripts.CSharp.Common.SceneManagement;
using Godot;
namespace Babushka.scripts.CSharp.Common.Fight;
public partial class FightSceneSwitcher : Node
{
2025-10-07 15:29:39 +02:00
[Export] private Node _sceneRoot = null!;
[Export] private string _fightRoomScenePath = null!;
[Export] private string _fightHappeningScene = null!;
2025-09-12 13:20:27 +02:00
private void LoadNext()
{
var nextRoom = FightWorld.Instance.currentRoom;
Debug.Assert(nextRoom != null, "nextRoom!=null");
2025-09-21 14:54:55 +02:00
var nextFightHappening = FightWorld.Instance.fightHappeningData;
SceneTransitionThreaded.Instance.ChangeSceneToFile(nextFightHappening != null
2025-10-07 15:29:39 +02:00
? _fightHappeningScene
: _fightRoomScenePath);
_ = UnloadAfterDelay();
2025-09-12 13:20:27 +02:00
}
2025-10-07 15:29:39 +02:00
private async Task UnloadAfterDelay()
2025-09-12 13:20:27 +02:00
{
await ToSignal(GetTree().CreateTimer(1.0f), "timeout"); // 1.0f seconds
2025-09-30 16:23:05 +02:00
//sceneRoot.QueueFree();
2025-09-12 13:20:27 +02:00
}
public void SwitchRoom(int pathIndex)
{
Debug.Assert(FightWorld.Instance.currentRoom != null, "FightWorld.Instance.currentRoom!=null");
2025-11-03 20:21:30 +01:00
2025-09-12 13:20:27 +02:00
if (!FightWorld.Instance.currentRoom.paths.TryGetValue(pathIndex, out var nextRoom))
throw new Exception("Trying to go down a non-existent path");
FightWorld.Instance.currentRoom = nextRoom;
LoadNext();
}
2025-09-30 16:23:05 +02:00
public void SwitchToFight(FightWorld.FighterGroup enemyGroup)
{
if (FightWorld.Instance.fightHappeningData != null)
throw new Exception("Trying to start a fight while already in a fight");
FightWorld.Instance.fightHappeningData = new FightWorld.FightHappeningData
{
enemyGroup = enemyGroup,
};
LoadNext();
}
2025-10-05 19:50:05 +02:00
public void ExitFight()
{
if (FightWorld.Instance.fightHappeningData == null)
throw new Exception("Trying to exit a fight while not in a fight");
FightWorld.Instance.fightHappeningData = null;
LoadNext();
}
2025-09-12 13:20:27 +02:00
}