Add custom enums for GameStates
This commit is contained in:
parent
4cfe1dcc4d
commit
9489c45e9f
@ -36,7 +36,7 @@ public struct Player
|
||||
|
||||
private static CS2Team CS2TeamFromString(string str)
|
||||
{
|
||||
return str switch
|
||||
return str.ToLower() switch
|
||||
{
|
||||
"t" => CS2Team.T,
|
||||
"ct" => CS2Team.CT,
|
||||
|
@ -5,12 +5,13 @@ namespace CS2GSI.GameState;
|
||||
public struct Round
|
||||
{
|
||||
public RoundPhase Phase;
|
||||
public string WinnerTeam, BombStatus;
|
||||
public BombStatus Bomb;
|
||||
public CS2Team WinnerTeam;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{GetType()}\n" +
|
||||
$"\t{Phase} {WinnerTeam} {BombStatus}\n";
|
||||
$"\t{Phase} {WinnerTeam} {Bomb}\n";
|
||||
}
|
||||
|
||||
internal static Round? ParseFromJObject(JObject jsonObject)
|
||||
@ -18,8 +19,8 @@ public struct Round
|
||||
return new Round()
|
||||
{
|
||||
Phase = RoundPhaseFromString(jsonObject.SelectToken("round.phase")!.Value<string>()!),
|
||||
WinnerTeam = jsonObject.SelectToken("round.win_team")!.Value<string>()!,
|
||||
BombStatus = jsonObject.SelectToken("round.bomb")!.Value<string>()!
|
||||
WinnerTeam = CS2TeamFromString(jsonObject.SelectToken("round.win_team")!.Value<string>()!),
|
||||
Bomb = BombStatusFromString(jsonObject.SelectToken("round.bomb")!.Value<string>()!)
|
||||
};
|
||||
}
|
||||
|
||||
@ -37,4 +38,30 @@ public struct Round
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
}
|
||||
|
||||
public enum BombStatus
|
||||
{
|
||||
Planted, Exploded, Defused
|
||||
}
|
||||
|
||||
private static BombStatus BombStatusFromString(string str)
|
||||
{
|
||||
return str switch
|
||||
{
|
||||
"planted" => BombStatus.Planted,
|
||||
"exploded" => BombStatus.Exploded,
|
||||
"defused" => BombStatus.Defused,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
}
|
||||
|
||||
private static CS2Team CS2TeamFromString(string str)
|
||||
{
|
||||
return str.ToLower() switch
|
||||
{
|
||||
"t" => CS2Team.T,
|
||||
"ct" => CS2Team.CT,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user