Add smoothing for diagonal walls (#13259)

This commit is contained in:
metalgearsloth
2023-01-27 15:03:42 +11:00
committed by GitHub
parent c58d0519d7
commit 9b0e0ad71d
5 changed files with 55 additions and 6 deletions

View File

@@ -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;