Data-oriented Construction System (#2152)
- Powerful - Data-oriented - Approved by PJB - Powered by node graphs and AI pathfinding - Coded by the same nerd who brought you atmos Co-authored-by: Exp <theexp111@gmail.com>
This commit is contained in:
committed by
GitHub
parent
a6647e8de1
commit
745401a41e
68
Content.Shared/Construction/ConstructionGraphNode.cs
Normal file
68
Content.Shared/Construction/ConstructionGraphNode.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Interfaces;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
using ObjectSerializer = Robust.Shared.Serialization.ObjectSerializer;
|
||||
|
||||
namespace Content.Shared.Construction
|
||||
{
|
||||
[Serializable]
|
||||
public class ConstructionGraphNode
|
||||
{
|
||||
private List<IGraphAction> _actions = new List<IGraphAction>();
|
||||
private List<ConstructionGraphEdge> _edges = new List<ConstructionGraphEdge>();
|
||||
|
||||
[ViewVariables]
|
||||
public string Name { get; private set; }
|
||||
|
||||
[ViewVariables]
|
||||
public IReadOnlyList<ConstructionGraphEdge> Edges => _edges;
|
||||
|
||||
[ViewVariables]
|
||||
public IReadOnlyList<IGraphAction> Actions => _actions;
|
||||
|
||||
[ViewVariables]
|
||||
public string Entity { get; private set; }
|
||||
|
||||
public void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
var moduleManager = IoCManager.Resolve<IModuleManager>();
|
||||
|
||||
serializer.DataField(this, x => x.Name, "node", string.Empty);
|
||||
serializer.DataField(this, x => x.Entity, "entity",string.Empty);
|
||||
if (!moduleManager.IsServerModule) return;
|
||||
serializer.DataField(ref _actions, "actions", new List<IGraphAction>());
|
||||
}
|
||||
|
||||
public void LoadFrom(YamlMappingNode mapping)
|
||||
{
|
||||
var serializer = YamlObjectSerializer.NewReader(mapping);
|
||||
ExposeData(serializer);
|
||||
|
||||
if (!mapping.TryGetNode("edges", out YamlSequenceNode edgesMapping)) return;
|
||||
|
||||
foreach (var yamlNode in edgesMapping)
|
||||
{
|
||||
var edgeMapping = (YamlMappingNode) yamlNode;
|
||||
var edge = new ConstructionGraphEdge();
|
||||
edge.LoadFrom(edgeMapping);
|
||||
_edges.Add(edge);
|
||||
}
|
||||
}
|
||||
|
||||
public ConstructionGraphEdge GetEdge(string target)
|
||||
{
|
||||
foreach (var edge in _edges)
|
||||
{
|
||||
if (edge.Target == target)
|
||||
return edge;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user