Use TimeSpan instead of DateTime in RoundEnd and Comms Console.

This commit is contained in:
zumorica
2020-04-09 20:28:22 +02:00
parent 83e9688133
commit 3c795ad283
3 changed files with 12 additions and 6 deletions

View File

@@ -3,6 +3,8 @@ using Content.Client.Command;
using Content.Shared.GameObjects.Components.Command;
using Robust.Client.GameObjects.Components.UserInterface;
using Robust.Shared.GameObjects.Components.UserInterface;
using Robust.Shared.Interfaces.Timing;
using Robust.Shared.IoC;
using Robust.Shared.ViewVariables;
namespace Content.Client.GameObjects.Components.Command
@@ -12,11 +14,13 @@ namespace Content.Client.GameObjects.Components.Command
[ViewVariables]
private CommunicationsConsoleMenu _menu;
[Dependency] private IGameTiming _gameTiming;
public bool CountdownStarted { get; private set; }
public int Countdown => _expectedCountdownTime == null
? 0 : Math.Max((int)(_expectedCountdownTime.Value.Subtract(DateTime.Now)).TotalSeconds, 0);
private DateTime? _expectedCountdownTime;
? 0 : Math.Max((int)_expectedCountdownTime.Value.Subtract(_gameTiming.CurTime).TotalSeconds, 0);
private TimeSpan? _expectedCountdownTime;
public CommunicationsConsoleBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
{

View File

@@ -2,6 +2,7 @@ using System;
using System.Threading;
using Content.Server.Interfaces.GameTicking;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.Timing;
using Robust.Shared.IoC;
using Timer = Robust.Shared.Timers.Timer;
@@ -11,12 +12,13 @@ namespace Content.Server.GameObjects.EntitySystems
{
#pragma warning disable 649
[Dependency] private IGameTicker _gameTicker;
[Dependency] private IGameTiming _gameTiming;
#pragma warning restore 649
private CancellationTokenSource _roundEndCancellationTokenSource = new CancellationTokenSource();
public bool IsRoundEndCountdownStarted { get; private set; }
public int RoundEndCountdownTime { get; set; } = 5000;
public DateTime? ExpectedCountdownEnd = null;
public TimeSpan? ExpectedCountdownEnd = null;
public delegate void RoundEndCountdownStarted();
public event RoundEndCountdownStarted OnRoundEndCountdownStarted;
@@ -34,7 +36,7 @@ namespace Content.Server.GameObjects.EntitySystems
IsRoundEndCountdownStarted = true;
ExpectedCountdownEnd = DateTime.Now.AddMilliseconds(RoundEndCountdownTime);
ExpectedCountdownEnd = _gameTiming.CurTime.Add(new TimeSpan(0,0,0,0,RoundEndCountdownTime));
Timer.Spawn(RoundEndCountdownTime, EndRound, _roundEndCancellationTokenSource.Token);
OnRoundEndCountdownStarted?.Invoke();
}

View File

@@ -14,10 +14,10 @@ namespace Content.Shared.GameObjects.Components.Command
[Serializable, NetSerializable]
public class CommunicationsConsoleInterfaceState : BoundUserInterfaceState
{
public readonly DateTime? ExpectedCountdownEnd;
public readonly TimeSpan? ExpectedCountdownEnd;
public readonly bool CountdownStarted;
public CommunicationsConsoleInterfaceState(DateTime? expectedCountdownEnd = null)
public CommunicationsConsoleInterfaceState(TimeSpan? expectedCountdownEnd = null)
{
ExpectedCountdownEnd = expectedCountdownEnd;
CountdownStarted = expectedCountdownEnd != null;