Visualizer systems update (#8203)
* optimize appearance updating for subfloor entities * sprite event args * a * stop double appearance update.
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
using Content.Shared.Wires;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Client.Power
|
||||
{
|
||||
[DataDefinition]
|
||||
public sealed class CableVisualizer : AppearanceVisualizer
|
||||
{
|
||||
[DataField("base")]
|
||||
public string? StateBase;
|
||||
|
||||
public override void OnChangeData(AppearanceComponent component)
|
||||
{
|
||||
base.OnChangeData(component);
|
||||
|
||||
var entities = IoCManager.Resolve<IEntityManager>();
|
||||
if (!entities.TryGetComponent(component.Owner, out SpriteComponent? sprite))
|
||||
return;
|
||||
|
||||
if (!component.TryGetData(WireVisVisuals.ConnectedMask, out WireVisDirFlags mask))
|
||||
mask = WireVisDirFlags.None;
|
||||
|
||||
sprite.LayerSetState(0, $"{StateBase}{(int) mask}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace Content.Client.Power.Visualizers;
|
||||
|
||||
[RegisterComponent]
|
||||
public sealed class CableVisualizerComponent : Component
|
||||
{
|
||||
[DataField("statePrefix")]
|
||||
public string? StatePrefix;
|
||||
}
|
||||
38
Content.Client/Power/Visualizers/CableVisualizerSystem.cs
Normal file
38
Content.Client/Power/Visualizers/CableVisualizerSystem.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Content.Client.SubFloor;
|
||||
using Content.Shared.SubFloor;
|
||||
using Content.Shared.Wires;
|
||||
using Robust.Client.GameObjects;
|
||||
|
||||
namespace Content.Client.Power.Visualizers;
|
||||
|
||||
public sealed partial class CableVisualizerSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<CableVisualizerComponent, AppearanceChangeEvent>(OnAppearanceChanged, after: new[] { typeof(SubFloorHideSystem) });
|
||||
}
|
||||
|
||||
private void OnAppearanceChanged(EntityUid uid, CableVisualizerComponent component, ref AppearanceChangeEvent args)
|
||||
{
|
||||
if (args.Sprite == null)
|
||||
return;
|
||||
|
||||
if (args.Component.TryGetData(SubFloorVisuals.Covered, out bool isUnderCover)
|
||||
&& isUnderCover
|
||||
&& args.Component.TryGetData(SubFloorVisuals.ScannerRevealed, out bool revealed)
|
||||
&& !revealed)
|
||||
{
|
||||
// This entity is below a floor and is not even visible to the user -> don't bother updating sprite data.
|
||||
// Note that if the subfloor visuals change, then another AppearanceChangeEvent will get triggered.
|
||||
return;
|
||||
}
|
||||
|
||||
if (!args.Component.TryGetData(WireVisVisuals.ConnectedMask, out WireVisDirFlags mask))
|
||||
mask = WireVisDirFlags.None;
|
||||
|
||||
args.Sprite.LayerSetState(0, $"{component.StatePrefix}{(int) mask}");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user