using Newtonsoft.Json.Linq; namespace CS2GSI.GameState; public struct Map { public string Mode, Name; public MapPhase Phase; public int Round, NumMatchesToWinSeries; public GameStateTeam GameStateTeamCT, GameStateTeamT; public override string ToString() { return $"{GetType()}\n" + $"\t{Mode} {Name} {Round} Matches to Win Series: {NumMatchesToWinSeries}\n" + $"\t{Phase}\n" + $"\t{GameStateTeamCT}\n" + $"\t{GameStateTeamT}\n"; } internal static Map? ParseFromJObject(JObject jsonObject) { return jsonObject.SelectToken("map") is { } mapToken ? new Map() { Mode = jsonObject.SelectToken("map.mode")!.Value()!, Name = jsonObject.SelectToken("map.name")!.Value()!, Phase = MapPhaseFromString(jsonObject.SelectToken("map.phase")!.Value()!), Round = jsonObject.SelectToken("map.round")!.Value(), NumMatchesToWinSeries = jsonObject.SelectToken("map.num_matches_to_win_series")!.Value(), GameStateTeamCT = GameStateTeam.ParseFromJObject(jsonObject, CS2Team.CT), GameStateTeamT = GameStateTeam.ParseFromJObject(jsonObject, CS2Team.T) } : null; } public enum MapPhase {Warmup, Live, Intermission, GameOver} private static MapPhase MapPhaseFromString(string str) { return str switch { "warmup" => MapPhase.Warmup, "live" => MapPhase.Live, "intermission" => MapPhase.Intermission, // ReSharper disable once StringLiteralTypo "gameover" => MapPhase.GameOver, _ => throw new ArgumentOutOfRangeException() }; } }