Node serialization change (#1497)
* NodeContainerComponent serializes a set of Nodes with ExposeData * Fixes Nodes to work when being created by serializer * ConduitNode * ConduitPlacer to replace WirePlacer * ConduitNode ConduitLayer setter * Map update * Comments * Map update again * Method ordering by privacy * Removes conduits * ignored component * reorg * map update * readd wireplacer Co-authored-by: py01 <pyronetics01@gmail.com>
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
|
||||
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
|
||||
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using System.Collections.Generic;
|
||||
@@ -21,37 +18,27 @@ namespace Content.Server.GameObjects.Components.NodeContainer
|
||||
public IReadOnlyList<Node> Nodes => _nodes;
|
||||
private List<Node> _nodes = new List<Node>();
|
||||
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly INodeFactory _nodeFactory;
|
||||
#pragma warning restore 649
|
||||
|
||||
/// <summary>
|
||||
/// A set of <see cref="NodeGroupID"/>s and <see cref="Node"/> implementation names
|
||||
/// to be created and held in this container.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
private Dictionary<NodeGroupID, List<string>> _nodeTypes;
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
serializer.DataField(ref _nodeTypes, "nodeTypes", new Dictionary<NodeGroupID, List<string>> { });
|
||||
serializer.DataField(ref _nodes, "nodes", new List<Node>());
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
foreach (var node in _nodes)
|
||||
{
|
||||
node.Initialize(Owner);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Startup()
|
||||
{
|
||||
base.Startup();
|
||||
foreach (var nodeType in _nodeTypes)
|
||||
{
|
||||
var nodeGroupID = nodeType.Key;
|
||||
foreach (var nodeName in nodeType.Value)
|
||||
{
|
||||
_nodes.Add(MakeNewNode(nodeName, nodeGroupID, Owner));
|
||||
}
|
||||
}
|
||||
foreach (var node in _nodes)
|
||||
{
|
||||
node.OnContainerInitialize();
|
||||
node.OnContainerStartup();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,13 +48,7 @@ namespace Content.Server.GameObjects.Components.NodeContainer
|
||||
{
|
||||
node.OnContainerRemove();
|
||||
}
|
||||
_nodes = null;
|
||||
base.OnRemove();
|
||||
}
|
||||
|
||||
private Node MakeNewNode(string nodeName, NodeGroupID groupID, IEntity owner)
|
||||
{
|
||||
return _nodeFactory.MakeNode(nodeName, groupID, owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
|
||||
using Robust.Shared.GameObjects.Components.Transform;
|
||||
using Robust.Shared.GameObjects.Components.Transform;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
@@ -8,7 +7,6 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
|
||||
/// <summary>
|
||||
/// A <see cref="Node"/> that can reach other <see cref="AdjacentNode"/>s that are directly adjacent to it.
|
||||
/// </summary>
|
||||
[Node("AdjacentNode")]
|
||||
public class AdjacentNode : Node
|
||||
{
|
||||
protected override IEnumerable<Node> GetReachableNodes()
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.ViewVariables;
|
||||
@@ -7,6 +6,8 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Robust.Shared.GameObjects.Components;
|
||||
using Robust.Shared.Interfaces.Serialization;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
|
||||
{
|
||||
@@ -14,7 +15,7 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
|
||||
/// Organizes themselves into distinct <see cref="INodeGroup"/>s with other <see cref="Node"/>s
|
||||
/// that they can "reach" and have the same <see cref="Node.NodeGroupID"/>.
|
||||
/// </summary>
|
||||
public abstract class Node
|
||||
public abstract class Node : IExposeData
|
||||
{
|
||||
/// <summary>
|
||||
/// An ID used as a criteria for combining into groups. Determines which <see cref="INodeGroup"/>
|
||||
@@ -45,17 +46,20 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
|
||||
/// </summary>
|
||||
private bool _deleting = false;
|
||||
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly INodeGroupFactory _nodeGroupFactory;
|
||||
#pragma warning restore 649
|
||||
private INodeGroupFactory _nodeGroupFactory;
|
||||
|
||||
public void Initialize(NodeGroupID nodeGroupID, IEntity owner)
|
||||
public virtual void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
NodeGroupID = nodeGroupID;
|
||||
Owner = owner;
|
||||
serializer.DataField(this, x => NodeGroupID, "nodeGroupID", NodeGroupID.Default);
|
||||
}
|
||||
|
||||
public void OnContainerInitialize()
|
||||
public void Initialize(IEntity owner)
|
||||
{
|
||||
Owner = owner;
|
||||
_nodeGroupFactory = IoCManager.Resolve<INodeGroupFactory>();
|
||||
}
|
||||
|
||||
public void OnContainerStartup()
|
||||
{
|
||||
TryAssignGroupIfNeeded();
|
||||
CombineGroupWithReachable();
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
|
||||
{
|
||||
/// <summary>
|
||||
/// Associates a <see cref="Node"/> implementation with a string. This is used
|
||||
/// to specify an <see cref="Node"/>'s strategy in yaml. Used by <see cref="INodeFactory"/>.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
|
||||
public class
|
||||
NodeAttribute : Attribute
|
||||
{
|
||||
public string Name { get; }
|
||||
|
||||
public NodeAttribute(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Reflection;
|
||||
using Robust.Shared.IoC;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
|
||||
{
|
||||
public interface INodeFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Performs reflection to associate <see cref="Node"/> implementations with the
|
||||
/// string specified in their <see cref="NodeAttribute"/>.
|
||||
/// </summary>
|
||||
void Initialize();
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Node"/> instance.
|
||||
/// </summary>
|
||||
Node MakeNode(string nodeName, NodeGroupID groupID, IEntity owner);
|
||||
}
|
||||
|
||||
public class NodeFactory : INodeFactory
|
||||
{
|
||||
private readonly Dictionary<string, Type> _groupTypes = new Dictionary<string, Type>();
|
||||
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly IReflectionManager _reflectionManager;
|
||||
[Dependency] private readonly IDynamicTypeFactory _typeFactory;
|
||||
#pragma warning restore 649
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
var nodeTypes = _reflectionManager.GetAllChildren<Node>();
|
||||
foreach (var nodeType in nodeTypes)
|
||||
{
|
||||
var att = nodeType.GetCustomAttribute<NodeAttribute>();
|
||||
if (att != null)
|
||||
{
|
||||
_groupTypes.Add(att.Name, nodeType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Node MakeNode(string nodeName, NodeGroupID groupID, IEntity owner)
|
||||
{
|
||||
if (_groupTypes.TryGetValue(nodeName, out var type))
|
||||
{
|
||||
var newNode = _typeFactory.CreateInstance<Node>(type);
|
||||
newNode.Initialize(groupID, owner);
|
||||
return newNode;
|
||||
}
|
||||
throw new ArgumentException($"{nodeName} did not have an associated {nameof(Node)}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user