misc: fmt
This commit is contained in:
@@ -3,4 +3,4 @@ using System;
|
|||||||
|
|
||||||
public partial class AddressUI : TextEdit {
|
public partial class AddressUI : TextEdit {
|
||||||
public override void _Ready() { Text = Connection.WS_DEFAULT_ADDRESS; }
|
public override void _Ready() { Text = Connection.WS_DEFAULT_ADDRESS; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,126 +8,126 @@ public partial class AdminControls : HBoxContainer {
|
|||||||
[Export] public Slider Timeout;
|
[Export] public Slider Timeout;
|
||||||
|
|
||||||
public override void _Ready() {
|
public override void _Ready() {
|
||||||
Connection.Instance.OnBecomeAdmin += UpdateUI;
|
Connection.Instance.OnBecomeAdmin += UpdateUI;
|
||||||
Connection.Instance.OnTournamentEnd += UpdateUI;
|
Connection.Instance.OnTournamentEnd += UpdateUI;
|
||||||
Connection.Instance.OnStartTournament += UpdateUI;
|
Connection.Instance.OnStartTournament += UpdateUI;
|
||||||
Connection.Instance.OnCancelTournamentAck += UpdateUI;
|
Connection.Instance.OnCancelTournamentAck += UpdateUI;
|
||||||
Connection.Instance.OnGetDataAcks += UpdateUI;
|
Connection.Instance.OnGetDataAcks += UpdateUI;
|
||||||
Connection.Instance.OnSetDataAcks += UpdateUI;
|
Connection.Instance.OnSetDataAcks += UpdateUI;
|
||||||
|
|
||||||
StartTournament.Pressed += () => Connection.Instance.StartTournament();
|
StartTournament.Pressed += () => Connection.Instance.StartTournament();
|
||||||
CancelTournament.Pressed += () => Connection.Instance.CancelTournament();
|
CancelTournament.Pressed += () => Connection.Instance.CancelTournament();
|
||||||
|
|
||||||
UpdateUI();
|
UpdateUI();
|
||||||
|
|
||||||
Timeout.ValueChanged += value =>
|
Timeout.ValueChanged += value =>
|
||||||
{
|
{
|
||||||
Connection.Instance.SetMoveWait((float)value);
|
Connection.Instance.SetMoveWait((float)value);
|
||||||
var time = Connection.Instance.CurrentWaitTimeout.ToString();
|
var time = Connection.Instance.CurrentWaitTimeout.ToString();
|
||||||
if (time.Length > 3) {
|
if (time.Length > 3) {
|
||||||
time = time.Substring(0, 3);
|
time = time.Substring(0, 3);
|
||||||
}
|
}
|
||||||
Label.Text = "Wait To Move: " + time + "s ";
|
Label.Text = "Wait To Move: " + time + "s ";
|
||||||
};
|
};
|
||||||
|
|
||||||
BecomeAdmin.Pressed += showAuthPopup;
|
BecomeAdmin.Pressed += showAuthPopup;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _ExitTree() {
|
public override void _ExitTree() {
|
||||||
Connection.Instance.OnBecomeAdmin -= UpdateUI;
|
Connection.Instance.OnBecomeAdmin -= UpdateUI;
|
||||||
Connection.Instance.OnTournamentEnd -= UpdateUI;
|
Connection.Instance.OnTournamentEnd -= UpdateUI;
|
||||||
Connection.Instance.OnStartTournament -= UpdateUI;
|
Connection.Instance.OnStartTournament -= UpdateUI;
|
||||||
Connection.Instance.OnCancelTournamentAck -= UpdateUI;
|
Connection.Instance.OnCancelTournamentAck -= UpdateUI;
|
||||||
Connection.Instance.OnGetDataAcks -= UpdateUI;
|
Connection.Instance.OnGetDataAcks -= UpdateUI;
|
||||||
Connection.Instance.OnSetDataAcks -= UpdateUI;
|
Connection.Instance.OnSetDataAcks -= UpdateUI;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateUI() {
|
private void UpdateUI() {
|
||||||
if (!Connection.Instance.IsAdmin) {
|
if (!Connection.Instance.IsAdmin) {
|
||||||
BecomeAdmin.Show();
|
BecomeAdmin.Show();
|
||||||
StartTournament.Hide();
|
StartTournament.Hide();
|
||||||
CancelTournament.Hide();
|
CancelTournament.Hide();
|
||||||
Label.Hide();
|
Label.Hide();
|
||||||
Timeout.Hide();
|
Timeout.Hide();
|
||||||
} else {
|
} else {
|
||||||
BecomeAdmin.Hide();
|
BecomeAdmin.Hide();
|
||||||
Label.Show();
|
Label.Show();
|
||||||
Timeout.Show();
|
Timeout.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Connection.Instance.IsAdmin && Connection.Instance.DemoMode) {
|
if (Connection.Instance.IsAdmin && Connection.Instance.DemoMode) {
|
||||||
StartTournament.Hide();
|
StartTournament.Hide();
|
||||||
CancelTournament.Hide();
|
CancelTournament.Hide();
|
||||||
} else if (Connection.Instance.IsAdmin && Connection.Instance.ActiveTournament != TournamentType.None) {
|
} else if (Connection.Instance.IsAdmin && Connection.Instance.ActiveTournament != TournamentType.None) {
|
||||||
StartTournament.Hide();
|
StartTournament.Hide();
|
||||||
CancelTournament.Show();
|
CancelTournament.Show();
|
||||||
} else if (Connection.Instance.IsAdmin) {
|
} else if (Connection.Instance.IsAdmin) {
|
||||||
StartTournament.Show();
|
StartTournament.Show();
|
||||||
CancelTournament.Hide();
|
CancelTournament.Hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
Timeout.Value = Connection.Instance.CurrentWaitTimeout;
|
Timeout.Value = Connection.Instance.CurrentWaitTimeout;
|
||||||
var time = Connection.Instance.CurrentWaitTimeout.ToString();
|
var time = Connection.Instance.CurrentWaitTimeout.ToString();
|
||||||
if (time.Length > 3) {
|
if (time.Length > 3) {
|
||||||
time = time.Substring(0, 3);
|
time = time.Substring(0, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
Label.Text = "Wait To Move: " + time + "s ";
|
Label.Text = "Wait To Move: " + time + "s ";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showAuthPopup() {
|
private void showAuthPopup() {
|
||||||
var authWindow = new Window();
|
var authWindow = new Window();
|
||||||
authWindow.Theme = GD.Load<Theme>("res://assets/theme.tres");
|
authWindow.Theme = GD.Load<Theme>("res://assets/theme.tres");
|
||||||
authWindow.AlwaysOnTop = true;
|
authWindow.AlwaysOnTop = true;
|
||||||
authWindow.MaximizeDisabled = true;
|
authWindow.MaximizeDisabled = true;
|
||||||
authWindow.Unresizable = true;
|
authWindow.Unresizable = true;
|
||||||
authWindow.InitialPosition = Window.WindowInitialPosition.CenterMainWindowScreen;
|
authWindow.InitialPosition = Window.WindowInitialPosition.CenterMainWindowScreen;
|
||||||
authWindow.Size = new Vector2I(256, 128);
|
authWindow.Size = new Vector2I(256, 128);
|
||||||
authWindow.CloseRequested += () =>
|
authWindow.CloseRequested += () =>
|
||||||
{
|
{
|
||||||
GetTree().Root.CallDeferred(Node.MethodName.RemoveChild, authWindow);
|
GetTree().Root.CallDeferred(Node.MethodName.RemoveChild, authWindow);
|
||||||
};
|
};
|
||||||
|
|
||||||
var vbox = new VBoxContainer();
|
var vbox = new VBoxContainer();
|
||||||
vbox.LayoutMode = 1;
|
vbox.LayoutMode = 1;
|
||||||
vbox.AnchorBottom = 1.0f;
|
vbox.AnchorBottom = 1.0f;
|
||||||
vbox.AnchorRight = 1.0f;
|
vbox.AnchorRight = 1.0f;
|
||||||
vbox.GrowHorizontal = GrowDirection.Both;
|
vbox.GrowHorizontal = GrowDirection.Both;
|
||||||
vbox.GrowVertical = GrowDirection.Both;
|
vbox.GrowVertical = GrowDirection.Both;
|
||||||
vbox.Alignment = AlignmentMode.Center;
|
vbox.Alignment = AlignmentMode.Center;
|
||||||
|
|
||||||
var passwordBox = new TextEdit();
|
var passwordBox = new TextEdit();
|
||||||
passwordBox.PlaceholderText = "Password";
|
passwordBox.PlaceholderText = "Password";
|
||||||
passwordBox.SetCustomMinimumSize(new Vector2(32, 32));
|
passwordBox.SetCustomMinimumSize(new Vector2(32, 32));
|
||||||
|
|
||||||
passwordBox.GuiInput += e =>
|
passwordBox.GuiInput += e =>
|
||||||
{
|
{
|
||||||
if (passwordBox.HasFocus() && e is InputEventKey inputEventKey && inputEventKey.IsPressed()) {
|
if (passwordBox.HasFocus() && e is InputEventKey inputEventKey && inputEventKey.IsPressed()) {
|
||||||
if (inputEventKey.KeyLabel == Key.Enter) {
|
if (inputEventKey.KeyLabel == Key.Enter) {
|
||||||
Connection.Instance.AdminAuth(passwordBox.Text);
|
Connection.Instance.AdminAuth(passwordBox.Text);
|
||||||
GetTree().Root.CallDeferred(Node.MethodName.RemoveChild, authWindow);
|
GetTree().Root.CallDeferred(Node.MethodName.RemoveChild, authWindow);
|
||||||
GetViewport().SetInputAsHandled();
|
GetViewport().SetInputAsHandled();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inputEventKey.KeyLabel == Key.Space) {
|
if (inputEventKey.KeyLabel == Key.Space) {
|
||||||
GetViewport().SetInputAsHandled();
|
GetViewport().SetInputAsHandled();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var button = new Button();
|
var button = new Button();
|
||||||
button.Text = "Login";
|
button.Text = "Login";
|
||||||
button.Pressed += () =>
|
button.Pressed += () =>
|
||||||
{
|
{
|
||||||
Connection.Instance.AdminAuth(passwordBox.Text);
|
Connection.Instance.AdminAuth(passwordBox.Text);
|
||||||
GetTree().Root.CallDeferred(Node.MethodName.RemoveChild, authWindow);
|
GetTree().Root.CallDeferred(Node.MethodName.RemoveChild, authWindow);
|
||||||
};
|
};
|
||||||
|
|
||||||
vbox.AddChild(passwordBox);
|
vbox.AddChild(passwordBox);
|
||||||
vbox.AddChild(button);
|
vbox.AddChild(button);
|
||||||
|
|
||||||
authWindow.AddChild(vbox);
|
authWindow.AddChild(vbox);
|
||||||
|
|
||||||
GetTree().Root.AddChild(authWindow);
|
GetTree().Root.AddChild(authWindow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ public partial class BackButton : TextureButton {
|
|||||||
private const string BRACKET_SCENE_PATH = "res://scenes/bracket_view.tscn";
|
private const string BRACKET_SCENE_PATH = "res://scenes/bracket_view.tscn";
|
||||||
|
|
||||||
public override void _Pressed() {
|
public override void _Pressed() {
|
||||||
transitionToBracket();
|
transitionToBracket();
|
||||||
base._Pressed();
|
base._Pressed();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void transitionToBracket() { GetTree().ChangeSceneToFile(BRACKET_SCENE_PATH); }
|
private void transitionToBracket() { GetTree().ChangeSceneToFile(BRACKET_SCENE_PATH); }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,131 +33,131 @@ public partial class BoardScreen : Node2D {
|
|||||||
|
|
||||||
// Called when the node enters the scene tree for the first time.
|
// Called when the node enters the scene tree for the first time.
|
||||||
public override void _Ready() {
|
public override void _Ready() {
|
||||||
// Node initialization
|
// Node initialization
|
||||||
player1Card = GetNode<Node2D>("Player1Card");
|
player1Card = GetNode<Node2D>("Player1Card");
|
||||||
player2Card = GetNode<Node2D>("Player2Card");
|
player2Card = GetNode<Node2D>("Player2Card");
|
||||||
|
|
||||||
player1Card.GetNode<Label>("Name").Resized += () =>
|
player1Card.GetNode<Label>("Name").Resized += () =>
|
||||||
setPlayerCardScale((player1Card.GetNode<Label>("Name").GetRect().Size.X + 7) / 16, player1Card);
|
setPlayerCardScale((player1Card.GetNode<Label>("Name").GetRect().Size.X + 7) / 16, player1Card);
|
||||||
player2Card.GetNode<Label>("Name").Resized += () =>
|
player2Card.GetNode<Label>("Name").Resized += () =>
|
||||||
setPlayerCardScale((player2Card.GetNode<Label>("Name").GetRect().Size.X + 7) / 16, player2Card);
|
setPlayerCardScale((player2Card.GetNode<Label>("Name").GetRect().Size.X + 7) / 16, player2Card);
|
||||||
|
|
||||||
redChip = GD.Load<PackedScene>(RED_CHIP_PATH);
|
redChip = GD.Load<PackedScene>(RED_CHIP_PATH);
|
||||||
ylwChip = GD.Load<PackedScene>(YELLOW_CHIP_PATH);
|
ylwChip = GD.Load<PackedScene>(YELLOW_CHIP_PATH);
|
||||||
|
|
||||||
matchData = Connection.Instance.CurrentObservingMatch;
|
matchData = Connection.Instance.CurrentObservingMatch;
|
||||||
player1Card.GetNode<Label>("Name").Text = matchData.player1;
|
player1Card.GetNode<Label>("Name").Text = matchData.player1;
|
||||||
player2Card.GetNode<Label>("Name").Text = matchData.player2;
|
player2Card.GetNode<Label>("Name").Text = matchData.player2;
|
||||||
|
|
||||||
if (Connection.Instance.PreviousMoves.Count == 0) {
|
if (Connection.Instance.PreviousMoves.Count == 0) {
|
||||||
player1Card.GetNode<Label>("Status").Show();
|
player1Card.GetNode<Label>("Status").Show();
|
||||||
player2Card.GetNode<Label>("Status").Hide();
|
player2Card.GetNode<Label>("Status").Hide();
|
||||||
} else if (Connection.Instance.PreviousMoves.Last().Item1 == matchData.player1) {
|
} else if (Connection.Instance.PreviousMoves.Last().Item1 == matchData.player1) {
|
||||||
player1Card.GetNode<Label>("Status").Hide();
|
player1Card.GetNode<Label>("Status").Hide();
|
||||||
player2Card.GetNode<Label>("Status").Show();
|
player2Card.GetNode<Label>("Status").Show();
|
||||||
} else {
|
} else {
|
||||||
player1Card.GetNode<Label>("Status").Show();
|
player1Card.GetNode<Label>("Status").Show();
|
||||||
player2Card.GetNode<Label>("Status").Hide();
|
player2Card.GetNode<Label>("Status").Hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
Connection.Instance.OnObserveWin += OnObserveWin;
|
Connection.Instance.OnObserveWin += OnObserveWin;
|
||||||
Connection.Instance.OnObserveDraw += OnObserveDraw;
|
Connection.Instance.OnObserveDraw += OnObserveDraw;
|
||||||
Connection.Instance.OnObserveTerminated += OnObserveTerminated;
|
Connection.Instance.OnObserveTerminated += OnObserveTerminated;
|
||||||
Connection.Instance.OnObserveMove += OnObserveMove;
|
Connection.Instance.OnObserveMove += OnObserveMove;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _Process(double delta) {
|
public override void _Process(double delta) {
|
||||||
if (Connection.Instance.PreviousMoves.Count != 0 && currentTimeout <= 0.0f) {
|
if (Connection.Instance.PreviousMoves.Count != 0 && currentTimeout <= 0.0f) {
|
||||||
var move = Connection.Instance.PreviousMoves[0];
|
var move = Connection.Instance.PreviousMoves[0];
|
||||||
Connection.Instance.PreviousMoves.RemoveAt(0);
|
Connection.Instance.PreviousMoves.RemoveAt(0);
|
||||||
if (move.Item1 == matchData.player1) {
|
if (move.Item1 == matchData.player1) {
|
||||||
spawnRed(move.Item2);
|
spawnRed(move.Item2);
|
||||||
} else {
|
} else {
|
||||||
spawnYellow(move.Item2);
|
spawnYellow(move.Item2);
|
||||||
}
|
}
|
||||||
|
|
||||||
currentTimeout = MOVE_TIMEOUT_BEFORE_PLACE;
|
currentTimeout = MOVE_TIMEOUT_BEFORE_PLACE;
|
||||||
} else if (currentTimeout >= 0.0f) {
|
} else if (currentTimeout >= 0.0f) {
|
||||||
currentTimeout -= delta;
|
currentTimeout -= delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_lastMove) {
|
if (_lastMove) {
|
||||||
_lastMoveTimer -= (float)delta;
|
_lastMoveTimer -= (float)delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_lastMoveTimer <= 0.0f) {
|
if (_lastMoveTimer <= 0.0f) {
|
||||||
if (_winner == "") {
|
if (_winner == "") {
|
||||||
showPopupMessage("Draw!");
|
showPopupMessage("Draw!");
|
||||||
} else {
|
} else {
|
||||||
showPopupMessage(_winner + " wins!");
|
showPopupMessage(_winner + " wins!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _ExitTree() {
|
public override void _ExitTree() {
|
||||||
Connection.Instance.OnObserveWin -= OnObserveWin;
|
Connection.Instance.OnObserveWin -= OnObserveWin;
|
||||||
Connection.Instance.OnObserveDraw -= OnObserveDraw;
|
Connection.Instance.OnObserveDraw -= OnObserveDraw;
|
||||||
Connection.Instance.OnObserveTerminated -= OnObserveTerminated;
|
Connection.Instance.OnObserveTerminated -= OnObserveTerminated;
|
||||||
Connection.Instance.OnObserveMove -= OnObserveMove;
|
Connection.Instance.OnObserveMove -= OnObserveMove;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnObserveWin(string winner) {
|
private void OnObserveWin(string winner) {
|
||||||
_lastMove = true;
|
_lastMove = true;
|
||||||
_winner = winner;
|
_winner = winner;
|
||||||
player1Card.GetNode<Label>("Status").Hide();
|
player1Card.GetNode<Label>("Status").Hide();
|
||||||
player2Card.GetNode<Label>("Status").Hide();
|
player2Card.GetNode<Label>("Status").Hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnObserveDraw() {
|
private void OnObserveDraw() {
|
||||||
_lastMove = true;
|
_lastMove = true;
|
||||||
player1Card.GetNode<Label>("Status").Hide();
|
player1Card.GetNode<Label>("Status").Hide();
|
||||||
player2Card.GetNode<Label>("Status").Hide();
|
player2Card.GetNode<Label>("Status").Hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnObserveTerminated() {
|
private void OnObserveTerminated() {
|
||||||
showPopupMessage("Match Terminated");
|
showPopupMessage("Match Terminated");
|
||||||
player1Card.GetNode<Label>("Status").Hide();
|
player1Card.GetNode<Label>("Status").Hide();
|
||||||
player2Card.GetNode<Label>("Status").Hide();
|
player2Card.GetNode<Label>("Status").Hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnObserveMove(string username, int column) {
|
private void OnObserveMove(string username, int column) {
|
||||||
if (username == matchData.player1) {
|
if (username == matchData.player1) {
|
||||||
if (!_lastMove)
|
if (!_lastMove)
|
||||||
player2Card.GetNode<Label>("Status").Show();
|
player2Card.GetNode<Label>("Status").Show();
|
||||||
player1Card.GetNode<Label>("Status").Hide();
|
player1Card.GetNode<Label>("Status").Hide();
|
||||||
} else {
|
} else {
|
||||||
if (!_lastMove)
|
if (!_lastMove)
|
||||||
player1Card.GetNode<Label>("Status").Show();
|
player1Card.GetNode<Label>("Status").Show();
|
||||||
player2Card.GetNode<Label>("Status").Hide();
|
player2Card.GetNode<Label>("Status").Hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
Connection.Instance.PreviousMoves.Add((username, column));
|
Connection.Instance.PreviousMoves.Add((username, column));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showPopupMessage(string message) {
|
private void showPopupMessage(string message) {
|
||||||
var popup = new Popup();
|
var popup = new Popup();
|
||||||
popup.AlwaysOnTop = true;
|
popup.AlwaysOnTop = true;
|
||||||
popup.Size = new Vector2I(200, 100);
|
popup.Size = new Vector2I(200, 100);
|
||||||
popup.Theme = GD.Load<Theme>("res://assets/theme.tres");
|
popup.Theme = GD.Load<Theme>("res://assets/theme.tres");
|
||||||
var text = new Label();
|
var text = new Label();
|
||||||
text.Text = message;
|
text.Text = message;
|
||||||
var sfx = new AudioStreamPlayer();
|
var sfx = new AudioStreamPlayer();
|
||||||
sfx.Stream = endingSfx;
|
sfx.Stream = endingSfx;
|
||||||
sfx.VolumeDb = -2;
|
sfx.VolumeDb = -2;
|
||||||
popup.AddChild(sfx);
|
popup.AddChild(sfx);
|
||||||
popup.AddChild(text);
|
popup.AddChild(text);
|
||||||
text.GrowHorizontal = Control.GrowDirection.Both;
|
text.GrowHorizontal = Control.GrowDirection.Both;
|
||||||
text.GrowVertical = Control.GrowDirection.Both;
|
text.GrowVertical = Control.GrowDirection.Both;
|
||||||
text.HorizontalAlignment = HorizontalAlignment.Center;
|
text.HorizontalAlignment = HorizontalAlignment.Center;
|
||||||
text.VerticalAlignment = VerticalAlignment.Center;
|
text.VerticalAlignment = VerticalAlignment.Center;
|
||||||
text.AnchorsPreset = (int)Control.LayoutPreset.FullRect;
|
text.AnchorsPreset = (int)Control.LayoutPreset.FullRect;
|
||||||
popup.InitialPosition = Window.WindowInitialPosition.CenterMainWindowScreen;
|
popup.InitialPosition = Window.WindowInitialPosition.CenterMainWindowScreen;
|
||||||
popup.PopupHide += () => popup.QueueFree();
|
popup.PopupHide += () => popup.QueueFree();
|
||||||
GetTree().Root.AddChild(popup);
|
GetTree().Root.AddChild(popup);
|
||||||
popup.PopupCentered();
|
popup.PopupCentered();
|
||||||
sfx.Play();
|
sfx.Play();
|
||||||
popup.Show();
|
popup.Show();
|
||||||
transitionToBracket();
|
transitionToBracket();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void transitionToBracket() { GetTree().ChangeSceneToFile(BRACKET_SCENE_PATH); }
|
private void transitionToBracket() { GetTree().ChangeSceneToFile(BRACKET_SCENE_PATH); }
|
||||||
@@ -169,63 +169,63 @@ public partial class BoardScreen : Node2D {
|
|||||||
* Will return row of board in which chip can be placed
|
* Will return row of board in which chip can be placed
|
||||||
*/
|
*/
|
||||||
private int canPlaceOnCol(int col) {
|
private int canPlaceOnCol(int col) {
|
||||||
if (col < 0 || col > 6) // Col out of range
|
if (col < 0 || col > 6) // Col out of range
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return getNextAvailRow(col);
|
return getNextAvailRow(col);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getNextAvailRow(int col) {
|
private int getNextAvailRow(int col) {
|
||||||
for (int i = chips.GetLength(0) - 1; i >= 0; i--) {
|
for (int i = chips.GetLength(0) - 1; i >= 0; i--) {
|
||||||
// Start at bottom
|
// Start at bottom
|
||||||
if (chips[i, col] == null)
|
if (chips[i, col] == null)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void spawnRed(int col) {
|
private void spawnRed(int col) {
|
||||||
int row = canPlaceOnCol(col);
|
int row = canPlaceOnCol(col);
|
||||||
if (row == -1) {
|
if (row == -1) {
|
||||||
GD.Print("Invalid Placement!");
|
GD.Print("Invalid Placement!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RigidBody2D newNode = redChip.Instantiate<RigidBody2D>();
|
RigidBody2D newNode = redChip.Instantiate<RigidBody2D>();
|
||||||
AddChild(newNode);
|
AddChild(newNode);
|
||||||
newNode.Position = new Vector2(CHIP_SCALE * (CHIP_X_OFF + (CHIP_SIZE + CHIP_PADDING) * col),
|
newNode.Position = new Vector2(CHIP_SCALE * (CHIP_X_OFF + (CHIP_SIZE + CHIP_PADDING) * col),
|
||||||
-(CHIP_SIZE + CHIP_PADDING) * 7);
|
-(CHIP_SIZE + CHIP_PADDING) * 7);
|
||||||
|
|
||||||
chips[row, col] = newNode;
|
chips[row, col] = newNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void spawnYellow(int col) {
|
private void spawnYellow(int col) {
|
||||||
int row = canPlaceOnCol(col);
|
int row = canPlaceOnCol(col);
|
||||||
if (row == -1) {
|
if (row == -1) {
|
||||||
GD.Print("Invalid Placement!");
|
GD.Print("Invalid Placement!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RigidBody2D newNode = ylwChip.Instantiate<RigidBody2D>();
|
RigidBody2D newNode = ylwChip.Instantiate<RigidBody2D>();
|
||||||
AddChild(newNode);
|
AddChild(newNode);
|
||||||
newNode.Position = new Vector2(CHIP_SCALE * (CHIP_X_OFF + (CHIP_SIZE + CHIP_PADDING) * col),
|
newNode.Position = new Vector2(CHIP_SCALE * (CHIP_X_OFF + (CHIP_SIZE + CHIP_PADDING) * col),
|
||||||
-(CHIP_SIZE + CHIP_PADDING) * 7);
|
-(CHIP_SIZE + CHIP_PADDING) * 7);
|
||||||
|
|
||||||
chips[row, col] = newNode;
|
chips[row, col] = newNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setPlayerCardScale(float x, Node2D playerCard) {
|
private void setPlayerCardScale(float x, Node2D playerCard) {
|
||||||
Sprite2D cardCenter = playerCard.GetNode<Sprite2D>("Center");
|
Sprite2D cardCenter = playerCard.GetNode<Sprite2D>("Center");
|
||||||
Sprite2D cardRight = playerCard.GetNode<Sprite2D>("Right");
|
Sprite2D cardRight = playerCard.GetNode<Sprite2D>("Right");
|
||||||
|
|
||||||
float offX = 16 * x / 2;
|
float offX = 16 * x / 2;
|
||||||
cardCenter.Scale = new Vector2(x, 2);
|
cardCenter.Scale = new Vector2(x, 2);
|
||||||
cardCenter.Position = new Vector2(CARD_CENTER_X_DEFAULT + offX, cardCenter.Position.Y);
|
cardCenter.Position = new Vector2(CARD_CENTER_X_DEFAULT + offX, cardCenter.Position.Y);
|
||||||
|
|
||||||
cardRight.Position =
|
cardRight.Position =
|
||||||
new Vector2(CARD_CENTER_X_DEFAULT + offX * 2 + 8,
|
new Vector2(CARD_CENTER_X_DEFAULT + offX * 2 + 8,
|
||||||
cardRight.Position.Y); // 8 is a magic number (im too lazy) for the size of the card edge multipled by 2
|
cardRight.Position.Y); // 8 is a magic number (im too lazy) for the size of the card edge multipled by 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,4 +238,4 @@ enum Direction {
|
|||||||
DOWN_LEFT,
|
DOWN_LEFT,
|
||||||
LEFT,
|
LEFT,
|
||||||
UP_LEFT
|
UP_LEFT
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,80 +12,80 @@ public partial class BracketScene : Control {
|
|||||||
private List<MatchData> matchList;
|
private List<MatchData> matchList;
|
||||||
|
|
||||||
public override void _Ready() {
|
public override void _Ready() {
|
||||||
Players.SetColumnTitle(0, "Name");
|
Players.SetColumnTitle(0, "Name");
|
||||||
Players.SetColumnTitle(1, "Ready");
|
Players.SetColumnTitle(1, "Ready");
|
||||||
Players.SetColumnTitle(2, "Playing");
|
Players.SetColumnTitle(2, "Playing");
|
||||||
Players.HideRoot = true;
|
Players.HideRoot = true;
|
||||||
Players.ButtonClicked += kickPlayer;
|
Players.ButtonClicked += kickPlayer;
|
||||||
|
|
||||||
|
|
||||||
Matches.SetColumnTitle(0, "Match");
|
Matches.SetColumnTitle(0, "Match");
|
||||||
Matches.SetColumnTitle(1, "Red");
|
Matches.SetColumnTitle(1, "Red");
|
||||||
Matches.SetColumnTitle(2, "Yellow");
|
Matches.SetColumnTitle(2, "Yellow");
|
||||||
Matches.HideRoot = true;
|
Matches.HideRoot = true;
|
||||||
Matches.ButtonClicked += watchGame;
|
Matches.ButtonClicked += watchGame;
|
||||||
Matches.ButtonClicked += terminateGame;
|
Matches.ButtonClicked += terminateGame;
|
||||||
|
|
||||||
Connection.Instance.OnUpdatedPlayers += updatePlayers;
|
Connection.Instance.OnUpdatedPlayers += updatePlayers;
|
||||||
Connection.Instance.OnUpdatedMatches += updateMatches;
|
Connection.Instance.OnUpdatedMatches += updateMatches;
|
||||||
Connection.Instance.OnWatchGameAck += transitionToBoard;
|
Connection.Instance.OnWatchGameAck += transitionToBoard;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _ExitTree() {
|
public override void _ExitTree() {
|
||||||
Connection.Instance.OnUpdatedPlayers -= updatePlayers;
|
Connection.Instance.OnUpdatedPlayers -= updatePlayers;
|
||||||
Connection.Instance.OnUpdatedMatches -= updateMatches;
|
Connection.Instance.OnUpdatedMatches -= updateMatches;
|
||||||
Connection.Instance.OnWatchGameAck -= transitionToBoard;
|
Connection.Instance.OnWatchGameAck -= transitionToBoard;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updatePlayers(List<PlayerData> newPlayerList) {
|
private void updatePlayers(List<PlayerData> newPlayerList) {
|
||||||
Players.Clear();
|
Players.Clear();
|
||||||
playerList = newPlayerList;
|
playerList = newPlayerList;
|
||||||
playerList.Sort((a, b) => a.Username.CompareTo(b.Username));
|
playerList.Sort((a, b) => a.Username.CompareTo(b.Username));
|
||||||
var root = Players.CreateItem();
|
var root = Players.CreateItem();
|
||||||
for (int i = 0; i < playerList.Count; i++) {
|
for (int i = 0; i < playerList.Count; i++) {
|
||||||
var item = Players.CreateItem(root);
|
var item = Players.CreateItem(root);
|
||||||
item.SetText(0, newPlayerList[i].Username);
|
item.SetText(0, newPlayerList[i].Username);
|
||||||
item.SetText(1, newPlayerList[i].IsReady ? "Yes" : "No");
|
item.SetText(1, newPlayerList[i].IsReady ? "Yes" : "No");
|
||||||
item.SetText(2, newPlayerList[i].IsPlaying ? "Yes" : "No");
|
item.SetText(2, newPlayerList[i].IsPlaying ? "Yes" : "No");
|
||||||
if (Connection.Instance.IsAdmin) {
|
if (Connection.Instance.IsAdmin) {
|
||||||
item.AddButton(0, TerminateKickButton, i, false, "Kick");
|
item.AddButton(0, TerminateKickButton, i, false, "Kick");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateMatches(List<MatchData> newMatchList) {
|
private void updateMatches(List<MatchData> newMatchList) {
|
||||||
Matches.Clear();
|
Matches.Clear();
|
||||||
matchList = newMatchList;
|
matchList = newMatchList;
|
||||||
var root = Matches.CreateItem();
|
var root = Matches.CreateItem();
|
||||||
for (int i = 0; i < newMatchList.Count; i++) {
|
for (int i = 0; i < newMatchList.Count; i++) {
|
||||||
var item = Matches.CreateItem(root);
|
var item = Matches.CreateItem(root);
|
||||||
item.SetText(0, newMatchList[i].matchId.ToString());
|
item.SetText(0, newMatchList[i].matchId.ToString());
|
||||||
item.SetText(1, newMatchList[i].player1);
|
item.SetText(1, newMatchList[i].player1);
|
||||||
item.SetText(2, newMatchList[i].player2);
|
item.SetText(2, newMatchList[i].player2);
|
||||||
item.AddButton(0, WatchButton, i, false, "Watch");
|
item.AddButton(0, WatchButton, i, false, "Watch");
|
||||||
if (Connection.Instance.IsAdmin) {
|
if (Connection.Instance.IsAdmin) {
|
||||||
item.AddButton(0, TerminateKickButton, 128 + i, false, "Terminate");
|
item.AddButton(0, TerminateKickButton, 128 + i, false, "Terminate");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void watchGame(TreeItem item, long column, long id, long mouseButtonIndex) {
|
private void watchGame(TreeItem item, long column, long id, long mouseButtonIndex) {
|
||||||
if (mouseButtonIndex == 1 && column == 0 && id < 128) {
|
if (mouseButtonIndex == 1 && column == 0 && id < 128) {
|
||||||
Connection.Instance.SendWatchGame(matchList[(int)id].matchId);
|
Connection.Instance.SendWatchGame(matchList[(int)id].matchId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void terminateGame(TreeItem item, long column, long id, long mouseButtonIndex) {
|
private void terminateGame(TreeItem item, long column, long id, long mouseButtonIndex) {
|
||||||
if (mouseButtonIndex == 1 && column == 0 && id - 128 >= 0 && matchList[(int)id - 128] != null) {
|
if (mouseButtonIndex == 1 && column == 0 && id - 128 >= 0 && matchList[(int)id - 128] != null) {
|
||||||
Connection.Instance.TerminateGame(matchList[(int)id - 128].matchId);
|
Connection.Instance.TerminateGame(matchList[(int)id - 128].matchId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void kickPlayer(TreeItem item, long column, long id, long mouseButtonIndex) {
|
private void kickPlayer(TreeItem item, long column, long id, long mouseButtonIndex) {
|
||||||
if (mouseButtonIndex == 1 && column == 0) {
|
if (mouseButtonIndex == 1 && column == 0) {
|
||||||
Connection.Instance.KickPlayer(playerList[(int)id].Username);
|
Connection.Instance.KickPlayer(playerList[(int)id].Username);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void transitionToBoard() { GetTree().ChangeSceneToFile(BOARD_SCENE_PATH); }
|
private void transitionToBoard() { GetTree().ChangeSceneToFile(BOARD_SCENE_PATH); }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,35 +6,35 @@ public partial class ConnectButtonUI : Button {
|
|||||||
private const string BRACKET_SCENE_PATH = "res://scenes/bracket_view.tscn";
|
private const string BRACKET_SCENE_PATH = "res://scenes/bracket_view.tscn";
|
||||||
|
|
||||||
public override void _Ready() {
|
public override void _Ready() {
|
||||||
Connection.Instance.OnWsConnectionSuccess += OnConnectionSuccess;
|
Connection.Instance.OnWsConnectionSuccess += OnConnectionSuccess;
|
||||||
Connection.Instance.OnWsConnectionFailed += OnConnectionFailed;
|
Connection.Instance.OnWsConnectionFailed += OnConnectionFailed;
|
||||||
|
|
||||||
if (Connection.Instance.LastUsedConnectionAddress.Length > 0) {
|
if (Connection.Instance.LastUsedConnectionAddress.Length > 0) {
|
||||||
AddressField.Text = Connection.Instance.LastUsedConnectionAddress;
|
AddressField.Text = Connection.Instance.LastUsedConnectionAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Connection.Instance.LastError.Length > 0) {
|
if (Connection.Instance.LastError.Length > 0) {
|
||||||
ErrorLabel.Text = Connection.Instance.LastError;
|
ErrorLabel.Text = Connection.Instance.LastError;
|
||||||
}
|
}
|
||||||
|
|
||||||
AddressField.GuiInput += e =>
|
AddressField.GuiInput += e =>
|
||||||
{
|
{
|
||||||
if (AddressField.HasFocus() && e is InputEventKey inputEventKey && inputEventKey.IsPressed()) {
|
if (AddressField.HasFocus() && e is InputEventKey inputEventKey && inputEventKey.IsPressed()) {
|
||||||
if (inputEventKey.KeyLabel == Key.Enter) {
|
if (inputEventKey.KeyLabel == Key.Enter) {
|
||||||
Connection.Instance.Connect(AddressField.Text);
|
Connection.Instance.Connect(AddressField.Text);
|
||||||
GetViewport().SetInputAsHandled();
|
GetViewport().SetInputAsHandled();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inputEventKey.KeyLabel == Key.Space) {
|
if (inputEventKey.KeyLabel == Key.Space) {
|
||||||
GetViewport().SetInputAsHandled();
|
GetViewport().SetInputAsHandled();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _ExitTree() {
|
public override void _ExitTree() {
|
||||||
Connection.Instance.OnWsConnectionSuccess -= OnConnectionSuccess;
|
Connection.Instance.OnWsConnectionSuccess -= OnConnectionSuccess;
|
||||||
Connection.Instance.OnWsConnectionFailed -= OnConnectionFailed;
|
Connection.Instance.OnWsConnectionFailed -= OnConnectionFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _Pressed() { Connection.Instance.Connect(AddressField.Text); }
|
public override void _Pressed() { Connection.Instance.Connect(AddressField.Text); }
|
||||||
@@ -42,6 +42,6 @@ public partial class ConnectButtonUI : Button {
|
|||||||
private void OnConnectionSuccess() { GetTree().ChangeSceneToFile(BRACKET_SCENE_PATH); }
|
private void OnConnectionSuccess() { GetTree().ChangeSceneToFile(BRACKET_SCENE_PATH); }
|
||||||
|
|
||||||
private void OnConnectionFailed() {
|
private void OnConnectionFailed() {
|
||||||
ErrorLabel.Text = "Couldn't connect to server! " + Connection.Instance.LastError;
|
ErrorLabel.Text = "Couldn't connect to server! " + Connection.Instance.LastError;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,14 +6,14 @@ public partial class Connection : Node {
|
|||||||
public const string WS_DEFAULT_ADDRESS = "wss://connect4.abunchofknowitalls.com";
|
public const string WS_DEFAULT_ADDRESS = "wss://connect4.abunchofknowitalls.com";
|
||||||
|
|
||||||
private static TournamentType? parseTournamentType(string type) {
|
private static TournamentType? parseTournamentType(string type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "RoundRobin":
|
case "RoundRobin":
|
||||||
return TournamentType.RoundRobin;
|
return TournamentType.RoundRobin;
|
||||||
case "false":
|
case "false":
|
||||||
return TournamentType.None;
|
return TournamentType.None;
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Connection Instance { get; private set; }
|
public static Connection Instance { get; private set; }
|
||||||
@@ -74,100 +74,98 @@ public partial class Connection : Node {
|
|||||||
private float refreshGamePlayerListTimer = 5.0f;
|
private float refreshGamePlayerListTimer = 5.0f;
|
||||||
|
|
||||||
public override void _Ready() {
|
public override void _Ready() {
|
||||||
Instance = this;
|
Instance = this;
|
||||||
webSocket.SetHeartbeatInterval(5.0);
|
webSocket.SetHeartbeatInterval(5.0);
|
||||||
webSocket.HeartbeatInterval = 5.0;
|
webSocket.HeartbeatInterval = 5.0;
|
||||||
Instance.OnWsDisconnect += () => GetTree().ChangeSceneToFile("res://scenes/main_menu.tscn");
|
Instance.OnWsDisconnect += () => GetTree().ChangeSceneToFile("res://scenes/main_menu.tscn");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Connect(string address) {
|
public void Connect(string address) {
|
||||||
isConnecting = true;
|
isConnecting = true;
|
||||||
LastUsedConnectionAddress = address;
|
LastUsedConnectionAddress = address;
|
||||||
if (isConnected) {
|
if (isConnected) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Error error = webSocket.ConnectToUrl(address);
|
Error error = webSocket.ConnectToUrl(address);
|
||||||
if (error != Error.Ok) {
|
if (error != Error.Ok) {
|
||||||
LastError = error.ToString();
|
LastError = error.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _Process(double delta) {
|
public override void _Process(double delta) {
|
||||||
webSocket.Poll();
|
webSocket.Poll();
|
||||||
WebSocketPeer.State state = webSocket.GetReadyState();
|
WebSocketPeer.State state = webSocket.GetReadyState();
|
||||||
if (state == WebSocketPeer.State.Open) {
|
if (state == WebSocketPeer.State.Open) {
|
||||||
if (isConnecting) {
|
if (isConnecting) {
|
||||||
isConnecting = false;
|
isConnecting = false;
|
||||||
isConnected = true;
|
isConnected = true;
|
||||||
LastError = "";
|
LastError = "";
|
||||||
OnWsConnectionSuccess?.Invoke();
|
OnWsConnectionSuccess?.Invoke();
|
||||||
UpdateGameList();
|
UpdateGameList();
|
||||||
UpdatePlayerList();
|
UpdatePlayerList();
|
||||||
GetReservations();
|
refreshGamePlayerListTimer = 5.0f;
|
||||||
refreshGamePlayerListTimer = 5.0f;
|
} else if (refreshGamePlayerListTimer <= 0.0f) {
|
||||||
} else if (refreshGamePlayerListTimer <= 0.0f) {
|
UpdateGameList();
|
||||||
UpdateGameList();
|
UpdatePlayerList();
|
||||||
UpdatePlayerList();
|
refreshGamePlayerListTimer = 5.0f;
|
||||||
GetReservations();
|
} else {
|
||||||
refreshGamePlayerListTimer = 5.0f;
|
refreshGamePlayerListTimer -= (float)delta;
|
||||||
} else {
|
}
|
||||||
refreshGamePlayerListTimer -= (float)delta;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (webSocket.GetAvailablePacketCount() > 0) {
|
while (webSocket.GetAvailablePacketCount() > 0) {
|
||||||
string message = webSocket.GetPacket().GetStringFromUtf8();
|
string message = webSocket.GetPacket().GetStringFromUtf8();
|
||||||
handleServerMessage(message);
|
handleServerMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldShowTournamentResults) {
|
if (shouldShowTournamentResults) {
|
||||||
var children = GetTree().Root.GetChildren();
|
var children = GetTree().Root.GetChildren();
|
||||||
foreach (var child in children) {
|
foreach (var child in children) {
|
||||||
if (child.Name.ToString() == "BracketView") {
|
if (child.Name.ToString() == "BracketView") {
|
||||||
shouldShowTournamentResults = false;
|
shouldShowTournamentResults = false;
|
||||||
ShowTournamentScoreboard(lastScoreboard);
|
ShowTournamentScoreboard(lastScoreboard);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (state == WebSocketPeer.State.Connecting) {
|
} else if (state == WebSocketPeer.State.Connecting) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
} else if (state == WebSocketPeer.State.Closing) {
|
} else if (state == WebSocketPeer.State.Closing) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
} else if (state == WebSocketPeer.State.Closed) {
|
} else if (state == WebSocketPeer.State.Closed) {
|
||||||
if (isConnecting) {
|
if (isConnecting) {
|
||||||
isConnecting = false;
|
isConnecting = false;
|
||||||
OnWsConnectionFailed?.Invoke();
|
OnWsConnectionFailed?.Invoke();
|
||||||
} else if (isConnected) {
|
} else if (isConnected) {
|
||||||
isConnected = false;
|
isConnected = false;
|
||||||
IsAdmin = false;
|
IsAdmin = false;
|
||||||
CurrentWaitTimeout = 5.0;
|
CurrentWaitTimeout = 5.0;
|
||||||
ActiveTournament = TournamentType.None;
|
ActiveTournament = TournamentType.None;
|
||||||
DemoMode = false;
|
DemoMode = false;
|
||||||
refreshGamePlayerListTimer = 5.0f;
|
refreshGamePlayerListTimer = 5.0f;
|
||||||
var code = webSocket.GetCloseCode();
|
var code = webSocket.GetCloseCode();
|
||||||
var reason = webSocket.GetCloseReason();
|
var reason = webSocket.GetCloseReason();
|
||||||
LastError = "Unexpected Disconnect. Reason: " + reason + ", Code: " + code;
|
LastError = "Unexpected Disconnect. Reason: " + reason + ", Code: " + code;
|
||||||
GD.PrintErr("WebSocket closed with code: " + code + ", reason " + reason + ". Clean: " + (code != -1));
|
GD.PrintErr("WebSocket closed with code: " + code + ", reason " + reason + ". Clean: " + (code != -1));
|
||||||
OnWsDisconnect?.Invoke();
|
OnWsDisconnect?.Invoke();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Player commands
|
// Player commands
|
||||||
public void SendConnect(string clientId) {
|
public void SendConnect(string clientId) {
|
||||||
if (string.IsNullOrWhiteSpace(clientId)) {
|
if (string.IsNullOrWhiteSpace(clientId)) {
|
||||||
GD.PrintErr("Client ID is required to CONNECT.");
|
GD.PrintErr("Client ID is required to CONNECT.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
clientId = clientId.Trim();
|
clientId = clientId.Trim();
|
||||||
|
|
||||||
if (clientId.Contains(":")) {
|
if (clientId.Contains(":")) {
|
||||||
GD.PrintErr("Client ID cannot contain ':' characters.");
|
GD.PrintErr("Client ID cannot contain ':' characters.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sendCommand("CONNECT", clientId);
|
sendCommand("CONNECT", clientId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendDisconnect() { sendCommand("DISCONNECT"); }
|
public void SendDisconnect() { sendCommand("DISCONNECT"); }
|
||||||
@@ -179,8 +177,8 @@ public partial class Connection : Node {
|
|||||||
public void UpdatePlayerList() { sendCommand("PLAYER", "LIST"); }
|
public void UpdatePlayerList() { sendCommand("PLAYER", "LIST"); }
|
||||||
public void SendWatchGame(int matchID) { sendCommand("GAME", "WATCH:" + matchID); }
|
public void SendWatchGame(int matchID) { sendCommand("GAME", "WATCH:" + matchID); }
|
||||||
public void AdminAuth(string password) {
|
public void AdminAuth(string password) {
|
||||||
if (IsAdmin) return;
|
if (IsAdmin) return;
|
||||||
sendCommand("ADMIN", "AUTH:" + password);
|
sendCommand("ADMIN", "AUTH:" + password);
|
||||||
}
|
}
|
||||||
public void GetMoveWait() { sendCommand("GET", "MOVE_WAIT"); }
|
public void GetMoveWait() { sendCommand("GET", "MOVE_WAIT"); }
|
||||||
public void GetTournamentStatus() { sendCommand("GET", "TOURNAMENT_STATUS"); }
|
public void GetTournamentStatus() { sendCommand("GET", "TOURNAMENT_STATUS"); }
|
||||||
@@ -189,23 +187,23 @@ public partial class Connection : Node {
|
|||||||
|
|
||||||
// Admin commands
|
// Admin commands
|
||||||
public void KickPlayer(string playerId) {
|
public void KickPlayer(string playerId) {
|
||||||
if (!IsAdmin) return;
|
if (!IsAdmin) return;
|
||||||
sendCommand("ADMIN", "KICK:" + playerId);
|
sendCommand("ADMIN", "KICK:" + playerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StartTournament(string tournamentType = "RoundRobin") {
|
public void StartTournament(string tournamentType = "RoundRobin") {
|
||||||
if (!IsAdmin) return;
|
if (!IsAdmin) return;
|
||||||
sendCommand("TOURNAMENT", "START:" + tournamentType);
|
sendCommand("TOURNAMENT", "START:" + tournamentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CancelTournament() {
|
public void CancelTournament() {
|
||||||
if (!IsAdmin) return;
|
if (!IsAdmin) return;
|
||||||
sendCommand("TOURNAMENT", "CANCEL");
|
sendCommand("TOURNAMENT", "CANCEL");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TerminateGame(int matchID) {
|
public void TerminateGame(int matchID) {
|
||||||
if (!IsAdmin) return;
|
if (!IsAdmin) return;
|
||||||
sendCommand("GAME", "TERMINATE:" + matchID);
|
sendCommand("GAME", "TERMINATE:" + matchID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AwardGameWinner(int matchID, string winnerUsername) {
|
public void AwardGameWinner(int matchID, string winnerUsername) {
|
||||||
@@ -215,21 +213,21 @@ public partial class Connection : Node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void SetMoveWait(float waitTime) {
|
public void SetMoveWait(float waitTime) {
|
||||||
if (!IsAdmin) return;
|
if (!IsAdmin) return;
|
||||||
CurrentWaitTimeout = waitTime;
|
CurrentWaitTimeout = waitTime;
|
||||||
sendCommand("SET", "MOVE_WAIT:" + waitTime);
|
sendCommand("SET", "MOVE_WAIT:" + waitTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetDemoMode(bool demoMode) {
|
public void SetDemoMode(bool demoMode) {
|
||||||
if (!IsAdmin) return;
|
if (!IsAdmin) return;
|
||||||
DemoMode = demoMode;
|
DemoMode = demoMode;
|
||||||
sendCommand("SET", "DEMO_MODE:" + demoMode);
|
sendCommand("SET", "DEMO_MODE:" + demoMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetMaxTimeout(float maxTimeout) {
|
public void SetMaxTimeout(float maxTimeout) {
|
||||||
if (!IsAdmin) return;
|
if (!IsAdmin) return;
|
||||||
MaxTimeout = maxTimeout;
|
MaxTimeout = maxTimeout;
|
||||||
sendCommand("SET", "MAX_TIMEOUT:" + maxTimeout);
|
sendCommand("SET", "MAX_TIMEOUT:" + maxTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddReservation(string player1Username, string player2Username) {
|
public void AddReservation(string player1Username, string player2Username) {
|
||||||
@@ -248,155 +246,151 @@ public partial class Connection : Node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sendCommand(string header, string body = "") {
|
private void sendCommand(string header, string body = "") {
|
||||||
if (!IsSocketOpen) {
|
if (!IsSocketOpen) {
|
||||||
GD.PrintErr($"Cannot send {header}, socket is not open.");
|
GD.PrintErr($"Cannot send {header}, socket is not open.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string payload = string.IsNullOrEmpty(body) ? header : $"{header}:{body}";
|
string payload = string.IsNullOrEmpty(body) ? header : $"{header}:{body}";
|
||||||
webSocket.SendText(payload);
|
webSocket.SendText(payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleServerMessage(string message) {
|
private void handleServerMessage(string message) {
|
||||||
if (string.IsNullOrWhiteSpace(message)) {
|
if (string.IsNullOrWhiteSpace(message)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
message = message.Trim();
|
message = message.Trim();
|
||||||
|
|
||||||
string header;
|
string header;
|
||||||
string body;
|
string body;
|
||||||
int separatorIndex = message.IndexOf(':');
|
int separatorIndex = message.IndexOf(':');
|
||||||
if (separatorIndex >= 0) {
|
if (separatorIndex >= 0) {
|
||||||
header = message.Substring(0, separatorIndex).Trim();
|
header = message.Substring(0, separatorIndex).Trim();
|
||||||
body = message.Substring(separatorIndex + 1).Trim();
|
body = message.Substring(separatorIndex + 1).Trim();
|
||||||
} else {
|
} else {
|
||||||
header = message.Trim();
|
header = message.Trim();
|
||||||
body = string.Empty;
|
body = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
header = header.ToUpperInvariant();
|
header = header.ToUpperInvariant();
|
||||||
|
|
||||||
switch (header) {
|
switch (header) {
|
||||||
case "CONNECT":
|
case "CONNECT":
|
||||||
if (body.Equals("ACK", StringComparison.OrdinalIgnoreCase)) {
|
if (body.Equals("ACK", StringComparison.OrdinalIgnoreCase)) {
|
||||||
IsPlayer = true;
|
IsPlayer = true;
|
||||||
OnConnected?.Invoke();
|
OnConnected?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "READY":
|
case "READY":
|
||||||
if (body.Equals("ACK", StringComparison.OrdinalIgnoreCase)) {
|
if (body.Equals("ACK", StringComparison.OrdinalIgnoreCase)) {
|
||||||
OnReadyAcknowledged?.Invoke();
|
OnReadyAcknowledged?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "GAME":
|
case "GAME":
|
||||||
handleGameMessage(body);
|
handleGameMessage(body);
|
||||||
break;
|
break;
|
||||||
case "PLAYER":
|
case "PLAYER":
|
||||||
handlePlayerList(body);
|
handlePlayerList(body);
|
||||||
break;
|
break;
|
||||||
case "OPPONENT":
|
case "OPPONENT":
|
||||||
if (int.TryParse(body, out int column)) {
|
if (int.TryParse(body, out int column)) {
|
||||||
OnOpponentMove?.Invoke(column);
|
OnOpponentMove?.Invoke(column);
|
||||||
} else {
|
} else {
|
||||||
GD.PrintErr($"Invalid opponent column: {body}");
|
GD.PrintErr($"Invalid opponent column: {body}");
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "ADMIN":
|
case "ADMIN":
|
||||||
if (body == "AUTH:ACK") {
|
if (body == "AUTH:ACK") {
|
||||||
IsAdmin = true;
|
IsAdmin = true;
|
||||||
GetMoveWait();
|
GetMoveWait();
|
||||||
GetTournamentStatus();
|
GetTournamentStatus();
|
||||||
GetReservations();
|
OnBecomeAdmin?.Invoke();
|
||||||
OnBecomeAdmin?.Invoke();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "TOURNAMENT":
|
case "TOURNAMENT":
|
||||||
handleTournamentMessage(body);
|
handleTournamentMessage(body);
|
||||||
break;
|
break;
|
||||||
case "RESERVATION":
|
case "GET":
|
||||||
handleReservationMessage(body);
|
string data = body.Split(":")[1];
|
||||||
break;
|
if (body.StartsWith("MOVE_WAIT")) {
|
||||||
case "GET":
|
CurrentWaitTimeout = double.Parse(data);
|
||||||
string data = body.Split(":")[1];
|
} else if (body.StartsWith("MAX_TIMEOUT")) {
|
||||||
if (body.StartsWith("MOVE_WAIT")) {
|
MaxTimeout = double.Parse(data);
|
||||||
CurrentWaitTimeout = double.Parse(data);
|
} else if (body.StartsWith("DEMO_MODE")) {
|
||||||
} else if (body.StartsWith("MAX_TIMEOUT")) {
|
DemoMode = bool.Parse(data);
|
||||||
MaxTimeout = double.Parse(data);
|
} else if (body.StartsWith("TOURNAMENT_STATUS")) {
|
||||||
} else if (body.StartsWith("DEMO_MODE")) {
|
TournamentType? type = parseTournamentType(data);
|
||||||
DemoMode = bool.Parse(data);
|
|
||||||
} else if (body.StartsWith("TOURNAMENT_STATUS")) {
|
|
||||||
TournamentType? type = parseTournamentType(data);
|
|
||||||
|
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
GD.PrintErr($"Unhandled tournament type: {data}");
|
GD.PrintErr($"Unhandled tournament type: {data}");
|
||||||
} else {
|
} else {
|
||||||
ActiveTournament = type.Value;
|
ActiveTournament = type.Value;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
GD.PrintErr($"Unhandled data get: {body}");
|
GD.PrintErr($"Unhandled data get: {body}");
|
||||||
}
|
}
|
||||||
|
|
||||||
OnGetDataAcks?.Invoke();
|
OnGetDataAcks?.Invoke();
|
||||||
break;
|
break;
|
||||||
case "SET":
|
case "SET":
|
||||||
OnSetDataAcks?.Invoke();
|
OnSetDataAcks?.Invoke();
|
||||||
break;
|
break;
|
||||||
case "ERROR":
|
case "ERROR":
|
||||||
GD.PrintErr(message);
|
GD.PrintErr(message);
|
||||||
OnError?.Invoke(message);
|
OnError?.Invoke(message);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
GD.Print($"Unhandled server message: {message}");
|
GD.Print($"Unhandled server message: {message}");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleTournamentMessage(string body) {
|
private void handleTournamentMessage(string body) {
|
||||||
if (string.IsNullOrWhiteSpace(body)) {
|
if (string.IsNullOrWhiteSpace(body)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string[] segments = body.Split(':');
|
string[] segments = body.Split(':');
|
||||||
string command = segments[0].Trim().ToUpperInvariant();
|
string command = segments[0].Trim().ToUpperInvariant();
|
||||||
string argument = segments.Length > 1 ? segments[1].Trim() : string.Empty;
|
string argument = segments.Length > 1 ? segments[1].Trim() : string.Empty;
|
||||||
|
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case "END": {
|
case "END": {
|
||||||
ActiveTournament = TournamentType.None;
|
ActiveTournament = TournamentType.None;
|
||||||
List<(string, int)> playerScoreboard = new List<(string, int)>();
|
List<(string, int)> playerScoreboard = new List<(string, int)>();
|
||||||
string[] entries = segments[1].Split("|");
|
string[] entries = segments[1].Split("|");
|
||||||
foreach (string entry in entries) {
|
foreach (string entry in entries) {
|
||||||
string[] data = entry.Split(',');
|
string[] data = entry.Split(',');
|
||||||
playerScoreboard.Add((data[0], int.Parse(data[1])));
|
playerScoreboard.Add((data[0], int.Parse(data[1])));
|
||||||
}
|
}
|
||||||
|
|
||||||
lastScoreboard = playerScoreboard;
|
lastScoreboard = playerScoreboard;
|
||||||
shouldShowTournamentResults = true;
|
shouldShowTournamentResults = true;
|
||||||
OnTournamentEnd?.Invoke();
|
OnTournamentEnd?.Invoke();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "START": {
|
case "START": {
|
||||||
TournamentType? type = parseTournamentType(argument);
|
TournamentType? type = parseTournamentType(argument);
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
GD.PrintErr($"Unhandled tournament type: {argument}");
|
GD.PrintErr($"Unhandled tournament type: {argument}");
|
||||||
} else {
|
} else {
|
||||||
ActiveTournament = type.Value;
|
ActiveTournament = type.Value;
|
||||||
OnStartTournament?.Invoke();
|
OnStartTournament?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "CANCEL": {
|
case "CANCEL": {
|
||||||
ActiveTournament = TournamentType.None;
|
ActiveTournament = TournamentType.None;
|
||||||
OnCancelTournamentAck?.Invoke();
|
OnCancelTournamentAck?.Invoke();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleReservationMessage(string body) {
|
private void handleReservationMessage(string body) {
|
||||||
@@ -453,151 +447,151 @@ public partial class Connection : Node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handlePlayerList(string body) {
|
private void handlePlayerList(string body) {
|
||||||
if (string.IsNullOrWhiteSpace(body)) {
|
if (string.IsNullOrWhiteSpace(body)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string[] segments = body.Split(':');
|
string[] segments = body.Split(':');
|
||||||
string command = segments[0].Trim().ToUpperInvariant();
|
string command = segments[0].Trim().ToUpperInvariant();
|
||||||
|
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case "LIST": {
|
case "LIST": {
|
||||||
List<PlayerData> players = new List<PlayerData>();
|
List<PlayerData> players = new List<PlayerData>();
|
||||||
|
|
||||||
if (segments.Length < 2) {
|
if (segments.Length < 2) {
|
||||||
OnUpdatedPlayers?.Invoke(players);
|
OnUpdatedPlayers?.Invoke(players);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
string[] entries = segments[1].Split("|");
|
string[] entries = segments[1].Split("|");
|
||||||
foreach (string entry in entries) {
|
foreach (string entry in entries) {
|
||||||
string[] data = entry.Split(',');
|
string[] data = entry.Split(',');
|
||||||
players.Add(new PlayerData(data[0], bool.Parse(data[1]), bool.Parse(data[2])));
|
players.Add(new PlayerData(data[0], bool.Parse(data[1]), bool.Parse(data[2])));
|
||||||
}
|
}
|
||||||
|
|
||||||
OnUpdatedPlayers?.Invoke(players);
|
OnUpdatedPlayers?.Invoke(players);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleGameMessage(string body) {
|
private void handleGameMessage(string body) {
|
||||||
if (string.IsNullOrWhiteSpace(body)) {
|
if (string.IsNullOrWhiteSpace(body)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string[] segments = body.Split(':');
|
string[] segments = body.Split(':');
|
||||||
string command = segments[0].Trim().ToUpperInvariant();
|
string command = segments[0].Trim().ToUpperInvariant();
|
||||||
string argument = segments.Length > 1 ? segments[1].Trim() : string.Empty;
|
string argument = segments.Length > 1 ? segments[1].Trim() : string.Empty;
|
||||||
|
|
||||||
if (IsPlayer) {
|
if (IsPlayer) {
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case "START":
|
case "START":
|
||||||
bool isFirst = argument == "1" || argument.Equals("TRUE", StringComparison.OrdinalIgnoreCase);
|
bool isFirst = argument == "1" || argument.Equals("TRUE", StringComparison.OrdinalIgnoreCase);
|
||||||
OnGameStart?.Invoke(isFirst);
|
OnGameStart?.Invoke(isFirst);
|
||||||
break;
|
break;
|
||||||
case "WINS":
|
case "WINS":
|
||||||
OnGameWin?.Invoke();
|
OnGameWin?.Invoke();
|
||||||
break;
|
break;
|
||||||
case "LOSS":
|
case "LOSS":
|
||||||
OnGameLoss?.Invoke();
|
OnGameLoss?.Invoke();
|
||||||
break;
|
break;
|
||||||
case "DRAW":
|
case "DRAW":
|
||||||
OnGameDraw?.Invoke();
|
OnGameDraw?.Invoke();
|
||||||
break;
|
break;
|
||||||
case "TERMINATED":
|
case "TERMINATED":
|
||||||
OnGameTerminated?.Invoke();
|
OnGameTerminated?.Invoke();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
GD.Print($"Unhandled GAME message: {body}");
|
GD.Print($"Unhandled GAME message: {body}");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else // Regular observer/admin
|
} else // Regular observer/admin
|
||||||
{
|
{
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case "WIN":
|
case "WIN":
|
||||||
OnObserveWin?.Invoke(segments[1]);
|
OnObserveWin?.Invoke(segments[1]);
|
||||||
break;
|
break;
|
||||||
case "MOVE":
|
case "MOVE":
|
||||||
OnObserveMove?.Invoke(segments[1], int.Parse(segments[2]));
|
OnObserveMove?.Invoke(segments[1], int.Parse(segments[2]));
|
||||||
break;
|
break;
|
||||||
case "DRAW":
|
case "DRAW":
|
||||||
OnObserveDraw?.Invoke();
|
OnObserveDraw?.Invoke();
|
||||||
break;
|
break;
|
||||||
case "TERMINATED":
|
case "TERMINATED":
|
||||||
OnObserveTerminated?.Invoke();
|
OnObserveTerminated?.Invoke();
|
||||||
break;
|
break;
|
||||||
case "LIST":
|
case "LIST":
|
||||||
List<MatchData> matches = new List<MatchData>();
|
List<MatchData> matches = new List<MatchData>();
|
||||||
|
|
||||||
if (segments.Length < 2) {
|
if (segments.Length < 2) {
|
||||||
OnUpdatedMatches?.Invoke(matches);
|
OnUpdatedMatches?.Invoke(matches);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
string[] entries = segments[1].Split("|");
|
string[] entries = segments[1].Split("|");
|
||||||
foreach (string entry in entries) {
|
foreach (string entry in entries) {
|
||||||
string[] data = entry.Split(',');
|
string[] data = entry.Split(',');
|
||||||
matches.Add(new MatchData(int.Parse(data[0]), data[1], data[2]));
|
matches.Add(new MatchData(int.Parse(data[0]), data[1], data[2]));
|
||||||
}
|
}
|
||||||
|
|
||||||
OnUpdatedMatches?.Invoke(matches);
|
OnUpdatedMatches?.Invoke(matches);
|
||||||
break;
|
break;
|
||||||
case "WATCH":
|
case "WATCH":
|
||||||
CurrentObservingMatch = null;
|
CurrentObservingMatch = null;
|
||||||
PreviousMoves.Clear();
|
PreviousMoves.Clear();
|
||||||
string[] activeMatchData = segments[2].Split("|");
|
string[] activeMatchData = segments[2].Split("|");
|
||||||
if (activeMatchData.IsEmpty()) {
|
if (activeMatchData.IsEmpty()) {
|
||||||
string[] matchData = segments[2].Split(',');
|
string[] matchData = segments[2].Split(',');
|
||||||
CurrentObservingMatch = new MatchData(int.Parse(matchData[0]), matchData[1], matchData[2]);
|
CurrentObservingMatch = new MatchData(int.Parse(matchData[0]), matchData[1], matchData[2]);
|
||||||
} else {
|
} else {
|
||||||
string[] matchData = activeMatchData[0].Split(',');
|
string[] matchData = activeMatchData[0].Split(',');
|
||||||
CurrentObservingMatch = new MatchData(int.Parse(matchData[0]), matchData[1], matchData[2]);
|
CurrentObservingMatch = new MatchData(int.Parse(matchData[0]), matchData[1], matchData[2]);
|
||||||
for (int i = 1; i < activeMatchData.Length; i++) {
|
for (int i = 1; i < activeMatchData.Length; i++) {
|
||||||
string[] moveData = activeMatchData[i].Split(',');
|
string[] moveData = activeMatchData[i].Split(',');
|
||||||
PreviousMoves.Add((moveData[0], int.Parse(moveData[1])));
|
PreviousMoves.Add((moveData[0], int.Parse(moveData[1])));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OnWatchGameAck?.Invoke();
|
OnWatchGameAck?.Invoke();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
GD.Print($"Unhandled GAME message: {body}");
|
GD.Print($"Unhandled GAME message: {body}");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ShowTournamentScoreboard(List<(string, int)> playerScoreboard) {
|
public void ShowTournamentScoreboard(List<(string, int)> playerScoreboard) {
|
||||||
var scoreboardWindow = new Window();
|
var scoreboardWindow = new Window();
|
||||||
scoreboardWindow.Theme = GD.Load<Theme>("res://assets/theme.tres");
|
scoreboardWindow.Theme = GD.Load<Theme>("res://assets/theme.tres");
|
||||||
scoreboardWindow.AlwaysOnTop = true;
|
scoreboardWindow.AlwaysOnTop = true;
|
||||||
scoreboardWindow.MaximizeDisabled = true;
|
scoreboardWindow.MaximizeDisabled = true;
|
||||||
scoreboardWindow.Unresizable = true;
|
scoreboardWindow.Unresizable = true;
|
||||||
scoreboardWindow.InitialPosition = Window.WindowInitialPosition.CenterMainWindowScreen;
|
scoreboardWindow.InitialPosition = Window.WindowInitialPosition.CenterMainWindowScreen;
|
||||||
scoreboardWindow.Size = new Vector2I(256, 512);
|
scoreboardWindow.Size = new Vector2I(256, 512);
|
||||||
scoreboardWindow.CloseRequested += () => { GetTree().Root.RemoveChild(scoreboardWindow); };
|
scoreboardWindow.CloseRequested += () => { GetTree().Root.RemoveChild(scoreboardWindow); };
|
||||||
|
|
||||||
var tree = new Tree();
|
var tree = new Tree();
|
||||||
tree.HideRoot = true;
|
tree.HideRoot = true;
|
||||||
tree.Columns = 2;
|
tree.Columns = 2;
|
||||||
tree.ColumnTitlesVisible = true;
|
tree.ColumnTitlesVisible = true;
|
||||||
tree.Theme = GD.Load<Theme>("res://assets/theme.tres");
|
tree.Theme = GD.Load<Theme>("res://assets/theme.tres");
|
||||||
tree.GrowHorizontal = Control.GrowDirection.Both;
|
tree.GrowHorizontal = Control.GrowDirection.Both;
|
||||||
tree.GrowVertical = Control.GrowDirection.Both;
|
tree.GrowVertical = Control.GrowDirection.Both;
|
||||||
tree.SetColumnTitle(0, "Player");
|
tree.SetColumnTitle(0, "Player");
|
||||||
tree.SetColumnTitle(1, "Score");
|
tree.SetColumnTitle(1, "Score");
|
||||||
var root = tree.CreateItem();
|
var root = tree.CreateItem();
|
||||||
|
|
||||||
foreach ((string, int) entry in playerScoreboard) {
|
foreach ((string, int) entry in playerScoreboard) {
|
||||||
var item = tree.CreateItem(root);
|
var item = tree.CreateItem(root);
|
||||||
item.SetText(0, entry.Item1);
|
item.SetText(0, entry.Item1);
|
||||||
item.SetText(1, entry.Item2.ToString());
|
item.SetText(1, entry.Item2.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
scoreboardWindow.AddChild(tree);
|
scoreboardWindow.AddChild(tree);
|
||||||
tree.SetAnchorsPreset(Control.LayoutPreset.FullRect);
|
tree.SetAnchorsPreset(Control.LayoutPreset.FullRect);
|
||||||
|
|
||||||
GetTree().Root.AddChild(scoreboardWindow);
|
GetTree().Root.AddChild(scoreboardWindow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
scripts/TournamentType.cs.uid
Normal file
1
scripts/TournamentType.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://dwb6ioubllb24
|
||||||
Reference in New Issue
Block a user