From bd6432f5689bfba7d218d6f95434c0617156e398 Mon Sep 17 00:00:00 2001 From: jonathan Date: Sun, 5 Oct 2025 19:50:05 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9BExiting=20fight=20happening=20when?= =?UTF-8?q?=20one=20side=20wins?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scenes/Babushka_scene_fight_happening.tscn | 11 ++++++++-- .../CSharp/Common/Fight/FightSceneSwitcher.cs | 9 ++++++++ .../Common/Fight/SwitchSceneOnFightEnd.cs | 22 +++++++++++++++++++ .../Common/Fight/SwitchSceneOnFightEnd.cs.uid | 1 + 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 scripts/CSharp/Common/Fight/SwitchSceneOnFightEnd.cs create mode 100644 scripts/CSharp/Common/Fight/SwitchSceneOnFightEnd.cs.uid diff --git a/scenes/Babushka_scene_fight_happening.tscn b/scenes/Babushka_scene_fight_happening.tscn index 7beedd9..b8ce694 100644 --- a/scenes/Babushka_scene_fight_happening.tscn +++ b/scenes/Babushka_scene_fight_happening.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=13 format=3 uid="uid://cjshlwk8ajpnp"] +[gd_scene load_steps=14 format=3 uid="uid://cjshlwk8ajpnp"] [ext_resource type="Script" uid="uid://cnhpnn8o0gybd" path="res://scripts/CSharp/Common/Fight/FightHappeningSceneSetup.cs" id="1_fiutj"] [ext_resource type="Script" uid="uid://c76mhhqyk4lgh" path="res://scripts/CSharp/Common/Fight/FightHappening.cs" id="1_gsk03"] @@ -12,6 +12,7 @@ [ext_resource type="Script" uid="uid://byf2ywov34g0x" path="res://scripts/CSharp/Common/Fight/UI/ActionSelectUiSetup.cs" id="8_bkwsr"] [ext_resource type="Script" uid="uid://bwm0nhvt1083k" path="res://scripts/CSharp/Common/Fight/FightMinigameHandler.cs" id="8_falfe"] [ext_resource type="Script" uid="uid://d2ugtb3dalrg3" path="res://scripts/CSharp/Common/Fight/FightHappeningStateDebugger.cs" id="8_tv7cl"] +[ext_resource type="Script" uid="uid://2f7rqk50gtdg" path="res://scripts/CSharp/Common/Fight/SwitchSceneOnFightEnd.cs" id="10_qqd8u"] [node name="BabushkaSceneFightHappening" type="Node2D"] @@ -54,7 +55,12 @@ _minigameController = NodePath("Minigame") process_mode = 4 visible = false -[node name="FightSceneSwitcher" parent="." instance=ExtResource("2_phrlx")] +[node name="SwitchSceneOnFightEnd" type="Node" parent="." node_paths=PackedStringArray("_fightSceneSwitcher")] +script = ExtResource("10_qqd8u") +_fightSceneSwitcher = NodePath("FightSceneSwitcher") + +[node name="FightSceneSwitcher" parent="SwitchSceneOnFightEnd" node_paths=PackedStringArray("sceneRoot") instance=ExtResource("2_phrlx")] +sceneRoot = NodePath("../..") [node name="ActionSelect" type="CanvasLayer" parent="." node_paths=PackedStringArray("_attackActionButton", "_summonActionButton", "_talkActionButton", "_fleeActionButton")] visible = false @@ -202,6 +208,7 @@ text = "Hello world" [connection signal="SignalTransitionState" from="FightHappening" to="ActionSelect/StateReactionInputActionSelect" method="FightHappeningStateTransitioned"] [connection signal="SignalTransitionState" from="FightHappening" to="StateMachineDebugger" method="StateChange"] [connection signal="SignalTransitionToState" from="FightHappening" to="MinigameHandler" method="OnStateEnter"] +[connection signal="SignalTransitionToState" from="FightHappening" to="SwitchSceneOnFightEnd" method="OnFightStateEnter"] [connection signal="OnStateEntered" from="ActionAnimationController/StateReactionActionAnimation" to="ActionAnimationController" method="StateEnter"] [connection signal="OnStateExited" from="ActionAnimationController/StateReactionActionAnimation" to="ActionAnimationController" method="StateExit"] [connection signal="pressed" from="ActionSelect/BottomPanel/VBoxContainer/MarginContainer/HBoxContainer/MarginContainer/AttackButton" to="ActionSelect" method="SelectAction" binds= [1]] diff --git a/scripts/CSharp/Common/Fight/FightSceneSwitcher.cs b/scripts/CSharp/Common/Fight/FightSceneSwitcher.cs index c25318c..0a84d4b 100644 --- a/scripts/CSharp/Common/Fight/FightSceneSwitcher.cs +++ b/scripts/CSharp/Common/Fight/FightSceneSwitcher.cs @@ -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(); + } } \ No newline at end of file diff --git a/scripts/CSharp/Common/Fight/SwitchSceneOnFightEnd.cs b/scripts/CSharp/Common/Fight/SwitchSceneOnFightEnd.cs new file mode 100644 index 0000000..d4b0cd3 --- /dev/null +++ b/scripts/CSharp/Common/Fight/SwitchSceneOnFightEnd.cs @@ -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(); + } +} \ No newline at end of file diff --git a/scripts/CSharp/Common/Fight/SwitchSceneOnFightEnd.cs.uid b/scripts/CSharp/Common/Fight/SwitchSceneOnFightEnd.cs.uid new file mode 100644 index 0000000..66971c1 --- /dev/null +++ b/scripts/CSharp/Common/Fight/SwitchSceneOnFightEnd.cs.uid @@ -0,0 +1 @@ +uid://2f7rqk50gtdg