Black box sim engine (commands in, events out) with 3 piece types (Rook, Bishop, Knight), cargo transfer system with social status priority, collision detection, and victory/defeat conditions. 57 tests covering rules, simulation, loading, and solvability. Godot 4 presentation layer scaffolding.
88 lines
2.6 KiB
C#
88 lines
2.6 KiB
C#
using Godot;
|
|
using System;
|
|
using Chessistics.Engine.Model;
|
|
|
|
namespace Chessistics.Scripts.UI;
|
|
|
|
public partial class ControlBar : HBoxContainer
|
|
{
|
|
[Signal]
|
|
public delegate void PlayPressedEventHandler();
|
|
[Signal]
|
|
public delegate void PausePressedEventHandler();
|
|
[Signal]
|
|
public delegate void StepPressedEventHandler();
|
|
[Signal]
|
|
public delegate void StopPressedEventHandler();
|
|
[Signal]
|
|
public delegate void SpeedChangedEventHandler(float speed);
|
|
|
|
private Button _playButton = null!;
|
|
private Button _pauseButton = null!;
|
|
private Button _stepButton = null!;
|
|
private Button _stopButton = null!;
|
|
private OptionButton _speedSelect = null!;
|
|
private Label _turnLabel = null!;
|
|
|
|
public override void _Ready()
|
|
{
|
|
_playButton = new Button { Text = "▶ PLAY" };
|
|
_playButton.Pressed += () => EmitSignal(SignalName.PlayPressed);
|
|
AddChild(_playButton);
|
|
|
|
_pauseButton = new Button { Text = "⏸ PAUSE" };
|
|
_pauseButton.Pressed += () => EmitSignal(SignalName.PausePressed);
|
|
AddChild(_pauseButton);
|
|
|
|
_stepButton = new Button { Text = "⏭ STEP" };
|
|
_stepButton.Pressed += () => EmitSignal(SignalName.StepPressed);
|
|
AddChild(_stepButton);
|
|
|
|
_stopButton = new Button { Text = "⏹ STOP" };
|
|
_stopButton.Pressed += () => EmitSignal(SignalName.StopPressed);
|
|
AddChild(_stopButton);
|
|
|
|
_speedSelect = new OptionButton();
|
|
_speedSelect.AddItem("x1", 0);
|
|
_speedSelect.AddItem("x2", 1);
|
|
_speedSelect.AddItem("x4", 2);
|
|
_speedSelect.ItemSelected += OnSpeedSelected;
|
|
AddChild(_speedSelect);
|
|
|
|
_turnLabel = new Label { Text = "Coup: --" };
|
|
_turnLabel.AddThemeFontSizeOverride("font_size", 14);
|
|
AddChild(_turnLabel);
|
|
|
|
UpdateForPhase(SimPhase.Edit);
|
|
}
|
|
|
|
private void OnSpeedSelected(long index)
|
|
{
|
|
float speed = index switch
|
|
{
|
|
0 => 1.0f,
|
|
1 => 0.5f,
|
|
2 => 0.25f,
|
|
_ => 1.0f
|
|
};
|
|
EmitSignal(SignalName.SpeedChanged, speed);
|
|
}
|
|
|
|
public void UpdateForPhase(SimPhase phase)
|
|
{
|
|
_playButton.Disabled = phase != SimPhase.Edit && phase != SimPhase.Paused;
|
|
_pauseButton.Disabled = phase != SimPhase.Running;
|
|
_stepButton.Disabled = phase == SimPhase.Running || phase == SimPhase.Victory || phase == SimPhase.Defeat;
|
|
_stopButton.Disabled = phase == SimPhase.Edit;
|
|
}
|
|
|
|
public void UpdateTurn(int turn)
|
|
{
|
|
_turnLabel.Text = $"Coup: {turn}";
|
|
}
|
|
|
|
public void ResetTurn()
|
|
{
|
|
_turnLabel.Text = "Coup: --";
|
|
}
|
|
}
|