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
29
Content.Client/IconSmoothing/ClientRandomIconSmoothSystem.cs
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,7 +30,7 @@ namespace Content.Client.IconSmoothing
|
|||||||
/// Prepended to the RSI state.
|
/// Prepended to the RSI state.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ViewVariables(VVAccess.ReadWrite), DataField("base")]
|
[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>))]
|
[DataField("shader", customTypeSerializer:typeof(PrototypeIdSerializer<ShaderPrototype>))]
|
||||||
public string? Shader;
|
public string? Shader;
|
||||||
|
|||||||
@@ -55,6 +55,33 @@ namespace Content.Client.IconSmoothing
|
|||||||
if (component.Mode != IconSmoothingMode.Corners || !TryComp(uid, out SpriteComponent? sprite))
|
if (component.Mode != IconSmoothingMode.Corners || !TryComp(uid, out SpriteComponent? sprite))
|
||||||
return;
|
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";
|
var state0 = $"{component.StateBase}0";
|
||||||
sprite.LayerMapSet(CornerLayers.SE, sprite.AddLayerState(state0));
|
sprite.LayerMapSet(CornerLayers.SE, sprite.AddLayerState(state0));
|
||||||
sprite.LayerSetDirOffset(CornerLayers.SE, DirectionOffset.None);
|
sprite.LayerSetDirOffset(CornerLayers.SE, DirectionOffset.None);
|
||||||
@@ -64,14 +91,6 @@ namespace Content.Client.IconSmoothing
|
|||||||
sprite.LayerSetDirOffset(CornerLayers.NW, DirectionOffset.Flip);
|
sprite.LayerSetDirOffset(CornerLayers.NW, DirectionOffset.Flip);
|
||||||
sprite.LayerMapSet(CornerLayers.SW, sprite.AddLayerState(state0));
|
sprite.LayerMapSet(CornerLayers.SW, sprite.AddLayerState(state0));
|
||||||
sprite.LayerSetDirOffset(CornerLayers.SW, DirectionOffset.Clockwise);
|
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)
|
private void OnShutdown(EntityUid uid, IconSmoothComponent component, ComponentShutdown args)
|
||||||
|
|||||||
26
Content.Server/IconSmoothing/RandomIconSmoothSystem.cs
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
16
Content.Shared/IconSmoothing/RandomIconSmoothComponent.cs
Normal file
@@ -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();
|
||||||
|
}
|
||||||
12
Content.Shared/IconSmoothing/SharedRandomIconSmoothSystem.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using Robust.Shared.Serialization;
|
||||||
|
|
||||||
|
namespace Content.Shared.IconSmoothing;
|
||||||
|
|
||||||
|
public abstract class SharedRandomIconSmoothSystem : EntitySystem
|
||||||
|
{
|
||||||
|
}
|
||||||
|
[Serializable, NetSerializable]
|
||||||
|
public enum RandomIconSmoothState : byte
|
||||||
|
{
|
||||||
|
State
|
||||||
|
}
|
||||||
@@ -1109,6 +1109,11 @@
|
|||||||
- type: IconSmooth
|
- type: IconSmooth
|
||||||
key: walls
|
key: walls
|
||||||
base: mining
|
base: mining
|
||||||
|
- type: RandomIconSmooth
|
||||||
|
randomStates:
|
||||||
|
- mining
|
||||||
|
- miningB
|
||||||
|
- type: Appearance
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
parent: WallShuttleDiagonal
|
parent: WallShuttleDiagonal
|
||||||
|
|||||||
@@ -41,6 +41,38 @@
|
|||||||
{
|
{
|
||||||
"name": "mining7",
|
"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
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
Resources/Textures/Structures/Walls/mining.rsi/miningB0.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
Resources/Textures/Structures/Walls/mining.rsi/miningB1.png
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
Resources/Textures/Structures/Walls/mining.rsi/miningB2.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
Resources/Textures/Structures/Walls/mining.rsi/miningB3.png
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
Resources/Textures/Structures/Walls/mining.rsi/miningB4.png
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
Resources/Textures/Structures/Walls/mining.rsi/miningB5.png
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
Resources/Textures/Structures/Walls/mining.rsi/miningB6.png
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
Resources/Textures/Structures/Walls/mining.rsi/miningB7.png
Normal file
|
After Width: | Height: | Size: 962 B |