fix: made disconnecct behavior more reliable, fixed some errors
This commit is contained in:
@@ -4,7 +4,6 @@ using System.Linq;
|
||||
|
||||
public partial class BoardScreen : Node2D
|
||||
{
|
||||
|
||||
[Export] private AudioStream endingSfx;
|
||||
[Export] private Theme theme;
|
||||
|
||||
@@ -71,7 +70,6 @@ public partial class BoardScreen : Node2D
|
||||
Connection.Instance.OnObserveTerminated += () => PopupMessage("Match Terminated");
|
||||
Connection.Instance.OnObserveMove += ObserveMove;
|
||||
Connection.Instance.OnTournamentEnd += ShowTournamentScoreboard;
|
||||
Connection.Instance.OnWSDisconnect += () => GetTree().ChangeSceneToFile("res://scenes/main_menu.tscn");
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
@@ -139,7 +137,6 @@ public partial class BoardScreen : Node2D
|
||||
{
|
||||
var popup = new Popup();
|
||||
popup.AlwaysOnTop = true;
|
||||
popup.PopupCentered();
|
||||
popup.Size = new Vector2I(200, 100);
|
||||
popup.Theme = GD.Load<Theme>("res://assets/theme.tres");
|
||||
var text = new Label();
|
||||
@@ -157,6 +154,7 @@ public partial class BoardScreen : Node2D
|
||||
popup.InitialPosition = Window.WindowInitialPosition.CenterMainWindowScreen;
|
||||
popup.PopupHide += () => popup.QueueFree();
|
||||
GetTree().Root.AddChild(popup);
|
||||
popup.PopupCentered();
|
||||
sfx.Play();
|
||||
popup.Show();
|
||||
TransitionToBracket();
|
||||
|
||||
@@ -32,7 +32,6 @@ public partial class BracketScene : Control
|
||||
Connection.Instance.OnUpdatedMatches += UpdateMatches;
|
||||
Connection.Instance.OnWatchGameAck += TransitionToBoard;
|
||||
Connection.Instance.OnTournamentEnd += ShowTournamentScoreboard;
|
||||
Connection.Instance.OnWSDisconnect += () => GetTree().ChangeSceneToFile("res://scenes/main_menu.tscn");
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
|
||||
@@ -8,8 +8,8 @@ public partial class ConnectButtonUI : Button
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Connection.Instance.OnWSConnectionSuccess += () => GetTree().ChangeSceneToFile(BRACKET_SCENE_PATH);
|
||||
Connection.Instance.OnWSConnectionFailed += () => ErrorLabel.Text = "Couldn't connect to server! " + Connection.Instance.LastError;
|
||||
Connection.Instance.OnWsConnectionSuccess += () => GetTree().ChangeSceneToFile(BRACKET_SCENE_PATH);
|
||||
Connection.Instance.OnWsConnectionFailed += () => ErrorLabel.Text = "Couldn't connect to server! " + Connection.Instance.LastError;
|
||||
}
|
||||
|
||||
public override void _Pressed()
|
||||
|
||||
@@ -33,9 +33,9 @@ public partial class Connection : Node
|
||||
public event Action<List<(string, int)>> OnTournamentEnd;
|
||||
public event Action OnBecomeAdmin;
|
||||
|
||||
public event Action OnWSConnectionSuccess;
|
||||
public event Action OnWSConnectionFailed;
|
||||
public event Action OnWSDisconnect;
|
||||
public event Action OnWsConnectionSuccess;
|
||||
public event Action OnWsConnectionFailed;
|
||||
public event Action OnWsDisconnect;
|
||||
|
||||
// Already prints to console
|
||||
public event Action<string> OnError;
|
||||
@@ -61,6 +61,7 @@ public partial class Connection : Node
|
||||
Instance = this;
|
||||
_webSocket.SetHeartbeatInterval(5.0);
|
||||
_webSocket.HeartbeatInterval = 5.0;
|
||||
Instance.OnWsDisconnect += () => GetTree().ChangeSceneToFile("res://scenes/main_menu.tscn");
|
||||
}
|
||||
|
||||
public void Connect(string address)
|
||||
@@ -93,7 +94,7 @@ public partial class Connection : Node
|
||||
{
|
||||
_connecting = false;
|
||||
_connected = true;
|
||||
OnWSConnectionSuccess?.Invoke();
|
||||
OnWsConnectionSuccess?.Invoke();
|
||||
StartGameListRefreshLoop();
|
||||
}
|
||||
|
||||
@@ -116,7 +117,7 @@ public partial class Connection : Node
|
||||
if (_connecting)
|
||||
{
|
||||
_connecting = false;
|
||||
OnWSConnectionFailed?.Invoke();
|
||||
OnWsConnectionFailed?.Invoke();
|
||||
}
|
||||
else if (_connected)
|
||||
{
|
||||
@@ -125,7 +126,7 @@ public partial class Connection : Node
|
||||
var code = _webSocket.GetCloseCode();
|
||||
var reason = _webSocket.GetCloseReason();
|
||||
GD.PrintErr("WebSocket closed with code: " + code + ", reason " + reason + ". Clean: " + (code != -1));
|
||||
OnWSDisconnect?.Invoke();
|
||||
OnWsDisconnect?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user