Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
EffectManager.cs
Go to the documentation of this file.
3
5
6public abstract class EffectManager<T> where T : GameEffect
7{
8 protected bool _isLoaded;
9
11
12 public bool IsLoaded => _isLoaded;
13
14 public T this[string key]
15 {
16 get
17 {
18 if (_effects.TryGetValue(key, out var value))
19 {
20 return value;
21 }
22 return null;
23 }
24 set
25 {
26 Bind(key, value);
27 }
28 }
29
30 public void Bind(string name, T effect)
31 {
32 _effects[name] = effect;
33 if (_isLoaded)
34 {
35 effect.Load();
36 }
37 }
38
39 public void Load()
40 {
41 if (_isLoaded)
42 {
43 return;
44 }
45 _isLoaded = true;
46 foreach (T value in _effects.Values)
47 {
48 value.Load();
49 }
50 }
51
52 public T Activate(string name, Vector2 position = default(Vector2), params object[] args)
53 {
54 if (!_effects.ContainsKey(name))
55 {
56 throw new MissingEffectException(string.Concat("Unable to find effect named: ", name, ". Type: ", typeof(T), "."));
57 }
58 T val = _effects[name];
59 OnActivate(val, position);
60 val.Activate(position, args);
61 return val;
62 }
63
64 public void Deactivate(string name, params object[] args)
65 {
66 if (!_effects.ContainsKey(name))
67 {
68 throw new MissingEffectException(string.Concat("Unable to find effect named: ", name, ". Type: ", typeof(T), "."));
69 }
70 T val = _effects[name];
71 OnDeactivate(val);
72 val.Deactivate(args);
73 }
74
75 public virtual void OnActivate(T effect, Vector2 position)
76 {
77 }
78
79 public virtual void OnDeactivate(T effect)
80 {
81 }
82}
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
T Activate(string name, Vector2 position=default(Vector2), params object[] args)
virtual void OnActivate(T effect, Vector2 position)
void Deactivate(string name, params object[] args)
void Bind(string name, T effect)