GameState ToString output TreeFormat

This commit is contained in:
glax 2024-01-16 04:24:09 +01:00
parent b45a68bf1c
commit bbfa9989ec
10 changed files with 43 additions and 54 deletions

2
CS2GSI.sln.DotSettings Normal file
View File

@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=CS/@EntryIndexedValue">CS</s:String></wpf:ResourceDictionary>

View File

@ -38,12 +38,12 @@ public class CS2GSI
if (_lastLocalGameState is not null && _allGameStates.Count > 0)
{
List<ValueTuple<CS2Event, CS2EventArgs>> generatedEvents = CS2EventGenerator.GenerateEvents(_lastLocalGameState.Value, newState, _allGameStates.Last());
List<ValueTuple<CS2Event, CS2EventArgs>> generatedEvents = CS2EventGenerator.GenerateEvents(_lastLocalGameState, newState, _allGameStates.Last());
this._logger?.Log(LogLevel.Information, $"Generated {generatedEvents.Count} events:\n\t{string.Join("\n\t", generatedEvents)}");
InvokeEvents(generatedEvents);
}
this._lastLocalGameState = newState.UpdateGameStateForLocal(_lastLocalGameState);
this._logger?.Log(LogLevel.Debug, $"Updated Local State:\n{_lastLocalGameState.ToString()}");
this._logger?.Log(LogLevel.Debug, $"\nUpdated Local State:\n{_lastLocalGameState}");
_allGameStates.Add(newState);
}

View File

@ -2,7 +2,7 @@
namespace CS2GSI.GameState;
public struct CS2GameState
public record CS2GameState : GameState
{
public string ProviderSteamId;
public int Timestamp;
@ -12,11 +12,7 @@ public struct CS2GameState
public override string ToString()
{
return $"{GetType().Name}\n" +
$"..Time: {Timestamp}\tProviderSteamId: {ProviderSteamId}\n" +
$"..{Map.ToString()?.Replace("\n", "\n...")}\n" +
$"..{Round.ToString()?.Replace("\n", "\n...")}\n" +
$"..{Player.ToString()?.Replace("\n", "\n...")}\n";
return base.ToString();
}
internal static CS2GameState ParseFromJObject(JObject jsonObject)
@ -25,9 +21,9 @@ 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),
Round = GameState.Round.ParseFromJObject(jsonObject)
Map = Map.ParseFromJObject(jsonObject),
Player = Player.ParseFromJObject(jsonObject),
Round = Round.ParseFromJObject(jsonObject)
};
}
@ -36,7 +32,7 @@ public struct CS2GameState
if (previousLocalState is null)
return this.Player?.SteamId == ProviderSteamId ? this : null;
if (this.Player?.SteamId != ProviderSteamId)
return this.WithPlayer(previousLocalState.Value.Player);
return this.WithPlayer(previousLocalState.Player);
return this;
}

View File

@ -0,0 +1,21 @@
using System.Reflection;
namespace CS2GSI.GameState;
public abstract record GameState
{
public override string ToString()
{
string ret = "";
foreach (FieldInfo field in GetType().GetFields())
{
string filler = GetType().GetFields().Last() != field ? "\u251c\u2500" : "\u2514\u2500";
string filler2 = GetType().GetFields().Last() != field ? "\u2502" : " ";
if (field.FieldType.BaseType == typeof(GameState))
ret += $"\b{filler}\u2510{field.Name}\n{field.GetValue(this)?.ToString()?.Replace("\b", $"\b{filler2} ")}";
else
ret += $"\b{filler} {field.Name}{new string('.', field.Name.Length > 25 ? 0 : 25-field.Name.Length)}{field.GetValue(this)}\n";
}
return ret;
}
}

View File

