From 8d865d49fd3911c8fcdbbbf704ed320b58581230 Mon Sep 17 00:00:00 2001 From: glax Date: Mon, 15 Jan 2024 21:13:26 +0100 Subject: [PATCH] CS2GameState made immutable --- GameState/CS2GameState.cs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/GameState/CS2GameState.cs b/GameState/CS2GameState.cs index d15a900..9d200c8 100644 --- a/GameState/CS2GameState.cs +++ b/GameState/CS2GameState.cs @@ -14,4 +14,31 @@ public struct CS2GameState $"\t{Map}\n" + $"\t{Player}\n"; } + + internal CS2GameState? UpdateGameStateForLocal(CS2GameState? previousLocalState) + { + if (previousLocalState is null) + return this.Player?.SteamId == ProviderSteamId ? this : null; + if (this.Player?.SteamId != ProviderSteamId) + return this.WithPlayer(previousLocalState.Value.Player); + return this; + } + + private CS2GameState WithPlayer(Player? player) + { + this.Player = player; + return this; + } + + private CS2GameState WithMap(Map? map) + { + this.Map = map; + return this; + } + + private CS2GameState WithTimestamp(int timestamp) + { + this.Timestamp = timestamp; + return this; + } } \ No newline at end of file