2022-06-04 19:17:48 +12:00
|
|
|
using Content.Client.Light.Components;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Light.Component;
|
2020-09-03 16:02:40 -04:00
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
using Robust.Client.GameObjects;
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Client.Light.Visualizers
|
2020-09-03 16:02:40 -04:00
|
|
|
{
|
|
|
|
|
[UsedImplicitly]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class ExpendableLightVisualizer : AppearanceVisualizer
|
2020-09-03 16:02:40 -04:00
|
|
|
{
|
2023-01-17 22:29:35 +13:00
|
|
|
[DataField("iconStateSpent")]
|
|
|
|
|
public string? IconStateSpent { get; set; }
|
|
|
|
|
|
|
|
|
|
[DataField("iconStateOn")]
|
|
|
|
|
public string? IconStateLit { get; set; }
|
|
|
|
|
|
2022-08-14 07:28:34 +02:00
|
|
|
[Obsolete("Subscribe to AppearanceChangeEvent instead.")]
|
2020-09-03 16:02:40 -04:00
|
|
|
public override void OnChangeData(AppearanceComponent component)
|
|
|
|
|
{
|
|
|
|
|
base.OnChangeData(component);
|
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
var entities = IoCManager.Resolve<IEntityManager>();
|
2023-01-17 22:29:35 +13:00
|
|
|
|
|
|
|
|
if (!entities.TryGetComponent(component.Owner, out ExpendableLightComponent? expendableLight))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!entities.TryGetComponent(component.Owner, out SpriteComponent? sprite))
|
|
|
|
|
return;
|
|
|
|
|
|
2021-07-31 12:41:59 +02:00
|
|
|
if (component.TryGetData(ExpendableLightVisuals.Behavior, out string lightBehaviourID))
|
2020-09-03 16:02:40 -04:00
|
|
|
{
|
2022-06-04 19:17:48 +12:00
|
|
|
if (entities.TryGetComponent(component.Owner, out LightBehaviourComponent? lightBehaviour))
|
2020-09-03 16:02:40 -04:00
|
|
|
{
|
|
|
|
|
lightBehaviour.StopLightBehaviour();
|
|
|
|
|
|
|
|
|
|
if (lightBehaviourID != string.Empty)
|
|
|
|
|
{
|
|
|
|
|
lightBehaviour.StartLightBehaviour(lightBehaviourID);
|
|
|
|
|
}
|
2022-06-04 19:17:48 +12:00
|
|
|
else if (entities.TryGetComponent(component.Owner, out PointLightComponent? light))
|
2020-09-03 16:02:40 -04:00
|
|
|
{
|
|
|
|
|
light.Enabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-31 12:41:59 +02:00
|
|
|
|
2023-01-17 22:29:35 +13:00
|
|
|
if (!component.TryGetData(ExpendableLightVisuals.State, out ExpendableLightState state))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
switch (state)
|
2021-07-31 12:41:59 +02:00
|
|
|
{
|
2023-01-17 22:29:35 +13:00
|
|
|
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;
|
2021-07-31 12:41:59 +02:00
|
|
|
}
|
2020-09-03 16:02:40 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|