diff --git a/Content.Client/IconSmoothing/ClientRandomIconSmoothSystem.cs b/Content.Client/IconSmoothing/ClientRandomIconSmoothSystem.cs new file mode 100644 index 00000000000000..e9cffa67abb57b --- /dev/null +++ b/Content.Client/IconSmoothing/ClientRandomIconSmoothSystem.cs @@ -0,0 +1,23 @@ +using Content.Shared.IconSmoothing; + +namespace Content.Client.IconSmoothing; + +public sealed class ClientRandomIconSmoothSystem : SharedRandomIconSmoothSystem +{ + [Dependency] private readonly IconSmoothSystem _iconSmooth = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnAfterHandleState); + } + + private void OnAfterHandleState(Entity ent, ref AfterAutoHandleStateEvent args) + { + if (!TryComp(ent, out var smooth)) + return; + smooth.StateBase = ent.Comp.SelectedState; + _iconSmooth.SetStateBase(ent, smooth, ent.Comp.SelectedState); + } +} diff --git a/Content.Client/IconSmoothing/IconSmoothComponent.cs b/Content.Client/IconSmoothing/IconSmoothComponent.cs index 88b1f613cb7c8a..040198529c751f 100644 --- a/Content.Client/IconSmoothing/IconSmoothComponent.cs +++ b/Content.Client/IconSmoothing/IconSmoothComponent.cs @@ -30,7 +30,7 @@ public sealed partial class IconSmoothComponent : Component /// 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 4b02560846505c..11ca75bc824b5b 100644 --- a/Content.Client/IconSmoothing/IconSmoothSystem.cs +++ b/Content.Client/IconSmoothing/IconSmoothSystem.cs @@ -55,6 +55,33 @@ private void OnStartup(EntityUid uid, IconSmoothComponent component, ComponentSt 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 @@ private void OnStartup(EntityUid uid, IconSmoothComponent component, ComponentSt 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 00000000000000..fbf91337bcb063 --- /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!; + + 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); + ent.Comp.SelectedState = state; + Dirty(ent); + } +} diff --git a/Content.Shared/IconSmoothing/RandomIconSmoothComponent.cs b/Content.Shared/IconSmoothing/RandomIconSmoothComponent.cs new file mode 100644 index 00000000000000..1825aa228561e4 --- /dev/null +++ b/Content.Shared/IconSmoothing/RandomIconSmoothComponent.cs @@ -0,0 +1,22 @@ +using Robust.Shared.GameStates; + +namespace Content.Shared.IconSmoothing; + +/// +/// Allow randomize StateBase of IconSmoothComponent for random visual variation +/// +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)] +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(); + + /// + /// save information about the selected state on the server for synchronization between clients + /// + [DataField, AutoNetworkedField] + public string SelectedState = string.Empty; +} diff --git a/Content.Shared/IconSmoothing/SharedRandomIconSmoothSystem.cs b/Content.Shared/IconSmoothing/SharedRandomIconSmoothSystem.cs new file mode 100644 index 00000000000000..c65d6942923011 --- /dev/null +++ b/Content.Shared/IconSmoothing/SharedRandomIconSmoothSystem.cs @@ -0,0 +1,5 @@ +namespace Content.Shared.IconSmoothing; + +public abstract class SharedRandomIconSmoothSystem : EntitySystem +{ +} diff --git a/Resources/Prototypes/Entities/Structures/Walls/walls.yml b/Resources/Prototypes/Entities/Structures/Walls/walls.yml index 7af998125551af..b528da39efeaa2 100644 --- a/Resources/Prototypes/Entities/Structures/Walls/walls.yml +++ b/Resources/Prototypes/Entities/Structures/Walls/walls.yml @@ -1109,6 +1109,10 @@ - type: IconSmooth key: walls base: mining + - type: RandomIconSmooth + randomStates: + - mining + - miningB - 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 4ce4691c5164a5..77f43229984bda 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 00000000000000..f65f066b65aa26 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 00000000000000..24c81aa87799bc 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 00000000000000..f65f066b65aa26 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 00000000000000..24c81aa87799bc 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 00000000000000..1412f002696455 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 00000000000000..8bbef8ca971727 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 00000000000000..1412f002696455 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 00000000000000..add9cddf83f671 Binary files /dev/null and b/Resources/Textures/Structures/Walls/mining.rsi/miningB7.png differ