♻️Code cleanup

test/music_setup
jonathan 3 months ago
parent bd6432f568
commit 719b1fa800

@ -2,8 +2,8 @@
[ext_resource type="Script" uid="uid://cql8mt5jsmcdl" path="res://scripts/CSharp/Common/Fight/FightSceneSwitcher.cs" id="1_5dt1r"]
[node name="FightSceneSwitcher" type="Node" node_paths=PackedStringArray("sceneRoot")]
[node name="FightSceneSwitcher" type="Node" node_paths=PackedStringArray("_sceneRoot")]
script = ExtResource("1_5dt1r")
sceneRoot = NodePath("")
fightRoomScenePath = "res://scenes/Babushka_scene_fight_world_room.tscn"
fightHappeningScene = "res://scenes/Babushka_scene_fight_happening.tscn"
_sceneRoot = NodePath("")
_fightRoomScenePath = "res://scenes/Babushka_scene_fight_world_room.tscn"
_fightHappeningScene = "res://scenes/Babushka_scene_fight_happening.tscn"

@ -59,8 +59,8 @@ visible = false
script = ExtResource("10_qqd8u")
_fightSceneSwitcher = NodePath("FightSceneSwitcher")
[node name="FightSceneSwitcher" parent="SwitchSceneOnFightEnd" node_paths=PackedStringArray("sceneRoot") instance=ExtResource("2_phrlx")]
sceneRoot = NodePath("../..")
[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

@ -2148,8 +2148,9 @@ position = Vector2(1560, 422)
[node name="Spawn4" type="Node2D" parent="YSorted/EnemyGroupSpawns"]
position = Vector2(-1127, 671)
[node name="FightSceneSwitcher" parent="." instance=ExtResource("40_elhbh")]
[node name="FightSceneSwitcher" parent="." node_paths=PackedStringArray("_sceneRoot") instance=ExtResource("40_elhbh")]
unique_name_in_owner = true
_sceneRoot = NodePath("..")
[node name="FightSceneSetup" type="Node" parent="." node_paths=PackedStringArray("_enemyGroupSpawns", "_fightSceneSwitcher")]
script = ExtResource("40_cvg1r")

@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Babushka.scripts.CSharp.Common.SceneManagement;
using Godot;
@ -7,9 +8,9 @@ namespace Babushka.scripts.CSharp.Common.Fight;
public partial class FightSceneSwitcher : Node
{
[Export] private Node sceneRoot;
[Export] private string fightRoomScenePath;
[Export] private string fightHappeningScene;
[Export] private Node _sceneRoot = null!;
[Export] private string _fightRoomScenePath = null!;
[Export] private string _fightHappeningScene = null!;
private void LoadNext()
{
@ -17,12 +18,12 @@ public partial class FightSceneSwitcher : Node
Debug.Assert(nextRoom != null, "nextRoom!=null");
var nextFightHappening = FightWorld.Instance.fightHappeningData;
SceneTransitionThreaded.Instance.ChangeSceneToFile(nextFightHappening != null
? fightHappeningScene
: fightRoomScenePath);
UnloadAfterDelay();
? _fightHappeningScene
: _fightRoomScenePath);
_ = UnloadAfterDelay();
}
private async void UnloadAfterDelay()
private async Task UnloadAfterDelay()
{
await ToSignal(GetTree().CreateTimer(1.0f), "timeout"); // 1.0f seconds
//sceneRoot.QueueFree();

@ -1,5 +1,5 @@
using System.Collections.Generic;
using Godot.NativeInterop;
using System;
using System.Diagnostics;
namespace Babushka.scripts.CSharp.Common.Fight;
@ -7,37 +7,39 @@ public class FighterStack
{
private class Node
{
public Node next;
public FightWorld.Fighter fighter;
public required Node next;
public required FightWorld.Fighter fighter;
}
private Node? currentNode;
private Node? _currentNode;
public FightWorld.Fighter Current => currentNode.fighter;
public FightWorld.Fighter Current => _currentNode?.fighter ?? throw new InvalidOperationException("No current fighter");
public void Next()
{
currentNode = currentNode.next;
Debug.Assert(_currentNode != null, "currentNode!=null");
_currentNode = _currentNode.next;
}
public FightWorld.Fighter PeekNext()
{
return currentNode.next.fighter;
Debug.Assert(_currentNode != null, "currentNode!=null");
return _currentNode.next.fighter;
}
public void AddAsLast(FightWorld.Fighter value)
{
// if first node
if (currentNode == null)
if (_currentNode == null)
{
currentNode = new Node { fighter = value };
currentNode.next = currentNode;
_currentNode = new Node { fighter = value, next = null! };
_currentNode.next = _currentNode;
return;
}
var newNode = new Node { fighter = value, next = currentNode };
var node = currentNode;
while (node.next != currentNode)
var newNode = new Node { fighter = value, next = _currentNode };
var node = _currentNode;
while (node.next != _currentNode)
{
node = node.next;
}
@ -48,47 +50,47 @@ public class FighterStack
public void AddAsNext(FightWorld.Fighter value)
{
// if first node
if (currentNode == null)
if (_currentNode == null)
{
AddAsLast(value);
return;
}
var newNode = new Node { fighter = value, next = currentNode.next };
currentNode.next = newNode;
var newNode = new Node { fighter = value, next = _currentNode.next };
_currentNode.next = newNode;
}
public bool Remove(FightWorld.Fighter value)
{
if (currentNode == null) return false;
if (_currentNode == null) return false;
// if only one node
if (currentNode.next == currentNode)
if (_currentNode.next == _currentNode)
{
if (currentNode.fighter == value)
if (_currentNode.fighter == value)
{
currentNode = null;
_currentNode = null;
return true;
}
return false;
}
var node = currentNode;
var node = _currentNode;
do
{
// next is the fighter to remove
if (node.next.fighter == value)
{
// if removing current, keep current
// it will be implicitly deleted on the next Next() call
// it will be implicitly deleted by loss of reference on the next Next() call
node.next = node.next.next;
return true;
}
node = node.next;
} while (node != currentNode);
} while (node != _currentNode);
return false;
}

Loading…
Cancel
Save