From: Ed <96445749+TheShuEd@users.noreply.github.com> Date: Fri, 19 Jul 2024 08:13:35 +0000 (+0300) Subject: randomize iconSmoothing (#28158) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=d6e0114126f778c298763d05fa59ee62c28f595a;p=space-station-14.git randomize iconSmoothing (#28158) * 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 --- diff --git a/Content.Client/IconSmoothing/ClientRandomIconSmoothSystem.cs b/Content.Client/IconSmoothing/ClientRandomIconSmoothSystem.cs new file mode 100644 index 0000000000..73db9e1ab9 --- /dev/null +++ b/Content.Client/IconSmoothing/ClientRandomIconSmoothSystem.cs @@ -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(OnAppearanceChange); + } + + private void OnAppearanceChange(Entity ent, ref AppearanceChangeEvent args) + { + if (!TryComp(ent, out var smooth)) + return; + + if (!_appearance.TryGetData(ent, RandomIconSmoothState.State, out var state, args.Component)) + return; + + smooth.StateBase = state; + _iconSmooth.SetStateBase(ent, smooth, state); + } +} diff --git a/Content.Client/IconSmoothing/IconSmoothComponent.cs b/Content.Client/IconSmoothing/IconSmoothComponent.cs index 88b1f613cb..040198529c 100644 --- a/Content.Client/IconSmoothing/IconSmoothComponent.cs +++ b/Content.Client/IconSmoothing/IconSmoothComponent.cs @@ -30,7 +30,7 @@ namespace Content.Client.IconSmoothing /// Prepended to the RSI state. /// [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))] public string? Shader; diff --git a/Content.Client/IconSmoothing/IconSmoothSystem.cs b/Content.Client/IconSmoothing/IconSmoothSystem.cs index 4b02560846..11ca75bc82 100644 --- a/Content.Client/IconSmoothing/IconSmoothSystem.cs +++ b/Content.Client/IconSmoothing/IconSmoothSystem.cs @@ -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(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 index 0000000000..4ddfb17ac8 --- /dev/null +++ b/Content.Server/IconSmoothing/RandomIconSmoothSystem.cs @@ -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(OnMapInit); + } + + private void OnMapInit(Entity 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 index 0000000000..6cdf167b29 --- /dev/null +++ b/Content.Shared/IconSmoothing/RandomIconSmoothComponent.cs @@ -0,0 +1,16 @@ +using Robust.Shared.GameStates; + +namespace Content.Shared.IconSmoothing; + +/// +/// Allow randomize StateBase of IconSmoothComponent for random visual variation +/// +[RegisterComponent, NetworkedComponent] +public sealed partial class RandomIconSmoothComponent : Component +{ + /// + /// StateBase will be randomly selected from this list. Allows to randomize the visual. + /// + [DataField(required: true)] + public List RandomStates = new(); +} diff --git a/Content.Shared/IconSmoothing/SharedRandomIconSmoothSystem.cs b/Content.Shared/IconSmoothing/SharedRandomIconSmoothSystem.cs new file mode 100644 index 0000000000..5cb5299858 --- /dev/null +++ b/Content.Shared/IconSmoothing/SharedRandomIconSmoothSystem.cs @@ -0,0 +1,12 @@ +using Robust.Shared.Serialization; + +namespace Content.Shared.IconSmoothing; + +public abstract class SharedRandomIconSmoothSystem : EntitySystem +{ +} +[Serializable, NetSerializable] +public enum RandomIconSmoothState : byte +{ + State +} diff --git a/Resources/Prototypes/Entities/Structures/Walls/walls.yml b/Resources/Prototypes/Entities/Structures/Walls/walls.yml index 7af9981255..1ab770812a 100644 --- a/Resources/Prototypes/Entities/Structures/Walls/walls.yml +++ b/Resources/Prototypes/Entities/Structures/Walls/walls.yml @@ -1109,6 +1109,11 @@ - type: IconSmooth key: walls base: mining + - type: RandomIconSmooth + randomStates: + - mining + - miningB + - type: Appearance - type: entity parent: WallShuttleDiagonal diff --git a/Resources/Textures/Structures/Walls/mining.rsi/meta.json b/Resources/Textures/Structures/Walls/mining.rsi/meta.json index 4ce4691c51..77f4322998 100644 --- a/Resources/Textures/Structures/Walls/mining.rsi/meta.json +++ b/Resources/Textures/Structures/Walls/mining.rsi/meta.json @@ -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 index 0000000000..f65f066b65 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 index 0000000000..24c81aa877 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 index 0000000000..f65f066b65 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 index 0000000000..24c81aa877 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 index 0000000000..1412f00269 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 index 0000000000..8bbef8ca97 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 index 0000000000..1412f00269 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 index 0000000000..add9cddf83 Binary files /dev/null and b/Resources/Textures/Structures/Walls/mining.rsi/miningB7.png differ