Skip to content

Commit ee2c779

Browse files
the 3 things walks said + gumballs
1 parent 06f70a9 commit ee2c779

6 files changed

Lines changed: 143 additions & 62 deletions

File tree

Content.IntegrationTests/Tests/Utility/EntityWhitelistTest.cs

Lines changed: 93 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,48 +13,75 @@ public sealed class EntityWhitelistTest : GameTest
1313
private const string InvalidComponent = "Sprite";
1414
private const string ValidComponent = "Physics";
1515

16-
[TestPrototypes]
17-
private const string Prototypes = $@"
18-
- type: Tag
19-
id: WhitelistTestValidTag
20-
- type: Tag
21-
id: WhitelistTestInvalidTag
22-
23-
- type: entity
24-
id: WhitelistDummy
25-
components:
26-
- type: ItemSlots
27-
slots:
28-
slotName:
29-
whitelist:
30-
prototypes:
31-
- ValidPrototypeDummy
32-
components:
33-
- {ValidComponent}
34-
tags:
35-
- WhitelistTestValidTag
36-
37-
- type: entity
38-
id: InvalidComponentDummy
39-
components:
40-
- type: {InvalidComponent}
41-
- type: entity
42-
id: WhitelistTestInvalidTagDummy
43-
components:
44-
- type: Tag
45-
tags:
46-
- WhitelistTestInvalidTag
47-
48-
- type: entity
49-
id: ValidComponentDummy
50-
components:
51-
- type: {ValidComponent}
52-
- type: entity
53-
id: WhitelistTestValidTagDummy
54-
components:
55-
- type: Tag
56-
tags:
57-
- WhitelistTestValidTag";
16+
[TestPrototypes] // Starlight, I didn't want to have to modify this entire section, but editor config will yell at me if I don't.
17+
private const string Prototypes = $"""
18+
- type: Tag
19+
id: WhitelistTestValidTag
20+
- type: Tag
21+
id: WhitelistTestInvalidTag
22+
23+
- type: entity
24+
id: WhitelistDummy
25+
components:
26+
- type: ItemSlots
27+
slots:
28+
slotName:
29+
whitelist:
30+
prototypes:
31+
- ValidPrototypeDummy
32+
components:
33+
- {ValidComponent}
34+
tags:
35+
- WhitelistTestValidTag
36+
toolQuality:
37+
- Slicing
38+
39+
- type: entity
40+
id: InvalidComponentDummy
41+
components:
42+
- type: {InvalidComponent}
43+
44+
- type: entity
45+
id: WhitelistTestInvalidTagDummy
46+
components:
47+
- type: Tag
48+
tags:
49+
- WhitelistTestInvalidTag
50+
51+
- type: entity
52+
id: ValidComponentDummy
53+
components:
54+
- type: {ValidComponent}
55+
56+
- type: entity
57+
id: WhitelistTestValidTagDummy
58+
components:
59+
- type: Tag
60+
tags:
61+
- WhitelistTestValidTag
62+
63+
- type: entity
64+
id: WhitelistTestInvalidToolQualityDummy
65+
components:
66+
- type: Tool
67+
qualities:
68+
- Anchoring
69+
70+
- type: entity
71+
id: WhitelistTestValidToolQualityDummy
72+
components:
73+
- type: Tool
74+
qualities:
75+
- Slicing
76+
77+
- type: entity
78+
id: WhitelistTestAllToolQualitiesDummy
79+
components:
80+
- type: Tool
81+
qualities:
82+
- Cutting
83+
- Slicing
84+
""";
5885

