Remove component.Startup calls (#18229)

This commit is contained in:
metalgearsloth
2023-07-23 16:11:13 +10:00
committed by GitHub
parent e755509fc7
commit 5dd4169c51
5 changed files with 102 additions and 93 deletions

View File

@@ -384,7 +384,7 @@ namespace Content.Client.Light.Components
public readonly List<LightBehaviourAnimationTrack> Behaviours = new();
[ViewVariables(VVAccess.ReadOnly)]
private readonly List<AnimationContainer> _animations = new();
public readonly List<AnimationContainer> Animations = new();
[ViewVariables(VVAccess.ReadOnly)]
private Dictionary<string, object> _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<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>
/// If we disable all the light behaviours we want to be able to revert the light to its original state.
/// </summary>
@@ -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<AnimationContainer>();
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));
}
/// <summary>
@@ -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)
{