Add "Round" GameState Struct
This commit is contained in:
parent
e83fbd7f66
commit
63c33e7227
@ -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
24
GameState/Round.cs
Normal 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>()!
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user