5986
[Test]
6087
public async Task Test()
@@ -72,24 +99,44 @@ await server.WaitAssertion(() =>
7299
{
73100
var validComponent = sEntities.SpawnEntity("ValidComponentDummy", mapCoordinates);
74101
var WhitelistTestValidTag = sEntities.SpawnEntity("WhitelistTestValidTagDummy", mapCoordinates);
102+
var validToolQuality = sEntities.SpawnEntity("WhitelistTestValidToolQualityDummy", mapCoordinates); // Starlight
103+
var allToolQualities = sEntities.SpawnEntity("WhitelistTestAllToolQualitiesDummy", mapCoordinates); // Starlight
75104

76105
var invalidComponent = sEntities.SpawnEntity("InvalidComponentDummy", mapCoordinates);
77106
var WhitelistTestInvalidTag = sEntities.SpawnEntity("WhitelistTestInvalidTagDummy", mapCoordinates);
107+
var invalidToolQuality = sEntities.SpawnEntity("WhitelistTestInvalidToolQualityDummy", mapCoordinates); // Starlight
78108

79109
// Test instantiated on its own
80110
var whitelistInst = new EntityWhitelist
81111
{
82112
Components = new[] { $"{ValidComponent}" },
83-
Tags = new() { "WhitelistTestValidTag" }
113+
Tags = new() { "WhitelistTestValidTag" },
114+
ToolQualities = new() { "Slicing" } // Starlight
84115
};
85116

86117
Assert.Multiple(() =>
87118
{
88119
Assert.That(sys.IsValid(whitelistInst, validComponent), Is.True);
89120
Assert.That(sys.IsValid(whitelistInst, WhitelistTestValidTag), Is.True);
121+
Assert.That(sys.IsValid(whitelistInst, validToolQuality), Is.True); // Starlight
90122

91123
Assert.That(sys.IsValid(whitelistInst, invalidComponent), Is.False);
92124
Assert.That(sys.IsValid(whitelistInst, WhitelistTestInvalidTag), Is.False);
125+
#region Starlight
126+
Assert.That(sys.IsValid(whitelistInst, invalidToolQuality), Is.False);
127+
});
128+
129+
var requireAllToolQualities = new EntityWhitelist
130+
{
131+
RequireAll = true,
132+
ToolQualities = new() { "Cutting", "Slicing" }
133+
};
134+
135+
Assert.Multiple(() =>
136+
{
137+
Assert.That(sys.IsValid(requireAllToolQualities, allToolQualities), Is.True);
138+
Assert.That(sys.IsValid(requireAllToolQualities, validToolQuality), Is.False);
139+
#endregion
93140
});
94141

95142
// Test from serialized
@@ -101,15 +148,18 @@ await server.WaitAssertion(() =>
101148
{
102149
Assert.That(whitelistSer.Components, Is.Not.Null);
103150
Assert.That(whitelistSer.Tags, Is.Not.Null);
151+
Assert.That(whitelistSer.ToolQualities, Is.Not.Null); // Starlight
104152
});
105153

106154
Assert.Multiple(() =>
107155
{
108156
Assert.That(sys.IsValid(whitelistSer, validComponent), Is.True);
109157
Assert.That(sys.IsValid(whitelistSer, WhitelistTestValidTag), Is.True);
158+
Assert.That(sys.IsValid(whitelistSer, validToolQuality), Is.True); // Starlight
110159

111160
Assert.That(sys.IsValid(whitelistSer, invalidComponent), Is.False);
112161
Assert.That(sys.IsValid(whitelistSer, WhitelistTestInvalidTag), Is.False);
162+
Assert.That(sys.IsValid(whitelistSer, invalidToolQuality), Is.False); // Starlight
113163
});
114164
});
115165
}

Content.Shared/Whitelist/EntityWhitelist.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Content.Shared.Item;
22
using Content.Shared.Tag;
3+
using Content.Shared.Tools;
34
using Robust.Shared.Prototypes;
45
using Robust.Shared.Serialization;
56
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
@@ -26,6 +27,8 @@ namespace Content.Shared.Whitelist;
2627
/// sizes:
2728
/// - Tiny
2829
/// - Large
30+
/// toolQuality: // Starlight, we support ToolQuality now
31+
/// - Slicing
2932
/// </code>
3033
[DataDefinition]
3134
[Serializable, NetSerializable]
@@ -52,9 +55,17 @@ public sealed partial class EntityWhitelist
5255
[DataField]
5356
public List<ProtoId<TagPrototype>>? Tags;
5457

