Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Switch.cs
Go to the documentation of this file.
5
6namespace System.Diagnostics;
7
8public abstract class Switch
9{
10 private readonly string _description;
11
12 private readonly string _displayName;
13
14 private int _switchSetting;
15
16 private volatile bool _initialized;
17
18 private bool _initializing;
19
20 private volatile string _switchValueString = string.Empty;
21
22 private readonly string _defaultValue;
23
24 private object _initializedLock;
25
27
28 private static int s_LastCollectionCount;
29
31
32 private object InitializedLock
33 {
34 get
35 {
36 if (_initializedLock == null)
37 {
38 object value = new object();
40 }
41 return _initializedLock;
42 }
43 }
44
45 public string DisplayName => _displayName;
46
47 public string Description
48 {
49 get
50 {
51 if (_description != null)
52 {
53 return _description;
54 }
55 return string.Empty;
56 }
57 }
58
60 {
61 get
62 {
63 Initialize();
64 if (_attributes == null)
65 {
67 }
68 return _attributes;
69 }
70 }
71
72 protected int SwitchSetting
73 {
74 get
75 {
77 {
79 }
80 return _switchSetting;
81 }
82 set
83 {
84 bool flag = false;
86 {
87 _initialized = true;
88 if (_switchSetting != value)
89 {
91 flag = true;
92 }
93 }
94 if (flag)
95 {
97 }
98 }
99 }
100
101 protected string Value
102 {
103 get
104 {
105 Initialize();
106 return _switchValueString;
107 }
108 set
109 {
110 Initialize();
113 }
114 }
115
116 protected Switch(string displayName, string? description)
117 : this(displayName, description, "0")
118 {
119 }
120
121 protected Switch(string displayName, string? description, string defaultSwitchValue)
122 {
123 if (displayName == null)
124 {
125 displayName = string.Empty;
126 }
128 _description = description;
130 {
132 s_switches.Add(new WeakReference<Switch>(this));
133 }
135 }
136
137 private static void _pruneCachedSwitches()
138 {
140 {
142 {
143 return;
144 }
146 for (int i = 0; i < s_switches.Count; i++)
147 {
148 if (s_switches[i].TryGetTarget(out var _))
149 {
150 list.Add(s_switches[i]);
151 }
152 }
153 if (list.Count < s_switches.Count)
154 {
155 s_switches.Clear();
156 s_switches.AddRange(list);
157 s_switches.TrimExcess();
158 }
160 }
161 }
162
163 protected internal virtual string[]? GetSupportedAttributes()
164 {
165 return null;
166 }
167
168 private void Initialize()
169 {
171 }
172
173 private bool InitializeWithStatus()
174 {
175 if (!_initialized)
176 {
178 {
180 {
181 return false;
182 }
183 _initializing = true;
186 _initialized = true;
187 _initializing = false;
188 }
189 }
190 return true;
191 }
192
193 protected virtual void OnSwitchSettingChanged()
194 {
195 }
196
197 protected virtual void OnValueChanged()
198 {
200 }
201
202 internal static void RefreshAll()
203 {
205 {
207 for (int i = 0; i < s_switches.Count; i++)
208 {
209 if (s_switches[i].TryGetTarget(out var target))
210 {
211 target.Refresh();
212 }
213 }
214 }
215 }
216
217 internal void Refresh()
218 {
220 {
221 _initialized = false;
222 Initialize();
223 }
224 }
225}
void Add(TKey key, TValue value)
readonly string _description
Definition Switch.cs:10
virtual void OnSwitchSettingChanged()
Definition Switch.cs:193
StringDictionary _attributes
Definition Switch.cs:30
Switch(string displayName, string? description, string defaultSwitchValue)
Definition Switch.cs:121
static int s_LastCollectionCount
Definition Switch.cs:28
static void RefreshAll()
Definition Switch.cs:202
StringDictionary Attributes
Definition Switch.cs:60
static readonly List< WeakReference< Switch > > s_switches
Definition Switch.cs:26
virtual ? string[] GetSupportedAttributes()
Definition Switch.cs:163
Switch(string displayName, string? description)
Definition Switch.cs:116
readonly string _displayName
Definition Switch.cs:12
static void _pruneCachedSwitches()
Definition Switch.cs:137
volatile string _switchValueString
Definition Switch.cs:20
virtual void OnValueChanged()
Definition Switch.cs:197
readonly string _defaultValue
Definition Switch.cs:22
volatile bool _initialized
Definition Switch.cs:16
static int CollectionCount(int generation)
Definition GC.cs:169
Definition GC.cs:8
static CultureInfo InvariantCulture
static int CompareExchange(ref int location1, int value, int comparand)