diff --git a/Content.Client/Light/Components/EmergencyLightComponent.cs b/Content.Client/Light/Components/EmergencyLightComponent.cs index 2ae15fd32e..ee1f69c079 100644 --- a/Content.Client/Light/Components/EmergencyLightComponent.cs +++ b/Content.Client/Light/Components/EmergencyLightComponent.cs @@ -1,45 +1,12 @@ -using System; -using Robust.Client.Animations; -using Robust.Client.GameObjects; -using Robust.Shared.Animations; +using Content.Shared.Light.Component; using Robust.Shared.GameObjects; -using Robust.Shared.Maths; +using Robust.Shared.GameStates; namespace Content.Client.Light.Components { [RegisterComponent] - public class EmergencyLightComponent : Component + [NetworkedComponent] + public class EmergencyLightComponent : SharedEmergencyLightComponent { - public override string Name => "EmergencyLight"; - - /// - protected override void Startup() - { - base.Startup(); - - var animation = new Animation - { - Length = TimeSpan.FromSeconds(4), - AnimationTracks = - { - new AnimationTrackComponentProperty - { - ComponentType = typeof(PointLightComponent), - InterpolationMode = AnimationInterpolationMode.Linear, - Property = nameof(PointLightComponent.Rotation), - KeyFrames = - { - new AnimationTrackProperty.KeyFrame(Angle.Zero, 0), - new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(1080), 4) - } - } - } - }; - - var playerComponent = Owner.EnsureComponent(); - playerComponent.Play(animation, "emergency"); - - playerComponent.AnimationCompleted += s => playerComponent.Play(animation, s); - } } } diff --git a/Content.Client/Light/EmergencyLightSystem.cs b/Content.Client/Light/EmergencyLightSystem.cs new file mode 100644 index 0000000000..40e16968b6 --- /dev/null +++ b/Content.Client/Light/EmergencyLightSystem.cs @@ -0,0 +1,86 @@ +using System; +using Content.Client.Light.Components; +using Content.Shared.Light; +using Content.Shared.Light.Component; +using Robust.Client.Animations; +using Robust.Client.GameObjects; +using Robust.Shared.Animations; +using Robust.Shared.GameObjects; +using Robust.Shared.GameStates; +using Robust.Shared.Maths; + +namespace Content.Client.Light +{ + public sealed class EmergencyLightSystem : SharedEmergencyLightSystem + { + private static Animation Animation => + new() + { + Length = TimeSpan.FromSeconds(4), + AnimationTracks = + { + new AnimationTrackComponentProperty + { + ComponentType = typeof(PointLightComponent), + InterpolationMode = AnimationInterpolationMode.Linear, + Property = nameof(PointLightComponent.Rotation), + KeyFrames = + { + new AnimationTrackProperty.KeyFrame(Angle.Zero, 0), + new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(1080), 4) + } + } + } + }; + + private const string AnimKey = "emergency"; + + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(HandleStartup); + SubscribeLocalEvent(HandleAnimationComplete); + SubscribeLocalEvent(HandleCompState); + } + + private void HandleCompState(EntityUid uid, EmergencyLightComponent component, ref ComponentHandleState args) + { + if (args.Current is not EmergencyLightComponentState state) return; + + if (component.Enabled == state.Enabled) return; + + var playerComponent = component.Owner.EnsureComponent(); + + component.Enabled = state.Enabled; + + if (component.Enabled && !playerComponent.HasRunningAnimation(AnimKey)) + playerComponent.Play(Animation, AnimKey); + + if (!component.Enabled) + playerComponent.Stop(AnimKey); + } + + private void HandleAnimationComplete(EntityUid uid, EmergencyLightComponent component, AnimationCompletedEvent args) + { + if (!component.Enabled || + !ComponentManager.TryGetComponent(uid, out var playerComponent)) return; + + playerComponent.Play(Animation, AnimKey); + } + + private void HandleStartup(EntityUid uid, EmergencyLightComponent component, ComponentStartup args) + { + PlayAnimation(component); + } + + private void PlayAnimation(EmergencyLightComponent component) + { + if (!component.Enabled) return; + + var playerComponent = component.Owner.EnsureComponent(); + + if (!playerComponent.HasRunningAnimation(AnimKey)) + playerComponent.Play(Animation, AnimKey); + } + } +} diff --git a/Content.Client/Light/LanternVisualizer.cs b/Content.Client/Light/LanternVisualizer.cs index 418802956d..c2463541fb 100644 --- a/Content.Client/Light/LanternVisualizer.cs +++ b/Content.Client/Light/LanternVisualizer.cs @@ -33,10 +33,6 @@ namespace Content.Client.Light public override void OnChangeData(AppearanceComponent component) { base.OnChangeData(component); - if (component.Deleted) - { - return; - } PlayAnimation(component); } diff --git a/Content.IntegrationTests/Tests/DummyIconTest.cs b/Content.IntegrationTests/Tests/DummyIconTest.cs index 1555481fe4..b1edda0a2d 100644 --- a/Content.IntegrationTests/Tests/DummyIconTest.cs +++ b/Content.IntegrationTests/Tests/DummyIconTest.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using NUnit.Framework; using Robust.Client.GameObjects; using Robust.Client.ResourceManagement; +using Robust.Shared.GameObjects; using Robust.Shared.Prototypes; namespace Content.IntegrationTests.Tests @@ -14,8 +15,7 @@ namespace Content.IntegrationTests.Tests [Test] public async Task Test() { - var client = StartClient(); - await client.WaitIdleAsync(); + var (client, _) = await StartConnectedServerClientPair(); var prototypeManager = client.ResolveDependency(); var resourceCache = client.ResolveDependency(); diff --git a/Content.Server/Light/Components/EmergencyLightComponent.cs b/Content.Server/Light/Components/EmergencyLightComponent.cs index b5df55fb28..51a07c67d2 100644 --- a/Content.Server/Light/Components/EmergencyLightComponent.cs +++ b/Content.Server/Light/Components/EmergencyLightComponent.cs @@ -16,10 +16,8 @@ namespace Content.Server.Light.Components /// Component that represents an emergency light, it has an internal battery that charges when the power is on. /// [RegisterComponent] - public class EmergencyLightComponent : Component, IExamine + public class EmergencyLightComponent : SharedEmergencyLightComponent, IExamine { - public override string Name => "EmergencyLight"; - [ViewVariables] private EmergencyLightState State { diff --git a/Content.Server/Light/EntitySystems/EmergencyLightSystem.cs b/Content.Server/Light/EntitySystems/EmergencyLightSystem.cs index e365f201f8..b66a19c029 100644 --- a/Content.Server/Light/EntitySystems/EmergencyLightSystem.cs +++ b/Content.Server/Light/EntitySystems/EmergencyLightSystem.cs @@ -1,13 +1,16 @@ using System; using System.Collections.Generic; using Content.Server.Light.Components; +using Content.Shared.Light; +using Content.Shared.Light.Component; using JetBrains.Annotations; using Robust.Shared.GameObjects; +using Robust.Shared.GameStates; namespace Content.Server.Light.EntitySystems { [UsedImplicitly] - internal sealed class EmergencyLightSystem : EntitySystem + public sealed class EmergencyLightSystem : SharedEmergencyLightSystem { private readonly HashSet _activeLights = new(); @@ -15,6 +18,20 @@ namespace Content.Server.Light.EntitySystems { base.Initialize(); SubscribeLocalEvent(HandleEmergencyLightMessage); + SubscribeLocalEvent(GetCompState); + SubscribeLocalEvent(HandleLightToggle); + } + + private void HandleLightToggle(EntityUid uid, EmergencyLightComponent component, PointLightToggleEvent args) + { + if (component.Enabled == args.Enabled) return; + component.Enabled = args.Enabled; + component.Dirty(); + } + + private void GetCompState(EntityUid uid, EmergencyLightComponent component, ref ComponentGetState args) + { + args.State = new EmergencyLightComponentState(component.Enabled); } private void HandleEmergencyLightMessage(EmergencyLightMessage message) diff --git a/Content.Shared/Light/Component/SharedEmergencyLightComponent.cs b/Content.Shared/Light/Component/SharedEmergencyLightComponent.cs index b7f1e9a95a..88ea4835a1 100644 --- a/Content.Shared/Light/Component/SharedEmergencyLightComponent.cs +++ b/Content.Shared/Light/Component/SharedEmergencyLightComponent.cs @@ -1,8 +1,29 @@ using System; +using Robust.Shared.GameObjects; +using Robust.Shared.GameStates; using Robust.Shared.Serialization; namespace Content.Shared.Light.Component { + [NetworkedComponent] + public abstract class SharedEmergencyLightComponent : Robust.Shared.GameObjects.Component + { + public override string Name => "EmergencyLight"; + + public bool Enabled { get; set; } = false; + } + + [Serializable, NetSerializable] + public sealed class EmergencyLightComponentState : ComponentState + { + public bool Enabled; + + public EmergencyLightComponentState(bool enabled) + { + Enabled = enabled; + } + } + [Serializable, NetSerializable] public enum EmergencyLightVisuals { diff --git a/Content.Shared/Light/SharedEmergencyLightSystem.cs b/Content.Shared/Light/SharedEmergencyLightSystem.cs new file mode 100644 index 0000000000..38dc309c2b --- /dev/null +++ b/Content.Shared/Light/SharedEmergencyLightSystem.cs @@ -0,0 +1,9 @@ +using Robust.Shared.GameObjects; + +namespace Content.Shared.Light +{ + public abstract class SharedEmergencyLightSystem : EntitySystem + { + + } +}