Skip to content

Commit 9549444

Browse files
committed
Major changes
* Updated README.md * Renamed GSIListener to GameStateListener * Removed GameStateListener.HasRootNode() * GameStateListener is no longer static * GameStateListener defaults to http://localhost:<port>/ instead of http://127.0.0.1:<port>/ to avoid permission issues * Removed UacHelper class * Added "CSGSI.Nodes" namespace * Added "Node" classes * Have not added documentation for most of the new features yet, although they're relatively self-explanatory * Release 1.1 is now available! **this does not mean that I'm going to be pushing regular updates from now on**
1 parent c6679e4 commit 9549444

20 files changed

+1046
-464
lines changed

CSGSI.sln

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 2012
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.24720.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
46
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSGSI", "CSGSI\CSGSI.csproj", "{8D55804C-2CF1-4A65-9C3E-8E41CD809535}"
57
EndProject
68
Global

CSGSI/CSGSI.csproj

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,19 @@
4545
</ItemGroup>
4646
<ItemGroup>
4747
<Compile Include="GameState.cs" />
48-
<Compile Include="GameStateNode.cs" />
49-
<Compile Include="GSIListener.cs" />
48+
<Compile Include="GameStateListener.cs" />
49+
<Compile Include="Nodes\AllPlayersNode.cs" />
50+
<Compile Include="Nodes\AuthNode.cs" />
51+
<Compile Include="Nodes\MapNode.cs" />
52+
<Compile Include="Nodes\MatchStatsNode.cs" />
53+
<Compile Include="Nodes\NodeBase.cs" />
54+
<Compile Include="Nodes\PlayerNode.cs" />
55+
<Compile Include="Nodes\ProviderNode.cs" />
56+
<Compile Include="Nodes\RoundNode.cs" />
57+
<Compile Include="Nodes\PlayerStateNode.cs" />
58+
<Compile Include="Nodes\WeaponNode.cs" />
59+
<Compile Include="Nodes\WeaponsNode.cs" />
5060
<Compile Include="Properties\AssemblyInfo.cs" />
51-
<Compile Include="UacHelper.cs" />
5261
</ItemGroup>
5362
<ItemGroup>
5463
<None Include="packages.config" />

CSGSI/GSIListener.cs

Lines changed: 0 additions & 132 deletions
This file was deleted.

CSGSI/GameState.cs

