2020-10-08 17:41:23 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2021-03-15 21:55:49 +01:00
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2021-03-05 01:08:38 +01:00
|
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2020-10-08 17:41:23 +02:00
|
|
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Content.Shared.Construction
|
|
|
|
|
|
{
|
|
|
|
|
|
[Serializable]
|
2021-03-05 01:08:38 +01:00
|
|
|
|
[DataDefinition]
|
2020-10-08 17:41:23 +02:00
|
|
|
|
public class ConstructionGraphNode
|
|
|
|
|
|
{
|
2021-03-05 01:08:38 +01:00
|
|
|
|
[DataField("actions", serverOnly: true)]
|
2020-11-27 11:00:49 +01:00
|
|
|
|
private List<IGraphAction> _actions = new();
|
2021-03-15 21:55:49 +01:00
|
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
|
[DataField("edges")]
|
2020-11-27 11:00:49 +01:00
|
|
|
|
private List<ConstructionGraphEdge> _edges = new();
|
2020-10-08 17:41:23 +02:00
|
|
|
|
|
|
|
|
|
|
[ViewVariables]
|
2021-03-15 21:55:49 +01:00
|
|
|
|
[DataField("node", required: true)]
|
|
|
|
|
|
public string Name { get; private set; } = default!;
|
2020-10-08 17:41:23 +02:00
|
|
|
|
|
|
|
|
|
|
[ViewVariables]
|
|
|
|
|
|
public IReadOnlyList<ConstructionGraphEdge> Edges => _edges;
|
|
|
|
|
|
|
|
|
|
|
|
[ViewVariables]
|
|
|
|
|
|
public IReadOnlyList<IGraphAction> Actions => _actions;
|
|
|
|
|
|
|
|
|
|
|
|
[ViewVariables]
|
2021-03-05 01:08:38 +01:00
|
|
|
|
[DataField("entity")]
|
2021-03-15 21:55:49 +01:00
|
|
|
|
public string? Entity { get; private set; }
|
2020-10-08 17:41:23 +02:00
|
|
|
|
|
2021-03-15 21:55:49 +01:00
|
|
|
|
public ConstructionGraphEdge? GetEdge(string target)
|
2020-10-08 17:41:23 +02:00
|
|
|
|
{
|
|
|
|
|
|
foreach (var edge in _edges)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (edge.Target == target)
|
|
|
|
|
|
return edge;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2021-03-15 21:55:49 +01:00
|
|
|
|
|
|
|
|
|
|
public bool TryGetEdge(string target, [NotNullWhen(true)] out ConstructionGraphEdge? edge)
|
|
|
|
|
|
{
|
|
|
|
|
|
return (edge = GetEdge(target)) != null;
|
|
|
|
|
|
}
|
2020-10-08 17:41:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|