You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
2.0 KiB
63 lines
2.0 KiB
using System;
|
|
using System.Diagnostics;
|
|
using System.Threading.Tasks;
|
|
using Babushka.scripts.CSharp.Common.SceneManagement;
|
|
using Godot;
|
|
|
|
namespace Babushka.scripts.CSharp.Common.Fight;
|
|
|
|
public partial class FightSceneSwitcher : Node
|
|
{
|
|
[Export] private Node _sceneRoot = null!;
|
|
[Export] private string _fightRoomScenePath = null!;
|
|
[Export] private string _fightHappeningScene = null!;
|
|
|
|
private void LoadNext()
|
|
{
|
|
var nextRoom = FightWorld.Instance.currentRoom;
|
|
Debug.Assert(nextRoom != null, "nextRoom!=null");
|
|
var nextFightHappening = FightWorld.Instance.fightHappeningData;
|
|
SceneTransitionThreaded.Instance.ChangeSceneToFile(nextFightHappening != null
|
|
? _fightHappeningScene
|
|
: _fightRoomScenePath);
|
|
_ = UnloadAfterDelay();
|
|
}
|
|
|
|
private async Task UnloadAfterDelay()
|
|
{
|
|
await ToSignal(GetTree().CreateTimer(1.0f), "timeout"); // 1.0f seconds
|
|
//sceneRoot.QueueFree();
|
|
}
|
|
|
|
public void SwitchRoom(int pathIndex)
|
|
{
|
|
Debug.Assert(FightWorld.Instance.currentRoom != null, "FightWorld.Instance.currentRoom!=null");
|
|
|
|
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();
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
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();
|
|
}
|
|
} |