Fix usages of TryIndex() (#39124)
* 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>
This commit is contained in:
committed by
GitHub
parent
fca45851cc
commit
0c97520276
@@ -100,7 +100,7 @@ public abstract class SharedBorgSwitchableTypeSystem : EntitySystem
|
||||
|
||||
protected void UpdateEntityAppearance(Entity<BorgSwitchableTypeComponent> entity)
|
||||
{
|
||||
if (!Prototypes.TryIndex(entity.Comp.SelectedBorgType, out var proto))
|
||||
if (!Prototypes.Resolve(entity.Comp.SelectedBorgType, out var proto))
|
||||
return;
|
||||
|
||||
UpdateEntityAppearance(entity, proto);
|
||||
|
||||
@@ -15,7 +15,7 @@ public abstract partial class SharedStationAiSystem
|
||||
|
||||
private void OnStationAiCustomization(Entity<StationAiCoreComponent> entity, ref StationAiCustomizationMessage args)
|
||||
{
|
||||
if (!_protoManager.TryIndex(args.GroupProtoId, out var groupPrototype) || !_protoManager.TryIndex(args.CustomizationProtoId, out var customizationProto))
|
||||
if (!_protoManager.Resolve(args.GroupProtoId, out var groupPrototype) || !_protoManager.Resolve(args.CustomizationProtoId, out var customizationProto))
|
||||
return;
|
||||
|
||||
if (!TryGetHeld((entity, entity.Comp), out var held))
|
||||
@@ -48,7 +48,7 @@ public abstract partial class SharedStationAiSystem
|
||||
if (!entity.Comp.ProtoIds.TryGetValue(_stationAiHologramCustomGroupProtoId, out var protoId))
|
||||
return;
|
||||
|
||||
if (!_protoManager.TryIndex(protoId, out var prototype))
|
||||
if (!_protoManager.Resolve(protoId, out var prototype))
|
||||
return;
|
||||
|
||||
if (!prototype.LayerData.TryGetValue(StationAiState.Hologram.ToString(), out var layerData))
|
||||
@@ -70,7 +70,7 @@ public abstract partial class SharedStationAiSystem
|
||||
|
||||
if (!TryComp<StationAiCustomizationComponent>(stationAi, out var stationAiCustomization) ||
|
||||
!stationAiCustomization.ProtoIds.TryGetValue(_stationAiCoreCustomGroupProtoId, out var protoId) ||
|
||||
!_protoManager.TryIndex(protoId, out var prototype) ||
|
||||
!_protoManager.Resolve(protoId, out var prototype) ||
|
||||
!prototype.LayerData.TryGetValue(state.ToString(), out var layerData))
|
||||
{
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user