misc: more formatting changes
This commit is contained in:
@@ -2,7 +2,5 @@ using Godot;
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
public partial class AddressUI : TextEdit {
|
public partial class AddressUI : TextEdit {
|
||||||
public override void _Ready() {
|
public override void _Ready() { Text = Connection.WS_DEFAULT_ADDRESS; }
|
||||||
Text = Connection.WS_DEFAULT_ADDRESS;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,151 +1,133 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
public partial class AdminControls : HBoxContainer
|
public partial class AdminControls : HBoxContainer {
|
||||||
{
|
[Export] public Button BecomeAdmin;
|
||||||
[Export] public Button BecomeAdmin;
|
[Export] public Button StartTournament;
|
||||||
[Export] public Button StartTournament;
|
[Export] public Button CancelTournament;
|
||||||
[Export] public Button CancelTournament;
|
[Export] public Label Label;
|
||||||
[Export] public Label Label;
|
[Export] public Slider Timeout;
|
||||||
[Export] public Slider Timeout;
|
|
||||||
|
|
||||||
public override void _Ready()
|
|
||||||
{
|
|
||||||
Connection.Instance.OnBecomeAdmin += UpdateUI;
|
|
||||||
Connection.Instance.OnTournamentEnd += UpdateUI;
|
|
||||||
Connection.Instance.OnStartTournament += UpdateUI;
|
|
||||||
Connection.Instance.OnCancelTournamentAck += UpdateUI;
|
|
||||||
Connection.Instance.OnGetDataAcks += UpdateUI;
|
|
||||||
Connection.Instance.OnSetDataAcks += UpdateUI;
|
|
||||||
|
|
||||||
StartTournament.Pressed += () => Connection.Instance.StartTournament();
|
|
||||||
CancelTournament.Pressed += () => Connection.Instance.CancelTournament();
|
|
||||||
|
|
||||||
UpdateUI();
|
|
||||||
|
|
||||||
Timeout.ValueChanged += value =>
|
|
||||||
{
|
|
||||||
Connection.Instance.SetMoveWait((float)value);
|
|
||||||
var time = Connection.Instance.CurrentWaitTimeout.ToString();
|
|
||||||
if (time.Length > 3)
|
|
||||||
{
|
|
||||||
time = time.Substring(0, 3);
|
|
||||||
}
|
|
||||||
Label.Text = "Wait To Move: " + time + "s ";
|
|
||||||
};
|
|
||||||
|
|
||||||
BecomeAdmin.Pressed += showAuthPopup;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void _ExitTree()
|
|
||||||
{
|
|
||||||
Connection.Instance.OnBecomeAdmin -= UpdateUI;
|
|
||||||
Connection.Instance.OnTournamentEnd -= UpdateUI;
|
|
||||||
Connection.Instance.OnStartTournament -= UpdateUI;
|
|
||||||
Connection.Instance.OnCancelTournamentAck -= UpdateUI;
|
|
||||||
Connection.Instance.OnGetDataAcks -= UpdateUI;
|
|
||||||
Connection.Instance.OnSetDataAcks -= UpdateUI;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdateUI()
|
public override void _Ready() {
|
||||||
{
|
Connection.Instance.OnBecomeAdmin += UpdateUI;
|
||||||
if (!Connection.Instance.IsAdmin)
|
Connection.Instance.OnTournamentEnd += UpdateUI;
|
||||||
{
|
Connection.Instance.OnStartTournament += UpdateUI;
|
||||||
BecomeAdmin.Show();
|
Connection.Instance.OnCancelTournamentAck += UpdateUI;
|
||||||
StartTournament.Hide();
|
Connection.Instance.OnGetDataAcks += UpdateUI;
|
||||||
CancelTournament.Hide();
|
Connection.Instance.OnSetDataAcks += UpdateUI;
|
||||||
Label.Hide();
|
|
||||||
Timeout.Hide();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
BecomeAdmin.Hide();
|
|
||||||
Label.Show();
|
|
||||||
Timeout.Show();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Connection.Instance.IsAdmin && Connection.Instance.DemoMode)
|
StartTournament.Pressed += () => Connection.Instance.StartTournament();
|
||||||
{
|
CancelTournament.Pressed += () => Connection.Instance.CancelTournament();
|
||||||
StartTournament.Hide();
|
|
||||||
CancelTournament.Hide();
|
|
||||||
}
|
|
||||||
else if (Connection.Instance.IsAdmin && Connection.Instance.ActiveTournament != TournamentType.None)
|
|
||||||
{
|
|
||||||
StartTournament.Hide();
|
|
||||||
CancelTournament.Show();
|
|
||||||
}
|
|
||||||
else if (Connection.Instance.IsAdmin)
|
|
||||||
{
|
|
||||||
StartTournament.Show();
|
|
||||||
CancelTournament.Hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
Timeout.Value = Connection.Instance.CurrentWaitTimeout;
|
UpdateUI();
|
||||||
var time = Connection.Instance.CurrentWaitTimeout.ToString();
|
|
||||||
if (time.Length > 3)
|
|
||||||
{
|
|
||||||
time = time.Substring(0, 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
Label.Text = "Wait To Move: " + time + "s ";
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showAuthPopup()
|
Timeout.ValueChanged += value =>
|
||||||
{
|
{
|
||||||
var authWindow = new Window();
|
Connection.Instance.SetMoveWait((float)value);
|
||||||
authWindow.Theme = GD.Load<Theme>("res://assets/theme.tres");
|
var time = Connection.Instance.CurrentWaitTimeout.ToString();
|
||||||
authWindow.AlwaysOnTop = true;
|
if (time.Length > 3) {
|
||||||
authWindow.MaximizeDisabled = true;
|
time = time.Substring(0, 3);
|
||||||
authWindow.Unresizable = true;
|
}
|
||||||
authWindow.InitialPosition = Window.WindowInitialPosition.CenterMainWindowScreen;
|
Label.Text = "Wait To Move: " + time + "s ";
|
||||||
authWindow.Size = new Vector2I(256, 128);
|
};
|
||||||
authWindow.CloseRequested += () =>
|
|
||||||
{
|
|
||||||
GetTree().Root.CallDeferred(Node.MethodName.RemoveChild, authWindow);
|
|
||||||
};
|
|
||||||
|
|
||||||
var vbox = new VBoxContainer();
|
|
||||||
vbox.LayoutMode = 1;
|
|
||||||
vbox.AnchorBottom = 1.0f;
|
|
||||||
vbox.AnchorRight = 1.0f;
|
|
||||||
vbox.GrowHorizontal = GrowDirection.Both;
|
|
||||||
vbox.GrowVertical = GrowDirection.Both;
|
|
||||||
vbox.Alignment = AlignmentMode.Center;
|
|
||||||
|
|
||||||
var passwordBox = new TextEdit();
|
|
||||||
passwordBox.PlaceholderText = "Password";
|
|
||||||
passwordBox.SetCustomMinimumSize(new Vector2(32, 32));
|
|
||||||
|
|
||||||
passwordBox.GuiInput += e =>
|
|
||||||
{
|
|
||||||
if (passwordBox.HasFocus() && e is InputEventKey inputEventKey && inputEventKey.IsPressed())
|
|
||||||
{
|
|
||||||
if (inputEventKey.KeyLabel == Key.Enter)
|
|
||||||
{
|
|
||||||
Connection.Instance.AdminAuth(passwordBox.Text);
|
|
||||||
GetTree().Root.CallDeferred(Node.MethodName.RemoveChild, authWindow);
|
|
||||||
GetViewport().SetInputAsHandled();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inputEventKey.KeyLabel == Key.Space)
|
BecomeAdmin.Pressed += showAuthPopup;
|
||||||
{
|
}
|
||||||
GetViewport().SetInputAsHandled();
|
|
||||||
}
|
public override void _ExitTree() {
|
||||||
}
|
Connection.Instance.OnBecomeAdmin -= UpdateUI;
|
||||||
};
|
Connection.Instance.OnTournamentEnd -= UpdateUI;
|
||||||
|
Connection.Instance.OnStartTournament -= UpdateUI;
|
||||||
var button = new Button();
|
Connection.Instance.OnCancelTournamentAck -= UpdateUI;
|
||||||
button.Text = "Login";
|
Connection.Instance.OnGetDataAcks -= UpdateUI;
|
||||||
button.Pressed += () =>
|
Connection.Instance.OnSetDataAcks -= UpdateUI;
|
||||||
{
|
}
|
||||||
Connection.Instance.AdminAuth(passwordBox.Text);
|
|
||||||
GetTree().Root.CallDeferred(Node.MethodName.RemoveChild, authWindow);
|
private void UpdateUI() {
|
||||||
};
|
if (!Connection.Instance.IsAdmin) {
|
||||||
|
BecomeAdmin.Show();
|
||||||
vbox.AddChild(passwordBox);
|
StartTournament.Hide();
|
||||||
vbox.AddChild(button);
|
CancelTournament.Hide();
|
||||||
|
Label.Hide();
|
||||||
authWindow.AddChild(vbox);
|
Timeout.Hide();
|
||||||
|
} else {
|
||||||
GetTree().Root.AddChild(authWindow);
|
BecomeAdmin.Hide();
|
||||||
}
|
Label.Show();
|
||||||
}
|
Timeout.Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Connection.Instance.IsAdmin && Connection.Instance.DemoMode) {
|
||||||
|
StartTournament.Hide();
|
||||||
|
CancelTournament.Hide();
|
||||||
|
} else if (Connection.Instance.IsAdmin && Connection.Instance.ActiveTournament != TournamentType.None) {
|
||||||
|
StartTournament.Hide();
|
||||||
|
CancelTournament.Show();
|
||||||
|
} else if (Connection.Instance.IsAdmin) {
|
||||||
|
StartTournament.Show();
|
||||||
|
CancelTournament.Hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
Timeout.Value = Connection.Instance.CurrentWaitTimeout;
|
||||||
|
var time = Connection.Instance.CurrentWaitTimeout.ToString();
|
||||||
|
if (time.Length > 3) {
|
||||||
|
time = time.Substring(0, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
Label.Text = "Wait To Move: " + time + "s ";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showAuthPopup() {
|
||||||
|
var authWindow = new Window();
|
||||||
|
authWindow.Theme = GD.Load<Theme>("res://assets/theme.tres");
|
||||||
|
authWindow.AlwaysOnTop = true;
|
||||||
|
authWindow.MaximizeDisabled = true;
|
||||||
|
authWindow.Unresizable = true;
|
||||||
|
authWindow.InitialPosition = Window.WindowInitialPosition.CenterMainWindowScreen;
|
||||||
|
authWindow.Size = new Vector2I(256, 128);
|
||||||
|
authWindow.CloseRequested += () =>
|
||||||
|
{
|
||||||
|
GetTree().Root.CallDeferred(Node.MethodName.RemoveChild, authWindow);
|
||||||
|
};
|
||||||
|
|
||||||
|
var vbox = new VBoxContainer();
|
||||||
|
vbox.LayoutMode = 1;
|
||||||
|
vbox.AnchorBottom = 1.0f;
|
||||||
|
vbox.AnchorRight = 1.0f;
|
||||||
|
vbox.GrowHorizontal = GrowDirection.Both;
|
||||||
|
vbox.GrowVertical = GrowDirection.Both;
|
||||||
|
vbox.Alignment = AlignmentMode.Center;
|
||||||
|
|
||||||
|
var passwordBox = new TextEdit();
|
||||||
|
passwordBox.PlaceholderText = "Password";
|
||||||
|
passwordBox.SetCustomMinimumSize(new Vector2(32, 32));
|
||||||
|
|
||||||
|
passwordBox.GuiInput += e =>
|
||||||
|
{
|
||||||
|
if (passwordBox.HasFocus() && e is InputEventKey inputEventKey && inputEventKey.IsPressed()) {
|
||||||
|
if (inputEventKey.KeyLabel == Key.Enter) {
|
||||||
|
Connection.Instance.AdminAuth(passwordBox.Text);
|
||||||
|
GetTree().Root.CallDeferred(Node.MethodName.RemoveChild, authWindow);
|
||||||
|
GetViewport().SetInputAsHandled();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inputEventKey.KeyLabel == Key.Space) {
|
||||||
|
GetViewport().SetInputAsHandled();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var button = new Button();
|
||||||
|
button.Text = "Login";
|
||||||
|
button.Pressed += () =>
|
||||||
|
{
|
||||||
|
Connection.Instance.AdminAuth(passwordBox.Text);
|
||||||
|
GetTree().Root.CallDeferred(Node.MethodName.RemoveChild, authWindow);
|
||||||
|
};
|
||||||
|
|
||||||
|
vbox.AddChild(passwordBox);
|
||||||
|
vbox.AddChild(button);
|
||||||
|
|
||||||
|
authWindow.AddChild(vbox);
|
||||||
|
|
||||||
|
GetTree().Root.AddChild(authWindow);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,11 +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() {
|
private void transitionToBracket() { GetTree().ChangeSceneToFile(BRACKET_SCENE_PATH); }
|
||||||
GetTree().ChangeSceneToFile(BRACKET_SCENE_PATH);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -52,12 +52,10 @@ public partial class BoardScreen : Node2D {
|
|||||||
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();
|
||||||
}
|
}
|
||||||
@@ -74,14 +72,12 @@ public partial class BoardScreen : Node2D {
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,8 +88,7 @@ public partial class BoardScreen : Node2D {
|
|||||||
if (_lastMoveTimer <= 0.0f) {
|
if (_lastMoveTimer <= 0.0f) {
|
||||||
if (_winner == "") {
|
if (_winner == "") {
|
||||||
showPopupMessage("Draw!");
|
showPopupMessage("Draw!");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
showPopupMessage(_winner + " wins!");
|
showPopupMessage(_winner + " wins!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -130,8 +125,7 @@ public partial class BoardScreen : Node2D {
|
|||||||
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();
|
||||||
@@ -166,9 +160,7 @@ public partial class BoardScreen : Node2D {
|
|||||||
transitionToBracket();
|
transitionToBracket();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void transitionToBracket() {
|
private void transitionToBracket() { GetTree().ChangeSceneToFile(BRACKET_SCENE_PATH); }
|
||||||
GetTree().ChangeSceneToFile(BRACKET_SCENE_PATH);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Determines if the column can have a new chip placed
|
* Determines if the column can have a new chip placed
|
||||||
|
|||||||
@@ -40,13 +40,13 @@ public partial class BracketScene : Control {
|
|||||||
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");
|
||||||
}
|
}
|
||||||
@@ -83,11 +83,9 @@ public partial class BracketScene : Control {
|
|||||||
|
|
||||||
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() {
|
private void transitionToBoard() { GetTree().ChangeSceneToFile(BOARD_SCENE_PATH); }
|
||||||
GetTree().ChangeSceneToFile(BOARD_SCENE_PATH);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -17,7 +17,8 @@ public partial class ConnectButtonUI : Button {
|
|||||||
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);
|
||||||
@@ -36,13 +37,9 @@ public partial class ConnectButtonUI : Button {
|
|||||||
Connection.Instance.OnWsConnectionFailed -= OnConnectionFailed;
|
Connection.Instance.OnWsConnectionFailed -= OnConnectionFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _Pressed() {
|
public override void _Pressed() { Connection.Instance.Connect(AddressField.Text); }
|
||||||
Connection.Instance.Connect(AddressField.Text);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnConnectionSuccess() {
|
private void OnConnectionSuccess() { GetTree().ChangeSceneToFile(BRACKET_SCENE_PATH); }
|
||||||
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;
|
||||||
|
|||||||
@@ -100,13 +100,11 @@ public partial class Connection : Node {
|
|||||||
UpdateGameList();
|
UpdateGameList();
|
||||||
UpdatePlayerList();
|
UpdatePlayerList();
|
||||||
refreshGamePlayerListTimer = 5.0f;
|
refreshGamePlayerListTimer = 5.0f;
|
||||||
}
|
} else if (refreshGamePlayerListTimer <= 0.0f) {
|
||||||
else if (refreshGamePlayerListTimer <= 0.0f) {
|
|
||||||
UpdateGameList();
|
UpdateGameList();
|
||||||
UpdatePlayerList();
|
UpdatePlayerList();
|
||||||
refreshGamePlayerListTimer = 5.0f;
|
refreshGamePlayerListTimer = 5.0f;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
refreshGamePlayerListTimer -= (float)delta;
|
refreshGamePlayerListTimer -= (float)delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,19 +122,15 @@ public partial class Connection : Node {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} 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;
|
||||||
@@ -169,52 +163,22 @@ public partial class Connection : Node {
|
|||||||
sendCommand("CONNECT", clientId);
|
sendCommand("CONNECT", clientId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendDisconnect() {
|
public void SendDisconnect() { sendCommand("DISCONNECT"); }
|
||||||
sendCommand("DISCONNECT");
|
public void SendReady() { sendCommand("READY"); }
|
||||||
}
|
public void SendPlay(int column) { sendCommand("PLAY", column.ToString()); }
|
||||||
|
|
||||||
public void SendReady() {
|
|
||||||
sendCommand("READY");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SendPlay(int column) {
|
|
||||||
sendCommand("PLAY", column.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Observer commands
|
// Observer commands
|
||||||
public void UpdateGameList() {
|
public void UpdateGameList() { sendCommand("GAME", "LIST"); }
|
||||||
sendCommand("GAME", "LIST");
|
public void UpdatePlayerList() { sendCommand("PLAYER", "LIST"); }
|
||||||
}
|
public void SendWatchGame(int matchID) { sendCommand("GAME", "WATCH:" + matchID); }
|
||||||
|
|
||||||
public void UpdatePlayerList() {
|
|
||||||
sendCommand("PLAYER", "LIST");
|
|
||||||
}
|
|
||||||
|
|
||||||
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() {
|
public void GetTournamentStatus() { sendCommand("GET", "TOURNAMENT_STATUS"); }
|
||||||
sendCommand("GET", "MOVE_WAIT");
|
public void GetDemoMode() { sendCommand("GET", "DEMO_MODE"); }
|
||||||
}
|
public void GetMaxTimeout() { sendCommand("GET", "MAX_TIMEOUT"); }
|
||||||
|
|
||||||
public void GetTournamentStatus() {
|
|
||||||
sendCommand("GET", "TOURNAMENT_STATUS");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void GetDemoMode() {
|
|
||||||
sendCommand("GET", "DEMO_MODE");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void GetMaxTimeout() {
|
|
||||||
sendCommand("GET", "MAX_TIMEOUT");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Admin commands
|
// Admin commands
|
||||||
public void KickPlayer(string playerId) {
|
public void KickPlayer(string playerId) {
|
||||||
@@ -278,8 +242,7 @@ public partial class Connection : Node {
|
|||||||
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;
|
||||||
}
|
}
|
||||||
@@ -309,8 +272,7 @@ public partial class Connection : Node {
|
|||||||
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}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -331,24 +293,19 @@ public partial class Connection : Node {
|
|||||||
string data = body.Split(":")[1];
|
string data = body.Split(":")[1];
|
||||||
if (body.StartsWith("MOVE_WAIT")) {
|
if (body.StartsWith("MOVE_WAIT")) {
|
||||||
CurrentWaitTimeout = double.Parse(data);
|
CurrentWaitTimeout = double.Parse(data);
|
||||||
}
|
} else if (body.StartsWith("MAX_TIMEOUT")) {
|
||||||
else if (body.StartsWith("MAX_TIMEOUT")) {
|
|
||||||
MaxTimeout = double.Parse(data);
|
MaxTimeout = double.Parse(data);
|
||||||
}
|
} else if (body.StartsWith("DEMO_MODE")) {
|
||||||
else if (body.StartsWith("DEMO_MODE")) {
|
|
||||||
DemoMode = bool.Parse(data);
|
DemoMode = bool.Parse(data);
|
||||||
}
|
} else if (body.StartsWith("TOURNAMENT_STATUS")) {
|
||||||
else if (body.StartsWith("TOURNAMENT_STATUS")) {
|
|
||||||
TournamentType? type = parseTournamentType(data);
|
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}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -395,8 +352,7 @@ public partial class Connection : Node {
|
|||||||
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();
|
||||||
}
|
}
|
||||||
@@ -471,8 +427,7 @@ public partial class Connection : Node {
|
|||||||
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":
|
||||||
@@ -510,8 +465,7 @@ public partial class Connection : Node {
|
|||||||
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++) {
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
public class PlayerData {
|
public class PlayerData {
|
||||||
public string username { get; private set; }
|
public string Username { get; private set; }
|
||||||
public bool isReady { get; private set; }
|
public bool IsReady { get; private set; }
|
||||||
public bool isPlaying { get; private set; }
|
public bool IsPlaying { get; private set; }
|
||||||
|
|
||||||
public PlayerData(string username, bool isReady, bool isPlaying) {
|
public PlayerData(string username, bool isReady, bool isPlaying) {
|
||||||
this.username = username;
|
Username = username;
|
||||||
this.isReady = isReady;
|
IsReady = isReady;
|
||||||
this.isPlaying = isPlaying;
|
IsPlaying = isPlaying;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
public enum TournamentType {
|
public enum TournamentType {
|
||||||
None,
|
None,
|
||||||
RoundRobin
|
RoundRobin
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user