Vote type delay, code comments.

Added doc comments to server side voting API.
There is now a 4 minute delay between creating votes of the same type.
Shuffled some code around.
Made a StandardVoteType enum instead of string IDs.
This commit is contained in:
Pieter-Jan Briers
2021-07-21 19:03:10 +02:00
parent 1187185b89
commit e9af56c7c3
13 changed files with 348 additions and 49 deletions

View File

@@ -19,7 +19,10 @@ namespace Content.Client.Voting
void ClearPopupContainer();
void SetPopupContainer(Control container);
bool CanCallVote { get; }
bool CanCallStandardVote(StandardVoteType type, out TimeSpan whenCan);
event Action<bool> CanCallVoteChanged;
event Action CanCallStandardVotesChanged;
}
public sealed class VoteManager : IVoteManager
@@ -29,13 +32,17 @@ namespace Content.Client.Voting
[Dependency] private readonly IClientConsoleHost _console = default!;
[Dependency] private readonly IBaseClient _client = default!;
private readonly Dictionary<StandardVoteType, TimeSpan> _standardVoteTimeouts = new();
private readonly Dictionary<int, ActiveVote> _votes = new();
private readonly Dictionary<int, UI.VotePopup> _votePopups = new();
private Control? _popupContainer;
public bool CanCallVote { get; private set; }
public event Action<bool>? CanCallVoteChanged;
public event Action? CanCallStandardVotesChanged;
public void Initialize()
{
_netManager.RegisterNetMessage<MsgVoteData>(ReceiveVoteData);
@@ -54,6 +61,11 @@ namespace Content.Client.Voting
}
}
public bool CanCallStandardVote(StandardVoteType type, out TimeSpan whenCan)
{
return !_standardVoteTimeouts.TryGetValue(type, out whenCan);
}
public void ClearPopupContainer()
{
if (_popupContainer == null)
@@ -161,11 +173,20 @@ namespace Content.Client.Voting
private void ReceiveVoteCanCall(MsgVoteCanCall message)
{
if (CanCallVote == message.CanCall)
return;
if (CanCallVote != message.CanCall)
{
// TODO: actually use the "when can call vote" time for UI display or something.
CanCallVote = message.CanCall;
CanCallVoteChanged?.Invoke(CanCallVote);
}
CanCallVote = message.CanCall;
CanCallVoteChanged?.Invoke(CanCallVote);
_standardVoteTimeouts.Clear();
foreach (var (type, time) in message.VotesUnavailable)
{
_standardVoteTimeouts.Add(type, _gameTiming.RealServerToLocal(time));
}
CanCallStandardVotesChanged?.Invoke();
}
public void SendCastVote(int voteId, int option)