A game about forced loneliness, made by TACStudios
1using System; 2using System.Collections; 3using System.Collections.Generic; 4using System.Linq; 5 6namespace Unity.VisualScripting 7{ 8 public class DebugDictionary<TKey, TValue> : IDictionary<TKey, TValue>, IDictionary 9 { 10 private readonly Dictionary<TKey, TValue> dictionary = new Dictionary<TKey, TValue>(); 11 12 public TValue this[TKey key] 13 { 14 get 15 { 16 return dictionary[key]; 17 } 18 set 19 { 20 Debug($"Set: {key} => {value}"); 21 dictionary[key] = value; 22 } 23 } 24 25 object IDictionary.this[object key] 26 { 27 get 28 { 29 return this[(TKey)key]; 30 } 31 set 32 { 33 this[(TKey)key] = (TValue)value; 34 } 35 } 36 37 public string label { get; set; } = "Dictionary"; 38 39 public bool debug { get; set; } = false; 40 41 public int Count => dictionary.Count; 42 43 object ICollection.SyncRoot => ((ICollection)dictionary).SyncRoot; 44 45 bool ICollection.IsSynchronized => ((ICollection)dictionary).IsSynchronized; 46 47 ICollection IDictionary.Values => ((IDictionary)dictionary).Values; 48 49 bool IDictionary.IsReadOnly => ((IDictionary)dictionary).IsReadOnly; 50 51 bool IDictionary.IsFixedSize => ((IDictionary)dictionary).IsFixedSize; 52 53 bool ICollection<KeyValuePair<TKey, TValue>>.IsReadOnly => ((ICollection<KeyValuePair<TKey, TValue>>)dictionary).IsReadOnly; 54 55 public ICollection<TKey> Keys => dictionary.Keys; 56 57 ICollection IDictionary.Keys => ((IDictionary)dictionary).Keys; 58 59 public ICollection<TValue> Values => dictionary.Values; 60 61 void ICollection.CopyTo(Array array, int index) 62 { 63 ((ICollection)dictionary).CopyTo(array, index); 64 } 65 66 private void Debug(string message) 67 { 68 if (!debug) 69 { 70 return; 71 } 72 73 if (!string.IsNullOrEmpty(label)) 74 { 75 message = $"[{label}] {message}"; 76 } 77 78 UnityEngine.Debug.Log(message + "\n"); 79 } 80 81 IEnumerator IEnumerable.GetEnumerator() 82 { 83 return ((IEnumerable)dictionary).GetEnumerator(); 84 } 85 86 void IDictionary.Remove(object key) 87 { 88 Remove((TKey)key); 89 } 90 91 bool IDictionary.Contains(object key) 92 { 93 return ContainsKey((TKey)key); 94 } 95 96 void IDictionary.Add(object key, object value) 97 { 98 Add((TKey)key, (TValue)value); 99 } 100 101 public void Clear() 102 { 103 Debug("Clear"); 104 dictionary.Clear(); 105 } 106 107 IDictionaryEnumerator IDictionary.GetEnumerator() 108 { 109 return ((IDictionary)dictionary).GetEnumerator(); 110 } 111 112 public bool Contains(KeyValuePair<TKey, TValue> item) 113 { 114 return dictionary.Contains(item); 115 } 116 117 void ICollection<KeyValuePair<TKey, TValue>>.Add(KeyValuePair<TKey, TValue> item) 118 { 119 ((ICollection<KeyValuePair<TKey, TValue>>)dictionary).Add(item); 120 } 121 122 void ICollection<KeyValuePair<TKey, TValue>>.CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex) 123 { 124 ((ICollection<KeyValuePair<TKey, TValue>>)dictionary).CopyTo(array, arrayIndex); 125 } 126 127 bool ICollection<KeyValuePair<TKey, TValue>>.Remove(KeyValuePair<TKey, TValue> item) 128 { 129 return ((ICollection<KeyValuePair<TKey, TValue>>)dictionary).Remove(item); 130 } 131 132 public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator() 133 { 134 return dictionary.GetEnumerator(); 135 } 136 137 public bool ContainsKey(TKey key) 138 { 139 return dictionary.ContainsKey(key); 140 } 141 142 public void Add(TKey key, TValue value) 143 { 144 Debug($"Add: {key} => {value}"); 145 dictionary.Add(key, value); 146 } 147 148 public bool Remove(TKey key) 149 { 150 Debug($"Remove: {key}"); 151 return dictionary.Remove(key); 152 } 153 154 public bool TryGetValue(TKey key, out TValue value) 155 { 156 return dictionary.TryGetValue(key, out value); 157 } 158 } 159}