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:
py01
2020-08-06 18:47:54 -06:00
committed by GitHub
parent 551c204a9f
commit 01b10cb687
11 changed files with 6109 additions and 10315 deletions

View File

@@ -61,7 +61,6 @@ namespace Content.Server
IoCManager.Resolve<IServerPreferencesManager>().StartInit(); IoCManager.Resolve<IServerPreferencesManager>().StartInit();
IoCManager.Resolve<INodeGroupFactory>().Initialize(); IoCManager.Resolve<INodeGroupFactory>().Initialize();
IoCManager.Resolve<INodeFactory>().Initialize();
IoCManager.Resolve<ISandboxManager>().Initialize(); IoCManager.Resolve<ISandboxManager>().Initialize();
} }

View File

@@ -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.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
using System.Collections.Generic; using System.Collections.Generic;
@@ -21,37 +18,27 @@ namespace Content.Server.GameObjects.Components.NodeContainer
public IReadOnlyList<Node> Nodes => _nodes; public IReadOnlyList<Node> Nodes => _nodes;
private List<Node> _nodes = new List<Node>(); 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) public override void ExposeData(ObjectSerializer serializer)
{ {
base.ExposeData(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() protected override void Startup()
{ {
base.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) foreach (var node in _nodes)
{ {
node.OnContainerInitialize(); node.OnContainerStartup();
} }
} }
@@ -61,13 +48,7 @@ namespace Content.Server.GameObjects.Components.NodeContainer
{ {
node.OnContainerRemove(); node.OnContainerRemove();
} }
_nodes = null;
base.OnRemove(); base.OnRemove();
} }
private Node MakeNewNode(string nodeName, NodeGroupID groupID, IEntity owner)
{
return _nodeFactory.MakeNode(nodeName, groupID, owner);
}
} }
} }

View File

@@ -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.Collections.Generic;
using System.Linq; using System.Linq;
@@ -8,7 +7,6 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
/// <summary> /// <summary>
/// A <see cref="Node"/> that can reach other <see cref="AdjacentNode"/>s that are directly adjacent to it. /// A <see cref="Node"/> that can reach other <see cref="AdjacentNode"/>s that are directly adjacent to it.
/// </summary> /// </summary>
[Node("AdjacentNode")]
public class AdjacentNode : Node public class AdjacentNode : Node
{ {
protected override IEnumerable<Node> GetReachableNodes() protected override IEnumerable<Node> GetReachableNodes()

View File

@@ -1,5 +1,4 @@
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups; using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
using Robust.Server.GameObjects;
using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
@@ -7,6 +6,8 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using Robust.Shared.GameObjects.Components; using Robust.Shared.GameObjects.Components;
using Robust.Shared.Interfaces.Serialization;
using Robust.Shared.Serialization;
namespace Content.Server.GameObjects.Components.NodeContainer.Nodes 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 /// 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"/>. /// that they can "reach" and have the same <see cref="Node.NodeGroupID"/>.
/// </summary> /// </summary>
public abstract class Node public abstract class Node : IExposeData
{ {
/// <summary> /// <summary>
/// An ID used as a criteria for combining into groups. Determines which <see cref="INodeGroup"/> /// 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> /// </summary>
private bool _deleting = false; private bool _deleting = false;
#pragma warning disable 649 private INodeGroupFactory _nodeGroupFactory;
[Dependency] private readonly INodeGroupFactory _nodeGroupFactory;
#pragma warning restore 649
public void Initialize(NodeGroupID nodeGroupID, IEntity owner) public virtual void ExposeData(ObjectSerializer serializer)
{ {
NodeGroupID = nodeGroupID; serializer.DataField(this, x => NodeGroupID, "nodeGroupID", NodeGroupID.Default);
Owner = owner;
} }
public void OnContainerInitialize() public void Initialize(IEntity owner)
{
Owner = owner;
_nodeGroupFactory = IoCManager.Resolve<INodeGroupFactory>();
}
public void OnContainerStartup()
{ {
TryAssignGroupIfNeeded(); TryAssignGroupIfNeeded();
CombineGroupWithReachable(); CombineGroupWithReachable();

View File

@@ -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;
}
}
}

View File

@@ -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)}.");
}
}
}