Lines changed: 107 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -5,93 +5,140 @@
55
using System.Collections.Generic;
66
using Newtonsoft.Json;
77
using Newtonsoft.Json.Linq;
8+
using CSGSI.Nodes;
89
namespace CSGSI
910
{
1011
/// <summary>
1112
/// This object represents the entire game state
1213
/// </summary>
1314
public class GameState
1415
{
15-
private JObject m_Data;
16+
private JObject _Data;
1617

17-
private GameStateNode m_Provider;
18-
private GameStateNode m_Map;
19-
private GameStateNode m_Round;
20-
private GameStateNode m_Player;
21-
private GameStateNode m_Auth;
22-
private GameStateNode m_Added;
23-
private GameStateNode m_Previously;
18+
private ProviderNode _Provider;
19+
private MapNode _Map;
20+
private RoundNode _Round;
21+
private PlayerNode _Player;
22+
private AllPlayersNode _AllPlayers;
23+
private GameState _Previously;
24+
private GameState _Added;
25+
private AuthNode _Auth;
2426

25-
/// <summary>
26-
/// The "provider" subnode
27-
/// </summary>
28-
public GameStateNode Provider { get { return m_Provider; } }
27+
public ProviderNode Provider
28+
{
29+
get
30+
{
31+
if (_Provider == null)
32+
{
33+
_Provider = new ProviderNode(_Data["provider"]?.ToString() ?? "");
34+
}
2935

30-
/// <summary>
31-
/// The "map" subnode
32-
/// </summary>
33-
public GameStateNode Map { get { return m_Map; } }
36+
return _Provider;
37+
}
38+
}
39+
public MapNode Map
40+
{
41+
get
42+
{
43+
if (_Map == null)
44+
{
45+
_Map = new MapNode(_Data["map"]?.ToString() ?? "");
46+
}
3447

35-
/// <summary>
36-
/// The "round" subnode
37-
/// </summary>
38-
public GameStateNode Round { get { return m_Round; } }
48+
return _Map;
49+
}
50+
}
51+
public RoundNode Round
52+
{
53+
get
54+
{
55+
if (_Round == null)
56+
{
57+
_Round = new RoundNode(_Data["round"]?.ToString() ?? "");
58+
}
3959

40-
/// <summary>
41-
/// The "player" subnode
42-
/// </summary>
43-
public GameStateNode Player { get { return m_Player; } }
60+
return _Round;
61+
}
62+
}
63+
public PlayerNode Player
64+
{
65+
get
66+
{
67+
if (_Player == null)
68+
{
69+
_Player = new PlayerNode(_Data["player"]?.ToString() ?? "");
70+
}
4471

45-
/// <summary>
46-
/// The "auth" subnode
47-
/// </summary>
48-
public GameStateNode Auth { get { return m_Auth; } }
72+
return _Player;
73+
}
74+
}
75+
public AllPlayersNode AllPlayers
76+
{
77+
get
78+
{
79+
if (_AllPlayers == null)
80+
{
81+
_AllPlayers = new AllPlayersNode(_Data["allplayers"]?.ToString() ?? "");
82+
}
4983

50-
/// <summary>
51-
/// The "added" subnode
52-
/// </summary>
53-
public GameStateNode Added { get { return m_Added; } }
84+
return _AllPlayers;
85+
}
86+
}
87+
public GameState Previously
88+
{
89+
get
90+
{
91+
if (_Previously == null)
92+
{
93+
_Previously = new GameState(_Data["previously"]?.ToString() ?? "");
94+
}
5495

55-
/// <summary>
56-
/// The "previously" subnode
57-
/// </summary>
58-
public GameStateNode Previously { get { return m_Previously; } }
96+
return _Previously;
97+
}
98+
}
99+
public GameState Added
100+
{
101+
get
102+
{
103+
if (_Added == null)
104+
{
105+
_Added = new GameState(_Data["added"]?.ToString() ?? "");
106+
}
107+
return _Added;
108+
}
109+
}
110+
public AuthNode Auth
111+
{
112+
get
113+
{
114+
if(_Auth == null)
115+
{
116+
_Auth = new AuthNode(_Data["auth"]?.ToString() ?? "");
117+
}
118+
119+
return _Auth;
120+
}
121+
}
59122

60-
private string m_JSON;
61123

62124
/// <summary>
63125
/// The JSON string that was used to generate this object
64126
/// </summary>
65-
public string JSON { get { return m_JSON; } }
66-
127+
public readonly string JSON;
128+
67129
/// <summary>
68130
/// Initialises a new GameState object using a JSON string
69131
/// </summary>
70132
/// <param name="JSONstring"></param>
71133
public GameState(string JSONstring)
72134
{
73-
m_JSON = JSONstring;
135+
if(JSONstring.Equals(""))
136+
{
137+
JSONstring = "{}";
138+
}
74139

75-
if (!JSONstring.Equals(""))
76-
m_Data = JObject.Parse(JSONstring);
77-
78-
m_Provider = (HasRootNode("provider") ? new GameStateNode(m_Data["provider"]) : GameStateNode.Empty());
79-
m_Map = (HasRootNode("map") ? new GameStateNode(m_Data["map"]) : GameStateNode.Empty());
80-
m_Round = (HasRootNode("round") ? new GameStateNode(m_Data["round"]) : GameStateNode.Empty());
81-
m_Player = (HasRootNode("player") ? new GameStateNode(m_Data["player"]) : GameStateNode.Empty());
82-
m_Auth = (HasRootNode("auth") ? new GameStateNode(m_Data["auth"]) : GameStateNode.Empty());
83-
m_Added = (HasRootNode("added") ? new GameStateNode(m_Data["added"]) : GameStateNode.Empty());
84-
m_Previously = (HasRootNode("previously") ? new GameStateNode(m_Data["previously"]) : GameStateNode.Empty());
85-
}
86-
87-
/// <summary>
88-
/// Determines if the specified node exists in this GameState object
89-
/// </summary>
90-
/// <param name="rootnode"></param>
91-
/// <returns>Returns true if the specified node exists, false otherwise</returns>
92-
public bool HasRootNode(string rootnode)
93-
{
94-
return (m_Data != null && m_Data[rootnode] != null);
140+
JSON = JSONstring;
141+
_Data = JObject.Parse(JSONstring);
95142
}
96143
}
97144
}

0 commit comments

Comments
 (0)