diff options
Diffstat (limited to 'scenes/turn_manager.tscn')
| -rw-r--r-- | scenes/turn_manager.tscn | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/scenes/turn_manager.tscn b/scenes/turn_manager.tscn index 4a1cf5c..9e9a4f7 100644 --- a/scenes/turn_manager.tscn +++ b/scenes/turn_manager.tscn @@ -1,6 +1,62 @@ [gd_scene load_steps=2 format=3 uid="uid://ie3vpgatjvkw"] -[ext_resource type="Script" uid="uid://ynjn2pmluvf6" path="res://scripts/TurnManager.cs" id="1_3c2a3"] +[sub_resource type="CSharpScript" id="CSharpScript_4jeo4"] +script/source = "using Godot; +using System; +using System.Collections.Generic; +using System.Reflection.Metadata.Ecma335; + +public partial class TurnManager : Node { + [Signal] + public delegate void turnBeginEventHandler(); + [Signal] + public delegate void turnEndEventHandler(); + + private Godot.Collections.Array<Node> actors = []; + private int index = 0; + + public int TurnCount { get; private set; } = 1; + + public void Tick() { + EmitSignal(SignalName.turnBegin); + + actors.Clear(); + actors = GetTree().GetNodesInGroup(\"TimeSlave\"); + + index = -1; + NextActor(); + } + + private void NextActor() { + index++; + if (index >= actors.Count) { + EndTurn(); + return; + } + Actor currentActor = (Actor) actors[index]; + currentActor.Energy += currentActor.Speed; + ActorPerformAction(); + } + + private void ActorPerformAction() { + Actor currentActor = (Actor) actors[index]; + if (currentActor.Energy > 0) { + currentActor.PerformAction(); + } else { + NextActor(); + } + } + + public void OnActionEnd() { + ActorPerformAction(); + } + + private void EndTurn() { + TurnCount++; + EmitSignal(SignalName.turnEnd); + } +} +" [node name="TurnManager" type="Node"] -script = ExtResource("1_3c2a3") +script = SubResource("CSharpScript_4jeo4") |
