using System; using Content.Client.Interfaces; using Content.Client.State; using Content.Shared; using Robust.Client.Interfaces.State; using Robust.Shared.Interfaces.Network; using Robust.Shared.IoC; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; namespace Content.Client.GameTicking { public class ClientGameTicker : SharedGameTicker, IClientGameTicker { #pragma warning disable 649 [Dependency] private IClientNetManager _netManager; [Dependency] private IStateManager _stateManager; #pragma warning restore 649 [ViewVariables] private bool _initialized; [ViewVariables] public bool AreWeReady { get; private set; } [ViewVariables] public bool IsGameStarted { get; private set; } [ViewVariables] public string ServerInfoBlob { get; private set; } [ViewVariables] public DateTime StartTime { get; private set; } public event Action InfoBlobUpdated; public event Action LobbyStatusUpdated; public void Initialize() { DebugTools.Assert(!_initialized); _netManager.RegisterNetMessage(nameof(MsgTickerJoinLobby), JoinLobby); _netManager.RegisterNetMessage(nameof(MsgTickerJoinGame), JoinGame); _netManager.RegisterNetMessage(nameof(MsgTickerLobbyStatus), LobbyStatus); _netManager.RegisterNetMessage(nameof(MsgTickerLobbyInfo), LobbyInfo); _initialized = true; } private void JoinLobby(MsgTickerJoinLobby message) { _stateManager.RequestStateChange(); } private void LobbyStatus(MsgTickerLobbyStatus message) { StartTime = message.StartTime; IsGameStarted = message.IsRoundStarted; AreWeReady = message.YouAreReady; LobbyStatusUpdated?.Invoke(); } private void LobbyInfo(MsgTickerLobbyInfo message) { ServerInfoBlob = message.TextBlob; InfoBlobUpdated?.Invoke(); } private void JoinGame(MsgTickerJoinGame message) { _stateManager.RequestStateChange(); } } }