using System; using System.Diagnostics; using Babushka.scripts.CSharp.Common.SceneManagement; using Godot; namespace Babushka.scripts.CSharp.Common.Fight; public partial class FightSceneSwitcher : Node { [Export] private Node sceneRoot; [Export] private string fightRoomScenePath; [Export] private string fightHappeningScene; 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 void 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(); } }