using Content.Client.Light.Components; using Content.Shared.Light.Components; using Robust.Client.GameObjects; using Robust.Client.Graphics; namespace Content.Client.Light.EntitySystems; public sealed class ExpendableLightSystem : VisualizerSystem { [Dependency] private readonly PointLightSystem _pointLightSystem = default!; [Dependency] private readonly SharedAudioSystem _audioSystem = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnLightShutdown); } private void OnLightShutdown(EntityUid uid, ExpendableLightComponent component, ComponentShutdown args) { component.PlayingStream?.Stop(); } protected override void OnAppearanceChange(EntityUid uid, ExpendableLightComponent comp, ref AppearanceChangeEvent args) { if (args.Sprite == null) return; if (AppearanceSystem.TryGetData(uid, ExpendableLightVisuals.Behavior, out var lightBehaviourID, args.Component) && TryComp(uid, out var lightBehaviour)) { lightBehaviour.StopLightBehaviour(); if (!string.IsNullOrEmpty(lightBehaviourID)) { lightBehaviour.StartLightBehaviour(lightBehaviourID); } else if (TryComp(uid, out var light)) { _pointLightSystem.SetEnabled(uid, false, light); } } if (!AppearanceSystem.TryGetData(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; } } }