1 Commits

3 changed files with 20 additions and 52 deletions

View File

@@ -11,7 +11,7 @@ config_version=5
[application]
config/name="Connect4 Observer"
config/version="0.2.0"
config/version="1.0.0"
run/main_scene="uid://dcx5nvs0pa7me"
config/features=PackedStringArray("4.5", "C#", "Forward Plus")
boot_splash/image="uid://dd7lvnidxr5ss"

View File

@@ -20,10 +20,10 @@ metadata/_snap_enabled = true
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -659.0
offset_top = -558.0
offset_right = 619.0
offset_bottom = 466.0
offset_left = -658.0
offset_top = -547.0
offset_right = 668.0
offset_bottom = 657.0
grow_horizontal = 2
grow_vertical = 2
texture = SubResource("GradientTexture2D_yqjtg")

View File

@@ -58,6 +58,7 @@ public partial class Connection : Node
private bool _connected = false;
private List<(string, int)> _lastScoreboard = [];
private bool _shouldShowTournamentResults = false;
private float _refreshGamePlayerListTimer = 5.0f;
public override void _Ready()
{
@@ -83,11 +84,6 @@ public partial class Connection : Node
}
}
public override void _ExitTree()
{
StopGameListRefreshLoop();
}
public override void _Process(double delta)
{
_webSocket.Poll();
@@ -100,7 +96,18 @@ public partial class Connection : Node
_connected = true;
LastError = "";
OnWsConnectionSuccess?.Invoke();
StartGameListRefreshLoop();
UpdateGameList();
UpdatePlayerList();
_refreshGamePlayerListTimer = 5.0f;
} else if (_refreshGamePlayerListTimer <= 0.0f)
{
UpdateGameList();
UpdatePlayerList();
_refreshGamePlayerListTimer = 5.0f;
}
else
{
_refreshGamePlayerListTimer -= (float) delta;
}
while (_webSocket.GetAvailablePacketCount() > 0)
@@ -144,7 +151,7 @@ public partial class Connection : Node
CurrentWaitTimeout = 5.0;
ActiveTournament = false;
DemoMode = false;
StopGameListRefreshLoop();
_refreshGamePlayerListTimer = 5.0f;
var code = _webSocket.GetCloseCode();
var reason = _webSocket.GetCloseReason();
LastError = "Unexpected Disconnect. Reason: " + reason + ", Code: " + code;
@@ -190,45 +197,6 @@ public partial class Connection : Node
SendCommand("GAME", "LIST");
}
private void StartGameListRefreshLoop()
{
if (_gameListThreadRunning)
{
return;
}
_gameListThreadRunning = true;
_gameListThread = new Thread(() =>
{
while (_gameListThreadRunning)
{
if (IsSocketOpen)
{
UpdateGameList();
UpdatePlayerList();
}
Thread.Sleep(TimeSpan.FromSeconds(5));
}
})
{
IsBackground = true
};
_gameListThread.Start();
}
private void StopGameListRefreshLoop()
{
if (!_gameListThreadRunning)
{
return;
}
_gameListThreadRunning = false;
_gameListThread?.Join();
_gameListThread = null;
}
public void UpdatePlayerList()
{
SendCommand("PLAYER", "LIST");
@@ -433,8 +401,8 @@ public partial class Connection : Node
}
case "START":
{
OnStartTournamentAck?.Invoke();
ActiveTournament = true;
OnStartTournamentAck?.Invoke();
break;
}
case "CANCEL":