Add "Round" GameState Struct

This commit is contained in:
glax 2024-01-15 22:08:37 +01:00
parent e83fbd7f66
commit 63c33e7227
2 changed files with 28 additions and 1 deletions

View File

@ -8,12 +8,14 @@ public struct CS2GameState
public int Timestamp;
public Map? Map;
public Player? Player;
public Round? Round;
public override string ToString()
{
return $"{GetType()}\n" +
$"\tTime: {Timestamp}\tSteamId: {ProviderSteamId}\n" +
$"\t{Map}\n" +
$"\t{Round}\n" +
$"\t{Player}\n";
}
@ -24,7 +26,8 @@ public struct CS2GameState
ProviderSteamId = jsonObject.SelectToken("provider.steamid")!.Value<string>()!,
Timestamp = jsonObject.SelectToken("provider.timestamp")!.Value<int>(),
Map = GameState.Map.ParseFromJObject(jsonObject),
Player = GameState.Player.ParseFromJObject(jsonObject)
Player = GameState.Player.ParseFromJObject(jsonObject),
Round = GameState.Round.ParseFromJObject(jsonObject)
};
}

24
GameState/Round.cs Normal file
View File

@ -0,0 +1,24 @@
using Newtonsoft.Json.Linq;
namespace CS2GSI.GameState;
public struct Round
{
public string Phase, WinnerTeam, BombStatus;
public override string ToString()
{
return $"{GetType()}\n" +
$"\t{Phase} {WinnerTeam} {BombStatus}\n";
}
internal static Round? ParseFromJObject(JObject jsonObject)
{
return new Round()
{
Phase = jsonObject.SelectToken("round.phase")!.Value<string>()!,
WinnerTeam = jsonObject.SelectToken("round.win_team")!.Value<string>()!,
BombStatus = jsonObject.SelectToken("round.bomb")!.Value<string>()!
};
}
}