Makes construction graphs turing complete (#3516)
* Makes construction graphs turing complete * Improvements
This commit is contained in:
committed by
GitHub
parent
2648ba4e57
commit
13e95ac9a8
@@ -10,6 +10,41 @@ namespace Content.IntegrationTests.Tests.Construction
|
||||
[TestFixture]
|
||||
public class ConstructionActionValid : ContentIntegrationTest
|
||||
{
|
||||
private bool IsValid(IGraphAction action, IPrototypeManager protoMan, out string prototype)
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case SpawnPrototype spawn:
|
||||
prototype = spawn.Prototype;
|
||||
return protoMan.TryIndex<EntityPrototype>(spawn.Prototype, out _);
|
||||
case SpawnPrototypeAtContainer spawn:
|
||||
prototype = spawn.Prototype;
|
||||
return protoMan.TryIndex<EntityPrototype>(spawn.Prototype, out _);
|
||||
case ConditionalAction conditional:
|
||||
var valid = IsValid(conditional.Action, protoMan, out var protoA) & IsValid(conditional.Else, protoMan, out var protoB);
|
||||
|
||||
if (!string.IsNullOrEmpty(protoA) && string.IsNullOrEmpty(protoB))
|
||||
{
|
||||
prototype = protoA;
|
||||
}
|
||||
|
||||
else if (string.IsNullOrEmpty(protoA) && !string.IsNullOrEmpty(protoB))
|
||||
{
|
||||
prototype = protoB;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
prototype = $"{protoA}, {protoB}";
|
||||
}
|
||||
|
||||
return valid;
|
||||
default:
|
||||
prototype = string.Empty;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ConstructionGraphSpawnPrototypeValid()
|
||||
{
|
||||
@@ -28,20 +63,20 @@ namespace Content.IntegrationTests.Tests.Construction
|
||||
{
|
||||
foreach (var action in node.Actions)
|
||||
{
|
||||
if (action is not SpawnPrototype spawn || protoMan.TryIndex(spawn.Prototype, out EntityPrototype _)) continue;
|
||||
if (IsValid(action, protoMan, out var prototype)) continue;
|
||||
|
||||
valid = false;
|
||||
message.Append($"Invalid entity prototype \"{spawn.Prototype}\" on graph action in node \"{node.Name}\" of graph \"{graph.ID}\"\n");
|
||||
message.Append($"Invalid entity prototype \"{prototype}\" on graph action in node \"{node.Name}\" of graph \"{graph.ID}\"\n");
|
||||
}
|
||||
|
||||
foreach (var edge in node.Edges)
|
||||
{
|
||||
foreach (var action in edge.Completed)
|
||||
{
|
||||
if (action is not SpawnPrototype spawn || protoMan.TryIndex(spawn.Prototype, out EntityPrototype _)) continue;
|
||||
if (IsValid(action, protoMan, out var prototype)) continue;
|
||||
|
||||
valid = false;
|
||||
message.Append($"Invalid entity prototype \"{spawn.Prototype}\" on graph action in edge \"{edge.Target}\" of node \"{node.Name}\" of graph \"{graph.ID}\"\n");
|
||||
message.Append($"Invalid entity prototype \"{prototype}\" on graph action in edge \"{edge.Target}\" of node \"{node.Name}\" of graph \"{graph.ID}\"\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user