♻️Code cleanup
This commit is contained in:
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
[ext_resource type="Script" uid="uid://cql8mt5jsmcdl" path="res://scripts/CSharp/Common/Fight/FightSceneSwitcher.cs" id="1_5dt1r"]
|
[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")
|
script = ExtResource("1_5dt1r")
|
||||||
sceneRoot = NodePath("")
|
_sceneRoot = NodePath("")
|
||||||
fightRoomScenePath = "res://scenes/Babushka_scene_fight_world_room.tscn"
|
_fightRoomScenePath = "res://scenes/Babushka_scene_fight_world_room.tscn"
|
||||||
fightHappeningScene = "res://scenes/Babushka_scene_fight_happening.tscn"
|
_fightHappeningScene = "res://scenes/Babushka_scene_fight_happening.tscn"
|
||||||
|
|||||||
@@ -59,8 +59,8 @@ visible = false
|
|||||||
script = ExtResource("10_qqd8u")
|
script = ExtResource("10_qqd8u")
|
||||||
_fightSceneSwitcher = NodePath("FightSceneSwitcher")
|
_fightSceneSwitcher = NodePath("FightSceneSwitcher")
|
||||||
|
|
||||||
[node name="FightSceneSwitcher" parent="SwitchSceneOnFightEnd" node_paths=PackedStringArray("sceneRoot") instance=ExtResource("2_phrlx")]
|
[node name="FightSceneSwitcher" parent="SwitchSceneOnFightEnd" node_paths=PackedStringArray("_sceneRoot") instance=ExtResource("2_phrlx")]
|
||||||
sceneRoot = NodePath("../..")
|
_sceneRoot = NodePath("../..")
|
||||||
|
|
||||||
[node name="ActionSelect" type="CanvasLayer" parent="." node_paths=PackedStringArray("_attackActionButton", "_summonActionButton", "_talkActionButton", "_fleeActionButton")]
|
[node name="ActionSelect" type="CanvasLayer" parent="." node_paths=PackedStringArray("_attackActionButton", "_summonActionButton", "_talkActionButton", "_fleeActionButton")]
|
||||||
visible = false
|
visible = false
|
||||||
|
|||||||
@@ -2148,8 +2148,9 @@ position = Vector2(1560, 422)
|
|||||||
[node name="Spawn4" type="Node2D" parent="YSorted/EnemyGroupSpawns"]
|
[node name="Spawn4" type="Node2D" parent="YSorted/EnemyGroupSpawns"]
|
||||||
position = Vector2(-1127, 671)
|
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
|
unique_name_in_owner = true
|
||||||
|
_sceneRoot = NodePath("..")
|
||||||
|
|
||||||
[node name="FightSceneSetup" type="Node" parent="." node_paths=PackedStringArray("_enemyGroupSpawns", "_fightSceneSwitcher")]
|
[node name="FightSceneSetup" type="Node" parent="." node_paths=PackedStringArray("_enemyGroupSpawns", "_fightSceneSwitcher")]
|
||||||
script = ExtResource("40_cvg1r")
|
script = ExtResource("40_cvg1r")
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Babushka.scripts.CSharp.Common.SceneManagement;
|
using Babushka.scripts.CSharp.Common.SceneManagement;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
@@ -7,9 +8,9 @@ namespace Babushka.scripts.CSharp.Common.Fight;
|
|||||||
|
|
||||||
public partial class FightSceneSwitcher : Node
|
public partial class FightSceneSwitcher : Node
|
||||||
{
|
{
|
||||||
[Export] private Node sceneRoot;
|
[Export] private Node _sceneRoot = null!;
|
||||||
[Export] private string fightRoomScenePath;
|
[Export] private string _fightRoomScenePath = null!;
|
||||||
[Export] private string fightHappeningScene;
|
[Export] private string _fightHappeningScene = null!;
|
||||||
|
|
||||||
private void LoadNext()
|
private void LoadNext()
|
||||||
{
|
{
|
||||||
@@ -17,12 +18,12 @@ public partial class FightSceneSwitcher : Node
|
|||||||
Debug.Assert(nextRoom != null, "nextRoom!=null");
|
Debug.Assert(nextRoom != null, "nextRoom!=null");
|
||||||
var nextFightHappening = FightWorld.Instance.fightHappeningData;
|
var nextFightHappening = FightWorld.Instance.fightHappeningData;
|
||||||
SceneTransitionThreaded.Instance.ChangeSceneToFile(nextFightHappening != null
|
SceneTransitionThreaded.Instance.ChangeSceneToFile(nextFightHappening != null
|
||||||
? fightHappeningScene
|
? _fightHappeningScene
|
||||||
: fightRoomScenePath);
|
: _fightRoomScenePath);
|
||||||
UnloadAfterDelay();
|
_ = UnloadAfterDelay();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void UnloadAfterDelay()
|
private async Task UnloadAfterDelay()
|
||||||
{
|
{
|
||||||
await ToSignal(GetTree().CreateTimer(1.0f), "timeout"); // 1.0f seconds
|
await ToSignal(GetTree().CreateTimer(1.0f), "timeout"); // 1.0f seconds
|
||||||
//sceneRoot.QueueFree();
|
//sceneRoot.QueueFree();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
using Godot.NativeInterop;
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace Babushka.scripts.CSharp.Common.Fight;
|
namespace Babushka.scripts.CSharp.Common.Fight;
|
||||||
|
|
||||||
@@ -7,37 +7,39 @@ public class FighterStack
|
|||||||
{
|
{
|
||||||
private class Node
|
private class Node
|
||||||
{
|
{
|
||||||
public Node next;
|
public required Node next;
|
||||||
public FightWorld.Fighter fighter;
|
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()
|
public void Next()
|
||||||
{
|
{
|
||||||
currentNode = currentNode.next;
|
Debug.Assert(_currentNode != null, "currentNode!=null");
|
||||||
|
_currentNode = _currentNode.next;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FightWorld.Fighter PeekNext()
|
public FightWorld.Fighter PeekNext()
|
||||||
{
|
{
|
||||||
return currentNode.next.fighter;
|
Debug.Assert(_currentNode != null, "currentNode!=null");
|
||||||
|
return _currentNode.next.fighter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddAsLast(FightWorld.Fighter value)
|
public void AddAsLast(FightWorld.Fighter value)
|
||||||
{
|
{
|
||||||
// if first node
|
// if first node
|
||||||
if (currentNode == null)
|
if (_currentNode == null)
|
||||||
{
|
{
|
||||||
currentNode = new Node { fighter = value };
|
_currentNode = new Node { fighter = value, next = null! };
|
||||||
currentNode.next = currentNode;
|
_currentNode.next = _currentNode;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var newNode = new Node { fighter = value, next = currentNode };
|
var newNode = new Node { fighter = value, next = _currentNode };
|
||||||
var node = currentNode;
|
var node = _currentNode;
|
||||||
while (node.next != currentNode)
|
while (node.next != _currentNode)
|
||||||
{
|
{
|
||||||
node = node.next;
|
node = node.next;
|
||||||
}
|
}
|
||||||
@@ -48,47 +50,47 @@ public class FighterStack
|
|||||||
public void AddAsNext(FightWorld.Fighter value)
|
public void AddAsNext(FightWorld.Fighter value)
|
||||||
{
|
{
|
||||||
// if first node
|
// if first node
|
||||||
if (currentNode == null)
|
if (_currentNode == null)
|
||||||
{
|
{
|
||||||
AddAsLast(value);
|
AddAsLast(value);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var newNode = new Node { fighter = value, next = currentNode.next };
|
var newNode = new Node { fighter = value, next = _currentNode.next };
|
||||||
currentNode.next = newNode;
|
_currentNode.next = newNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Remove(FightWorld.Fighter value)
|
public bool Remove(FightWorld.Fighter value)
|
||||||
{
|
{
|
||||||
if (currentNode == null) return false;
|
if (_currentNode == null) return false;
|
||||||
|
|
||||||
// if only one node
|
// 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 true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var node = currentNode;
|
var node = _currentNode;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
// next is the fighter to remove
|
// next is the fighter to remove
|
||||||
if (node.next.fighter == value)
|
if (node.next.fighter == value)
|
||||||
{
|
{
|
||||||
// if removing current, keep current
|
// 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;
|
node.next = node.next.next;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
node = node.next;
|
node = node.next;
|
||||||
} while (node != currentNode);
|
} while (node != _currentNode);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user