Make shallow copies of resources

This commit is contained in:
Marco 2025-02-14 14:24:26 +01:00
commit 0203af4642
8 changed files with 55 additions and 15 deletions

View file

@ -25,7 +25,7 @@ public partial class Bullet : Area2D
public BulletInfo BulletInfo => _bulletInfo;
private List<ModifierWrapper> _modifiers = new();
private List<TimeModifier> _modifiers = new();
private GameManager _gameManager;
@ -35,9 +35,15 @@ public partial class Bullet : Area2D
_gameManager = gameManager;
// Ugly hack to make instances unique
_modifiers = _bulletInfo.TimeModifiers.Select(x => x.Wrap()).ToList();
_modifiers = _bulletInfo.TimeModifiers;
// var clonedModifiers = _bulletInfo.TimeModifiers.Select(x => x.MakeClone());
// _modifiers = clonedModifiers.ToList();
// Ugly hack to make instances unique
//_modifiers = _bulletInfo.TimeModifiers.Select(x => x.Wrap()).ToList();
}
private void ApplyTimeModifiers()
@ -48,17 +54,17 @@ public partial class Bullet : Area2D
{
continue;
}
if (_elapsedTime >= modifier.TimeModifier.TimeInSeconds)
if (_elapsedTime >= modifier.TimeInSeconds)
{
GD.Print("Applied time modifier");
switch (modifier.TimeModifier.ModifierType)
switch (modifier.ModifierType)
{
case TimeModifierType.SpeedChange:
//_bulletInfo.Speed += modifier.Value;
Speed = modifier.TimeModifier.Value;
Speed = modifier.Value;
break;
case TimeModifierType.RotationChange:
RotateBullet(modifier.TimeModifier.Value);
RotateBullet(modifier.Value);
//Rotation += Mathf.DegToRad(modifier.Value);
break;
case TimeModifierType.FacePlayer:
@ -66,7 +72,7 @@ public partial class Bullet : Area2D
break;
}
if (!modifier.TimeModifier.Continuous)
if (!modifier.Continuous)
{
modifier.Applied = true;
}
@ -121,7 +127,10 @@ public partial class Bullet : Area2D
{
ApplyTimeModifiers();
}
}
public override void _PhysicsProcess(double delta)
{
this.Position += ((float)(Speed * delta) * _direction);
}