Makes construction graphs turing complete (#3516)
* Makes construction graphs turing complete * Improvements
This commit is contained in:
committed by
GitHub
parent
2648ba4e57
commit
13e95ac9a8
34
Content.Server/Construction/Completions/MoveContainer.cs
Normal file
34
Content.Server/Construction/Completions/MoveContainer.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
#nullable enable
|
||||
using System.Linq;
|
||||
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;
|
||||
|
||||
namespace Content.Server.Construction.Completions
|
||||
{
|
||||
[UsedImplicitly]
|
||||
[DataDefinition]
|
||||
public class MoveContainer : IGraphAction
|
||||
{
|
||||
[field: DataField("from")] public string? FromContainer { get; } = null;
|
||||
[field: DataField("to")] public string? ToContainer { get; } = null;
|
||||
|
||||
public async Task PerformAction(IEntity entity, IEntity? user)
|
||||
{
|
||||
if (string.IsNullOrEmpty(FromContainer) || string.IsNullOrEmpty(ToContainer))
|
||||
return;
|
||||
|
||||
var from = entity.EnsureContainer<Container>(FromContainer);
|
||||
var to = entity.EnsureContainer<Container>(ToContainer);
|
||||
|
||||
foreach (var contained in from.ContainedEntities.ToArray())
|
||||
{
|
||||
if (from.Remove(contained))
|
||||
to.Insert(contained);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user