@ -2,18 +2,14 @@
namespace CS2GSI.GameState;
public struct GameStateTeam
public record GameStateTeam : GameState
{
public CS2Team Team;
public int Score, ConsecutiveRoundLosses, TimeoutsRemaining, MatchesWonThisSeries;
public override string ToString()
{
return $"{GetType().Name}\n" +
$"..Team {Team}\tScore: {Score}\n" +
$"..ConsecutiveRoundLosses: {ConsecutiveRoundLosses}\n" +
$"..TimeoutsRemaining: {TimeoutsRemaining}\n" +
$"..MatchesWonThisSeries: {MatchesWonThisSeries}\n";
return base.ToString();
}
internal static GameStateTeam ParseFromJObject(JObject jsonObject, CS2Team team)

View File

@ -2,7 +2,7 @@
namespace CS2GSI.GameState;
public struct Map
public record Map : GameState
{
public string Mode, MapName;
public MapPhase Phase;
@ -11,13 +11,7 @@ public struct Map
public override string ToString()
{
return $"{GetType().Name}\n" +
$"..Mode: {Mode} Map: {MapName}\n" +
$"..Round: {Round}\n" +
$"..Matches to Win Series: {NumMatchesToWinSeries}\n" +
$"..Phase: {Phase}\n" +
$"..{GameStateTeamCT.ToString().Replace("\n", "\n...")}\n" +
$"..{GameStateTeamT.ToString().Replace("\n", "\n...")}\n";
return base.ToString();
}
internal static Map? ParseFromJObject(JObject jsonObject)

View File

@ -2,7 +2,7 @@
namespace CS2GSI.GameState;
public struct Player
public record Player : GameState
{
public string SteamId, Name;
public PlayerActivity Activity;
@ -13,12 +13,7 @@ public struct Player
public override string ToString()
{
return $"{GetType().Name}\n" +
$"..Name: {Name} SteamId: {SteamId}\n" +
$"..Activity: {Activity}\n" +
$"..Team: {Team}\n" +
$"..{State.ToString()?.Replace("\n", "\n...")}\n" +
$"..{MatchStats.ToString()?.Replace("\n", "\n...")}\n";
return base.ToString();
}
internal static Player? ParseFromJObject(JObject jsonObject)

View File

@ -2,16 +2,13 @@
namespace CS2GSI.GameState;
public struct PlayerMatchStats
public record PlayerMatchStats : GameState
{
public int Kills, Assists, Deaths, MVPs, Score;
public override string ToString()
{
return $"{GetType().Name}\n" +
$"..KAD: {Kills} {Assists} {Deaths}\n" +
$"..MVPs: {MVPs}\n" +
$"..Score: {Score}\n";
return base.ToString();
}
internal static PlayerMatchStats? ParseFromJObject(JObject jsonObject)

View File

@ -2,23 +2,14 @@
namespace CS2GSI.GameState;
public struct PlayerState
public record PlayerState : GameState
{
public int Health, Armor, Flashed, Smoked, Burning, Money, RoundKills, RoundHs, EquipmentValue;
public bool Helmet;
public override string ToString()
{
return $"{GetType().Name}\n" +
$"..Health: {Health}\n" +
$"..Armor: {Armor}\n" +
$"..Flashed: {Flashed}\n" +
$"..Smoked: {Smoked}\n" +
$"..Burning: {Burning}\n" +
$"..Money: {Money}\n" +
$"..RoundKills: {RoundKills}\n" +
$"..RoundHs: {RoundHs}\n" +
$"..EquipmentValue: {EquipmentValue}\n";
return base.ToString();
}
internal static PlayerState? ParseFromJObject(JObject jsonObject)

View File

@ -2,7 +2,7 @@
namespace CS2GSI.GameState;
public struct Round
public record Round : GameState
{
public RoundPhase Phase;
public BombStatus? Bomb;
@ -10,10 +10,7 @@ public struct Round
public override string ToString()
{
return $"{GetType().Name}\n" +
$"..Phase: {Phase}\n" +
$"..Winner: {WinnerTeam}\n" +
$"..Bomb: {Bomb}\n";
return base.ToString();
}
internal static Round? ParseFromJObject(JObject jsonObject)