Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate that ProtoId values are not abstract #5716

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Tayrtahn
Copy link
Member

@Tayrtahn Tayrtahn commented Mar 1, 2025

Adds an extra validation step to ProtoId<T> and EntProtoId which makes sure that the prototype is not abstract. This lets YAML linter prevent attempts to spawn abstract prototypes (example: space-wizards/space-station-14#35562)

If there's a valid reason to have a ProtoId field for an abstract prototype, then go ahead and close this. I can't think of one, and there don't seem to be any existing uses of it.

@deltanedas
Copy link
Contributor

does TryIndex even work for abstract, and if so why

@Tayrtahn
Copy link
Member Author

Tayrtahn commented Mar 1, 2025

does TryIndex even work for abstract, and if so why

Nope, it returns false for abstract prototypes (which is how this PR checks for them). The problem linked above snuck through because the entity spawn table stuff doesn't check for abstract prototypes (which it probably should). That would just be a runtime check though - this extra validation would let the linter catch the problem.

@@ -23,7 +23,12 @@ public ValidationNode Validate(ISerializationManager serialization, ValueDataNod
{
var prototypes = dependencies.Resolve<IPrototypeManager>();
if (prototypes.TryGetKindFrom<EntityPrototype>(out _) && prototypes.HasMapping<EntityPrototype>(node.Value))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these checks for HasMapping even necessary at this point?

@@ -23,7 +23,12 @@ public ValidationNode Validate(ISerializationManager serialization, ValueDataNod
{
var prototypes = dependencies.Resolve<IPrototypeManager>();
if (prototypes.TryGetKindFrom<EntityPrototype>(out _) && prototypes.HasMapping<EntityPrototype>(node.Value))
{
if (!prototypes.TryIndex<EntityPrototype>(node.Value, out _))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use HasIndex instead

@@ -21,7 +21,12 @@ public ValidationNode Validate(ISerializationManager serialization, ValueDataNod
{
var prototypes = dependencies.Resolve<IPrototypeManager>();
if (prototypes.TryGetKindFrom<T>(out _) && prototypes.HasMapping<T>(node.Value))
{
if (!prototypes.TryIndex<T>(node.Value, out _))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

@@ -21,7 +21,12 @@ public ValidationNode Validate(ISerializationManager serialization, ValueDataNod
{
var prototypes = dependencies.Resolve<IPrototypeManager>();
if (prototypes.TryGetKindFrom<T>(out _) && prototypes.HasMapping<T>(node.Value))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants