Resolves ExpendableLightVisualizer is Obsolete (#13888)

This commit is contained in:
TemporalOroboros
2023-05-01 08:03:26 -07:00
committed by GitHub
parent 43042b0c1a
commit 750032b002
6 changed files with 147 additions and 159 deletions

View File

@@ -1,14 +1,55 @@
using Content.Client.Light.EntitySystems;
using Content.Shared.Light.Component;
using Robust.Shared.Audio;
namespace Content.Client.Light.Components
namespace Content.Client.Light.Components;
/// <summary>
/// Component that represents a handheld expendable light which can be activated and eventually dies over time.
/// </summary>
[RegisterComponent]
public sealed class ExpendableLightComponent : SharedExpendableLightComponent
{
/// <summary>
/// Component that represents a handheld expendable light which can be activated and eventually dies over time.
/// The icon state used by expendable lights when the they have been completely expended.
/// </summary>
[RegisterComponent]
public sealed class ExpendableLightComponent : SharedExpendableLightComponent
{
public IPlayingAudioStream? PlayingStream { get; set; }
}
[DataField("iconStateSpent")]
public string? IconStateSpent;
/// <summary>
/// The icon state used by expendable lights while they are lit.
/// </summary>
[DataField("iconStateLit")]
public string? IconStateLit;
/// <summary>
/// The sprite layer shader used while the expendable light is lit.
/// </summary>
[DataField("spriteShaderLit")]
public string? SpriteShaderLit = null;
/// <summary>
/// The sprite layer shader used after the expendable light has burnt out.
/// </summary>
[DataField("spriteShaderSpent")]
public string? SpriteShaderSpent = null;
/// <summary>
/// The sprite layer shader used after the expendable light has burnt out.
/// </summary>
[DataField("glowColorLit")]
public Color? GlowColorLit = null;
/// <summary>
/// The sound that plays when the expendable light is lit.
/// </summary>
[Access(typeof(ExpendableLightSystem))]
public IPlayingAudioStream? PlayingStream;
}
public enum ExpendableLightVisualLayers : byte
{
Base = 0,
Glow = 1,
Overlay = 2,
}

View File

@@ -1,9 +1,15 @@
using Content.Client.Light.Components;
using Content.Shared.Light.Component;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
namespace Content.Client.Light.EntitySystems;
public sealed class ExpendableLightSystem : EntitySystem
public sealed class ExpendableLightSystem : VisualizerSystem<ExpendableLightComponent>
{
[Dependency] private readonly PointLightSystem _pointLightSystem = default!;
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
public override void Initialize()
{
base.Initialize();
@@ -15,4 +21,71 @@ public sealed class ExpendableLightSystem : EntitySystem
{
component.PlayingStream?.Stop();
}
protected override void OnAppearanceChange(EntityUid uid, ExpendableLightComponent comp, ref AppearanceChangeEvent args)
{
if (args.Sprite == null)
return;
if (AppearanceSystem.TryGetData<string>(uid, ExpendableLightVisuals.Behavior, out var lightBehaviourID, args.Component)
&& TryComp<LightBehaviourComponent>(uid, out var lightBehaviour))
{
lightBehaviour.StopLightBehaviour();
if (!string.IsNullOrEmpty(lightBehaviourID))
{
lightBehaviour.StartLightBehaviour(lightBehaviourID);
}
else if (TryComp<PointLightComponent>(uid, out var light))
{
_pointLightSystem.SetEnabled(uid, false, light);
}
}
if (!AppearanceSystem.TryGetData<ExpendableLightState>(uid, ExpendableLightVisuals.State, out var state, args.Component))
return;
switch (state)
{
case ExpendableLightState.Lit:
comp.PlayingStream?.Stop();
comp.PlayingStream = _audioSystem.PlayPvs(
comp.LoopedSound,
uid,
SharedExpendableLightComponent.LoopedSoundParams
);
if (args.Sprite.LayerMapTryGet(ExpendableLightVisualLayers.Overlay, out var layerIdx, true))
{
if (!string.IsNullOrWhiteSpace(comp.IconStateLit))
args.Sprite.LayerSetState(layerIdx, comp.IconStateLit);
if (!string.IsNullOrWhiteSpace(comp.SpriteShaderLit))
args.Sprite.LayerSetShader(layerIdx, comp.SpriteShaderLit);
else
args.Sprite.LayerSetShader(layerIdx, null, null);
if (comp.GlowColorLit.HasValue)
args.Sprite.LayerSetColor(layerIdx, comp.GlowColorLit.Value);
args.Sprite.LayerSetVisible(layerIdx, true);
}
if (comp.GlowColorLit.HasValue)
args.Sprite.LayerSetColor(ExpendableLightVisualLayers.Glow, comp.GlowColorLit.Value);
args.Sprite.LayerSetVisible(ExpendableLightVisualLayers.Glow, true);
break;
case ExpendableLightState.Dead:
comp.PlayingStream?.Stop();
if (args.Sprite.LayerMapTryGet(ExpendableLightVisualLayers.Overlay, out layerIdx, true))
{
if (!string.IsNullOrWhiteSpace(comp.IconStateSpent))
args.Sprite.LayerSetState(layerIdx, comp.IconStateSpent);
if (!string.IsNullOrWhiteSpace(comp.SpriteShaderSpent))
args.Sprite.LayerSetShader(layerIdx, comp.SpriteShaderSpent);
else
args.Sprite.LayerSetShader(layerIdx, null, null);
}
args.Sprite.LayerSetVisible(ExpendableLightVisualLayers.Glow, false);
break;
}
}
}

View File

@@ -1,80 +0,0 @@
using Content.Client.Light.Components;
using Content.Shared.Light.Component;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
namespace Content.Client.Light.Visualizers
{
[UsedImplicitly]
public sealed class ExpendableLightVisualizer : AppearanceVisualizer
{
[DataField("iconStateSpent")]
public string? IconStateSpent { get; set; }
[DataField("iconStateOn")]
public string? IconStateLit { get; set; }
[Obsolete("Subscribe to AppearanceChangeEvent instead.")]
public override void OnChangeData(AppearanceComponent component)
{
base.OnChangeData(component);
var entities = IoCManager.Resolve<IEntityManager>();
if (!entities.TryGetComponent(component.Owner, out ExpendableLightComponent? expendableLight))
return;
if (!entities.TryGetComponent(component.Owner, out SpriteComponent? sprite))
return;
if (component.TryGetData(ExpendableLightVisuals.Behavior, out string lightBehaviourID))
{
if (entities.TryGetComponent(component.Owner, out LightBehaviourComponent? lightBehaviour))
{
lightBehaviour.StopLightBehaviour();
if (lightBehaviourID != string.Empty)
{
lightBehaviour.StartLightBehaviour(lightBehaviourID);
}
else if (entities.TryGetComponent(component.Owner, out PointLightComponent? light))
{
light.Enabled = false;
}
}
}
if (!component.TryGetData(ExpendableLightVisuals.State, out ExpendableLightState state))
return;
switch (state)
{
case ExpendableLightState.Lit:
expendableLight.PlayingStream?.Stop();
expendableLight.PlayingStream = entities.EntitySysManager.GetEntitySystem<SharedAudioSystem>().PlayPvs(
expendableLight.LoopedSound,
expendableLight.Owner,
SharedExpendableLightComponent.LoopedSoundParams);
if (!string.IsNullOrWhiteSpace(IconStateLit))
{
sprite.LayerSetState(2, IconStateLit);
sprite.LayerSetShader(2, "shaded");
}
sprite.LayerSetVisible(1, true);
break;
case ExpendableLightState.Dead:
expendableLight.PlayingStream?.Stop();
if (!string.IsNullOrWhiteSpace(IconStateSpent))
{
sprite.LayerSetState(0, IconStateSpent);
sprite.LayerSetShader(0, "shaded");
}
sprite.LayerSetVisible(1, false);
break;
}
}
}
}