TableturfBattleApp/TableturfBattleServer/DataStructures.cs
Andrio Celos d4e8d86571 Rework sync procedure and add a loading indicator
The server will now send a sync message when the client connects via WebSocket. This removes the need to send another GET request to sync game data.
2022-10-25 12:08:18 +11:00

45 lines
1.3 KiB
C#

using Newtonsoft.Json;
namespace TableturfBattleServer.DTO;
internal class WebSocketPayload<T> {
[JsonProperty("event")]
public string EventName;
[JsonProperty("data")]
public T Payload;
public WebSocketPayload(string eventName, T payload) {
this.EventName = eventName ?? throw new ArgumentNullException(nameof(eventName));
this.Payload = payload;
}
}
internal class WebSocketPayloadWithPlayerData<T> : WebSocketPayload<T> {
[JsonProperty("playerData")]
public PlayerData? PlayerData;
public WebSocketPayloadWithPlayerData(string eventName, T payload, PlayerData? playerData) : base(eventName, payload)
=> this.PlayerData = playerData;
}
public class PlayerData {
[JsonProperty("playerIndex")]
public int PlayerIndex;
[JsonProperty("hand")]
public Card[]? Hand;
[JsonProperty("deck")]
public Card[]? Deck;
[JsonProperty("move")]
public Move? Move;
[JsonProperty("cardsUsed")]
public List<int>? CardsUsed;
public PlayerData(int playerIndex, Card[]? hand, Card[]? deck, Move? move, List<int>? cardsUsed) {
this.PlayerIndex = playerIndex;
this.Hand = hand;
this.Deck = deck;
this.Move = move;
this.CardsUsed = cardsUsed;
}
public PlayerData(int playerIndex, Player player) : this(playerIndex, player.Hand, player.Deck, player.Move, player.CardsUsed) { }
}