Add smoothing for diagonal walls (#13259)
This commit is contained in:
@@ -18,19 +18,19 @@ namespace Content.Client.IconSmoothing
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// We will smooth with other objects with the same key.
|
/// We will smooth with other objects with the same key.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("key")]
|
[ViewVariables(VVAccess.ReadWrite), DataField("key")]
|
||||||
public string? SmoothKey { get; }
|
public string? SmoothKey { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Prepended to the RSI state.
|
/// Prepended to the RSI state.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("base")]
|
[ViewVariables(VVAccess.ReadWrite), DataField("base")]
|
||||||
public string StateBase { get; } = string.Empty;
|
public string StateBase { get; } = string.Empty;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Mode that controls how the icon should be selected.
|
/// Mode that controls how the icon should be selected.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("mode")]
|
[ViewVariables(VVAccess.ReadWrite), DataField("mode")]
|
||||||
public IconSmoothingMode Mode = IconSmoothingMode.Corners;
|
public IconSmoothingMode Mode = IconSmoothingMode.Corners;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -57,6 +57,11 @@ namespace Content.Client.IconSmoothing
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
CardinalFlags,
|
CardinalFlags,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The icon represents a triangular sprite with only 2 states, representing South / East being occupied or not.
|
||||||
|
/// </summary>
|
||||||
|
Diagonal,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Where this component contributes to our neighbors being calculated but we do not update our own sprite.
|
/// Where this component contributes to our neighbors being calculated but we do not update our own sprite.
|
||||||
/// </summary>
|
/// </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.
|
// 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(-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)));
|
||||||
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)));
|
||||||
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:
|
case IconSmoothingMode.CardinalFlags:
|
||||||
CalculateNewSpriteCardinal(grid, smooth, sprite, xform, smoothQuery);
|
CalculateNewSpriteCardinal(grid, smooth, sprite, xform, smoothQuery);
|
||||||
break;
|
break;
|
||||||
|
case IconSmoothingMode.Diagonal:
|
||||||
|
CalculateNewSpriteDiagonal(grid, smooth, sprite, xform, smoothQuery);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException();
|
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)
|
private void CalculateNewSpriteCardinal(MapGridComponent? grid, IconSmoothComponent smooth, SpriteComponent sprite, TransformComponent xform, EntityQuery<IconSmoothComponent> smoothQuery)
|
||||||
{
|
{
|
||||||
var dirs = CardinalConnectDirs.None;
|
var dirs = CardinalConnectDirs.None;
|
||||||
|
|||||||
@@ -588,9 +588,12 @@
|
|||||||
- type: Sprite
|
- type: Sprite
|
||||||
netsync: false
|
netsync: false
|
||||||
drawdepth: Walls
|
drawdepth: Walls
|
||||||
# TODO: Icon smoothing support
|
|
||||||
sprite: Structures/Walls/shuttle_diagonal.rsi
|
sprite: Structures/Walls/shuttle_diagonal.rsi
|
||||||
state: state0
|
state: state0
|
||||||
|
- type: IconSmooth
|
||||||
|
mode: Diagonal
|
||||||
|
key: walls
|
||||||
|
base: state
|
||||||
- type: Icon
|
- type: Icon
|
||||||
sprite: Structures/Walls/shuttle_diagonal.rsi
|
sprite: Structures/Walls/shuttle_diagonal.rsi
|
||||||
state: state0
|
state: state0
|
||||||
|
|||||||
@@ -9,6 +9,9 @@
|
|||||||
"states": [
|
"states": [
|
||||||
{
|
{
|
||||||
"name": "state0"
|
"name": "state0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "state1"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 5.7 KiB |
Reference in New Issue
Block a user