mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-07-05 07:51:17 +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
|
|
@ -303,7 +303,7 @@ position = Vector2(-1239.5, 10.9699)
|
||||||
position = Vector2(-1432, 12)
|
position = Vector2(-1432, 12)
|
||||||
|
|
||||||
[node name="Enemy7" parent="." instance=ExtResource("18_ixcwn")]
|
[node name="Enemy7" parent="." instance=ExtResource("18_ixcwn")]
|
||||||
position = Vector2(-1470, -205)
|
position = Vector2(-1506, -167)
|
||||||
|
|
||||||
[node name="Elevator" parent="." instance=ExtResource("16_n40rt")]
|
[node name="Elevator" parent="." instance=ExtResource("16_n40rt")]
|
||||||
position = Vector2(-581, -485)
|
position = Vector2(-581, -485)
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,8 @@ public partial class SpiralPattern : AttackPattern
|
||||||
BulletScene = BulletScene,
|
BulletScene = BulletScene,
|
||||||
RotationOffset = angleOffset,
|
RotationOffset = angleOffset,
|
||||||
Modifier = _modifier,
|
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;
|
public BulletInfo BulletInfo => _bulletInfo;
|
||||||
|
|
||||||
private List<ModifierWrapper> _modifiers = new();
|
private List<TimeModifier> _modifiers = new();
|
||||||
|
|
||||||
private GameManager _gameManager;
|
private GameManager _gameManager;
|
||||||
|
|
||||||
|
|
@ -35,9 +35,15 @@ public partial class Bullet : Area2D
|
||||||
|
|
||||||
_gameManager = gameManager;
|
_gameManager = gameManager;
|
||||||
|
|
||||||
// Ugly hack to make instances unique
|
_modifiers = _bulletInfo.TimeModifiers;
|
||||||
_modifiers = _bulletInfo.TimeModifiers.Select(x => x.Wrap()).ToList();
|
|
||||||
|
|
||||||
|
// 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()
|
private void ApplyTimeModifiers()
|
||||||
|
|
@ -48,17 +54,17 @@ public partial class Bullet : Area2D
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (_elapsedTime >= modifier.TimeModifier.TimeInSeconds)
|
if (_elapsedTime >= modifier.TimeInSeconds)
|
||||||
{
|
{
|
||||||
GD.Print("Applied time modifier");
|
GD.Print("Applied time modifier");
|
||||||
switch (modifier.TimeModifier.ModifierType)
|
switch (modifier.ModifierType)
|
||||||
{
|
{
|
||||||
case TimeModifierType.SpeedChange:
|
case TimeModifierType.SpeedChange:
|
||||||
//_bulletInfo.Speed += modifier.Value;
|
//_bulletInfo.Speed += modifier.Value;
|
||||||
Speed = modifier.TimeModifier.Value;
|
Speed = modifier.Value;
|
||||||
break;
|
break;
|
||||||
case TimeModifierType.RotationChange:
|
case TimeModifierType.RotationChange:
|
||||||
RotateBullet(modifier.TimeModifier.Value);
|
RotateBullet(modifier.Value);
|
||||||
//Rotation += Mathf.DegToRad(modifier.Value);
|
//Rotation += Mathf.DegToRad(modifier.Value);
|
||||||
break;
|
break;
|
||||||
case TimeModifierType.FacePlayer:
|
case TimeModifierType.FacePlayer:
|
||||||
|
|
@ -66,7 +72,7 @@ public partial class Bullet : Area2D
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!modifier.TimeModifier.Continuous)
|
if (!modifier.Continuous)
|
||||||
{
|
{
|
||||||
modifier.Applied = true;
|
modifier.Applied = true;
|
||||||
}
|
}
|
||||||
|
|
@ -121,7 +127,10 @@ public partial class Bullet : Area2D
|
||||||
{
|
{
|
||||||
ApplyTimeModifiers();
|
ApplyTimeModifiers();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void _PhysicsProcess(double delta)
|
||||||
|
{
|
||||||
this.Position += ((float)(Speed * delta) * _direction);
|
this.Position += ((float)(Speed * delta) * _direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -373,9 +373,6 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
||||||
MoveAndSlide();
|
MoveAndSlide();
|
||||||
|
|
||||||
_crosshair.Position = CalculateCrosshairPosition();
|
_crosshair.Position = CalculateCrosshairPosition();
|
||||||
|
|
||||||
//FindInteractable();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _on_interaction_controller_area_entered(Area2D area)
|
private void _on_interaction_controller_area_entered(Area2D area)
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ public partial class BulletResource : Resource
|
||||||
Modifier = Modifier,
|
Modifier = Modifier,
|
||||||
LifeTime = LifeTime,
|
LifeTime = LifeTime,
|
||||||
DestructionParticlesScene = DestructionParticlesScene,
|
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()
|
// TimeModifiers = TimeModifiers?.Where(mod => mod is TimeModifier).Cast<TimeModifier>().Select(m => new ModifierWrapper()
|
||||||
// {
|
// {
|
||||||
// TimeModifier = m,
|
// 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 TimeModifierType ModifierType;
|
||||||
[Export] public float Value;
|
[Export] public float Value;
|
||||||
[Export] public bool Continuous = false;
|
[Export] public bool Continuous = false;
|
||||||
|
public bool Applied { get; set; } = false;
|
||||||
|
|
||||||
public ModifierWrapper Wrap()
|
public ModifierWrapper Wrap()
|
||||||
{
|
{
|
||||||
|
|
@ -18,6 +19,11 @@ public partial class TimeModifier : Resource
|
||||||
Applied = false
|
Applied = false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TimeModifier MakeClone()
|
||||||
|
{
|
||||||
|
return this.MemberwiseClone() as TimeModifier;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ModifierWrapper
|
public class ModifierWrapper
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue