From 9b0e0ad71d98c4b83710b2c8e0c9ae03e44c27a8 Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Fri, 27 Jan 2023 15:03:42 +1100 Subject: [PATCH] Add smoothing for diagonal walls (#13259) --- .../IconSmoothing/IconSmoothComponent.cs | 11 +++-- .../IconSmoothing/IconSmoothSystem.cs | 42 +++++++++++++++++- .../Entities/Structures/Walls/walls.yml | 5 ++- .../Walls/shuttle_diagonal.rsi/meta.json | 3 ++ .../Walls/shuttle_diagonal.rsi/state1.png | Bin 0 -> 5804 bytes 5 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 Resources/Textures/Structures/Walls/shuttle_diagonal.rsi/state1.png diff --git a/Content.Client/IconSmoothing/IconSmoothComponent.cs b/Content.Client/IconSmoothing/IconSmoothComponent.cs index c4b6e25ec6..bc7667d222 100644 --- a/Content.Client/IconSmoothing/IconSmoothComponent.cs +++ b/Content.Client/IconSmoothing/IconSmoothComponent.cs @@ -18,19 +18,19 @@ namespace Content.Client.IconSmoothing /// /// We will smooth with other objects with the same key. /// - [DataField("key")] + [ViewVariables(VVAccess.ReadWrite), DataField("key")] public string? SmoothKey { get; } /// /// Prepended to the RSI state. /// - [DataField("base")] + [ViewVariables(VVAccess.ReadWrite), DataField("base")] public string StateBase { get; } = string.Empty; /// /// Mode that controls how the icon should be selected. /// - [DataField("mode")] + [ViewVariables(VVAccess.ReadWrite), DataField("mode")] public IconSmoothingMode Mode = IconSmoothingMode.Corners; /// @@ -57,6 +57,11 @@ namespace Content.Client.IconSmoothing /// CardinalFlags, + /// + /// The icon represents a triangular sprite with only 2 states, representing South / East being occupied or not. + /// + Diagonal, + /// /// Where this component contributes to our neighbors being calculated but we do not update our own sprite. /// diff --git a/Content.Client/IconSmoothing/IconSmoothSystem.cs b/Content.Client/IconSmoothing/IconSmoothSystem.cs index d1cc36becd..2206821303 100644 --- a/Content.Client/IconSmoothing/IconSmoothSystem.cs +++ b/Content.Client/IconSmoothing/IconSmoothSystem.cs @@ -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 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 smoothQuery) { var dirs = CardinalConnectDirs.None; diff --git a/Resources/Prototypes/Entities/Structures/Walls/walls.yml b/Resources/Prototypes/Entities/Structures/Walls/walls.yml index fdb30ab809..3c7c63dd88 100644 --- a/Resources/Prototypes/Entities/Structures/Walls/walls.yml +++ b/Resources/Prototypes/Entities/Structures/Walls/walls.yml @@ -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 diff --git a/Resources/Textures/Structures/Walls/shuttle_diagonal.rsi/meta.json b/Resources/Textures/Structures/Walls/shuttle_diagonal.rsi/meta.json index d031322d2d..bfe6cd74ef 100644 --- a/Resources/Textures/Structures/Walls/shuttle_diagonal.rsi/meta.json +++ b/Resources/Textures/Structures/Walls/shuttle_diagonal.rsi/meta.json @@ -9,6 +9,9 @@ "states": [ { "name": "state0" + }, + { + "name": "state1" } ] } \ No newline at end of file diff --git a/Resources/Textures/Structures/Walls/shuttle_diagonal.rsi/state1.png b/Resources/Textures/Structures/Walls/shuttle_diagonal.rsi/state1.png new file mode 100644 index 0000000000000000000000000000000000000000..127a0ce55f80ac565bf1e8377e7be901668c1852 GIT binary patch literal 5804 zcmeHLXIK;I7M_4~P$`0-Kny6Lq!J(rpp=B(q-N1oCdniONHGb7Vh|A(ToeIU6cJg( z3RqYRhzJM>wgr|2L9qc=xFQzH+U^9<)#u(nKF_`X%#)eSeCM3^ob#UZee+E+1N}X; z)Q!{u0MPRCqz1viNck~K5k7AW;j{pNa$HgfT@nOJkwTGx&5ebSl0+edgc7)H07$rf zh#pfgV5#}O&1y{59cj|?a8j1M$?43%NRruyEz z6-UQadPm-NcDg2WEcCtVMmE1%)7p^~Ij#Uz$E6qcAJm8|KX;(0^sTMv^)vohew|tS zP?l_Ahp^kYD$nOSV6m37+NI@$gBLdHz`FC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