Resolves SmokeVisualizer is Obsolete (#13881)

This commit is contained in:
TemporalOroboros
2023-02-03 11:43:53 -08:00
committed by GitHub
parent 0edbc21ce8
commit a8fd975edd
4 changed files with 33 additions and 30 deletions

View File

@@ -1,28 +0,0 @@
using Content.Shared.Smoking;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
namespace Content.Client.Chemistry.Visualizers
{
[UsedImplicitly]
public sealed class SmokeVisualizer : AppearanceVisualizer
{
[Obsolete("Subscribe to AppearanceChangeEvent instead.")]
public override void OnChangeData(AppearanceComponent component)
{
base.OnChangeData(component);
var entities = IoCManager.Resolve<IEntityManager>();
if (component.TryGetData<Color>(SmokeVisuals.Color, out var color))
{
if (entities.TryGetComponent(component.Owner, out SpriteComponent? sprite))
{
sprite.Color = color;
}
}
}
}
}

View File

@@ -0,0 +1,22 @@
using Content.Shared.Smoking;
using Robust.Client.GameObjects;
namespace Content.Client.Chemistry.Visualizers;
/// <summary>
/// Ensures entities with <see cref="SmokeVisualsComponent"/> have a color corresponding with their contained reagents.
/// </summary>
public sealed class SmokeVisualizerSystem : VisualizerSystem<SmokeVisualsComponent>
{
/// <summary>
/// Syncs the color of the smoke with the color of its contained reagents.
/// </summary>
protected override void OnAppearanceChange(EntityUid uid, SmokeVisualsComponent comp, ref AppearanceChangeEvent args)
{
if (args.Sprite == null)
return;
if(!AppearanceSystem.TryGetData<Color>(uid, SmokeVisuals.Color, out var color))
return;
args.Sprite.Color = color;
}
}

View File

@@ -0,0 +1,10 @@
namespace Content.Client.Chemistry.Visualizers;
/// <summary>
/// A component that changes color to match its contained reagents.
/// Managed by <see cref="SmokeVisualizerSystem"/>.
/// Only functions with smoke at the moment.
/// </summary>
[RegisterComponent]
[Access(typeof(SmokeVisualizerSystem))]
public sealed class SmokeVisualsComponent : Component {}

View File

@@ -8,8 +8,7 @@
sprite: Effects/chemsmoke.rsi sprite: Effects/chemsmoke.rsi
state: chemsmoke state: chemsmoke
- type: Appearance - type: Appearance
visuals: - type: SmokeVisuals
- type: SmokeVisualizer
- type: Occluder - type: Occluder
- type: Transform - type: Transform
anchored: true anchored: true