mirror of
https://github.com/AndrioCelos/TableturfBattleApp.git
synced 2026-10-20 16:48:49 -05:00
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.
This commit is contained in:
44
TableturfBattleServer/DataStructures.cs
Normal file
44
TableturfBattleServer/DataStructures.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
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) { }
|
||||
}
|
||||
Reference in New Issue
Block a user