A game about forced loneliness, made by TACStudios
1using System.Collections;
2using System.Collections.Generic;
3using UnityEngine;
4
5namespace Unity.VisualScripting
6{
7 [IncludeInSettings(false)]
8 public sealed class DictionaryAsset : LudiqScriptableObject, IDictionary<string, object>
9 {
10 public object this[string key]
11 {
12 get
13 {
14 return dictionary[key];
15 }
16 set
17 {
18 dictionary[key] = value;
19 }
20 }
21
22 [Serialize]
23 public Dictionary<string, object> dictionary { get; private set; } = new Dictionary<string, object>();
24
25 public int Count => dictionary.Count;
26
27 public ICollection<string> Keys => dictionary.Keys;
28
29 public ICollection<object> Values => dictionary.Values;
30
31 bool ICollection<KeyValuePair<string, object>>.IsReadOnly => ((ICollection<KeyValuePair<string, object>>)dictionary).IsReadOnly;
32
33 protected override void OnAfterDeserialize()
34 {
35 base.OnAfterDeserialize();
36
37 if (dictionary == null)
38 {
39 dictionary = new Dictionary<string, object>();
40 }
41 }
42
43 public void Clear()
44 {
45 dictionary.Clear();
46 }
47
48 public bool ContainsKey(string key)
49 {
50 return dictionary.ContainsKey(key);
51 }
52
53 public void Add(string key, object value)
54 {
55 dictionary.Add(key, value);
56 }
57
58 public void Merge(DictionaryAsset other, bool overwriteExisting = true)
59 {
60 foreach (var key in other.Keys)
61 {
62 if (overwriteExisting)
63 {
64 dictionary[key] = other[key];
65 }
66 else if (!dictionary.ContainsKey(key))
67 {
68 dictionary.Add(key, other[key]);
69 }
70 }
71 }
72
73 public bool Remove(string key)
74 {
75 return dictionary.Remove(key);
76 }
77
78 public bool TryGetValue(string key, out object value)
79 {
80 return dictionary.TryGetValue(key, out value);
81 }
82
83 public IEnumerator<KeyValuePair<string, object>> GetEnumerator()
84 {
85 return dictionary.GetEnumerator();
86 }
87
88 IEnumerator IEnumerable.GetEnumerator()
89 {
90 return ((IEnumerable)dictionary).GetEnumerator();
91 }
92
93 void ICollection<KeyValuePair<string, object>>.Add(KeyValuePair<string, object> item)
94 {
95 ((ICollection<KeyValuePair<string, object>>)dictionary).Add(item);
96 }
97
98 bool ICollection<KeyValuePair<string, object>>.Contains(KeyValuePair<string, object> item)
99 {
100 return ((ICollection<KeyValuePair<string, object>>)dictionary).Contains(item);
101 }
102
103 void ICollection<KeyValuePair<string, object>>.CopyTo(KeyValuePair<string, object>[] array, int arrayIndex)
104 {
105 ((ICollection<KeyValuePair<string, object>>)dictionary).CopyTo(array, arrayIndex);
106 }
107
108 bool ICollection<KeyValuePair<string, object>>.Remove(KeyValuePair<string, object> item)
109 {
110 return ((ICollection<KeyValuePair<string, object>>)dictionary).Remove(item);
111 }
112
113 [ContextMenu("Show Data...")]
114 protected override void ShowData()
115 {
116 base.ShowData();
117 }
118 }
119}