View File

@@ -15,7 +15,6 @@ using Content.Shared.Interfaces;
using Content.Shared.Kitchen; using Content.Shared.Kitchen;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups; using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
using Content.Server.GameObjects.Components.Power.PowerNetComponents; using Content.Server.GameObjects.Components.Power.PowerNetComponents;
namespace Content.Server namespace Content.Server
@@ -38,7 +37,6 @@ namespace Content.Server
IoCManager.Register<INodeGroupFactory, NodeGroupFactory>(); IoCManager.Register<INodeGroupFactory, NodeGroupFactory>();
IoCManager.Register<INodeGroupManager, NodeGroupManager>(); IoCManager.Register<INodeGroupManager, NodeGroupManager>();
IoCManager.Register<IPowerNetManager, PowerNetManager>(); IoCManager.Register<IPowerNetManager, PowerNetManager>();
IoCManager.Register<INodeFactory, NodeFactory>();
IoCManager.Register<BlackboardManager, BlackboardManager>(); IoCManager.Register<BlackboardManager, BlackboardManager>();
IoCManager.Register<ConsiderationsManager, ConsiderationsManager>(); IoCManager.Register<ConsiderationsManager, ConsiderationsManager>();
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,4 @@
- type: entity - type: entity
abstract: true abstract: true
id: WireBase id: WireBase
placement: placement:
@@ -33,7 +33,9 @@
base: hvcable_ base: hvcable_
key: hv_cables key: hv_cables
- type: NodeContainer - type: NodeContainer
nodeTypes: { HVPower : ["AdjacentNode"] } nodes:
- !type:AdjacentNode
nodeGroupID: HVPower
- type: Wire - type: Wire
wireDroppedOnCutPrototype: HVWireStack1 wireDroppedOnCutPrototype: HVWireStack1
wireType: HighVoltage wireType: HighVoltage
@@ -53,7 +55,9 @@
base: mvcable_ base: mvcable_
key: mv_cables key: mv_cables
- type: NodeContainer - type: NodeContainer
nodeTypes: { MVPower : ["AdjacentNode"] } nodes:
- !type:AdjacentNode
nodeGroupID: MVPower
- type: Wire - type: Wire
wireDroppedOnCutPrototype: MVWireStack1 wireDroppedOnCutPrototype: MVWireStack1
wireType: MediumVoltage wireType: MediumVoltage
@@ -73,7 +77,9 @@
base: lvcable_ base: lvcable_
key: lv_cables key: lv_cables
- type: NodeContainer - type: NodeContainer
nodeTypes: { Apc : ["AdjacentNode"] } nodes:
- !type:AdjacentNode
nodeGroupID: Apc
- type: PowerProvider - type: PowerProvider
voltage: Apc voltage: Apc
- type: Wire - type: Wire
@@ -90,14 +96,8 @@
parent: ApcExtensionCable parent: ApcExtensionCable
components: components:
- type: NodeContainer - type: NodeContainer
nodeTypes: { HVPower : ["AdjacentNode"], Apc : ["AdjacentNode"] } nodes:
- !type:AdjacentNode
- type: entity nodeGroupID: HVPower
id: Generator - !type:AdjacentNode
name: Depriciated Generator nodeGroupID: Apc
parent: DebugGenerator
components:
- type: PowerSupplier
voltage: High
supplyRate: 100000

View File

