com.wallstop-studios.unity-helpers 2.0.3 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Docs/DATA_STRUCTURES.md +7 -7
- package/Docs/EFFECTS_SYSTEM.md +836 -8
- package/Docs/EFFECTS_SYSTEM_TUTORIAL.md +77 -18
- package/Docs/HULLS.md +2 -2
- package/Docs/RANDOM_PERFORMANCE.md +1 -1
- package/Docs/REFLECTION_HELPERS.md +1 -1
- package/Docs/RELATIONAL_COMPONENTS.md +51 -6
- package/Docs/SERIALIZATION.md +1 -1
- package/Docs/SINGLETONS.md +2 -2
- package/Docs/SPATIAL_TREES_2D_GUIDE.md +3 -3
- package/Docs/SPATIAL_TREES_3D_GUIDE.md +3 -3
- package/Docs/SPATIAL_TREE_SEMANTICS.md +7 -7
- package/Editor/CustomDrawers/WShowIfPropertyDrawer.cs +131 -41
- package/Editor/Utils/ScriptableObjectSingletonCreator.cs +175 -18
- package/README.md +17 -3
- package/Runtime/Core/Helper/UnityMainThreadDispatcher.cs +4 -2
- package/Runtime/Tags/Attribute.cs +144 -24
- package/Runtime/Tags/AttributeEffect.cs +278 -11
- package/Runtime/Tags/AttributeModification.cs +59 -29
- package/Runtime/Tags/AttributeUtilities.cs +465 -0
- package/Runtime/Tags/AttributesComponent.cs +20 -0
- package/Runtime/Tags/EffectBehavior.cs +171 -0
- package/Runtime/Tags/EffectBehavior.cs.meta +4 -0
- package/Runtime/Tags/EffectHandle.cs +5 -0
- package/Runtime/Tags/EffectHandler.cs +564 -39
- package/Runtime/Tags/EffectStackKey.cs +79 -0
- package/Runtime/Tags/EffectStackKey.cs.meta +4 -0
- package/Runtime/Tags/PeriodicEffectDefinition.cs +102 -0
- package/Runtime/Tags/PeriodicEffectDefinition.cs.meta +4 -0
- package/Runtime/Tags/PeriodicEffectRuntimeState.cs +40 -0
- package/Runtime/Tags/PeriodicEffectRuntimeState.cs.meta +4 -0
- package/Runtime/Tags/TagHandler.cs +375 -21
- package/Samples~/DI - Zenject/README.md +0 -2
- package/Tests/Editor/Attributes/WShowIfPropertyDrawerTests.cs +285 -0
- package/Tests/Editor/Attributes/WShowIfPropertyDrawerTests.cs.meta +11 -0
- package/Tests/Editor/Core/Attributes/RelationalComponentAssignerTests.cs +2 -2
- package/Tests/Editor/Utils/ScriptableObjectSingletonTests.cs +41 -0
- package/Tests/Runtime/Serialization/JsonSerializationTest.cs +4 -3
- package/Tests/Runtime/Tags/AttributeEffectTests.cs +135 -0
- package/Tests/Runtime/Tags/AttributeEffectTests.cs.meta +3 -0
- package/Tests/Runtime/Tags/AttributeModificationTests.cs +137 -0
- package/Tests/Runtime/Tags/AttributeTests.cs +192 -0
- package/Tests/Runtime/Tags/AttributeTests.cs.meta +3 -0
- package/Tests/Runtime/Tags/AttributeUtilitiesTests.cs +245 -0
- package/Tests/Runtime/Tags/CosmeticAndCollisionTests.cs +1 -1
- package/Tests/Runtime/Tags/EffectBehaviorTests.cs +184 -0
- package/Tests/Runtime/Tags/EffectBehaviorTests.cs.meta +3 -0
- package/Tests/Runtime/Tags/EffectHandlerTests.cs +809 -0
- package/Tests/Runtime/Tags/Helpers/RecordingEffectBehavior.cs +89 -0
- package/Tests/Runtime/Tags/Helpers/RecordingEffectBehavior.cs.meta +4 -0
- package/Tests/Runtime/Tags/PeriodicEffectDefinitionSerializationTests.cs +92 -0
- package/Tests/Runtime/Tags/PeriodicEffectDefinitionSerializationTests.cs.meta +3 -0
- package/Tests/Runtime/Tags/TagHandlerTests.cs +130 -6
- package/package.json +1 -1
- package/scripts/lint-doc-links.ps1 +156 -11
- package/Tests/Runtime/Tags/AttributeDataTests.cs +0 -312
- package/node_modules.meta +0 -8
- /package/Tests/Runtime/Tags/{AttributeDataTests.cs.meta → AttributeModificationTests.cs.meta} +0 -0
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
namespace WallstopStudios.UnityHelpers.Tests.Tags
|
|
2
|
-
{
|
|
3
|
-
using System.Text.Json;
|
|
4
|
-
using NUnit.Framework;
|
|
5
|
-
using UnityEngine;
|
|
6
|
-
using WallstopStudios.UnityHelpers.Tags;
|
|
7
|
-
using WallstopStudios.UnityHelpers.Tests.TestUtils;
|
|
8
|
-
using Attribute = WallstopStudios.UnityHelpers.Tags.Attribute;
|
|
9
|
-
|
|
10
|
-
public abstract class AttributeTagsTestBase : CommonTestBase
|
|
11
|
-
{
|
|
12
|
-
protected static void ResetEffectHandleId(long value = 0)
|
|
13
|
-
{
|
|
14
|
-
EffectHandle.Id = value;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
[TestFixture]
|
|
19
|
-
public sealed class AttributeModificationTests
|
|
20
|
-
{
|
|
21
|
-
[Test]
|
|
22
|
-
public void EqualityOperatorsRespectFields()
|
|
23
|
-
{
|
|
24
|
-
AttributeModification baseline = new()
|
|
25
|
-
{
|
|
26
|
-
attribute = "health",
|
|
27
|
-
action = ModificationAction.Multiplication,
|
|
28
|
-
value = 1.5f,
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
AttributeModification clone = baseline;
|
|
32
|
-
Assert.IsTrue(baseline == clone);
|
|
33
|
-
Assert.IsFalse(baseline != clone);
|
|
34
|
-
Assert.AreEqual(baseline, clone);
|
|
35
|
-
Assert.AreEqual(baseline.GetHashCode(), clone.GetHashCode());
|
|
36
|
-
|
|
37
|
-
AttributeModification differentAttribute = baseline;
|
|
38
|
-
differentAttribute.attribute = "armor";
|
|
39
|
-
Assert.IsFalse(baseline == differentAttribute);
|
|
40
|
-
Assert.IsTrue(baseline != differentAttribute);
|
|
41
|
-
|
|
42
|
-
AttributeModification differentAction = baseline;
|
|
43
|
-
differentAction.action = ModificationAction.Addition;
|
|
44
|
-
Assert.IsFalse(baseline.Equals(differentAction));
|
|
45
|
-
|
|
46
|
-
AttributeModification differentValue = baseline;
|
|
47
|
-
differentValue.value = 2f;
|
|
48
|
-
Assert.IsFalse(baseline.Equals(differentValue));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
[Test]
|
|
52
|
-
public void ToStringSerializesAllFields()
|
|
53
|
-
{
|
|
54
|
-
AttributeModification modification = new()
|
|
55
|
-
{
|
|
56
|
-
attribute = "health",
|
|
57
|
-
action = ModificationAction.Override,
|
|
58
|
-
value = 42.5f,
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
using JsonDocument document = JsonDocument.Parse(modification.ToString());
|
|
62
|
-
JsonElement root = document.RootElement;
|
|
63
|
-
Assert.AreEqual("health", root.GetProperty("attribute").GetString());
|
|
64
|
-
Assert.AreEqual("Override", root.GetProperty("action").GetString());
|
|
65
|
-
Assert.AreEqual(42.5f, root.GetProperty("value").GetSingle());
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
[TestFixture]
|
|
70
|
-
public sealed class AttributeTests : AttributeTagsTestBase
|
|
71
|
-
{
|
|
72
|
-
[SetUp]
|
|
73
|
-
public void SetUp()
|
|
74
|
-
{
|
|
75
|
-
ResetEffectHandleId();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
[Test]
|
|
79
|
-
public void CurrentValueReflectsBaseValueWhenUnmodified()
|
|
80
|
-
{
|
|
81
|
-
Attribute attribute = new(12f);
|
|
82
|
-
Assert.AreEqual(12f, attribute.CurrentValue);
|
|
83
|
-
Assert.AreEqual(12f, attribute.BaseValue);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
[Test]
|
|
87
|
-
public void ApplyAttributeModificationWithoutHandleMutatesBase()
|
|
88
|
-
{
|
|
89
|
-
Attribute attribute = new(10f);
|
|
90
|
-
AttributeModification modification = new()
|
|
91
|
-
{
|
|
92
|
-
attribute = "health",
|
|
93
|
-
action = ModificationAction.Addition,
|
|
94
|
-
value = 5f,
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
attribute.ApplyAttributeModification(modification);
|
|
98
|
-
Assert.AreEqual(15f, attribute.BaseValue);
|
|
99
|
-
Assert.AreEqual(15f, attribute.CurrentValue);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
[Test]
|
|
103
|
-
public void ApplyAndRemoveAttributeModificationWithHandleRecalculates()
|
|
104
|
-
{
|
|
105
|
-
Attribute attribute = new(100f);
|
|
106
|
-
AttributeModification addition = new()
|
|
107
|
-
{
|
|
108
|
-
attribute = "health",
|
|
109
|
-
action = ModificationAction.Addition,
|
|
110
|
-
value = 25f,
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
AttributeEffect effect = Track(ScriptableObject.CreateInstance<AttributeEffect>());
|
|
114
|
-
effect.name = "Buff";
|
|
115
|
-
EffectHandle handle = EffectHandle.CreateInstance(effect);
|
|
116
|
-
|
|
117
|
-
attribute.ApplyAttributeModification(addition, handle);
|
|
118
|
-
Assert.AreEqual(125f, attribute.CurrentValue);
|
|
119
|
-
Assert.AreEqual(100f, attribute.BaseValue);
|
|
120
|
-
|
|
121
|
-
bool removed = attribute.RemoveAttributeModification(handle);
|
|
122
|
-
Assert.IsTrue(removed);
|
|
123
|
-
Assert.AreEqual(100f, attribute.CurrentValue);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
[Test]
|
|
127
|
-
public void ApplyAttributeModificationWithMultiplicationExecutesInOrder()
|
|
128
|
-
{
|
|
129
|
-
Attribute attribute = new(10f);
|
|
130
|
-
AttributeEffect effect = Track(ScriptableObject.CreateInstance<AttributeEffect>());
|
|
131
|
-
effect.name = "Stacking";
|
|
132
|
-
EffectHandle handle = EffectHandle.CreateInstance(effect);
|
|
133
|
-
|
|
134
|
-
attribute.ApplyAttributeModification(
|
|
135
|
-
new AttributeModification
|
|
136
|
-
{
|
|
137
|
-
attribute = "health",
|
|
138
|
-
action = ModificationAction.Addition,
|
|
139
|
-
value = 5f,
|
|
140
|
-
},
|
|
141
|
-
handle
|
|
142
|
-
);
|
|
143
|
-
attribute.ApplyAttributeModification(
|
|
144
|
-
new AttributeModification
|
|
145
|
-
{
|
|
146
|
-
attribute = "health",
|
|
147
|
-
action = ModificationAction.Multiplication,
|
|
148
|
-
value = 2f,
|
|
149
|
-
},
|
|
150
|
-
handle
|
|
151
|
-
);
|
|
152
|
-
|
|
153
|
-
Assert.AreEqual(30f, attribute.CurrentValue);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
[Test]
|
|
157
|
-
public void AttributeEqualsSupportsFloatComparisons()
|
|
158
|
-
{
|
|
159
|
-
Attribute attribute = new(7.25f);
|
|
160
|
-
Assert.IsTrue(attribute.Equals(7.25f));
|
|
161
|
-
Assert.IsTrue(attribute.Equals((double)7.25f));
|
|
162
|
-
Assert.IsFalse(attribute.Equals(7.5f));
|
|
163
|
-
Assert.AreEqual("7.25", attribute.ToString());
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
[Test]
|
|
167
|
-
public void ClearCacheForcesRecalculation()
|
|
168
|
-
{
|
|
169
|
-
Attribute attribute = new(10f);
|
|
170
|
-
AttributeModification addition = new()
|
|
171
|
-
{
|
|
172
|
-
attribute = "health",
|
|
173
|
-
action = ModificationAction.Addition,
|
|
174
|
-
value = 5f,
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
attribute.ApplyAttributeModification(addition);
|
|
178
|
-
Assert.AreEqual(15f, attribute.CurrentValue);
|
|
179
|
-
|
|
180
|
-
attribute.ClearCache();
|
|
181
|
-
Assert.AreEqual(15f, attribute.CurrentValue);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
[TestFixture]
|
|
186
|
-
public sealed class AttributeEffectTests : AttributeTagsTestBase
|
|
187
|
-
{
|
|
188
|
-
[Test]
|
|
189
|
-
public void HumanReadableDescriptionFormatsAllModificationTypes()
|
|
190
|
-
{
|
|
191
|
-
AttributeEffect effect = Track(ScriptableObject.CreateInstance<AttributeEffect>());
|
|
192
|
-
effect.name = "Composite";
|
|
193
|
-
effect.modifications.Add(
|
|
194
|
-
new AttributeModification
|
|
195
|
-
{
|
|
196
|
-
attribute = "health",
|
|
197
|
-
action = ModificationAction.Addition,
|
|
198
|
-
value = 5f,
|
|
199
|
-
}
|
|
200
|
-
);
|
|
201
|
-
effect.modifications.Add(
|
|
202
|
-
new AttributeModification
|
|
203
|
-
{
|
|
204
|
-
attribute = "attack_speed",
|
|
205
|
-
action = ModificationAction.Multiplication,
|
|
206
|
-
value = 1.5f,
|
|
207
|
-
}
|
|
208
|
-
);
|
|
209
|
-
effect.modifications.Add(
|
|
210
|
-
new AttributeModification
|
|
211
|
-
{
|
|
212
|
-
attribute = "armor",
|
|
213
|
-
action = ModificationAction.Override,
|
|
214
|
-
value = 10f,
|
|
215
|
-
}
|
|
216
|
-
);
|
|
217
|
-
|
|
218
|
-
string description = effect.HumanReadableDescription;
|
|
219
|
-
Assert.AreEqual("+5 Health, +50% Attack Speed, 10 Armor", description);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
[Test]
|
|
223
|
-
public void HumanReadableDescriptionSkipsNeutralModifications()
|
|
224
|
-
{
|
|
225
|
-
AttributeEffect effect = Track(ScriptableObject.CreateInstance<AttributeEffect>());
|
|
226
|
-
effect.modifications.Add(
|
|
227
|
-
new AttributeModification
|
|
228
|
-
{
|
|
229
|
-
attribute = "health",
|
|
230
|
-
action = ModificationAction.Addition,
|
|
231
|
-
value = 0f,
|
|
232
|
-
}
|
|
233
|
-
);
|
|
234
|
-
effect.modifications.Add(
|
|
235
|
-
new AttributeModification
|
|
236
|
-
{
|
|
237
|
-
attribute = "speed",
|
|
238
|
-
action = ModificationAction.Multiplication,
|
|
239
|
-
value = 1f,
|
|
240
|
-
}
|
|
241
|
-
);
|
|
242
|
-
|
|
243
|
-
Assert.IsEmpty(effect.HumanReadableDescription);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
[Test]
|
|
247
|
-
public void ToStringSerializesSummaryAndCollections()
|
|
248
|
-
{
|
|
249
|
-
AttributeEffect effect = Track(ScriptableObject.CreateInstance<AttributeEffect>());
|
|
250
|
-
effect.name = "JsonEffect";
|
|
251
|
-
effect.durationType = ModifierDurationType.Duration;
|
|
252
|
-
effect.duration = 3.25f;
|
|
253
|
-
effect.resetDurationOnReapplication = true;
|
|
254
|
-
effect.modifications.Add(
|
|
255
|
-
new AttributeModification
|
|
256
|
-
{
|
|
257
|
-
attribute = "health",
|
|
258
|
-
action = ModificationAction.Addition,
|
|
259
|
-
value = 10f,
|
|
260
|
-
}
|
|
261
|
-
);
|
|
262
|
-
effect.effectTags.Add("Buff");
|
|
263
|
-
|
|
264
|
-
GameObject cosmeticHolder = Track(new GameObject("Glow", typeof(CosmeticEffectData)));
|
|
265
|
-
CosmeticEffectData cosmeticData = cosmeticHolder.GetComponent<CosmeticEffectData>();
|
|
266
|
-
effect.cosmeticEffects.Add(cosmeticData);
|
|
267
|
-
|
|
268
|
-
using JsonDocument document = JsonDocument.Parse(effect.ToString());
|
|
269
|
-
JsonElement root = document.RootElement;
|
|
270
|
-
Assert.AreEqual(
|
|
271
|
-
effect.HumanReadableDescription,
|
|
272
|
-
root.GetProperty("Description").GetString()
|
|
273
|
-
);
|
|
274
|
-
Assert.AreEqual("Duration", root.GetProperty("durationType").GetString());
|
|
275
|
-
Assert.AreEqual(3.25f, root.GetProperty("duration").GetSingle());
|
|
276
|
-
Assert.AreEqual("Buff", root.GetProperty("tags")[0].GetString());
|
|
277
|
-
Assert.AreEqual("Glow", root.GetProperty("CosmeticEffects")[0].GetString());
|
|
278
|
-
Assert.AreEqual(1, root.GetProperty("modifications").GetArrayLength());
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
[Test]
|
|
282
|
-
public void EqualsRequiresMatchingState()
|
|
283
|
-
{
|
|
284
|
-
AttributeEffect left = Track(ScriptableObject.CreateInstance<AttributeEffect>());
|
|
285
|
-
AttributeEffect right = Track(ScriptableObject.CreateInstance<AttributeEffect>());
|
|
286
|
-
left.name = right.name = "Stack";
|
|
287
|
-
left.durationType = right.durationType = ModifierDurationType.Duration;
|
|
288
|
-
left.duration = right.duration = 2f;
|
|
289
|
-
left.resetDurationOnReapplication = right.resetDurationOnReapplication = false;
|
|
290
|
-
|
|
291
|
-
AttributeModification modification = new()
|
|
292
|
-
{
|
|
293
|
-
attribute = "health",
|
|
294
|
-
action = ModificationAction.Addition,
|
|
295
|
-
value = 5f,
|
|
296
|
-
};
|
|
297
|
-
|
|
298
|
-
left.modifications.Add(modification);
|
|
299
|
-
right.modifications.Add(modification);
|
|
300
|
-
Assert.IsTrue(left.Equals(right));
|
|
301
|
-
|
|
302
|
-
right.modifications[0] = new AttributeModification
|
|
303
|
-
{
|
|
304
|
-
attribute = "health",
|
|
305
|
-
action = ModificationAction.Addition,
|
|
306
|
-
value = 10f,
|
|
307
|
-
};
|
|
308
|
-
|
|
309
|
-
Assert.IsFalse(left.Equals(right));
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}
|
package/node_modules.meta
DELETED
/package/Tests/Runtime/Tags/{AttributeDataTests.cs.meta → AttributeModificationTests.cs.meta}
RENAMED
|
File without changes
|