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
This commit is contained in:
Ed
2024-07-19 11:13:35 +03:00
committed by GitHub
parent 6005a9f4cb
commit d6e0114126
16 changed files with 165 additions and 26 deletions

View 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);
}
}

View 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;

View 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)

View 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);
}
}

View 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();
}

View 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
}

View File

@@ -1109,6 +1109,11 @@
- type: IconSmooth
key: walls
base: mining
- type: RandomIconSmooth
randomStates:
- mining
- miningB
- type: Appearance
- type: entity
parent: WallShuttleDiagonal

View 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
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 962 B