mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
parent
41ecaa27d0
commit
ca2efb626e
2 changed files with 83 additions and 77 deletions
|
|
@ -1,84 +1,91 @@
|
|||
using JetBrains.Annotations;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Client.IconSmoothing
|
||||
namespace Content.Client.IconSmoothing;
|
||||
|
||||
/// <summary>
|
||||
/// Makes sprites of other grid-aligned entities like us connect.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The system is based on Baystation12's smoothwalling, and thus will work with those.
|
||||
/// To use, set <c>base</c> equal to the prefix of the corner states in the sprite base RSI.
|
||||
/// Any objects with the same <c>key</c> will connect.
|
||||
/// </remarks>
|
||||
[RegisterComponent]
|
||||
public sealed partial class IconSmoothComponent : Component
|
||||
{
|
||||
[DataField]
|
||||
public bool Enabled = true;
|
||||
|
||||
public (EntityUid?, Vector2i)? LastPosition;
|
||||
|
||||
/// <summary>
|
||||
/// Objects with this key can smooth with us, and vice versa.
|
||||
/// TODO: YAML HELL, Make smoothing one way.
|
||||
/// </summary>
|
||||
[DataField("key", required: true)]
|
||||
public string SmoothKey { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// We will attempt to smooth with any objects that contain these keys.
|
||||
/// Only works one way, objects with these keys will not smooth with us
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public List<string> AdditionalKeys = new();
|
||||
|
||||
/// <summary>
|
||||
/// Index override for our iconsmooth layers. If null, layers will appear on top.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public int? Index;
|
||||
|
||||
/// <summary>
|
||||
/// Prepended to the RSI state.
|
||||
/// </summary>
|
||||
[DataField("base")]
|
||||
public string StateBase { get; set; } = string.Empty;
|
||||
|
||||
[DataField]
|
||||
public ProtoId<ShaderPrototype>? Shader;
|
||||
|
||||
/// <summary>
|
||||
/// Mode that controls how the icon should be selected.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public IconSmoothingMode Mode = IconSmoothingMode.Corners;
|
||||
|
||||
/// <summary>
|
||||
/// Used by <see cref="IconSmoothSystem"/> to reduce redundant updates.
|
||||
/// </summary>
|
||||
internal int UpdateGeneration { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Controls the mode with which icon smoothing is calculated.
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public enum IconSmoothingMode : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// Makes sprites of other grid-aligned entities like us connect.
|
||||
/// Each icon is made up of 4 corners, each of which can get a different state depending on
|
||||
/// adjacent entities clockwise, counter-clockwise and diagonal with the corner.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The system is based on Baystation12's smoothwalling, and thus will work with those.
|
||||
/// To use, set <c>base</c> equal to the prefix of the corner states in the sprite base RSI.
|
||||
/// Any objects with the same <c>key</c> will connect.
|
||||
/// </remarks>
|
||||
[RegisterComponent]
|
||||
public sealed partial class IconSmoothComponent : Component
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("enabled")]
|
||||
public bool Enabled = true;
|
||||
|
||||
public (EntityUid?, Vector2i)? LastPosition;
|
||||
|
||||
/// <summary>
|
||||
/// We will smooth with other objects with the same key.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("key")]
|
||||
public string? SmoothKey { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Additional keys to smooth with.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public List<string> AdditionalKeys = new();
|
||||
|
||||
/// <summary>
|
||||
/// Prepended to the RSI state.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("base")]
|
||||
public string StateBase { get; set; } = string.Empty;
|
||||
|
||||
[DataField("shader", customTypeSerializer:typeof(PrototypeIdSerializer<ShaderPrototype>))]
|
||||
public string? Shader;
|
||||
|
||||
/// <summary>
|
||||
/// Mode that controls how the icon should be selected.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("mode")]
|
||||
public IconSmoothingMode Mode = IconSmoothingMode.Corners;
|
||||
|
||||
/// <summary>
|
||||
/// Used by <see cref="IconSmoothSystem"/> to reduce redundant updates.
|
||||
/// </summary>
|
||||
internal int UpdateGeneration { get; set; }
|
||||
}
|
||||
Corners,
|
||||
|
||||
/// <summary>
|
||||
/// Controls the mode with which icon smoothing is calculated.
|
||||
/// There are 16 icons, only one of which is used at once.
|
||||
/// The icon selected is a bit field made up of the cardinal direction flags that have adjacent entities.
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public enum IconSmoothingMode : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// Each icon is made up of 4 corners, each of which can get a different state depending on
|
||||
/// adjacent entities clockwise, counter-clockwise and diagonal with the corner.
|
||||
/// </summary>
|
||||
Corners,
|
||||
CardinalFlags,
|
||||
|
||||
/// <summary>
|
||||
/// There are 16 icons, only one of which is used at once.
|
||||
/// The icon selected is a bit field made up of the cardinal direction flags that have adjacent entities.
|
||||
/// </summary>
|
||||
CardinalFlags,
|
||||
/// <summary>
|
||||
/// The icon represents a triangular sprite with only 2 states, representing South / East being occupied or not.
|
||||
/// </summary>
|
||||
Diagonal,
|
||||
|
||||
/// <summary>
|
||||
/// The icon represents a triangular sprite with only 2 states, representing South / East being occupied or not.
|
||||
/// </summary>
|
||||
Diagonal,
|
||||
|
||||
/// <summary>
|
||||
/// Where this component contributes to our neighbors being calculated but we do not update our own sprite.
|
||||
/// </summary>
|
||||
NoSprite,
|
||||
}
|
||||
/// <summary>
|
||||
/// Where this component contributes to our neighbors being calculated but we do not update our own sprite.
|
||||
/// </summary>
|
||||
NoSprite,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,13 +88,13 @@ namespace Content.Client.IconSmoothing
|
|||
_sprite.LayerMapRemove(sprite, CornerLayers.SW);
|
||||
|
||||
var state0 = $"{component.StateBase}0";
|
||||
_sprite.LayerMapSet(sprite, CornerLayers.SE, _sprite.AddRsiLayer(sprite, state0));
|
||||
_sprite.LayerMapSet(sprite, CornerLayers.SE, _sprite.AddRsiLayer(sprite, state0, index: component.Index));
|
||||
_sprite.LayerSetDirOffset(sprite, CornerLayers.SE, DirectionOffset.None);
|
||||
_sprite.LayerMapSet(sprite, CornerLayers.NE, _sprite.AddRsiLayer(sprite, state0));
|
||||
_sprite.LayerMapSet(sprite, CornerLayers.NE, _sprite.AddRsiLayer(sprite, state0, index: component.Index));
|
||||
_sprite.LayerSetDirOffset(sprite, CornerLayers.NE, DirectionOffset.CounterClockwise);
|
||||
_sprite.LayerMapSet(sprite, CornerLayers.NW, _sprite.AddRsiLayer(sprite, state0));
|
||||
_sprite.LayerMapSet(sprite, CornerLayers.NW, _sprite.AddRsiLayer(sprite, state0, index: component.Index));
|
||||
_sprite.LayerSetDirOffset(sprite, CornerLayers.NW, DirectionOffset.Flip);
|
||||
_sprite.LayerMapSet(sprite, CornerLayers.SW, _sprite.AddRsiLayer(sprite, state0));
|
||||
_sprite.LayerMapSet(sprite, CornerLayers.SW, _sprite.AddRsiLayer(sprite, state0, index: component.Index));
|
||||
_sprite.LayerSetDirOffset(sprite, CornerLayers.SW, DirectionOffset.Clockwise);
|
||||
}
|
||||
|
||||
|
|
@ -369,7 +369,6 @@ namespace Content.Client.IconSmoothing
|
|||
while (candidates.MoveNext(out var entity))
|
||||
{
|
||||
if (_iconSmoothQuery.TryGetComponent(entity, out var other) &&
|
||||
other.SmoothKey != null &&
|
||||
(other.SmoothKey == smooth.SmoothKey || smooth.AdditionalKeys.Contains(other.SmoothKey)) &&
|
||||
other.Enabled)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue