]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
randomize iconSmoothing (#28158)
authorEd <96445749+TheShuEd@users.noreply.github.com>
Fri, 19 Jul 2024 08:13:35 +0000 (11:13 +0300)
committerGitHub <noreply@github.com>
Fri, 19 Jul 2024 08:13:35 +0000 (18:13 +1000)
* randomize iconSmoothing

* Revert "randomize iconSmoothing"

This reverts commit 094356f975737c0af24ce39d849aec7852b9af6e.

* try 2

* trying work with client-server communication

* still dont work

* Tayrtahn good suggestion

* remove outdated code

* Fix!

* move data to Appearance

* Update RandomIconSmoothComponent.cs

16 files changed:
Content.Client/IconSmoothing/ClientRandomIconSmoothSystem.cs [new file with mode: 0644]
Content.Client/IconSmoothing/IconSmoothComponent.cs
Content.Client/IconSmoothing/IconSmoothSystem.cs
Content.Server/IconSmoothing/RandomIconSmoothSystem.cs [new file with mode: 0644]
Content.Shared/IconSmoothing/RandomIconSmoothComponent.cs [new file with mode: 0644]
Content.Shared/IconSmoothing/SharedRandomIconSmoothSystem.cs [new file with mode: 0644]
Resources/Prototypes/Entities/Structures/Walls/walls.yml
Resources/Textures/Structures/Walls/mining.rsi/meta.json
Resources/Textures/Structures/Walls/mining.rsi/miningB0.png [new file with mode: 0644]
Resources/Textures/Structures/Walls/mining.rsi/miningB1.png [new file with mode: 0644]
Resources/Textures/Structures/Walls/mining.rsi/miningB2.png [new file with mode: 0644]
Resources/Textures/Structures/Walls/mining.rsi/miningB3.png [new file with mode: 0644]
Resources/Textures/Structures/Walls/mining.rsi/miningB4.png [new file with mode: 0644]
Resources/Textures/Structures/Walls/mining.rsi/miningB5.png [new file with mode: 0644]
Resources/Textures/Structures/Walls/mining.rsi/miningB6.png [new file with mode: 0644]
Resources/Textures/Structures/Walls/mining.rsi/miningB7.png [new file with mode: 0644]

diff --git a/Content.Client/IconSmoothing/ClientRandomIconSmoothSystem.cs b/Content.Client/IconSmoothing/ClientRandomIconSmoothSystem.cs
new file mode 100644 (file)
index 0000000..73db9e1
--- /dev/null
@@ -0,0 +1,29 @@
+using Content.Shared.IconSmoothing;
+using Robust.Client.GameObjects;
+
+namespace Content.Client.IconSmoothing;
+
+public sealed class ClientRandomIconSmoothSystem : SharedRandomIconSmoothSystem
+{
+    [Dependency] private readonly IconSmoothSystem _iconSmooth = default!;
+    [Dependency] private readonly AppearanceSystem _appearance = default!;
+
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        SubscribeLocalEvent<RandomIconSmoothComponent, AppearanceChangeEvent>(OnAppearanceChange);
+    }
+
+    private void OnAppearanceChange(Entity<RandomIconSmoothComponent> ent, ref AppearanceChangeEvent args)
+    {
+        if (!TryComp<IconSmoothComponent>(ent, out var smooth))
+            return;
+
+        if (!_appearance.TryGetData<string>(ent, RandomIconSmoothState.State, out var state, args.Component))
+            return;
+
+        smooth.StateBase = state;
+        _iconSmooth.SetStateBase(ent, smooth, state);
+    }
+}
index 88b1f613cb7c8abbd4ee689e97bceaea102b4e97..040198529c751ff54274c236b2ae77c0f866673d 100644 (file)
@@ -30,7 +30,7 @@ namespace Content.Client.IconSmoothing
         ///     Prepended to the RSI state.
         /// </summary>
         [ViewVariables(VVAccess.ReadWrite), DataField("base")]
-        public string StateBase { get; private set; } = string.Empty;
+        public string StateBase { get; set; } = string.Empty;
 
         [DataField("shader", customTypeSerializer:typeof(PrototypeIdSerializer<ShaderPrototype>))]
         public string? Shader;
index 4b02560846505c2eb5e4550253443e63b8b458c8..11ca75bc824b5b9194ef95e6c7320b43cbe1e1d6 100644 (file)
@@ -55,6 +55,33 @@ namespace Content.Client.IconSmoothing
             if (component.Mode != IconSmoothingMode.Corners || !TryComp(uid, out SpriteComponent? sprite))
                 return;
 
