CS2GSI/GameState/Round.cs

40 lines
1.1 KiB
C#
Raw Normal View History

2024-01-15 22:08:37 +01:00
using Newtonsoft.Json.Linq;
namespace CS2GSI.GameState;
public struct Round
{
2024-01-15 22:22:36 +01:00
public RoundPhase Phase;
public string WinnerTeam, BombStatus;
2024-01-15 22:08:37 +01:00
public override string ToString()
{
return $"{GetType()}\n" +
$"\t{Phase} {WinnerTeam} {BombStatus}\n";
}
internal static Round? ParseFromJObject(JObject jsonObject)
{
return new Round()
{
2024-01-15 22:22:36 +01:00
Phase = RoundPhaseFromString(jsonObject.SelectToken("round.phase")!.Value<string>()!),
2024-01-15 22:08:37 +01:00
WinnerTeam = jsonObject.SelectToken("round.win_team")!.Value<string>()!,
BombStatus = jsonObject.SelectToken("round.bomb")!.Value<string>()!
};
}
2024-01-15 22:22:36 +01:00
public enum RoundPhase
{
Over, Freezetime, Live
}
private static RoundPhase RoundPhaseFromString(string str)
{
return str switch
{
"over" => RoundPhase.Over,
"live" => RoundPhase.Live,
"freezetime" => RoundPhase.Freezetime,
_ => throw new ArgumentOutOfRangeException()
};
}
2024-01-15 22:08:37 +01:00
}