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 fightingGroupScene; private void LoadNext() { var nextRoom = FightWorld.Instance.currentRoom; Debug.Assert(nextRoom != null, "nextRoom!=null"); var nextEnemyGroup = FightWorld.Instance.inFightWith; SceneTransitionThreaded.Instance.ChangeSceneToFile(nextEnemyGroup != null ? fightingGroupScene : 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(); } }