+            SetCornerLayers(sprite, component);
+
+            if (component.Shader != null)
+            {
+                sprite.LayerSetShader(CornerLayers.SE, component.Shader);
+                sprite.LayerSetShader(CornerLayers.NE, component.Shader);
+                sprite.LayerSetShader(CornerLayers.NW, component.Shader);
+                sprite.LayerSetShader(CornerLayers.SW, component.Shader);
+            }
+        }
+
+        public void SetStateBase(EntityUid uid, IconSmoothComponent component, string newState)
+        {
+            if (!TryComp<SpriteComponent>(uid, out var sprite))
+                return;
+
+            component.StateBase = newState;
+            SetCornerLayers(sprite, component);
+        }
+
+        private void SetCornerLayers(SpriteComponent sprite, IconSmoothComponent component)
+        {
+            sprite.LayerMapRemove(CornerLayers.SE);
+            sprite.LayerMapRemove(CornerLayers.NE);
+            sprite.LayerMapRemove(CornerLayers.NW);
+            sprite.LayerMapRemove(CornerLayers.SW);
+
             var state0 = $"{component.StateBase}0";
             sprite.LayerMapSet(CornerLayers.SE, sprite.AddLayerState(state0));
             sprite.LayerSetDirOffset(CornerLayers.SE, DirectionOffset.None);
@@ -64,14 +91,6 @@ namespace Content.Client.IconSmoothing
             sprite.LayerSetDirOffset(CornerLayers.NW, DirectionOffset.Flip);
             sprite.LayerMapSet(CornerLayers.SW, sprite.AddLayerState(state0));
             sprite.LayerSetDirOffset(CornerLayers.SW, DirectionOffset.Clockwise);
-
-            if (component.Shader != null)
-            {
-                sprite.LayerSetShader(CornerLayers.SE, component.Shader);
-                sprite.LayerSetShader(CornerLayers.NE, component.Shader);
-                sprite.LayerSetShader(CornerLayers.NW, component.Shader);
-                sprite.LayerSetShader(CornerLayers.SW, component.Shader);
-            }
         }
 
         private void OnShutdown(EntityUid uid, IconSmoothComponent component, ComponentShutdown args)
diff --git a/Content.Server/IconSmoothing/RandomIconSmoothSystem.cs b/Content.Server/IconSmoothing/RandomIconSmoothSystem.cs
new file mode 100644 (file)
index 0000000..4ddfb17
--- /dev/null
@@ -0,0 +1,26 @@
+using Content.Shared.IconSmoothing;
+using Robust.Shared.Random;
+
+namespace Content.Server.IconSmoothing;
+
+public sealed partial class RandomIconSmoothSystem : SharedRandomIconSmoothSystem
+{
+    [Dependency] private readonly IRobustRandom _random = default!;
+    [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
+
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        SubscribeLocalEvent<RandomIconSmoothComponent, MapInitEvent>(OnMapInit);
+    }
+
+    private void OnMapInit(Entity<RandomIconSmoothComponent> ent, ref MapInitEvent args)
+    {
+        if (ent.Comp.RandomStates.Count == 0)
+            return;
+
+        var state = _random.Pick(ent.Comp.RandomStates);
+        _appearance.SetData(ent, RandomIconSmoothState.State, state);
+    }
+}
diff --git a/Content.Shared/IconSmoothing/RandomIconSmoothComponent.cs b/Content.Shared/IconSmoothing/RandomIconSmoothComponent.cs
new file mode 100644 (file)
index 0000000..6cdf167
--- /dev/null
@@ -0,0 +1,16 @@
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.IconSmoothing;
+
+/// <summary>
+/// Allow randomize StateBase of IconSmoothComponent for random visual variation
+/// </summary>
+[RegisterComponent, NetworkedComponent]
+public sealed partial class RandomIconSmoothComponent : Component
+{
+    /// <summary>
+    /// StateBase will be randomly selected from this list. Allows to randomize the visual.
+    /// </summary>
+    [DataField(required: true)]
+    public List<string> RandomStates = new();
+}
diff --git a/Content.Shared/IconSmoothing/SharedRandomIconSmoothSystem.cs b/Content.Shared/IconSmoothing/SharedRandomIconSmoothSystem.cs
new file mode 100644 (file)
index 0000000..5cb5299
--- /dev/null
@@ -0,0 +1,12 @@
+using Robust.Shared.Serialization;
+
+namespace Content.Shared.IconSmoothing;
+
+public abstract class SharedRandomIconSmoothSystem : EntitySystem
+{
+}
+[Serializable, NetSerializable]
+public enum RandomIconSmoothState : byte
+{
+    State
+}
index 7af998125551afee4fb15101cc7bfa8201b093f0..1ab770812a65ceeeef9e5e7410b3eb513eb44a8d 100644 (file)
   - type: IconSmooth
     key: walls
     base: mining
