🐛Exiting fight happening when one side wins

This commit is contained in:
jonathan
2025-10-05 19:50:05 +02:00
parent 83c9dfc945
commit 3326bde40c
4 changed files with 41 additions and 2 deletions
@@ -50,4 +50,13 @@ public partial class FightSceneSwitcher : Node
};
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();
}
}
@@ -0,0 +1,22 @@
using System.Threading.Tasks;
using Godot;
namespace Babushka.scripts.CSharp.Common.Fight;
public partial class SwitchSceneOnFightEnd : Node
{
[Export] private FightSceneSwitcher _fightSceneSwitcher = null!;
public void OnFightStateEnter(FightHappening.FightState to)
{
if (to is FightHappening.FightState.PlayerWin
or FightHappening.FightState.EnemyWin)
_ = SwitchSceneAfterTime(2.0f);
}
private async Task SwitchSceneAfterTime(float seconds)
{
await ToSignal(GetTree().CreateTimer(seconds), "timeout");
_fightSceneSwitcher.ExitFight();
}
}
@@ -0,0 +1 @@
uid://2f7rqk50gtdg