diff --git a/Content.Client/Light/Components/LightBehaviourComponent.cs b/Content.Client/Light/Components/LightBehaviourComponent.cs index 5f574cdd5b..6e4c26df53 100644 --- a/Content.Client/Light/Components/LightBehaviourComponent.cs +++ b/Content.Client/Light/Components/LightBehaviourComponent.cs @@ -384,7 +384,7 @@ namespace Content.Client.Light.Components public readonly List Behaviours = new(); [ViewVariables(VVAccess.ReadOnly)] - private readonly List _animations = new(); + public readonly List Animations = new(); [ViewVariables(VVAccess.ReadOnly)] private Dictionary _originalPropertyValues = new(); @@ -400,60 +400,11 @@ namespace Content.Client.Light.Components AnimationTracks = {behaviour} }; - _animations.Add(new AnimationContainer(key, animation, behaviour)); + Animations.Add(new AnimationContainer(key, animation, behaviour)); key++; } } - protected override void Startup() - { - base.Startup(); - - // TODO: Do NOT ensure component here. And use eventbus events instead... - Owner.EnsureComponent(); - - if (_entMan.TryGetComponent(Owner, out AnimationPlayerComponent? animation)) - { -#pragma warning disable 618 - animation.AnimationCompleted += OnAnimationCompleted; -#pragma warning restore 618 - } - - foreach (var container in _animations) - { - container.LightBehaviour.Initialize(Owner, _random, _entMan); - } - - // we need to initialize all behaviours before starting any - foreach (var container in _animations) - { - if (container.LightBehaviour.Enabled) - { - StartLightBehaviour(container.LightBehaviour.ID); - } - } - } - - private void OnAnimationCompleted(string key) - { - var container = _animations.FirstOrDefault(x => x.FullKey == key); - - if (container == null) - { - return; - } - - if (container.LightBehaviour.IsLooped) - { - container.LightBehaviour.UpdatePlaybackValues(container.Animation); - - if (_entMan.TryGetComponent(Owner, out AnimationPlayerComponent? animation)) - { - animation.Play(container.Animation, container.FullKey); - } - } - } - /// /// If we disable all the light behaviours we want to be able to revert the light to its original state. /// @@ -485,7 +436,7 @@ namespace Content.Client.Light.Components return; } - foreach (var container in _animations) + foreach (var container in Animations) { if (container.LightBehaviour.ID == id || id == string.Empty) { @@ -516,7 +467,7 @@ namespace Content.Client.Light.Components var toRemove = new List(); - foreach (var container in _animations) + foreach (var container in Animations) { if (container.LightBehaviour.ID == id || id == string.Empty) { @@ -534,7 +485,7 @@ namespace Content.Client.Light.Components foreach (var container in toRemove) { - _animations.Remove(container); + Animations.Remove(container); } if (resetToOriginalSettings && _entMan.TryGetComponent(Owner, out PointLightComponent? light)) @@ -559,7 +510,7 @@ namespace Content.Client.Light.Components return false; } - return _animations.Any(container => animation.HasRunningAnimation(KeyPrefix + container.Key)); + return Animations.Any(container => animation.HasRunningAnimation(KeyPrefix + container.Key)); } /// @@ -569,7 +520,7 @@ namespace Content.Client.Light.Components { var key = 0; - while (_animations.Any(x => x.Key == key)) + while (Animations.Any(x => x.Key == key)) { key++; } @@ -582,7 +533,7 @@ namespace Content.Client.Light.Components behaviour.Initialize(Owner, _random, _entMan); var container = new AnimationContainer(key, animation, behaviour); - _animations.Add(container); + Animations.Add(container); if (playImmediately) { diff --git a/Content.Client/Light/EntitySystems/LightBehaviorSystem.cs b/Content.Client/Light/EntitySystems/LightBehaviorSystem.cs new file mode 100644 index 0000000000..11f69165cf --- /dev/null +++ b/Content.Client/Light/EntitySystems/LightBehaviorSystem.cs @@ -0,0 +1,55 @@ +using System.Linq; +using Content.Client.Light.Components; +using Robust.Client.GameObjects; +using Robust.Shared.Random; + +namespace Content.Client.Light.EntitySystems; + +public sealed class LightBehaviorSystem : EntitySystem +{ + [Dependency] private readonly IRobustRandom _random = default!; + [Dependency] private readonly AnimationPlayerSystem _player = default!; + + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(OnLightStartup); + SubscribeLocalEvent(OnBehaviorAnimationCompleted); + } + + private void OnBehaviorAnimationCompleted(EntityUid uid, LightBehaviourComponent component, AnimationCompletedEvent args) + { + var container = component.Animations.FirstOrDefault(x => x.FullKey == args.Key); + + if (container == null) + { + return; + } + + if (container.LightBehaviour.IsLooped) + { + container.LightBehaviour.UpdatePlaybackValues(container.Animation); + _player.Play(uid, container.Animation, container.FullKey); + } + } + + private void OnLightStartup(EntityUid uid, LightBehaviourComponent component, ComponentStartup args) + { + // TODO: Do NOT ensure component here. And use eventbus events instead... + EnsureComp(uid); + + foreach (var container in component.Animations) + { + container.LightBehaviour.Initialize(uid, _random, EntityManager); + } + + // we need to initialize all behaviours before starting any + foreach (var container in component.Animations) + { + if (container.LightBehaviour.Enabled) + { + component.StartLightBehaviour(container.LightBehaviour.ID); + } + } + } +} diff --git a/Content.Server/Movement/Components/StressTestMovementComponent.cs b/Content.Server/Movement/Components/StressTestMovementComponent.cs index 10b8fbc674..d897b5fae2 100644 --- a/Content.Server/Movement/Components/StressTestMovementComponent.cs +++ b/Content.Server/Movement/Components/StressTestMovementComponent.cs @@ -1,18 +1,10 @@ using System.Numerics; -namespace Content.Server.Movement.Components +namespace Content.Server.Movement.Components; + +[RegisterComponent] +public sealed class StressTestMovementComponent : Component { - [RegisterComponent] - public sealed class StressTestMovementComponent : Component - { - public float Progress { get; set; } - public Vector2 Origin { get; set; } - - protected override void Startup() - { - base.Startup(); - - Origin = IoCManager.Resolve().GetComponent(Owner).WorldPosition; - } - } + public float Progress { get; set; } + public Vector2 Origin { get; set; } } diff --git a/Content.Server/Movement/StressTestMovementSystem.cs b/Content.Server/Movement/StressTestMovementSystem.cs index 5483b89b48..632af9cecf 100644 --- a/Content.Server/Movement/StressTestMovementSystem.cs +++ b/Content.Server/Movement/StressTestMovementSystem.cs @@ -1,32 +1,42 @@ using System.Numerics; using Content.Server.Movement.Components; -using JetBrains.Annotations; -namespace Content.Server.Movement +namespace Content.Server.Movement; + +public sealed class StressTestMovementSystem : EntitySystem { - [UsedImplicitly] - internal sealed class StressTestMovementSystem : EntitySystem + [Dependency] private readonly SharedTransformSystem _transform = default!; + + public override void Initialize() { - public override void Update(float frameTime) + base.Initialize(); + SubscribeLocalEvent(OnStressStartup); + } + + private void OnStressStartup(EntityUid uid, StressTestMovementComponent component, ComponentStartup args) + { + component.Origin = _transform.GetWorldPosition(uid); + } + + public override void Update(float frameTime) + { + base.Update(frameTime); + + var query = EntityQueryEnumerator(); + + while (query.MoveNext(out var uid, out var stressTest, out var transform)) { - base.Update(frameTime); + stressTest.Progress += frameTime; - foreach (var stressTest in EntityManager.EntityQuery(true)) + if (stressTest.Progress > 1) { - var transform = EntityManager.GetComponent(stressTest.Owner); - - stressTest.Progress += frameTime; - - if (stressTest.Progress > 1) - { - stressTest.Progress -= 1; - } - - var x = MathF.Sin(stressTest.Progress * MathHelper.TwoPi); - var y = MathF.Cos(stressTest.Progress * MathHelper.TwoPi); - - transform.WorldPosition = stressTest.Origin + (new Vector2(x, y) * 5); + stressTest.Progress -= 1; } + + var x = MathF.Sin(stressTest.Progress * MathHelper.TwoPi); + var y = MathF.Cos(stressTest.Progress * MathHelper.TwoPi); + + _transform.SetWorldPosition(transform, stressTest.Origin + new Vector2(x, y) * 5); } } } diff --git a/Content.Server/Tabletop/TabletopSystem.Map.cs b/Content.Server/Tabletop/TabletopSystem.Map.cs index 4048962591..362fbc5550 100644 --- a/Content.Server/Tabletop/TabletopSystem.Map.cs +++ b/Content.Server/Tabletop/TabletopSystem.Map.cs @@ -50,12 +50,13 @@ namespace Content.Server.Tabletop TabletopMap = _mapManager.CreateMap(); _tabletops = 0; + var mapUid = _mapManager.GetMapEntityId(TabletopMap); - var mapComp = EntityManager.GetComponent(_mapManager.GetMapEntityId(TabletopMap)); + var mapComp = EntityManager.GetComponent(mapUid); // Lighting is always disabled in tabletop world. mapComp.LightingEnabled = false; - mapComp.Dirty(); + Dirty(mapUid, mapComp); } ///