summaryrefslogtreecommitdiff
path: root/Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSONClass.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSONClass.cs')
-rw-r--r--Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSONClass.cs171
1 files changed, 171 insertions, 0 deletions
diff --git a/Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSONClass.cs b/Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSONClass.cs
new file mode 100644
index 0000000..da9c432
--- /dev/null
+++ b/Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSONClass.cs
@@ -0,0 +1,171 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+
+namespace I2.Loc.SimpleJSON;
+
+public class JSONClass : JSONNode, IEnumerable
+{
+ private Dictionary<string, JSONNode> m_Dict = new Dictionary<string, JSONNode>(StringComparer.Ordinal);
+
+ public override JSONNode this[string aKey]
+ {
+ get
+ {
+ if (m_Dict.ContainsKey(aKey))
+ {
+ return m_Dict[aKey];
+ }
+ return new JSONLazyCreator(this, aKey);
+ }
+ set
+ {
+ if (m_Dict.ContainsKey(aKey))
+ {
+ m_Dict[aKey] = value;
+ }
+ else
+ {
+ m_Dict.Add(aKey, value);
+ }
+ }
+ }
+
+ public override JSONNode this[int aIndex]
+ {
+ get
+ {
+ if (aIndex < 0 || aIndex >= m_Dict.Count)
+ {
+ return null;
+ }
+ return m_Dict.ElementAt(aIndex).Value;
+ }
+ set
+ {
+ if (aIndex >= 0 && aIndex < m_Dict.Count)
+ {
+ string key = m_Dict.ElementAt(aIndex).Key;
+ m_Dict[key] = value;
+ }
+ }
+ }
+
+ public override int Count => m_Dict.Count;
+
+ public override IEnumerable<JSONNode> Childs
+ {
+ get
+ {
+ foreach (KeyValuePair<string, JSONNode> item in m_Dict)
+ {
+ yield return item.Value;
+ }
+ }
+ }
+
+ public override void Add(string aKey, JSONNode aItem)
+ {
+ if (!string.IsNullOrEmpty(aKey))
+ {
+ if (m_Dict.ContainsKey(aKey))
+ {
+ m_Dict[aKey] = aItem;
+ }
+ else
+ {
+ m_Dict.Add(aKey, aItem);
+ }
+ }
+ else
+ {
+ m_Dict.Add(Guid.NewGuid().ToString(), aItem);
+ }
+ }
+
+ public override JSONNode Remove(string aKey)
+ {
+ if (!m_Dict.ContainsKey(aKey))
+ {
+ return null;
+ }
+ JSONNode result = m_Dict[aKey];
+ m_Dict.Remove(aKey);
+ return result;
+ }
+
+ public override JSONNode Remove(int aIndex)
+ {
+ if (aIndex < 0 || aIndex >= m_Dict.Count)
+ {
+ return null;
+ }
+ KeyValuePair<string, JSONNode> keyValuePair = m_Dict.ElementAt(aIndex);
+ m_Dict.Remove(keyValuePair.Key);
+ return keyValuePair.Value;
+ }
+
+ public override JSONNode Remove(JSONNode aNode)
+ {
+ try
+ {
+ KeyValuePair<string, JSONNode> keyValuePair = m_Dict.Where((KeyValuePair<string, JSONNode> k) => k.Value == aNode).First();
+ m_Dict.Remove(keyValuePair.Key);
+ return aNode;
+ }
+ catch
+ {
+ return null;
+ }
+ }
+
+ public IEnumerator GetEnumerator()
+ {
+ foreach (KeyValuePair<string, JSONNode> item in m_Dict)
+ {
+ yield return item;
+ }
+ }
+
+ public override string ToString()
+ {
+ string text = "{";
+ foreach (KeyValuePair<string, JSONNode> item in m_Dict)
+ {
+ if (text.Length > 2)
+ {
+ text += ", ";
+ }
+ text = text + "\"" + JSONNode.Escape(item.Key) + "\":" + item.Value;
+ }
+ return text + "}";
+ }
+
+ public override string ToString(string aPrefix)
+ {
+ string text = "{ ";
+ foreach (KeyValuePair<string, JSONNode> item in m_Dict)
+ {
+ if (text.Length > 3)
+ {
+ text += ", ";
+ }
+ text = text + "\n" + aPrefix + " ";
+ text = text + "\"" + JSONNode.Escape(item.Key) + "\" : " + item.Value.ToString(aPrefix + " ");
+ }
+ return text + "\n" + aPrefix + "}";
+ }
+
+ public override void Serialize(BinaryWriter aWriter)
+ {
+ aWriter.Write((byte)2);
+ aWriter.Write(m_Dict.Count);
+ foreach (string key in m_Dict.Keys)
+ {
+ aWriter.Write(key);
+ m_Dict[key].Serialize(aWriter);
+ }
+ }
+}