@@ -18,7 +18,9 @@
- type: Icon - type: Icon
texture: Constructible/Power/generator.png texture: Constructible/Power/generator.png
- type: NodeContainer - type: NodeContainer
nodeTypes: { HVPower : ["AdjacentNode"] } nodes:
- !type:AdjacentNode
nodeGroupID: HVPower
- type: PowerSupplier - type: PowerSupplier
supplyRate: 3000 supplyRate: 3000
- type: Physics - type: Physics
@@ -45,7 +47,9 @@
- type: Icon - type: Icon
texture: Constructible/Power/wiredmachine.png texture: Constructible/Power/wiredmachine.png
- type: NodeContainer - type: NodeContainer
nodeTypes: { HVPower : ["AdjacentNode"] } nodes:
- !type:AdjacentNode
nodeGroupID: HVPower
- type: PowerConsumer - type: PowerConsumer
drawRate: 50 drawRate: 50
- type: Damageable - type: Damageable
@@ -76,7 +80,9 @@
texture: Constructible/Power/provider.png texture: Constructible/Power/provider.png
- type: Battery - type: Battery
- type: NodeContainer - type: NodeContainer
nodeTypes: { HVPower : ["AdjacentNode"] } nodes:
- !type:AdjacentNode
nodeGroupID: HVPower
- type: PowerConsumer - type: PowerConsumer
- type: BatteryStorage - type: BatteryStorage
- type: Physics - type: Physics
@@ -104,7 +110,9 @@
texture: Constructible/Power/provider.png texture: Constructible/Power/provider.png
- type: Battery - type: Battery
- type: NodeContainer - type: NodeContainer
nodeTypes: { HVPower : ["AdjacentNode"] } nodes:
- !type:AdjacentNode
nodeGroupID: HVPower
- type: PowerSupplier - type: PowerSupplier
- type: BatteryDischarger - type: BatteryDischarger
- type: Physics - type: Physics
@@ -144,7 +152,9 @@
maxCharge: 1000 maxCharge: 1000
startingCharge: 1000 startingCharge: 1000
- type: NodeContainer - type: NodeContainer
nodeTypes: { HVPower : ["AdjacentNode"] } nodes:
- !type:AdjacentNode
nodeGroupID: HVPower
- type: PowerConsumer - type: PowerConsumer
- type: BatteryStorage - type: BatteryStorage
activeDrawRate: 1500 activeDrawRate: 1500
@@ -179,7 +189,11 @@
maxCharge: 1000 maxCharge: 1000
startingCharge: 1000 startingCharge: 1000
- type: NodeContainer - type: NodeContainer
nodeTypes: { HVPower : ["AdjacentNode"], MVPower : ["AdjacentNode"] } nodes:
- !type:AdjacentNode
nodeGroupID: HVPower
- !type:AdjacentNode
nodeGroupID: MVPower
- type: PowerConsumer - type: PowerConsumer
- type: BatteryStorage - type: BatteryStorage
activeDrawRate: 1500 activeDrawRate: 1500
@@ -220,7 +234,11 @@
maxCharge: 10000 maxCharge: 10000
startingCharge: 10000 startingCharge: 10000
- type: NodeContainer - type: NodeContainer
nodeTypes: { MVPower : ["AdjacentNode"], Apc : ["AdjacentNode"] } nodes:
- !type:AdjacentNode
nodeGroupID: MVPower
- !type:AdjacentNode
nodeGroupID: Apc
- type: PowerConsumer - type: PowerConsumer
voltage: Medium voltage: Medium
- type: BatteryStorage - type: BatteryStorage
@@ -278,7 +296,9 @@
sprite: Constructible/Power/solar_panel.rsi sprite: Constructible/Power/solar_panel.rsi
state: normal state: normal
- type: NodeContainer - type: NodeContainer
nodeTypes: { HVPower : ["AdjacentNode"] } nodes:
- !type:AdjacentNode
nodeGroupID: HVPower
- type: PowerSupplier - type: PowerSupplier
- type: SolarPanel - type: SolarPanel
supply: 1500 supply: 1500
@@ -290,13 +310,26 @@
#Depriciated, to be removed from maps #Depriciated, to be removed from maps
- type: entity
id: Generator
name: Depriciated Generator
parent: DebugGenerator
components:
- type: PowerSupplier
voltage: High
supplyRate: 100000
- type: entity - type: entity
id: APC id: APC
name: Depriciated Apc name: Depriciated Apc
parent: DebugApc parent: DebugApc
components: components:
- type: NodeContainer - type: NodeContainer
nodeTypes: { HVPower : ["AdjacentNode"], Apc : ["AdjacentNode"] } nodes:
- !type:AdjacentNode
nodeGroupID: HVPower
- !type:AdjacentNode
nodeGroupID: Apc
- type: PowerConsumer - type: PowerConsumer
voltage: High voltage: High
- type: BatteryStorage - type: BatteryStorage