Add smoothing for diagonal walls (#13259)
This commit is contained in:
@@ -18,19 +18,19 @@ namespace Content.Client.IconSmoothing
|
||||
/// <summary>
|
||||
/// We will smooth with other objects with the same key.
|
||||
/// </summary>
|
||||
[DataField("key")]
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("key")]
|
||||
public string? SmoothKey { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Prepended to the RSI state.
|
||||
/// </summary>
|
||||
[DataField("base")]
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("base")]
|
||||
public string StateBase { get; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Mode that controls how the icon should be selected.
|
||||
/// </summary>
|
||||
[DataField("mode")]
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("mode")]
|
||||
public IconSmoothingMode Mode = IconSmoothingMode.Corners;
|
||||
|
||||
/// <summary>
|
||||
@@ -57,6 +57,11 @@ namespace Content.Client.IconSmoothing
|
||||
/// </summary>
|
||||
CardinalFlags,
|
||||
|
||||
/// <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>
|
||||
|
||||
@@ -129,12 +129,12 @@ namespace Content.Client.IconSmoothing
|
||||
}
|
||||
|
||||
// Yes, we updates ALL smoothing entities surrounding us even if they would never smooth with us.
|
||||
|
||||
DirtyEntities(grid.GetAnchoredEntities(pos + new Vector2i(1, 0)));
|
||||
DirtyEntities(grid.GetAnchoredEntities(pos + new Vector2i(-1, 0)));
|
||||
DirtyEntities(grid.GetAnchoredEntities(pos + new Vector2i(0, 1)));
|
||||
DirtyEntities(grid.GetAnchoredEntities(pos + new Vector2i(0, -1)));
|
||||
if (comp.Mode == IconSmoothingMode.Corners)
|
||||
|
||||
if (comp.Mode is IconSmoothingMode.Corners or IconSmoothingMode.NoSprite or IconSmoothingMode.Diagonal)
|
||||
{
|
||||
DirtyEntities(grid.GetAnchoredEntities(pos + new Vector2i(1, 1)));
|
||||
DirtyEntities(grid.GetAnchoredEntities(pos + new Vector2i(-1, -1)));
|
||||
@@ -205,11 +205,49 @@ namespace Content.Client.IconSmoothing
|
||||
case IconSmoothingMode.CardinalFlags:
|
||||
CalculateNewSpriteCardinal(grid, smooth, sprite, xform, smoothQuery);
|
||||
break;
|
||||
case IconSmoothingMode.Diagonal:
|
||||
CalculateNewSpriteDiagonal(grid, smooth, sprite, xform, smoothQuery);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
private void CalculateNewSpriteDiagonal(MapGridComponent? grid, IconSmoothComponent smooth,
|
||||
SpriteComponent sprite, TransformComponent xform, EntityQuery<IconSmoothComponent> smoothQuery)
|
||||
{
|
||||
if (grid == null)
|
||||
{
|
||||
sprite.LayerSetState(0, $"{smooth.StateBase}0");
|
||||
return;
|
||||
}
|
||||
|
||||
var neighbors = new Vector2[]
|
||||
{
|
||||
new(1, 0),
|
||||
new(1, -1),
|
||||
new(0, -1),
|
||||
};
|
||||
|
||||
var pos = grid.TileIndicesFor(xform.Coordinates);
|
||||
var rotation = xform.LocalRotation;
|
||||
var matching = true;
|
||||
|
||||
for (var i = 0; i < neighbors.Length; i++)
|
||||
{
|
||||
var neighbor = (Vector2i) rotation.RotateVec(neighbors[i]);
|
||||
matching = matching && MatchingEntity(smooth, grid.GetAnchoredEntities(pos + neighbor), smoothQuery);
|
||||
}
|
||||
|
||||
if (matching)
|
||||
{
|
||||
sprite.LayerSetState(0, $"{smooth.StateBase}1");
|
||||
return;
|
||||
}
|
||||
|
||||
sprite.LayerSetState(0, $"{smooth.StateBase}0");
|
||||
}
|
||||
|
||||
private void CalculateNewSpriteCardinal(MapGridComponent? grid, IconSmoothComponent smooth, SpriteComponent sprite, TransformComponent xform, EntityQuery<IconSmoothComponent> smoothQuery)
|
||||
{
|
||||
var dirs = CardinalConnectDirs.None;
|
||||
|
||||
@@ -588,9 +588,12 @@
|
||||
- type: Sprite
|
||||
netsync: false
|
||||
drawdepth: Walls
|
||||
# TODO: Icon smoothing support
|
||||
sprite: Structures/Walls/shuttle_diagonal.rsi
|
||||
state: state0
|
||||
- type: IconSmooth
|
||||
mode: Diagonal
|
||||
key: walls
|
||||
base: state
|
||||
- type: Icon
|
||||
sprite: Structures/Walls/shuttle_diagonal.rsi
|
||||
state: state0
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
"states": [
|
||||
{
|
||||
"name": "state0"
|
||||
},
|
||||
{
|
||||
"name": "state1"
|
||||
}
|
||||
]
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 5.7 KiB |
Reference in New Issue
Block a user