2021-12-05 18:09:01 +01: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-07-31 12:41:59 +02:00
|
|
|
|
using Robust.Shared.Audio;
|
2021-11-22 23:22:59 -08:00
|
|
|
|
using Robust.Shared.GameObjects;
|
2021-12-05 18:09:01 +01:00
|
|
|
|
using Robust.Shared.IoC;
|
2021-07-31 12:41:59 +02:00
|
|
|
|
using Robust.Shared.Player;
|
2020-09-03 16:02:40 -04:00
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
|
public override void OnChangeData(AppearanceComponent component)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnChangeData(component);
|
|
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
|
var entities = IoCManager.Resolve<IEntityManager>();
|
2021-07-31 12:41:59 +02:00
|
|
|
|
if (component.TryGetData(ExpendableLightVisuals.Behavior, out string lightBehaviourID))
|
2020-09-03 16:02:40 -04:00
|
|
|
|
{
|
2021-12-05 18:09:01 +01: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);
|
|
|
|
|
|
}
|
2021-12-05 18:09:01 +01: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
|
|
|
|
|
|
|
|
|
|
void TryStopStream(IPlayingAudioStream? stream)
|
|
|
|
|
|
{
|
2021-09-20 11:24:28 +02:00
|
|
|
|
stream?.Stop();
|
2021-07-31 12:41:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (component.TryGetData(ExpendableLightVisuals.State, out ExpendableLightState state)
|
2021-12-05 18:09:01 +01:00
|
|
|
|
&& entities.TryGetComponent(component.Owner, out ExpendableLightComponent expendableLight))
|
2021-07-31 12:41:59 +02:00
|
|
|
|
{
|
|
|
|
|
|
switch (state)
|
|
|
|
|
|
{
|
|
|
|
|
|
case ExpendableLightState.Lit:
|
2021-08-13 21:31:37 -07:00
|
|
|
|
{
|
2021-07-31 12:41:59 +02:00
|
|
|
|
TryStopStream(expendableLight.PlayingStream);
|
2021-08-13 21:31:37 -07:00
|
|
|
|
if (expendableLight.LoopedSound != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
expendableLight.PlayingStream = SoundSystem.Play(Filter.Local(),
|
|
|
|
|
|
expendableLight.LoopedSound, expendableLight.Owner,
|
|
|
|
|
|
SharedExpendableLightComponent.LoopedSoundParams.WithLoop(true));
|
|
|
|
|
|
}
|
2021-07-31 12:41:59 +02:00
|
|
|
|
break;
|
2021-08-13 21:31:37 -07:00
|
|
|
|
}
|
2021-07-31 12:41:59 +02:00
|
|
|
|
case ExpendableLightState.Dead:
|
2021-08-13 21:31:37 -07:00
|
|
|
|
{
|
2021-07-31 12:41:59 +02:00
|
|
|
|
TryStopStream(expendableLight.PlayingStream);
|
|
|
|
|
|
break;
|
2021-08-13 21:31:37 -07:00
|
|
|
|
}
|
2021-07-31 12:41:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-09-03 16:02:40 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|