CS2GSI/GameState/GameStateTeam.cs

30 lines
1.2 KiB
C#
Raw Normal View History

2024-01-15 21:49:09 +01:00
using Newtonsoft.Json.Linq;
namespace CS2GSI.GameState;
2024-01-15 20:04:37 +01:00
2024-01-15 22:22:36 +01:00
public struct GameStateTeam
2024-01-15 20:04:37 +01:00
{
2024-01-15 22:22:36 +01:00
public CS2Team Team;
2024-01-15 20:04:37 +01:00
public int Score, ConsecutiveRoundLosses, TimeoutsRemaining, MatchesWonThisSeries;
2024-01-15 20:39:38 +01:00
public override string ToString()
{
return $"{GetType()}\n" +
$"\tScore: {Score}\n" +
$"\tConsecutiveRoundLosses: {ConsecutiveRoundLosses}\n" +
$"\tTimeoutsRemaining: {TimeoutsRemaining}\n" +
$"\tMatchesWonThisSeries: {MatchesWonThisSeries}\n";
}
2024-01-15 21:49:09 +01:00
2024-01-15 22:22:36 +01:00
internal static GameStateTeam ParseFromJObject(JObject jsonObject, CS2Team team)
2024-01-15 21:49:09 +01:00
{
2024-01-15 22:22:36 +01:00
return new GameStateTeam()
2024-01-15 21:49:09 +01:00
{
2024-01-15 22:22:36 +01:00
Team = team,
Score = jsonObject.SelectToken($"map.team_{team.ToString().ToLower()}.score")!.Value<int>(),
ConsecutiveRoundLosses = jsonObject.SelectToken($"map.team_{team.ToString().ToLower()}.consecutive_round_losses")!.Value<int>(),
TimeoutsRemaining = jsonObject.SelectToken($"map.team_{team.ToString().ToLower()}.timeouts_remaining")!.Value<int>(),
MatchesWonThisSeries = jsonObject.SelectToken($"map.team_{team.ToString().ToLower()}.matches_won_this_series")!.Value<int>(),
2024-01-15 21:49:09 +01:00
};
}
2024-01-15 20:04:37 +01:00
}