Enable nullability in Content.Client (#3257)
* Enable nullability in Content.Client * Remove #nullable enable * Merge fixes * Remove Debug.Assert * Merge fixes * Fix build * Fix build
This commit is contained in:
@@ -26,6 +26,8 @@ namespace Content.Client.GameObjects.Components
|
||||
[ImplicitDataDefinitionForInheritors]
|
||||
public abstract class LightBehaviourAnimationTrack : AnimationTrackProperty
|
||||
{
|
||||
[Dependency] protected readonly IRobustRandom RobustRandom = default!;
|
||||
|
||||
[DataField("id")] [ViewVariables] public string ID { get; set; } = string.Empty;
|
||||
|
||||
[DataField("property")]
|
||||
@@ -55,19 +57,17 @@ namespace Content.Client.GameObjects.Components
|
||||
public AnimationInterpolationMode InterpolateMode { get; set; } = AnimationInterpolationMode.Linear;
|
||||
|
||||
[ViewVariables] protected float MaxTime { get; set; }
|
||||
protected PointLightComponent Light;
|
||||
protected IRobustRandom RobustRandom;
|
||||
|
||||
private float _maxTime = default;
|
||||
private IEntity _parent = default!;
|
||||
|
||||
public void Initialize(PointLightComponent light)
|
||||
public void Initialize(IEntity parent)
|
||||
{
|
||||
Light = light;
|
||||
RobustRandom = IoCManager.Resolve<IRobustRandom>();
|
||||
_parent = parent;
|
||||
|
||||
if (Enabled)
|
||||
if (Enabled && _parent.TryGetComponent(out PointLightComponent? light))
|
||||
{
|
||||
Light.Enabled = true;
|
||||
light.Enabled = true;
|
||||
}
|
||||
|
||||
OnInitialize();
|
||||
@@ -75,7 +75,10 @@ namespace Content.Client.GameObjects.Components
|
||||
|
||||
public void UpdatePlaybackValues(Animation owner)
|
||||
{
|
||||
Light.Enabled = true;
|
||||
if (_parent.TryGetComponent(out PointLightComponent? light))
|
||||
{
|
||||
light.Enabled = true;
|
||||
}
|
||||
|
||||
if (MinDuration > 0)
|
||||
{
|
||||
@@ -103,13 +106,9 @@ namespace Content.Client.GameObjects.Components
|
||||
throw new InvalidOperationException("Property parameter is null! Check the prototype!");
|
||||
}
|
||||
|
||||
if (Light is IAnimationProperties properties)
|
||||
if (_parent.TryGetComponent(out PointLightComponent? light))
|
||||
{
|
||||
properties.SetAnimatableProperty(Property, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
AnimationHelper.SetAnimatableProperty(Light, Property, value);
|
||||
AnimationHelper.SetAnimatableProperty(light, Property, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,10 +218,10 @@ namespace Content.Client.GameObjects.Components
|
||||
[UsedImplicitly]
|
||||
public class RandomizeBehaviour : LightBehaviourAnimationTrack
|
||||
{
|
||||
private object _randomValue1;
|
||||
private object _randomValue2;
|
||||
private object _randomValue3;
|
||||
private object _randomValue4;
|
||||
private object? _randomValue1;
|
||||
private object _randomValue2 = default!;
|
||||
private object _randomValue3 = default!;
|
||||
private object _randomValue4 = default!;
|
||||
|
||||
public override void OnInitialize()
|
||||
{
|
||||
@@ -235,7 +234,7 @@ namespace Content.Client.GameObjects.Components
|
||||
{
|
||||
if (Property == "Enabled") // special case for boolean, we randomize it
|
||||
{
|
||||
ApplyProperty(RobustRandom.NextDouble() < 0.5 ? true : false);
|
||||
ApplyProperty(RobustRandom.NextDouble() < 0.5);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -266,7 +265,7 @@ namespace Content.Client.GameObjects.Components
|
||||
ApplyProperty(InterpolateLinear(_randomValue3, _randomValue4, interpolateValue));
|
||||
break;
|
||||
case AnimationInterpolationMode.Cubic:
|
||||
ApplyProperty(InterpolateCubic(_randomValue1, _randomValue2, _randomValue3, _randomValue4, interpolateValue));
|
||||
ApplyProperty(InterpolateCubic(_randomValue1!, _randomValue2, _randomValue3, _randomValue4, interpolateValue));
|
||||
break;
|
||||
default:
|
||||
case AnimationInterpolationMode.Nearest:
|
||||
@@ -377,8 +376,6 @@ namespace Content.Client.GameObjects.Components
|
||||
private Angle _originalRotation;
|
||||
private Color _originalColor;
|
||||
private bool _originalEnabled;
|
||||
private PointLightComponent _lightComponent;
|
||||
private AnimationPlayerComponent _animationPlayer;
|
||||
|
||||
void ISerializationHooks.AfterDeserialization()
|
||||
{
|
||||
@@ -388,7 +385,7 @@ namespace Content.Client.GameObjects.Components
|
||||
{
|
||||
var animation = new Animation()
|
||||
{
|
||||
AnimationTracks = { behaviour }
|
||||
AnimationTracks = {behaviour}
|
||||
};
|
||||
|
||||
_animations.Add(new AnimationContainer(key, animation, behaviour));
|
||||
@@ -401,12 +398,16 @@ namespace Content.Client.GameObjects.Components
|
||||
base.Startup();
|
||||
|
||||
CopyLightSettings();
|
||||
_animationPlayer = Owner.EnsureComponent<AnimationPlayerComponent>();
|
||||
_animationPlayer.AnimationCompleted += OnAnimationCompleted;
|
||||
Owner.EnsureComponentWarn<AnimationPlayerComponent>();
|
||||
|
||||
if (Owner.TryGetComponent(out AnimationPlayerComponent? animation))
|
||||
{
|
||||
animation.AnimationCompleted += OnAnimationCompleted;
|
||||
}
|
||||
|
||||
foreach (var container in _animations)
|
||||
{
|
||||
container.LightBehaviour.Initialize(_lightComponent);
|
||||
container.LightBehaviour.Initialize(Owner);
|
||||
}
|
||||
|
||||
// we need to initialize all behaviours before starting any
|
||||
@@ -423,10 +424,19 @@ namespace Content.Client.GameObjects.Components
|
||||
{
|
||||
var container = _animations.FirstOrDefault(x => x.FullKey == key);
|
||||
|
||||
if (container == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (container.LightBehaviour.IsLooped)
|
||||
{
|
||||
container.LightBehaviour.UpdatePlaybackValues(container.Animation);
|
||||
_animationPlayer.Play(container.Animation, container.FullKey);
|
||||
|
||||
if (Owner.TryGetComponent(out AnimationPlayerComponent? animation))
|
||||
{
|
||||
animation.Play(container.Animation, container.FullKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -435,13 +445,13 @@ namespace Content.Client.GameObjects.Components
|
||||
/// </summary>
|
||||
private void CopyLightSettings()
|
||||
{
|
||||
if (Owner.TryGetComponent(out _lightComponent))
|
||||
if (Owner.TryGetComponent(out PointLightComponent? light))
|
||||
{
|
||||
_originalColor = _lightComponent.Color;
|
||||
_originalEnabled = _lightComponent.Enabled;
|
||||
_originalEnergy = _lightComponent.Energy;
|
||||
_originalRadius = _lightComponent.Radius;
|
||||
_originalRotation = _lightComponent.Rotation;
|
||||
_originalColor = light.Color;
|
||||
_originalEnabled = light.Enabled;
|
||||
_originalEnergy = light.Energy;
|
||||
_originalRadius = light.Radius;
|
||||
_originalRotation = light.Rotation;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -456,14 +466,19 @@ namespace Content.Client.GameObjects.Components
|
||||
/// </summary>
|
||||
public void StartLightBehaviour(string id = "")
|
||||
{
|
||||
if (!Owner.TryGetComponent(out AnimationPlayerComponent? animation))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var container in _animations)
|
||||
{
|
||||
if (container.LightBehaviour.ID == id || id == string.Empty)
|
||||
{
|
||||
if (!_animationPlayer.HasRunningAnimation(KeyPrefix + container.Key))
|
||||
if (!animation.HasRunningAnimation(KeyPrefix + container.Key))
|
||||
{
|
||||
container.LightBehaviour.UpdatePlaybackValues(container.Animation);
|
||||
_animationPlayer.Play(container.Animation, KeyPrefix + container.Key);
|
||||
animation.Play(container.Animation, KeyPrefix + container.Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -479,15 +494,20 @@ namespace Content.Client.GameObjects.Components
|
||||
/// <param name="resetToOriginalSettings">Should the light have its original settings applied?</param>
|
||||
public void StopLightBehaviour(string id = "", bool removeBehaviour = false, bool resetToOriginalSettings = false)
|
||||
{
|
||||
if (!Owner.TryGetComponent(out AnimationPlayerComponent? animation))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var toRemove = new List<AnimationContainer>();
|
||||
|
||||
foreach (var container in _animations)
|
||||
{
|
||||
if (container.LightBehaviour.ID == id || id == string.Empty)
|
||||
{
|
||||
if (_animationPlayer.HasRunningAnimation(KeyPrefix + container.Key))
|
||||
if (animation.HasRunningAnimation(KeyPrefix + container.Key))
|
||||
{
|
||||
_animationPlayer.Stop(KeyPrefix + container.Key);
|
||||
animation.Stop(KeyPrefix + container.Key);
|
||||
}
|
||||
|
||||
if (removeBehaviour)
|
||||
@@ -502,13 +522,13 @@ namespace Content.Client.GameObjects.Components
|
||||
_animations.Remove(container);
|
||||
}
|
||||
|
||||
if (resetToOriginalSettings)
|
||||
if (resetToOriginalSettings && Owner.TryGetComponent(out PointLightComponent? light))
|
||||
{
|
||||
_lightComponent.Color = _originalColor;
|
||||
_lightComponent.Enabled = _originalEnabled;
|
||||
_lightComponent.Energy = _originalEnergy;
|
||||
_lightComponent.Radius = _originalRadius;
|
||||
_lightComponent.Rotation = _originalRotation;
|
||||
light.Color = _originalColor;
|
||||
light.Enabled = _originalEnabled;
|
||||
light.Energy = _originalEnergy;
|
||||
light.Radius = _originalRadius;
|
||||
light.Rotation = _originalRotation;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -517,7 +537,7 @@ namespace Content.Client.GameObjects.Components
|
||||
/// </summary>
|
||||
public void AddNewLightBehaviour(LightBehaviourAnimationTrack behaviour, bool playImmediately = true)
|
||||
{
|
||||
int key = 0;
|
||||
var key = 0;
|
||||
|
||||
while (_animations.Any(x => x.Key == key))
|
||||
{
|
||||
@@ -526,10 +546,11 @@ namespace Content.Client.GameObjects.Components
|
||||
|
||||
var animation = new Animation()
|
||||
{
|
||||
AnimationTracks = { behaviour }
|
||||
AnimationTracks = {behaviour}
|
||||
};
|
||||
|
||||
behaviour.Initialize(_lightComponent);
|
||||
behaviour.Initialize(Owner);
|
||||
|
||||
var container = new AnimationContainer(key, animation, behaviour);
|
||||
_animations.Add(container);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user