* Fix usages of TryIndex()
Most usages of TryIndex() were using it incorrectly. Checking whether prototype IDs specified in prototypes actually existed before using them. This is not appropriate as it's just hiding bugs that should be getting caught by the YAML linter and other tools. (#39115)
This then resulted in TryIndex() getting modified to log errors (94f98073b0), which is incorrect as it causes false-positive errors in proper uses of the API: external data validation. (#39098)
This commit goes through and checks every call site of TryIndex() to see whether they were correct. Most call sites were replaced with the new Resolve(), which is suitable for these "defensive programming" use cases.
Fixes #39115
Breaking change: while doing this I noticed IdCardComponent and related systems were erroneously using ProtoId<AccessLevelPrototype> for job prototypes. This has been corrected.
* fix tests
---------
Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
60 lines
1.8 KiB
C#
60 lines
1.8 KiB
C#
using Content.Shared.Access.Systems;
|
|
using Robust.Shared.GameStates;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
|
|
|
namespace Content.Shared.Access.Components;
|
|
|
|
/// <summary>
|
|
/// Simple mutable access provider found on ID cards and such.
|
|
/// </summary>
|
|
[RegisterComponent, NetworkedComponent]
|
|
[Access(typeof(SharedAccessSystem))]
|
|
[AutoGenerateComponentState]
|
|
public sealed partial class AccessComponent : Component
|
|
{
|
|
/// <summary>
|
|
/// True if the access provider is enabled and can grant access.
|
|
/// </summary>
|
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
|
[AutoNetworkedField]
|
|
public bool Enabled = true;
|
|
|
|
[DataField]
|
|
[Access(typeof(SharedAccessSystem), Other = AccessPermissions.ReadExecute)] // FIXME Friends
|
|
[AutoNetworkedField]
|
|
public HashSet<ProtoId<AccessLevelPrototype>> Tags = new();
|
|
|
|
/// <summary>
|
|
/// Access Groups. These are added to the tags during map init. After map init this will have no effect.
|
|
/// </summary>
|
|
[DataField(readOnly: true)]
|
|
[AutoNetworkedField]
|
|
public HashSet<ProtoId<AccessGroupPrototype>> Groups = new();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Event raised on an entity to find additional entities which provide access.
|
|
/// </summary>
|
|
[ByRefEvent]
|
|
public struct GetAdditionalAccessEvent
|
|
{
|
|
public HashSet<EntityUid> Entities = new();
|
|
|
|
public GetAdditionalAccessEvent()
|
|
{
|
|
}
|
|
}
|
|
|
|
[ByRefEvent]
|
|
public record struct GetAccessTagsEvent(HashSet<ProtoId<AccessLevelPrototype>> Tags, IPrototypeManager PrototypeManager)
|
|
{
|
|
public void AddGroup(ProtoId<AccessGroupPrototype> group)
|
|
{
|
|
if (!PrototypeManager.Resolve<AccessGroupPrototype>(group, out var groupPrototype))
|
|
return;
|
|
|
|
Tags.UnionWith(groupPrototype.Tags);
|
|
}
|
|
}
|