Makes construction graphs turing complete (#3516)
* Makes construction graphs turing complete * Improvements
This commit is contained in:
committed by
GitHub
parent
2648ba4e57
commit
13e95ac9a8
28
Content.Server/Construction/Conditions/AllConditions.cs
Normal file
28
Content.Server/Construction/Conditions/AllConditions.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Shared.Construction;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Server.Construction.Conditions
|
||||
{
|
||||
[UsedImplicitly]
|
||||
[DataDefinition]
|
||||
public class AllConditions : IEdgeCondition
|
||||
{
|
||||
[field: DataField("conditions")]
|
||||
public IEdgeCondition[] Conditions { get; } = Array.Empty<IEdgeCondition>();
|
||||
|
||||
public async Task<bool> Condition(IEntity entity)
|
||||
{
|
||||
foreach (var condition in Conditions)
|
||||
{
|
||||
if (!await condition.Condition(entity))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
28
Content.Server/Construction/Conditions/AnyConditions.cs
Normal file
28
Content.Server/Construction/Conditions/AnyConditions.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Shared.Construction;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Server.Construction.Conditions
|
||||
{
|
||||
[UsedImplicitly]
|
||||
[DataDefinition]
|
||||
public class AnyConditions : IEdgeCondition
|
||||
{
|
||||
[field: DataField("conditions")]
|
||||
public IEdgeCondition[] Conditions { get; } = Array.Empty<IEdgeCondition>();
|
||||
|
||||
public async Task<bool> Condition(IEntity entity)
|
||||
{
|
||||
foreach (var condition in Conditions)
|
||||
{
|
||||
if (await condition.Condition(entity))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
40
Content.Server/Construction/Conditions/ContainerNotEmpty.cs
Normal file
40
Content.Server/Construction/Conditions/ContainerNotEmpty.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
#nullable enable
|
||||
using System.Threading.Tasks;
|
||||
using Content.Shared.Construction;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Construction.Conditions
|
||||
{
|
||||
[UsedImplicitly]
|
||||
[DataDefinition]
|
||||
public class ContainerNotEmpty : IEdgeCondition
|
||||
{
|
||||
[DataField("container")] public string Container { get; private set; } = string.Empty;
|
||||
[DataField("text")] public string Text { get; private set; } = string.Empty;
|
||||
|
||||
public async Task<bool> Condition(IEntity entity)
|
||||
{
|
||||
if (!entity.TryGetComponent(out ContainerManagerComponent? containerManager) ||
|
||||
!containerManager.TryGetContainer(Container, out var container)) return false;
|
||||
|
||||
return container.ContainedEntities.Count != 0;
|
||||
}
|
||||
|
||||
public bool DoExamine(IEntity entity, FormattedMessage message, bool inDetailsRange)
|
||||
{
|
||||
if (!entity.TryGetComponent(out ContainerManagerComponent? containerManager) ||
|
||||
!containerManager.TryGetContainer(Container, out var container)) return false;
|
||||
|
||||
if (container.ContainedEntities.Count != 0)
|
||||
return false;
|
||||
|
||||
message.AddMarkup(Text);
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user