Files
tbd-station-14/Content.Client/Light/Visualizers/ExpendableLightVisualizer.cs
Vera Aguilera Puerto dc18997bf8 Removes LoopingSoundComponent. (#4396)
I'm sorry.
2021-07-31 12:41:59 +02:00

71 lines
2.4 KiB
C#

using System;
using Content.Client.Light.Components;
using Content.Shared.Light.Component;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.Player;
namespace Content.Client.Light.Visualizers
{
[UsedImplicitly]
public class ExpendableLightVisualizer : AppearanceVisualizer
{
public override void OnChangeData(AppearanceComponent component)
{
base.OnChangeData(component);
if (component.Deleted)
{
return;
}
if (component.TryGetData(ExpendableLightVisuals.Behavior, out string lightBehaviourID))
{
if (component.Owner.TryGetComponent<LightBehaviourComponent>(out var lightBehaviour))
{
lightBehaviour.StopLightBehaviour();
if (lightBehaviourID != string.Empty)
{
lightBehaviour.StartLightBehaviour(lightBehaviourID);
}
else if (component.Owner.TryGetComponent<PointLightComponent>(out var light))
{
light.Enabled = false;
}
}
}
void TryStopStream(IPlayingAudioStream? stream)
{
try
{
stream?.Stop();
}
catch (Exception _)
{
// TODO: HOLY SHIT EXPOSE SOME DISPOSED PROPERTY ON PLAYING STREAM OR SOMETHING.
}
}
if (component.TryGetData(ExpendableLightVisuals.State, out ExpendableLightState state)
&& component.Owner.TryGetComponent<ExpendableLightComponent>(out var expendableLight))
{
switch (state)
{
case ExpendableLightState.Lit:
TryStopStream(expendableLight.PlayingStream);
expendableLight.PlayingStream = SoundSystem.Play(Filter.Local(), expendableLight.LoopedSound,
expendableLight.Owner, SharedExpendableLightComponent.LoopedSoundParams.WithLoop(true));
break;
case ExpendableLightState.Dead:
TryStopStream(expendableLight.PlayingStream);
break;
}
}
}
}
}