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:
Pieter-Jan Briers
2025-09-09 18:17:56 +02:00
committed by GitHub
parent fca45851cc
commit 0c97520276
136 changed files with 229 additions and 228 deletions

View File

@@ -45,7 +45,7 @@ public sealed class FoodSequenceSystem : SharedFoodSequenceSystem
if (!TryComp<FoodSequenceStartPointComponent>(args.Start, out var start))
return;
if (!_proto.TryIndex(args.Proto, out var elementProto))
if (!_proto.Resolve(args.Proto, out var elementProto))
return;
if (!ent.Comp.OnlyFinal || elementProto.Final || start.FoodLayers.Count == start.MaxLayers)
@@ -117,8 +117,7 @@ public sealed class FoodSequenceSystem : SharedFoodSequenceSystem
//looking for a suitable FoodSequence prototype
if (!element.Comp1.Entries.TryGetValue(start.Comp.Key, out var elementProto))
return false;
if (!_proto.TryIndex(elementProto, out var elementIndexed))
if (!_proto.Resolve(elementProto, out var elementIndexed))
return false;
//if we run out of space, we can still put in one last, final finishing element.
@@ -185,7 +184,7 @@ public sealed class FoodSequenceSystem : SharedFoodSequenceSystem
var nameCounter = 1;
foreach (var proto in existedContentNames)
{
if (!_proto.TryIndex(proto, out var protoIndexed))
if (!_proto.Resolve(proto, out var protoIndexed))
continue;
if (protoIndexed.Name is null)