Remove component.Startup calls (#18229)
This commit is contained in:
@@ -384,7 +384,7 @@ namespace Content.Client.Light.Components
|
|||||||
public readonly List<LightBehaviourAnimationTrack> Behaviours = new();
|
public readonly List<LightBehaviourAnimationTrack> Behaviours = new();
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadOnly)]
|
[ViewVariables(VVAccess.ReadOnly)]
|
||||||
private readonly List<AnimationContainer> _animations = new();
|
public readonly List<AnimationContainer> Animations = new();
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadOnly)]
|
[ViewVariables(VVAccess.ReadOnly)]
|
||||||
private Dictionary<string, object> _originalPropertyValues = new();
|
private Dictionary<string, object> _originalPropertyValues = new();
|
||||||
@@ -400,60 +400,11 @@ namespace Content.Client.Light.Components
|
|||||||
AnimationTracks = {behaviour}
|
AnimationTracks = {behaviour}
|
||||||
};
|
};
|
||||||
|
|
||||||
_animations.Add(new AnimationContainer(key, animation, behaviour));
|
Animations.Add(new AnimationContainer(key, animation, behaviour));
|
||||||
key++;
|
key++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Startup()
|
|
||||||
{
|
|
||||||
base.Startup();
|
|
||||||
|
|
||||||
// TODO: Do NOT ensure component here. And use eventbus events instead...
|
|
||||||
Owner.EnsureComponent<AnimationPlayerComponent>();
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// If we disable all the light behaviours we want to be able to revert the light to its original state.
|
/// If we disable all the light behaviours we want to be able to revert the light to its original state.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -485,7 +436,7 @@ namespace Content.Client.Light.Components
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var container in _animations)
|
foreach (var container in Animations)
|
||||||
{
|
{
|
||||||
if (container.LightBehaviour.ID == id || id == string.Empty)
|
if (container.LightBehaviour.ID == id || id == string.Empty)
|
||||||
{
|
{
|
||||||
@@ -516,7 +467,7 @@ namespace Content.Client.Light.Components
|
|||||||
|
|
||||||
var toRemove = new List<AnimationContainer>();
|
var toRemove = new List<AnimationContainer>();
|
||||||
|
|
||||||
foreach (var container in _animations)
|
foreach (var container in Animations)
|
||||||
{
|
{
|
||||||
if (container.LightBehaviour.ID == id || id == string.Empty)
|
if (container.LightBehaviour.ID == id || id == string.Empty)
|
||||||
{
|
{
|
||||||
@@ -534,7 +485,7 @@ namespace Content.Client.Light.Components
|
|||||||
|
|
||||||
foreach (var container in toRemove)
|
foreach (var container in toRemove)
|
||||||
{
|
{
|
||||||
_animations.Remove(container);
|
Animations.Remove(container);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resetToOriginalSettings && _entMan.TryGetComponent(Owner, out PointLightComponent? light))
|
if (resetToOriginalSettings && _entMan.TryGetComponent(Owner, out PointLightComponent? light))
|
||||||
@@ -559,7 +510,7 @@ namespace Content.Client.Light.Components
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _animations.Any(container => animation.HasRunningAnimation(KeyPrefix + container.Key));
|
return Animations.Any(container => animation.HasRunningAnimation(KeyPrefix + container.Key));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -569,7 +520,7 @@ namespace Content.Client.Light.Components
|
|||||||
{
|
{
|
||||||
var key = 0;
|
var key = 0;
|
||||||
|
|
||||||
while (_animations.Any(x => x.Key == key))
|
while (Animations.Any(x => x.Key == key))
|
||||||
{
|
{
|
||||||
key++;
|
key++;
|
||||||
}
|
}
|
||||||
@@ -582,7 +533,7 @@ namespace Content.Client.Light.Components
|
|||||||
behaviour.Initialize(Owner, _random, _entMan);
|
behaviour.Initialize(Owner, _random, _entMan);
|
||||||
|
|
||||||
var container = new AnimationContainer(key, animation, behaviour);
|
var container = new AnimationContainer(key, animation, behaviour);
|
||||||
_animations.Add(container);
|
Animations.Add(container);
|
||||||
|
|
||||||
if (playImmediately)
|
if (playImmediately)
|
||||||
{
|
{
|
||||||
|
|||||||
55
Content.Client/Light/EntitySystems/LightBehaviorSystem.cs
Normal file
55
Content.Client/Light/EntitySystems/LightBehaviorSystem.cs
Normal file
@@ -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<LightBehaviourComponent, ComponentStartup>(OnLightStartup);
|
||||||
|
SubscribeLocalEvent<LightBehaviourComponent, AnimationCompletedEvent>(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<AnimationPlayerComponent>(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,18 +1,10 @@
|
|||||||
using System.Numerics;
|
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 float Progress { get; set; }
|
||||||
public Vector2 Origin { get; set; }
|
public Vector2 Origin { get; set; }
|
||||||
|
|
||||||
protected override void Startup()
|
|
||||||
{
|
|
||||||
base.Startup();
|
|
||||||
|
|
||||||
Origin = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).WorldPosition;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,31 @@
|
|||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using Content.Server.Movement.Components;
|
using Content.Server.Movement.Components;
|
||||||
using JetBrains.Annotations;
|
|
||||||
|
|
||||||
namespace Content.Server.Movement
|
namespace Content.Server.Movement;
|
||||||
|
|
||||||
|
public sealed class StressTestMovementSystem : EntitySystem
|
||||||
{
|
{
|
||||||
[UsedImplicitly]
|
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||||
internal sealed class StressTestMovementSystem : EntitySystem
|
|
||||||
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
|
base.Initialize();
|
||||||
|
SubscribeLocalEvent<StressTestMovementComponent, ComponentStartup>(OnStressStartup);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnStressStartup(EntityUid uid, StressTestMovementComponent component, ComponentStartup args)
|
||||||
|
{
|
||||||
|
component.Origin = _transform.GetWorldPosition(uid);
|
||||||
|
}
|
||||||
|
|
||||||
public override void Update(float frameTime)
|
public override void Update(float frameTime)
|
||||||
{
|
{
|
||||||
base.Update(frameTime);
|
base.Update(frameTime);
|
||||||
|
|
||||||
foreach (var stressTest in EntityManager.EntityQuery<StressTestMovementComponent>(true))
|
var query = EntityQueryEnumerator<StressTestMovementComponent, TransformComponent>();
|
||||||
{
|
|
||||||
var transform = EntityManager.GetComponent<TransformComponent>(stressTest.Owner);
|
|
||||||
|
|
||||||
|
while (query.MoveNext(out var uid, out var stressTest, out var transform))
|
||||||
|
{
|
||||||
stressTest.Progress += frameTime;
|
stressTest.Progress += frameTime;
|
||||||
|
|
||||||
if (stressTest.Progress > 1)
|
if (stressTest.Progress > 1)
|
||||||
@@ -25,8 +36,7 @@ namespace Content.Server.Movement
|
|||||||
var x = MathF.Sin(stressTest.Progress * MathHelper.TwoPi);
|
var x = MathF.Sin(stressTest.Progress * MathHelper.TwoPi);
|
||||||
var y = MathF.Cos(stressTest.Progress * MathHelper.TwoPi);
|
var y = MathF.Cos(stressTest.Progress * MathHelper.TwoPi);
|
||||||
|
|
||||||
transform.WorldPosition = stressTest.Origin + (new Vector2(x, y) * 5);
|
_transform.SetWorldPosition(transform, stressTest.Origin + new Vector2(x, y) * 5);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,12 +50,13 @@ namespace Content.Server.Tabletop
|
|||||||
|
|
||||||
TabletopMap = _mapManager.CreateMap();
|
TabletopMap = _mapManager.CreateMap();
|
||||||
_tabletops = 0;
|
_tabletops = 0;
|
||||||
|
var mapUid = _mapManager.GetMapEntityId(TabletopMap);
|
||||||
|
|
||||||
var mapComp = EntityManager.GetComponent<MapComponent>(_mapManager.GetMapEntityId(TabletopMap));
|
var mapComp = EntityManager.GetComponent<MapComponent>(mapUid);
|
||||||
|
|
||||||
// Lighting is always disabled in tabletop world.
|
// Lighting is always disabled in tabletop world.
|
||||||
mapComp.LightingEnabled = false;
|
mapComp.LightingEnabled = false;
|
||||||
mapComp.Dirty();
|
Dirty(mapUid, mapComp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user