Construction graph improvements (#17960)
This commit is contained in:
committed by
GitHub
parent
fbf1d476f2
commit
9243050e1a
@@ -84,32 +84,6 @@ namespace Content.IntegrationTests.Tests.Construction
|
||||
Assert.That(valid, Is.True, $"One or more SpawnPrototype actions specified invalid entity prototypes!\n{message}");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ConstructionGraphNodeEntityPrototypeValid()
|
||||
{
|
||||
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { NoClient = true });
|
||||
var server = pairTracker.Pair.Server;
|
||||
|
||||
var protoMan = server.ResolveDependency<IPrototypeManager>();
|
||||
|
||||
var valid = true;
|
||||
var message = new StringBuilder();
|
||||
|
||||
foreach (var graph in protoMan.EnumeratePrototypes<ConstructionGraphPrototype>())
|
||||
{
|
||||
foreach (var node in graph.Nodes.Values)
|
||||
{
|
||||
if (string.IsNullOrEmpty(node.Entity) || protoMan.TryIndex(node.Entity, out EntityPrototype _)) continue;
|
||||
|
||||
valid = false;
|
||||
message.Append($"Invalid entity prototype \"{node.Entity}\" on node \"{node.Name}\" of graph \"{graph.ID}\"\n");
|
||||
}
|
||||
}
|
||||
await pairTracker.CleanReturnAsync();
|
||||
|
||||
Assert.That(valid, Is.True, $"One or more nodes specified invalid entity prototypes!\n{message}");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ConstructionGraphEdgeValid()
|
||||
{
|
||||
|
||||
@@ -124,6 +124,7 @@ namespace Content.IntegrationTests.Tests.Construction
|
||||
var server = pairTracker.Pair.Server;
|
||||
|
||||
var protoMan = server.ResolveDependency<IPrototypeManager>();
|
||||
var entMan = server.ResolveDependency<IEntityManager>();
|
||||
|
||||
foreach (var proto in protoMan.EnumeratePrototypes<ConstructionPrototype>())
|
||||
{
|
||||
@@ -135,8 +136,9 @@ namespace Content.IntegrationTests.Tests.Construction
|
||||
Assert.That(graph.TryPath(start, target, out var path), $"Unable to find path from \"{start}\" to \"{target}\" on graph \"{graph.ID}\"");
|
||||
Assert.That(path, Has.Length.GreaterThanOrEqualTo(1), $"Unable to find path from \"{start}\" to \"{target}\" on graph \"{graph.ID}\".");
|
||||
var next = path[0];
|
||||
Assert.That(next.Entity, Is.Not.Null, $"The next node ({next.Name}) in the path from the start node ({start}) to the target node ({target}) must specify an entity! Graph: {graph.ID}");
|
||||
Assert.That(protoMan.TryIndex(next.Entity, out EntityPrototype entity), $"The next node ({next.Name}) in the path from the start node ({start}) to the target node ({target}) specified an invalid entity prototype ({next.Entity})");
|
||||
var nextId = next.Entity.GetId(null, null, new(entMan));
|
||||
Assert.That(nextId, Is.Not.Null, $"The next node ({next.Name}) in the path from the start node ({start}) to the target node ({target}) must specify an entity! Graph: {graph.ID}");
|
||||
Assert.That(protoMan.TryIndex(nextId, out EntityPrototype entity), $"The next node ({next.Name}) in the path from the start node ({start}) to the target node ({target}) specified an invalid entity prototype ({nextId} [{next.Entity}])");
|
||||
Assert.That(entity.Components.ContainsKey("Construction"), $"The next node ({next.Name}) in the path from the start node ({start}) to the target node ({target}) specified an entity prototype ({next.Entity}) without a ConstructionComponent.");
|
||||
#pragma warning restore NUnit2045
|
||||
}
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Construction.Components;
|
||||
using Content.Shared.Construction;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.Containers;
|
||||
using Robust.Shared.Containers;
|
||||
|
||||
namespace Content.Server.Construction.Completions
|
||||
{
|
||||
[UsedImplicitly]
|
||||
[DataDefinition]
|
||||
public sealed class BuildComputer : IGraphAction
|
||||
{
|
||||
[DataField("container")] public string Container { get; private set; } = string.Empty;
|
||||
|
||||
// TODO use or generalize ConstructionSystem.ChangeEntity();
|
||||
// TODO pass in node/edge & graph ID for better error logs.
|
||||
public void PerformAction(EntityUid uid, EntityUid? userUid, IEntityManager entityManager)
|
||||
{
|
||||
if (!entityManager.TryGetComponent(uid, out ContainerManagerComponent? containerManager))
|
||||
{
|
||||
Logger.Error($"Computer entity {entityManager.ToPrettyString(uid)} did not have a container manager! Aborting build computer action.");
|
||||
return;
|
||||
}
|
||||
|
||||
var containerSystem = entityManager.EntitySysManager.GetEntitySystem<ContainerSystem>();
|
||||
|
||||
if (!containerSystem.TryGetContainer(uid, Container, out var container, containerManager))
|
||||
{
|
||||
Logger.Error($"Computer entity {entityManager.ToPrettyString(uid)} did not have the specified '{Container}' container! Aborting build computer action.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (container.ContainedEntities.Count != 1)
|
||||
{
|
||||
Logger.Error($"Computer entity {entityManager.ToPrettyString(uid)} did not have exactly one item in the specified '{Container}' container! Aborting build computer action.");
|
||||
return;
|
||||
}
|
||||
|
||||
var board = container.ContainedEntities[0];
|
||||
|
||||
if (!entityManager.TryGetComponent(board, out ComputerBoardComponent? boardComponent))
|
||||
{
|
||||
Logger.Error($"Computer entity {entityManager.ToPrettyString(uid)} had an invalid entity in container \"{Container}\"! Aborting build computer action.");
|
||||
return;
|
||||
}
|
||||
|
||||
container.Remove(board);
|
||||
|
||||
var transform = entityManager.GetComponent<TransformComponent>(uid);
|
||||
var computer = entityManager.SpawnEntity(boardComponent.Prototype, transform.Coordinates);
|
||||
entityManager.GetComponent<TransformComponent>(computer).LocalRotation = transform.LocalRotation;
|
||||
|
||||
var computerContainer = containerSystem.EnsureContainer<Container>(computer, Container);
|
||||
|
||||
// In case it already existed and there are any entities inside the container, delete them.
|
||||
foreach (var ent in computerContainer.ContainedEntities.ToArray())
|
||||
{
|
||||
computerContainer.ForceRemove(ent);
|
||||
entityManager.DeleteEntity(ent);
|
||||
}
|
||||
|
||||
computerContainer.Insert(board);
|
||||
|
||||
// We only add this container. If some construction needs to take other containers into account, fix this.
|
||||
entityManager.EntitySysManager.GetEntitySystem<ConstructionSystem>().AddContainer(computer, Container);
|
||||
|
||||
var entChangeEv = new ConstructionChangeEntityEvent(computer, uid);
|
||||
entityManager.EventBus.RaiseLocalEvent(uid, entChangeEv);
|
||||
entityManager.EventBus.RaiseLocalEvent(computer, entChangeEv, broadcast: true);
|
||||
|
||||
// Delete the original entity.
|
||||
entityManager.QueueDeleteEntity(uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Construction.Components;
|
||||
using Content.Shared.Construction;
|
||||
using Content.Shared.Construction.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.Containers;
|
||||
using Robust.Shared.Containers;
|
||||
|
||||
namespace Content.Server.Construction.Completions
|
||||
{
|
||||
[UsedImplicitly]
|
||||
[DataDefinition]
|
||||
public sealed class BuildMachine : IGraphAction
|
||||
{
|
||||
// TODO use or generalize ConstructionSystem.ChangeEntity();
|
||||
public void PerformAction(EntityUid uid, EntityUid? userUid, IEntityManager entityManager)
|
||||
{
|
||||
if (!entityManager.TryGetComponent(uid, out ContainerManagerComponent? containerManager))
|
||||
{
|
||||
Logger.Warning($"Machine frame entity {uid} did not have a container manager! Aborting build machine action.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!entityManager.TryGetComponent(uid, out MachineFrameComponent? machineFrame))
|
||||
{
|
||||
Logger.Warning($"Machine frame entity {uid} did not have a machine frame component! Aborting build machine action.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!entityManager.EntitySysManager.GetEntitySystem<MachineFrameSystem>().IsComplete(machineFrame))
|
||||
{
|
||||
Logger.Warning($"Machine frame entity {uid} doesn't have all required parts to be built! Aborting build machine action.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!containerManager.TryGetContainer(MachineFrameComponent.BoardContainerName, out var entBoardContainer))
|
||||
{
|
||||
Logger.Warning($"Machine frame entity {uid} did not have the '{MachineFrameComponent.BoardContainerName}' container! Aborting build machine action.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!containerManager.TryGetContainer(MachineFrameComponent.PartContainerName, out var entPartContainer))
|
||||
{
|
||||
Logger.Warning($"Machine frame entity {uid} did not have the '{MachineFrameComponent.PartContainerName}' container! Aborting build machine action.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (entBoardContainer.ContainedEntities.Count != 1)
|
||||
{
|
||||
Logger.Warning($"Machine frame entity {uid} did not have exactly one item in the '{MachineFrameComponent.BoardContainerName}' container! Aborting build machine action.");
|
||||
}
|
||||
|
||||
var board = entBoardContainer.ContainedEntities[0];
|
||||
|
||||
if (!entityManager.TryGetComponent(board, out MachineBoardComponent? boardComponent))
|
||||
{
|
||||
Logger.Warning($"Machine frame entity {uid} had an invalid entity in container \"{MachineFrameComponent.BoardContainerName}\"! Aborting build machine action.");
|
||||
return;
|
||||
}
|
||||
|
||||
entBoardContainer.Remove(board);
|
||||
|
||||
var containerSys = entityManager.EntitySysManager.GetEntitySystem<ContainerSystem>();
|
||||
var transform = entityManager.GetComponent<TransformComponent>(uid);
|
||||
var machine = entityManager.SpawnEntity(boardComponent.Prototype, transform.Coordinates);
|
||||
entityManager.GetComponent<TransformComponent>(machine).LocalRotation = transform.LocalRotation;
|
||||
|
||||
var boardContainer = containerSys.EnsureContainer<Container>(machine, MachineFrameComponent.BoardContainerName, out var existed);
|
||||
|
||||
if (existed)
|
||||
{
|
||||
// Clean that up...
|
||||
containerSys.CleanContainer(boardContainer);
|
||||
}
|
||||
|
||||
var partContainer = containerSys.EnsureContainer<Container>(machine, MachineFrameComponent.PartContainerName, out existed);
|
||||
|
||||
if (existed)
|
||||
{
|
||||
// Clean that up, too...
|
||||
containerSys.CleanContainer(partContainer);
|
||||
}
|
||||
|
||||
boardContainer.Insert(board);
|
||||
|
||||
// Now we insert all parts.
|
||||
foreach (var part in entPartContainer.ContainedEntities.ToArray())
|
||||
{
|
||||
entPartContainer.ForceRemove(part);
|
||||
partContainer.Insert(part);
|
||||
}
|
||||
|
||||
var constructionSystem = entityManager.EntitySysManager.GetEntitySystem<ConstructionSystem>();
|
||||
if (entityManager.TryGetComponent(machine, out ConstructionComponent? construction))
|
||||
{
|
||||
// We only add these two container. If some construction needs to take other containers into account, fix this.
|
||||
constructionSystem.AddContainer(machine, MachineFrameComponent.BoardContainerName, construction);
|
||||
constructionSystem.AddContainer(machine, MachineFrameComponent.PartContainerName, construction);
|
||||
}
|
||||
|
||||
if (entityManager.TryGetComponent(machine, out MachineComponent? machineComp))
|
||||
{
|
||||
constructionSystem.RefreshParts(machine, machineComp);
|
||||
}
|
||||
|
||||
var entChangeEv = new ConstructionChangeEntityEvent(machine, uid);
|
||||
entityManager.EventBus.RaiseLocalEvent(uid, entChangeEv);
|
||||
entityManager.EventBus.RaiseLocalEvent(machine, entChangeEv, broadcast: true);
|
||||
entityManager.QueueDeleteEntity(uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -256,7 +256,8 @@ namespace Content.Server.Construction
|
||||
$"{ToPrettyString(userUid.Value):player} changed {ToPrettyString(uid):entity}'s node from \"{oldNode}\" to \"{id}\"");
|
||||
|
||||
// ChangeEntity will handle the pathfinding update.
|
||||
if (node.Entity is {} newEntity && ChangeEntity(uid, userUid, newEntity, construction) != null)
|
||||
if (node.Entity.GetId(uid, userUid, new(EntityManager)) is {} newEntity
|
||||
&& ChangeEntity(uid, userUid, newEntity, construction) != null)
|
||||
return true;
|
||||
|
||||
if(performActions)
|
||||
@@ -323,8 +324,6 @@ namespace Content.Server.Construction
|
||||
}
|
||||
}
|
||||
|
||||
EntityManager.InitializeAndStartEntity(newUid);
|
||||
|
||||
// We set the graph and node accordingly.
|
||||
ChangeGraph(newUid, userUid, construction.Graph, construction.Node, false, newConstruction);
|
||||
|
||||
@@ -374,6 +373,13 @@ namespace Content.Server.Construction
|
||||
RaiseLocalEvent(uid, entChangeEv);
|
||||
RaiseLocalEvent(newUid, entChangeEv, broadcast: true);
|
||||
|
||||
foreach (var logic in GetCurrentNode(newUid, newConstruction)!.TransformLogic)
|
||||
{
|
||||
logic.Transform(uid, newUid, userUid, new(EntityManager));
|
||||
}
|
||||
|
||||
EntityManager.InitializeAndStartEntity(newUid);
|
||||
|
||||
QueueDel(uid);
|
||||
|
||||
return newUid;
|
||||
|
||||
@@ -252,7 +252,7 @@ namespace Content.Server.Construction
|
||||
return null;
|
||||
}
|
||||
|
||||
var newEntityProto = graph.Nodes[edge.Target].Entity;
|
||||
var newEntityProto = graph.Nodes[edge.Target].Entity.GetId(null, user, new(EntityManager));
|
||||
var newEntity = EntityManager.SpawnEntity(newEntityProto, EntityManager.GetComponent<TransformComponent>(user).Coordinates);
|
||||
|
||||
if (!TryComp(newEntity, out ConstructionComponent? construction))
|
||||
|
||||
@@ -37,7 +37,7 @@ public sealed class MachineFrameSystem : EntitySystem
|
||||
{
|
||||
RegenerateProgress(component);
|
||||
|
||||
if (TryComp<ConstructionComponent>(uid, out var construction))
|
||||
if (TryComp<ConstructionComponent>(uid, out var construction) && construction.TargetNode == null)
|
||||
{
|
||||
// Attempt to set pathfinding to the machine node...
|
||||
_construction.SetPathfindingTarget(uid, "machine", construction);
|
||||
|
||||
41
Content.Server/Construction/NodeEntities/BoardNodeEntity.cs
Normal file
41
Content.Server/Construction/NodeEntities/BoardNodeEntity.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using Content.Server.Construction.Components;
|
||||
using Content.Shared.Construction;
|
||||
using Content.Shared.Construction.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.Containers;
|
||||
|
||||
namespace Content.Server.Construction.NodeEntities;
|
||||
|
||||
/// <summary>
|
||||
/// Works for both <see cref="ComputerBoardComponent"/> and <see cref="MachineBoardComponent"/>
|
||||
/// because duplicating code just for this is really stinky.
|
||||
/// </summary>
|
||||
[UsedImplicitly]
|
||||
[DataDefinition]
|
||||
public sealed class BoardNodeEntity : IGraphNodeEntity
|
||||
{
|
||||
[DataField("container")] public string Container { get; private set; } = string.Empty;
|
||||
|
||||
public string? GetId(EntityUid? uid, EntityUid? userUid, GraphNodeEntityArgs args)
|
||||
{
|
||||
if (uid == null)
|
||||
return null;
|
||||
|
||||
var containerSystem = args.EntityManager.EntitySysManager.GetEntitySystem<ContainerSystem>();
|
||||
|
||||
if (!containerSystem.TryGetContainer(uid.Value, Container, out var container)
|
||||
|| container.ContainedEntities.Count == 0)
|
||||
return null;
|
||||
|
||||
var board = container.ContainedEntities[0];
|
||||
|
||||
// There should not be a case where both of these components exist on the same entity...
|
||||
if (args.EntityManager.TryGetComponent(board, out MachineBoardComponent? machine))
|
||||
return machine.Prototype;
|
||||
|
||||
if(args.EntityManager.TryGetComponent(board, out ComputerBoardComponent? computer))
|
||||
return computer.Prototype;
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,5 @@
|
||||
<ProjectReference Include="..\RobustToolbox\Robust.Server\Robust.Server.csproj" />
|
||||
<ProjectReference Include="..\Content.Shared\Content.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="..\RobustToolbox\MSBuild\Robust.Properties.targets" />
|
||||
</Project>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Shared.Construction.NodeEntities;
|
||||
using Content.Shared.Construction.Serialization;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
@@ -23,8 +25,11 @@ namespace Content.Shared.Construction
|
||||
[ViewVariables]
|
||||
public IReadOnlyList<IGraphAction> Actions => _actions;
|
||||
|
||||
[DataField("entity", customTypeSerializer:typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
public string? Entity { get; private set; }
|
||||
[DataField("transform")]
|
||||
public IGraphTransform[] TransformLogic = Array.Empty<IGraphTransform>();
|
||||
|
||||
[DataField("entity", customTypeSerializer: typeof(GraphNodeEntitySerializer), serverOnly:true)]
|
||||
public IGraphNodeEntity Entity { get; private set; } = new NullNodeEntity();
|
||||
|
||||
public ConstructionGraphEdge? GetEdge(string target)
|
||||
{
|
||||
|
||||
29
Content.Shared/Construction/IGraphNodeEntity.cs
Normal file
29
Content.Shared/Construction/IGraphNodeEntity.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared.Construction;
|
||||
|
||||
public interface IGraphNodeEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="EntityPrototype"/> ID for a node, given the <see cref="EntityUid"/> of both the
|
||||
/// construction entity and the user entity.
|
||||
/// If the construction entity is null, then we are dealing with a "start construction" for an entity that
|
||||
/// does not exist yet.
|
||||
/// If the user entity is null, this node was reached through means other some sort of "user interaction".
|
||||
/// </summary>
|
||||
/// <param name="uid">Uid of the construction entity.</param>
|
||||
/// <param name="userUid">Uid of the user that caused the transition to the node.</param>
|
||||
/// <param name="args">Arguments with useful instances, etc.</param>
|
||||
/// <returns></returns>
|
||||
public string? GetId(EntityUid? uid, EntityUid? userUid, GraphNodeEntityArgs args);
|
||||
}
|
||||
|
||||
public readonly struct GraphNodeEntityArgs
|
||||
{
|
||||
public readonly IEntityManager EntityManager;
|
||||
|
||||
public GraphNodeEntityArgs(IEntityManager entityManager)
|
||||
{
|
||||
EntityManager = entityManager;
|
||||
}
|
||||
}
|
||||
16
Content.Shared/Construction/IGraphTransform.cs
Normal file
16
Content.Shared/Construction/IGraphTransform.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace Content.Shared.Construction;
|
||||
|
||||
public interface IGraphTransform
|
||||
{
|
||||
public void Transform(EntityUid oldUid, EntityUid newUid, EntityUid? userUid, GraphTransformArgs args);
|
||||
}
|
||||
|
||||
public readonly struct GraphTransformArgs
|
||||
{
|
||||
public readonly IEntityManager EntityManager;
|
||||
|
||||
public GraphTransformArgs(IEntityManager entityManager)
|
||||
{
|
||||
EntityManager = entityManager;
|
||||
}
|
||||
}
|
||||
13
Content.Shared/Construction/NodeEntities/NullNodeEntity.cs
Normal file
13
Content.Shared/Construction/NodeEntities/NullNodeEntity.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace Content.Shared.Construction.NodeEntities;
|
||||
|
||||
[UsedImplicitly]
|
||||
[DataDefinition]
|
||||
public sealed class NullNodeEntity : IGraphNodeEntity
|
||||
{
|
||||
public string? GetId(EntityUid? uid, EntityUid? userUid, GraphNodeEntityArgs args)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
28
Content.Shared/Construction/NodeEntities/StaticNodeEntity.cs
Normal file
28
Content.Shared/Construction/NodeEntities/StaticNodeEntity.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Shared.Construction.NodeEntities;
|
||||
|
||||
[UsedImplicitly]
|
||||
[DataDefinition]
|
||||
public sealed class StaticNodeEntity : IGraphNodeEntity
|
||||
{
|
||||
[DataField("id", customTypeSerializer:typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public string? Id { get; }
|
||||
|
||||
public StaticNodeEntity()
|
||||
{
|
||||
}
|
||||
|
||||
public StaticNodeEntity(string id)
|
||||
{
|
||||
Id = id;
|
||||
}
|
||||
|
||||
public string? GetId(EntityUid? uid, EntityUid? userUid, GraphNodeEntityArgs args)
|
||||
{
|
||||
return Id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using Content.Shared.Construction.NodeEntities;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager;
|
||||
using Robust.Shared.Serialization.Markdown;
|
||||
using Robust.Shared.Serialization.Markdown.Mapping;
|
||||
using Robust.Shared.Serialization.Markdown.Validation;
|
||||
using Robust.Shared.Serialization.Markdown.Value;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Interfaces;
|
||||
|
||||
namespace Content.Shared.Construction.Serialization;
|
||||
|
||||
public sealed class GraphNodeEntitySerializer : ITypeSerializer<IGraphNodeEntity, ValueDataNode>, ITypeSerializer<IGraphNodeEntity, MappingDataNode>
|
||||
{
|
||||
public ValidationNode Validate(ISerializationManager serializationManager, ValueDataNode node,
|
||||
IDependencyCollection dependencies, ISerializationContext? context = null)
|
||||
{
|
||||
var id = node.Value;
|
||||
|
||||
var protoMan = dependencies.Resolve<IPrototypeManager>();
|
||||
|
||||
if (!protoMan.HasIndex<EntityPrototype>(id))
|
||||
{
|
||||
return new ErrorNode(node, $"Entity Prototype {id} was not found!");
|
||||
}
|
||||
|
||||
return new ValidatedValueNode(node);
|
||||
}
|
||||
|
||||
public IGraphNodeEntity Read(ISerializationManager serializationManager, ValueDataNode node,
|
||||
IDependencyCollection dependencies, SerializationHookContext hookCtx, ISerializationContext? context = null, ISerializationManager.InstantiationDelegate<IGraphNodeEntity>? instanceProvider = null)
|
||||
{
|
||||
return new StaticNodeEntity(node.Value);
|
||||
}
|
||||
|
||||
public ValidationNode Validate(ISerializationManager serializationManager, MappingDataNode node,
|
||||
IDependencyCollection dependencies, ISerializationContext? context = null)
|
||||
{
|
||||
return serializationManager.ValidateNode<IGraphNodeEntity>(node, context);
|
||||
}
|
||||
|
||||
public IGraphNodeEntity Read(ISerializationManager serializationManager, MappingDataNode node,
|
||||
IDependencyCollection dependencies, SerializationHookContext hookCtx, ISerializationContext? context = null, ISerializationManager.InstantiationDelegate<IGraphNodeEntity>? instanceProvider = null)
|
||||
{
|
||||
return serializationManager.Read(node, hookCtx, context, instanceProvider, false);
|
||||
}
|
||||
|
||||
public DataNode Write(ISerializationManager serializationManager, IGraphNodeEntity value, IDependencyCollection dependencies,
|
||||
bool alwaysWrite = false, ISerializationContext? context = null)
|
||||
{
|
||||
return serializationManager.WriteValue(value, alwaysWrite, context, false);
|
||||
}
|
||||
}
|
||||
@@ -32,11 +32,14 @@ namespace Content.Shared.Storage.EntitySystems
|
||||
val.Layer = layerName;
|
||||
}
|
||||
|
||||
if (EntityManager.TryGetComponent(component.Owner, out AppearanceComponent? appearanceComponent))
|
||||
if (EntityManager.TryGetComponent(uid, out AppearanceComponent? appearanceComponent))
|
||||
{
|
||||
var list = new List<string>(component.MapLayers.Keys);
|
||||
_appearance.SetData(component.Owner, StorageMapVisuals.InitLayers, new ShowLayerData(list), appearanceComponent);
|
||||
_appearance.SetData(uid, StorageMapVisuals.InitLayers, new ShowLayerData(list), appearanceComponent);
|
||||
}
|
||||
|
||||
// Ensure appearance is correct with current contained entities.
|
||||
UpdateAppearance(uid, component);
|
||||
}
|
||||
|
||||
private void MapperEntityRemoved(EntityUid uid, ItemMapperComponent itemMapper,
|
||||
@@ -45,7 +48,7 @@ namespace Content.Shared.Storage.EntitySystems
|
||||
if (itemMapper.ContainerWhitelist != null && !itemMapper.ContainerWhitelist.Contains(args.Container.ID))
|
||||
return;
|
||||
|
||||
UpdateAppearance(uid, itemMapper, args);
|
||||
UpdateAppearance(uid, itemMapper);
|
||||
}
|
||||
|
||||
private void MapperEntityInserted(EntityUid uid, ItemMapperComponent itemMapper,
|
||||
@@ -54,40 +57,43 @@ namespace Content.Shared.Storage.EntitySystems
|
||||
if (itemMapper.ContainerWhitelist != null && !itemMapper.ContainerWhitelist.Contains(args.Container.ID))
|
||||
return;
|
||||
|
||||
UpdateAppearance(uid, itemMapper, args);
|
||||
UpdateAppearance(uid, itemMapper);
|
||||
}
|
||||
|
||||
private void UpdateAppearance(EntityUid uid, ItemMapperComponent itemMapper, ContainerModifiedMessage message)
|
||||
private void UpdateAppearance(EntityUid uid, ItemMapperComponent? itemMapper = null)
|
||||
{
|
||||
if (EntityManager.TryGetComponent(itemMapper.Owner, out AppearanceComponent? appearanceComponent)
|
||||
&& TryGetLayers(message, itemMapper, out var containedLayers))
|
||||
if(!Resolve(uid, ref itemMapper))
|
||||
return;
|
||||
|
||||
if (EntityManager.TryGetComponent(uid, out AppearanceComponent? appearanceComponent)
|
||||
&& TryGetLayers(uid, itemMapper, out var containedLayers))
|
||||
{
|
||||
_appearance.SetData(itemMapper.Owner, StorageMapVisuals.LayerChanged, new ShowLayerData(containedLayers), appearanceComponent);
|
||||
_appearance.SetData(uid, StorageMapVisuals.LayerChanged, new ShowLayerData(containedLayers), appearanceComponent);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method that iterates over storage of the entity in <paramref name="msg"/> and sets <paramref name="containedLayers"/> according to
|
||||
/// Method that iterates over storage of the entity in <paramref name="uid"/> and sets <paramref name="containedLayers"/> according to
|
||||
/// <paramref name="itemMapper"/> definition. It will have O(n*m) time behavior (n - number of entities in container, and m - number of
|
||||
/// definitions in <paramref name="containedLayers"/>.
|
||||
/// </summary>
|
||||
/// <param name="msg">event with EntityUid used to search the storage</param>
|
||||
/// <param name="uid">EntityUid used to search the storage</param>
|
||||
/// <param name="itemMapper">component that contains definition used to map <see cref="Content.Shared.Whitelist.EntityWhitelist">whitelist</see> in
|
||||
/// <c>mapLayers</c> to string.
|
||||
/// </param>
|
||||
/// <param name="containedLayers">list of <paramref name="itemMapper"/> layers that should be visible</param>
|
||||
/// <returns>false if <c>msg.Container.Owner</c> is not a storage, true otherwise.</returns>
|
||||
private bool TryGetLayers(ContainerModifiedMessage msg,
|
||||
private bool TryGetLayers(EntityUid uid,
|
||||
ItemMapperComponent itemMapper,
|
||||
out List<string> showLayers)
|
||||
{
|
||||
var containedLayers = _container.GetAllContainers(msg.Container.Owner)
|
||||
var containedLayers = _container.GetAllContainers(uid)
|
||||
.Where(c => itemMapper.ContainerWhitelist?.Contains(c.ID) ?? true).SelectMany(cont => cont.ContainedEntities).ToArray();
|
||||
|
||||
var list = new List<string>();
|
||||
foreach (var mapLayerData in itemMapper.MapLayers.Values)
|
||||
{
|
||||
var count = containedLayers.Count(uid => mapLayerData.ServerWhitelist.IsValid(uid));
|
||||
var count = containedLayers.Count(ent => mapLayerData.ServerWhitelist.IsValid(ent));
|
||||
if (count >= mapLayerData.MinCount && count <= mapLayerData.MaxCount)
|
||||
{
|
||||
list.Add(mapLayerData.Layer);
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
- type: Construction
|
||||
graph: Computer
|
||||
node: computer
|
||||
containers:
|
||||
- board
|
||||
- type: Computer
|
||||
- type: ApcPowerReceiver
|
||||
powerLoad: 200
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
- type: Rotatable
|
||||
- type: Pullable
|
||||
- type: Construction
|
||||
containers:
|
||||
- machine_board
|
||||
- machine_parts
|
||||
graph: Machine
|
||||
node: missingWires
|
||||
- type: ContainerContainer
|
||||
@@ -83,6 +86,9 @@
|
||||
graph: Machine
|
||||
node: machineFrame
|
||||
defaultTarget: machine
|
||||
containers:
|
||||
- machine_board
|
||||
- machine_parts
|
||||
- type: Damageable
|
||||
damageContainer: Inorganic
|
||||
damageModifierSet: Metallic
|
||||
|
||||
@@ -107,9 +107,6 @@
|
||||
- to: computer
|
||||
conditions:
|
||||
- !type:EntityAnchored {}
|
||||
completed:
|
||||
- !type:BuildComputer
|
||||
container: board
|
||||
steps:
|
||||
- tool: Screwing
|
||||
|
||||
@@ -124,6 +121,7 @@
|
||||
- tool: Prying
|
||||
|
||||
- node: computer
|
||||
entity: !type:BoardNodeEntity { container: board }
|
||||
edges:
|
||||
- to: monitorUnsecured
|
||||
steps:
|
||||
|
||||
@@ -48,6 +48,10 @@
|
||||
- node: machineFrame
|
||||
entity: MachineFrame
|
||||
actions:
|
||||
- !type:AddContainer
|
||||
container: machine_parts
|
||||
- !type:AddContainer
|
||||
container: machine_board
|
||||
- !type:MachineFrameRegenerateProgress
|
||||
edges:
|
||||
- to: machine
|
||||
@@ -60,9 +64,6 @@
|
||||
guideIconParts:
|
||||
sprite: Objects/Misc/stock_parts.rsi
|
||||
state: scan_module
|
||||
completed:
|
||||
# Yes, this is snowflaked so we don't have to make an unique graph per machine. You're welcome.
|
||||
- !type:BuildMachine
|
||||
steps:
|
||||
- tool: Screwing
|
||||
doAfter: 0.5
|
||||
@@ -93,11 +94,7 @@
|
||||
doAfter: 0.25
|
||||
|
||||
- node: machine
|
||||
actions:
|
||||
- !type:AddContainer
|
||||
container: machine_parts
|
||||
- !type:AddContainer
|
||||
container: machine_board
|
||||
entity: !type:BoardNodeEntity { container: machine_board }
|
||||
edges:
|
||||
- to: machineFrame
|
||||
completed:
|
||||
|
||||
Reference in New Issue
Block a user