mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-13 20:55:55 +00:00
Make shallow copies of resources
This commit is contained in:
parent
c318bd8c13
commit
0203af4642
8 changed files with 55 additions and 15 deletions
|
|
@ -98,7 +98,8 @@ public partial class SpiralPattern : AttackPattern
|
|||
BulletScene = BulletScene,
|
||||
RotationOffset = angleOffset,
|
||||
Modifier = _modifier,
|
||||
TimeModifiers = _timeModifiers?.Where(mod => mod != null).ToList() ?? new List<TimeModifier>()
|
||||
TimeModifiers = _timeModifiers.Select(x => x.MakeClone()).ToList()
|
||||
// TimeModifiers = _timeModifiers?.Where(mod => mod != null).ToList() ?? new List<TimeModifier>()
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -373,9 +373,6 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
MoveAndSlide();
|
||||
|
||||
_crosshair.Position = CalculateCrosshairPosition();
|
||||
|
||||
//FindInteractable();
|
||||
|
||||
}
|
||||
|
||||
private void _on_interaction_controller_area_entered(Area2D area)
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public partial class BulletResource : Resource
|
|||
Modifier = Modifier,
|
||||
LifeTime = LifeTime,
|
||||
DestructionParticlesScene = DestructionParticlesScene,
|
||||
TimeModifiers = TimeModifiers.ToList()
|
||||
TimeModifiers = TimeModifiers.Select(x => x.MakeClone()).ToList()
|
||||
// TimeModifiers = TimeModifiers?.Where(mod => mod is TimeModifier).Cast<TimeModifier>().Select(m => new ModifierWrapper()
|
||||
// {
|
||||
// TimeModifier = m,
|
||||
|
|
|
|||
12
Scripts/Resources/TestGeneric/GenericTestNode.cs
Normal file
12
Scripts/Resources/TestGeneric/GenericTestNode.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Resources.TestGeneric;
|
||||
|
||||
public partial class GenericTestNode : Node2D
|
||||
{
|
||||
|
||||
[Export] public GenericTestResourceBase TestResource { get; set; } = null!;
|
||||
|
||||
|
||||
|
||||
}
|
||||
15
Scripts/Resources/TestGeneric/GenericTestResourceBase.cs
Normal file
15
Scripts/Resources/TestGeneric/GenericTestResourceBase.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Resources.TestGeneric;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class GenericTestResourceBase : Resource
|
||||
{
|
||||
[Export]
|
||||
public int Value { get; set; }
|
||||
|
||||
public void Test()
|
||||
{
|
||||
var asfd = this.MemberwiseClone() as GenericTestResourceBase;
|
||||
}
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@ public partial class TimeModifier : Resource
|
|||
[Export] public TimeModifierType ModifierType;
|
||||
[Export] public float Value;
|
||||
[Export] public bool Continuous = false;
|
||||
public bool Applied { get; set; } = false;
|
||||
|
||||
public ModifierWrapper Wrap()
|
||||
{
|
||||
|
|
@ -18,6 +19,11 @@ public partial class TimeModifier : Resource
|
|||
Applied = false
|
||||
};
|
||||
}
|
||||
|
||||
public TimeModifier MakeClone()
|
||||
{
|
||||
return this.MemberwiseClone() as TimeModifier;
|
||||
}
|
||||
}
|
||||
|
||||
public class ModifierWrapper
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue