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

@ -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,

View file

@ -0,0 +1,12 @@
using Godot;
namespace Cirno.Scripts.Resources.TestGeneric;
public partial class GenericTestNode : Node2D
{
[Export] public GenericTestResourceBase TestResource { get; set; } = null!;
}

View 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;
}
}

View file

@ -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