2021-07-31 12:41:59 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
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;
|
|
|
|
|
|
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]
|
|
|
|
|
|
public class ExpendableLightVisualizer : AppearanceVisualizer
|
|
|
|
|
|
{
|
|
|
|
|
|
public override void OnChangeData(AppearanceComponent component)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnChangeData(component);
|
|
|
|
|
|
|
|
|
|
|
|
if (component.Deleted)
|
|
|
|
|
|
{
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
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)
|
|
|
|
|
|
&& component.Owner.TryGetComponent<ExpendableLightComponent>(out var expendableLight))
|
|
|
|
|
|
{
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|