+  - type: RandomIconSmooth
+    randomStates:
+    - mining
+    - miningB
+  - type: Appearance
 
 - type: entity
   parent: WallShuttleDiagonal
index 4ce4691c5164a5867628b79aefce66e79b057da1..77f43229984bda3f1a89a6eaab20efd6173a7ff2 100644 (file)
@@ -7,40 +7,72 @@
     "y": 32
   },
   "states": [
-         {
+    {
       "name": "full"
     }, 
-         {
+    {
       "name": "mining0",
-           "directions": 4
+        "directions": 4
     },
-         {
+    {
       "name": "mining1",
-           "directions": 4
+        "directions": 4
     },
-         {
+    {
       "name": "mining2",
-           "directions": 4
+        "directions": 4
     },
-         {
+    {
       "name": "mining3",
-           "directions": 4
+        "directions": 4
     },
-         {
+    {
       "name": "mining4",
-           "directions": 4
+        "directions": 4
     },
-         {
+    {
       "name": "mining5",
-           "directions": 4
+        "directions": 4
     },
-         {
+    {
       "name": "mining6",
-           "directions": 4
+        "directions": 4
     },
-         {
+    {
       "name": "mining7",
-           "directions": 4
+        "directions": 4
+    }, 
+    {
+      "name": "miningB0",
+        "directions": 4
+    },
+    {
+      "name": "miningB1",
+        "directions": 4
+    },
+    {
+      "name": "miningB2",
+        "directions": 4
+    },
+    {
+      "name": "miningB3",
+        "directions": 4
+    },
+    {
+      "name": "miningB4",
+        "directions": 4
+    },
+    {
+      "name": "miningB5",
+        "directions": 4
+    },
+    {
+      "name": "miningB6",
+        "directions": 4
+    },
+    {
+      "name": "miningB7",
+        "directions": 4
     }
   ]
 }
diff --git a/Resources/Textures/Structures/Walls/mining.rsi/miningB0.png b/Resources/Textures/Structures/Walls/mining.rsi/miningB0.png
new file mode 100644 (file)
index 0000000..f65f066
Binary files /dev/null and b/Resources/Textures/Structures/Walls/mining.rsi/miningB0.png differ
diff --git a/Resources/Textures/Structures/Walls/mining.rsi/miningB1.png b/Resources/Textures/Structures/Walls/mining.rsi/miningB1.png
new file mode 100644 (file)
index 0000000..24c81aa
Binary files /dev/null and b/Resources/Textures/Structures/Walls/mining.rsi/miningB1.png differ
diff --git a/Resources/Textures/Structures/Walls/mining.rsi/miningB2.png b/Resources/Textures/Structures/Walls/mining.rsi/miningB2.png
new file mode 100644 (file)
index 0000000..f65f066
Binary files /dev/null and b/Resources/Textures/Structures/Walls/mining.rsi/miningB2.png differ
diff --git a/Resources/Textures/Structures/Walls/mining.rsi/miningB3.png b/Resources/Textures/Structures/Walls/mining.rsi/miningB3.png
new file mode 100644 (file)
index 0000000..24c81aa
Binary files /dev/null and b/Resources/Textures/Structures/Walls/mining.rsi/miningB3.png differ
diff --git a/Resources/Textures/Structures/Walls/mining.rsi/miningB4.png b/Resources/Textures/Structures/Walls/mining.rsi/miningB4.png
new file mode 100644 (file)
index 0000000..1412f00
Binary files /dev/null and b/Resources/Textures/Structures/Walls/mining.rsi/miningB4.png differ
diff --git a/Resources/Textures/Structures/Walls/mining.rsi/miningB5.png b/Resources/Textures/Structures/Walls/mining.rsi/miningB5.png
new file mode 100644 (file)
index 0000000..8bbef8c
Binary files /dev/null and b/Resources/Textures/Structures/Walls/mining.rsi/miningB5.png differ
diff --git a/Resources/Textures/Structures/Walls/mining.rsi/miningB6.png b/Resources/Textures/Structures/Walls/mining.rsi/miningB6.png
new file mode 100644 (file)
index 0000000..1412f00
Binary files /dev/null and b/Resources/Textures/Structures/Walls/mining.rsi/miningB6.png differ
diff --git a/Resources/Textures/Structures/Walls/mining.rsi/miningB7.png b/Resources/Textures/Structures/Walls/mining.rsi/miningB7.png
new file mode 100644 (file)
index 0000000..add9cdd
Binary files /dev/null and b/Resources/Textures/Structures/Walls/mining.rsi/miningB7.png differ