58+
#region starlight
5559
/// <summary>
56-
/// If false, an entity only requires one of these components or tags to pass the whitelist. If true, an
57-
/// entity requires to have ALL of these components and tags to pass.
60+
/// Tool qualities that are allowed in the whitelist.
61+
/// </summary>
62+
[DataField("toolQuality")]
63+
public HashSet<ProtoId<ToolQualityPrototype>>? ToolQualities;
64+
#endregion
65+
66+
/// <summary>
67+
/// If false, an entity only requires one of these components, tags, or tool qualities to pass the whitelist.
68+
/// If true, an entity requires to have ALL of these components, tags, and tool qualities to pass.
5869
/// The "Sizes" criteria will ignores this, since an item can only have one size.
5970
/// </summary>
6071
[DataField]

Content.Shared/Whitelist/EntityWhitelistSystem.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
using System.Diagnostics.CodeAnalysis;
22
using Content.Shared.Item;
33
using Content.Shared.Tag;
4+
using Content.Shared.Tools.Systems;
45
using Robust.Shared.Utility;
56

67
namespace Content.Shared.Whitelist;
78

89
public sealed partial class EntityWhitelistSystem : EntitySystem
910
{
1011
[Dependency] private TagSystem _tag = default!;
12+
[Dependency] private SharedToolSystem _tools = default!; // Starlight
1113

1214
private EntityQuery<ItemComponent> _itemQuery;
1315

@@ -69,6 +71,25 @@ public bool IsValid(EntityWhitelist list, EntityUid uid)
6971
return true;
7072
}
7173

74+
#region Starlight
75+
if (list.ToolQualities != null)
76+
{
77+
if (list.RequireAll)
78+
{
79+
if (!_tools.HasAllQualities(uid, list.ToolQualities))
80+
return false;
81+
}
82+
else
83+
{
84+
foreach (var quality in list.ToolQualities)
85+
{
86+
if (_tools.HasQuality(uid, quality))
87+
return true;
88+
}
89+
}
90+
}
91+
#endregion
92+
7293
if (list.Tags != null)
7394
{
7495
return list.RequireAll

Resources/Prototypes/_Starlight/Body/Prototypes/rodentia.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
blacklist:
1212
components:
1313
- MindContainer
14+
toolQuality:
15+
- Slicing
1416
- type: ContainerContainer
1517
containers:
1618
storagebase: !type:Container

Resources/Prototypes/_Starlight/CosmicCult/glyphs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@
107107
- SwordCosmicCult
108108
- SpearCosmicCult
109109
whitelist:
110-
components:
111-
- Tool
110+
toolQuality:
111+
- Slicing
112112
- type: CosmicGlyph
113113
requiredCultists: 2
114114
activationDamage:

Resources/Prototypes/_Starlight/Entities/Objects/Consumable/Food/gumballs.yml

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@
1515
- FoodSnack
1616
- ReptilianFood
1717
- ClothMade
18-
- type: SolutionContainerManager
19-
solutions:
20-
food:
21-
maxVol: 15
22-
reagents:
18+
- type: Solution
19+
id: food
20+
solution:
21+
reagents:
2322
- ReagentId: Sugar
2423
Quantity: 10
2524
- type: FlavorProfile
@@ -95,11 +94,10 @@
9594
components:
9695
- type: Sprite
9796
color: "#3d3d3d"
98-
- type: SolutionContainerManager
99-
solutions:
100-
food:
101-
maxVol: 25
102-
reagents:
97+
- type: Solution
98+
id: food
99+
solution:
100+
reagents:
103101
- ReagentId: Sugar
104102
Quantity: 10
105103
- ReagentId: CarpoToxin
@@ -111,11 +109,10 @@
111109
components:
112110
- type: Sprite
113111
color: "#b30000"
114-
- type: SolutionContainerManager
115-
solutions:
116-
food:
117-
maxVol: 25
118-
reagents:
112+
- type: Solution
113+
id: food
114+
solution:
115+
reagents:
119116
- ReagentId: Sugar
120117
Quantity: 10
121118
- ReagentId: Omnizine

0 commit comments

Comments
 (0)