Replace SpriteStateChange construction action with AppearanceChange (#15914)
This commit is contained in:
42
Content.Server/Construction/Completions/AppearanceChange.cs
Normal file
42
Content.Server/Construction/Completions/AppearanceChange.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using Content.Server.Construction.Components;
|
||||
using Content.Shared.Construction;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
|
||||
namespace Content.Server.Construction.Completions;
|
||||
|
||||
[UsedImplicitly]
|
||||
[DataDefinition]
|
||||
public sealed class AppearanceChange : IGraphAction
|
||||
{
|
||||
/// <summary>
|
||||
/// The appearance key to use.
|
||||
/// </summary>
|
||||
[DataField("key")]
|
||||
public Enum Key = ConstructionVisuals.Key;
|
||||
|
||||
/// <summary>
|
||||
/// The enum data to set. If not specified, will set the data to the name of the current edges' target node
|
||||
/// (or the current node). This is because appearance changes are usually associated with reaching a new node.
|
||||
/// </summary>
|
||||
[DataField("data")]
|
||||
public Enum? Data;
|
||||
|
||||
public void PerformAction(EntityUid uid, EntityUid? userUid, IEntityManager entityManager)
|
||||
{
|
||||
if (!entityManager.TryGetComponent(uid, out AppearanceComponent? appearance))
|
||||
return;
|
||||
|
||||
if (Data != null)
|
||||
{
|
||||
entityManager.System<AppearanceSystem>().SetData(uid, Key, Data, appearance);
|
||||
return;
|
||||
}
|
||||
|
||||
var (node, edge) = entityManager.System<ConstructionSystem>().GetCurrentNodeAndEdge(uid);
|
||||
var nodeName = edge?.Target ?? node?.Name;
|
||||
|
||||
if (nodeName != null)
|
||||
entityManager.System<AppearanceSystem>().SetData(uid, Key, nodeName, appearance);
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
using Content.Shared.Construction;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
|
||||
namespace Content.Server.Construction.Completions
|
||||
{
|
||||
[UsedImplicitly]
|
||||
[DataDefinition]
|
||||
public sealed class SpriteStateChange : IGraphAction
|
||||
{
|
||||
[DataField("layer")] public int Layer { get; private set; } = 0;
|
||||
[DataField("state")] public string? State { get; private set; } = string.Empty;
|
||||
|
||||
public void PerformAction(EntityUid uid, EntityUid? userUid, IEntityManager entityManager)
|
||||
{
|
||||
if (string.IsNullOrEmpty(State) || !entityManager.TryGetComponent(uid, out SpriteComponent? sprite))
|
||||
return;
|
||||
|
||||
// That layer doesn't exist, we do nothing.
|
||||
if (sprite.LayerCount <= Layer)
|
||||
return;
|
||||
|
||||
sprite.LayerSetState(Layer, State);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,6 +90,23 @@ namespace Content.Server.Construction
|
||||
return GetCurrentNode(uid, construction) is not {} node ? null : GetEdgeFromNode(node, edgeIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Variant of <see cref="GetCurrentEdge"/> that returns both the node and edge.
|
||||
/// </summary>
|
||||
public (ConstructionGraphNode?, ConstructionGraphEdge?) GetCurrentNodeAndEdge(EntityUid uid, ConstructionComponent? construction = null)
|
||||
{
|
||||
if (!Resolve(uid, ref construction, false))
|
||||
return (null, null);
|
||||
|
||||
if (GetCurrentNode(uid, construction) is not { } node)
|
||||
return (null, null);
|
||||
|
||||
if (construction.EdgeIndex is not {} edgeIndex)
|
||||
return (node, null);
|
||||
|
||||
return (node, GetEdgeFromNode(node, edgeIndex));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the construction graph step the entity is currently at, or null.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user