basic tests for a wider variety of files
This commit is contained in:
@@ -5,12 +5,8 @@
|
|||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANode_002Ecs_002Fl_003AC_0021_003FUsers_003FMinimata_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003F716d154fef5cbe863cd637bd32beda6e3cec5f12e8fed2dc5b2d8149a0d558ab_003FNode_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANode_002Ecs_002Fl_003AC_0021_003FUsers_003FMinimata_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003F716d154fef5cbe863cd637bd32beda6e3cec5f12e8fed2dc5b2d8149a0d558ab_003FNode_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANode_002Ecs_002Fl_003AC_0021_003FUsers_003FMinimata_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003Fdf73a4db74df89d59655c5fb6326406f47fbfa9af1fa81518fe0a07c49d34133_003FNode_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANode_002Ecs_002Fl_003AC_0021_003FUsers_003FMinimata_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003Fdf73a4db74df89d59655c5fb6326406f47fbfa9af1fa81518fe0a07c49d34133_003FNode_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASceneTree_002Ecs_002Fl_003AC_0021_003FUsers_003FMinimata_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003F8d6960554e939a669841b1ece03d27df4ab42f92bb80be3767eaec8cdaccf84b_003FSceneTree_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASceneTree_002Ecs_002Fl_003AC_0021_003FUsers_003FMinimata_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003F8d6960554e939a669841b1ece03d27df4ab42f92bb80be3767eaec8cdaccf84b_003FSceneTree_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=7ce84f90_002D6ae2_002D4e9e_002D860e_002Deb90f45871f3/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" IsActive="True" Name="Junie Session" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
|
|
||||||
<TestAncestor>
|
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=dd9a7ac6_002Dbb9b_002D4001_002Db145_002D15e6509b7e78/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from Solution" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
|
||||||
<TestId>VsTest::22FEBE6E-769C-4716-A687-A0AC8F3EF84A::net9.0::executor://gdunit4.testadapter/#Movementtests.tests.PlayerControllerUnitTest</TestId>
|
|
||||||
</TestAncestor>
|
|
||||||
</SessionState></s:String>
|
|
||||||
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=dd9a7ac6_002Dbb9b_002D4001_002Db145_002D15e6509b7e78/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" Name="All tests from Solution" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
|
|
||||||
<Solution />
|
<Solution />
|
||||||
</SessionState></s:String>
|
</SessionState></s:String>
|
||||||
<s:String x:Key="/Default/Housekeeping/UnitTestingMru/UnitTestRunner/RunConfigurationFilename/@EntryValue">D:\Godot\Projects\movement-tests\.runsettings</s:String>
|
<s:String x:Key="/Default/Housekeeping/UnitTestingMru/UnitTestRunner/RunConfigurationFilename/@EntryValue">D:\Godot\Projects\movement-tests\.runsettings</s:String>
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ HealthInputs = ExtResource("7_ucbss")
|
|||||||
DamageInputs = ExtResource("8_2brdd")
|
DamageInputs = ExtResource("8_2brdd")
|
||||||
Target = NodePath("../Player")
|
Target = NodePath("../Player")
|
||||||
SpawnInterval = 5.0
|
SpawnInterval = 5.0
|
||||||
IsActiveOnStart = false
|
|
||||||
|
|
||||||
[node name="GroundedSpawner2" parent="." index="9" unique_id=1026317919 node_paths=PackedStringArray("Target") instance=ExtResource("4_jaqjx")]
|
[node name="GroundedSpawner2" parent="." index="9" unique_id=1026317919 node_paths=PackedStringArray("Target") instance=ExtResource("4_jaqjx")]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 46.5, 11.5, -34.5)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 46.5, 11.5, -34.5)
|
||||||
@@ -42,7 +41,6 @@ HealthInputs = ExtResource("7_ucbss")
|
|||||||
DamageInputs = ExtResource("8_2brdd")
|
DamageInputs = ExtResource("8_2brdd")
|
||||||
Target = NodePath("../Player")
|
Target = NodePath("../Player")
|
||||||
SpawnInterval = 5.0
|
SpawnInterval = 5.0
|
||||||
IsActiveOnStart = false
|
|
||||||
|
|
||||||
[node name="GroundedSpawner3" parent="." index="10" unique_id=241829575 node_paths=PackedStringArray("Target") instance=ExtResource("4_jaqjx")]
|
[node name="GroundedSpawner3" parent="." index="10" unique_id=241829575 node_paths=PackedStringArray("Target") instance=ExtResource("4_jaqjx")]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 44.5, 0, -3)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 44.5, 0, -3)
|
||||||
@@ -52,7 +50,6 @@ HealthInputs = ExtResource("7_ucbss")
|
|||||||
DamageInputs = ExtResource("8_2brdd")
|
DamageInputs = ExtResource("8_2brdd")
|
||||||
Target = NodePath("../Player")
|
Target = NodePath("../Player")
|
||||||
SpawnInterval = 5.0
|
SpawnInterval = 5.0
|
||||||
IsActiveOnStart = false
|
|
||||||
|
|
||||||
[node name="FlyingSpawner" parent="." index="11" unique_id=962840208 node_paths=PackedStringArray("Target") instance=ExtResource("4_jaqjx")]
|
[node name="FlyingSpawner" parent="." index="11" unique_id=962840208 node_paths=PackedStringArray("Target") instance=ExtResource("4_jaqjx")]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 16.5, 19, -19.5)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 16.5, 19, -19.5)
|
||||||
@@ -62,7 +59,6 @@ HealthInputs = ExtResource("11_5jlg7")
|
|||||||
DamageInputs = ExtResource("12_pjgox")
|
DamageInputs = ExtResource("12_pjgox")
|
||||||
Target = NodePath("../Player")
|
Target = NodePath("../Player")
|
||||||
SpawnInterval = 5.0
|
SpawnInterval = 5.0
|
||||||
IsActiveOnStart = false
|
|
||||||
|
|
||||||
[node name="FlyingSpawner2" parent="." index="12" unique_id=365997644 node_paths=PackedStringArray("Target") instance=ExtResource("4_jaqjx")]
|
[node name="FlyingSpawner2" parent="." index="12" unique_id=365997644 node_paths=PackedStringArray("Target") instance=ExtResource("4_jaqjx")]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 45.5, 25.5, -42.5)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 45.5, 25.5, -42.5)
|
||||||
@@ -72,7 +68,6 @@ HealthInputs = ExtResource("11_5jlg7")
|
|||||||
DamageInputs = ExtResource("12_pjgox")
|
DamageInputs = ExtResource("12_pjgox")
|
||||||
Target = NodePath("../Player")
|
Target = NodePath("../Player")
|
||||||
SpawnInterval = 5.0
|
SpawnInterval = 5.0
|
||||||
IsActiveOnStart = false
|
|
||||||
|
|
||||||
[node name="Targets" type="Node3D" parent="." index="13" unique_id=1620747784]
|
[node name="Targets" type="Node3D" parent="." index="13" unique_id=1620747784]
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ using Movementtests.systems.damage;
|
|||||||
[GlobalClass]
|
[GlobalClass]
|
||||||
public partial class RDamageModifier : Resource, IDamageable
|
public partial class RDamageModifier : Resource, IDamageable
|
||||||
{
|
{
|
||||||
public event Action<IDamageable, DamageRecord> DamageTaken;
|
public event Action<IDamageable, DamageRecord> DamageTaken = null!;
|
||||||
|
|
||||||
[Export]
|
[Export]
|
||||||
public EDamageTypes DamageType { get; set;}
|
public EDamageTypes DamageType { get; set;}
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ using Movementtests.interfaces;
|
|||||||
[GlobalClass, Icon("res://assets/ui/IconGodotNode/white/icon_heart.png")]
|
[GlobalClass, Icon("res://assets/ui/IconGodotNode/white/icon_heart.png")]
|
||||||
public partial class CHealth : Node, IHealthable
|
public partial class CHealth : Node, IHealthable
|
||||||
{
|
{
|
||||||
public event Action<IHealthable, HealthChangedRecord> HealthChanged;
|
public event Action<IHealthable, HealthChangedRecord> HealthChanged = null!;
|
||||||
public event Action<IHealthable> HealthDepleted;
|
public event Action<IHealthable> HealthDepleted = null!;
|
||||||
|
|
||||||
[Export]
|
[Export]
|
||||||
public RHealth RHealth { get; set; }
|
public RHealth RHealth { get; set; } = null!;
|
||||||
|
|
||||||
public float CurrentHealth { get; set; }
|
public float CurrentHealth { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ using Movementtests.interfaces;
|
|||||||
[GlobalClass, Icon("res://assets/ui/IconGodotNode/node_3D/icon_wind.png")]
|
[GlobalClass, Icon("res://assets/ui/IconGodotNode/node_3D/icon_wind.png")]
|
||||||
public partial class CKnockback : Node3D, IKnockbackable
|
public partial class CKnockback : Node3D, IKnockbackable
|
||||||
{
|
{
|
||||||
[Export] public RKnockback RKnockback { get; set;}
|
[Export] public RKnockback RKnockback { get; set;} = null!;
|
||||||
|
|
||||||
private KnockbackRecord _knockbackRecord = null;
|
private KnockbackRecord _knockbackRecord = null!;
|
||||||
|
|
||||||
public void RegisterKnockback(KnockbackRecord knockbackRecord)
|
public void RegisterKnockback(KnockbackRecord knockbackRecord)
|
||||||
{
|
{
|
||||||
@@ -20,7 +20,7 @@ public partial class CKnockback : Node3D, IKnockbackable
|
|||||||
|
|
||||||
var knockbackDirection = GlobalPosition - _knockbackRecord.DamageRecord.SourceLocation;
|
var knockbackDirection = GlobalPosition - _knockbackRecord.DamageRecord.SourceLocation;
|
||||||
var finalKnockback = knockbackDirection.Normalized() * RKnockback.Modifier * _knockbackRecord.ForceMultiplier;
|
var finalKnockback = knockbackDirection.Normalized() * RKnockback.Modifier * _knockbackRecord.ForceMultiplier;
|
||||||
_knockbackRecord = null;
|
_knockbackRecord = null!;
|
||||||
return finalKnockback;
|
return finalKnockback;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,9 @@ namespace Movementtests.scenes.movement;
|
|||||||
[GlobalClass, Icon("res://assets/ui/IconGodotNode/node_3D/icon_path_follow.png")]
|
[GlobalClass, Icon("res://assets/ui/IconGodotNode/node_3D/icon_path_follow.png")]
|
||||||
public partial class CGroundedMovement : Node3D, IMoveable
|
public partial class CGroundedMovement : Node3D, IMoveable
|
||||||
{
|
{
|
||||||
[Export] public RMovement RMovement { get; set; }
|
[Export] public RMovement RMovement { get; set; } = null!;
|
||||||
|
|
||||||
[Export]
|
[Export] public RayCast3D WallInFrontRayCast { get; set; } = null!;
|
||||||
public RayCast3D WallInFrontRayCast { get; set; }
|
|
||||||
|
|
||||||
|
|
||||||
public Vector3 ComputeVelocity(MovementInputs inputs)
|
public Vector3 ComputeVelocity(MovementInputs inputs)
|
||||||
|
|||||||
@@ -16,36 +16,37 @@ public partial class Enemy : CharacterBody3D,
|
|||||||
IStunnable
|
IStunnable
|
||||||
{
|
{
|
||||||
// Signals and events
|
// Signals and events
|
||||||
public event Action<IDamageable, DamageRecord> DamageTaken;
|
public event Action<IDamageable, DamageRecord> DamageTaken = null!;
|
||||||
public event Action<IHealthable, HealthChangedRecord> HealthChanged;
|
public event Action<IHealthable, HealthChangedRecord> HealthChanged = null!;
|
||||||
public event Action<IHealthable> HealthDepleted;
|
public event Action<IHealthable> HealthDepleted = null!;
|
||||||
|
|
||||||
// Public export components
|
// Public export components
|
||||||
[Export]
|
[Export]
|
||||||
public Node3D Target { get; set; }
|
public Node3D Target { get; set; } = null!;
|
||||||
|
|
||||||
[Export]
|
[Export]
|
||||||
public float EnemyHeight { get; set; } = 1f;
|
public float EnemyHeight { get; set; } = 1f;
|
||||||
|
|
||||||
[ExportGroup("Health")]
|
[ExportGroup("Health")]
|
||||||
[Export]
|
[Export]
|
||||||
public RHealth RHealth { get; set; }
|
public RHealth RHealth { get; set; } = null!;
|
||||||
[Export]
|
[Export]
|
||||||
public RDeathEffect[] DeathEffects { get; set; }
|
public RDeathEffect[] DeathEffects { get; set; } = null!;
|
||||||
public IHealthable CHealth { get; set; }
|
public IHealthable CHealth { get; set; } = null!;
|
||||||
|
|
||||||
[ExportGroup("Damage")]
|
[ExportGroup("Damage")]
|
||||||
[Export]
|
[Export]
|
||||||
public RDamage RDamage { get; set; }
|
public RDamage RDamage { get; set; } = null!;
|
||||||
public IDamageable CDamageable { get; set; }
|
public IDamageable CDamageable { get; set; } = null!;
|
||||||
|
|
||||||
[Export]
|
[Export]
|
||||||
public RKnockback RKnockback { get; set; }
|
public RKnockback RKnockback { get; set; } = null!;
|
||||||
public IKnockbackable CKnockback { get; set; }
|
public IKnockbackable CKnockback { get; set; } = null!;
|
||||||
|
|
||||||
[ExportGroup("Movement")]
|
[ExportGroup("Movement")]
|
||||||
[Export]
|
[Export]
|
||||||
public RMovement RMovement { get; set; }
|
public RMovement RMovement { get; set; } = null!;
|
||||||
public IMoveable CMovement { get; set; }
|
public IMoveable CMovement { get; set; } = null!;
|
||||||
|
|
||||||
// Public stuff
|
// Public stuff
|
||||||
public float CurrentHealth
|
public float CurrentHealth
|
||||||
@@ -55,9 +56,9 @@ public partial class Enemy : CharacterBody3D,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Private stuff
|
// Private stuff
|
||||||
private Area3D _damageBox;
|
private Area3D _damageBox = null!;
|
||||||
private Node3D _target;
|
internal Node3D _target = null!;
|
||||||
private Healthbar _healthbar;
|
private Healthbar _healthbar = null!;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
@@ -70,34 +71,28 @@ public partial class Enemy : CharacterBody3D,
|
|||||||
_damageBox = GetNode<Area3D>("DamageBox");
|
_damageBox = GetNode<Area3D>("DamageBox");
|
||||||
_target = GetNode<Node3D>("CTarget");
|
_target = GetNode<Node3D>("CTarget");
|
||||||
|
|
||||||
CDamageable = GetNode<Node>("CDamageable") as IDamageable;
|
CDamageable = (GetNode<Node>("CDamageable") as IDamageable)!;
|
||||||
CMovement = GetNode<Node>("CMovement") as IMoveable;
|
CMovement = (GetNode<Node>("CMovement") as IMoveable)!;
|
||||||
CHealth = GetNode<Node>("CHealth") as IHealthable;
|
CHealth = (GetNode<Node>("CHealth") as IHealthable)!;
|
||||||
CKnockback = GetNode<Node>("CKnockback") as IKnockbackable;
|
CKnockback = (GetNode<Node>("CKnockback") as IKnockbackable)!;
|
||||||
if (CDamageable is null) GD.PrintErr("This node needs a 'CDamage' child of type IDamageable!");
|
|
||||||
if (CMovement is null) GD.PrintErr("This node needs a 'CMovement' child of type IMoveable!");
|
|
||||||
if (CHealth is null) GD.PrintErr("This node needs a 'CHealth' child of type IHealthable!");
|
|
||||||
if (CKnockback is null) GD.PrintErr("This node needs a 'CKnockback' child of type IKnockbackable!");
|
|
||||||
|
|
||||||
_healthbar = GetNode<CHealthbar>("CHealthBar").Healthbar;
|
_healthbar = GetNode<CHealthbar>("CHealthBar").Healthbar;
|
||||||
|
|
||||||
if (RMovement != null) CMovement!.RMovement = RMovement;
|
CMovement.RMovement = RMovement;
|
||||||
if (RHealth != null)
|
CHealth.RHealth = RHealth;
|
||||||
{
|
|
||||||
CHealth!.RHealth = RHealth;
|
|
||||||
CHealth.CurrentHealth = RHealth.StartingHealth;
|
CHealth.CurrentHealth = RHealth.StartingHealth;
|
||||||
}
|
CKnockback.RKnockback = RKnockback;
|
||||||
if (RKnockback != null) CKnockback!.RKnockback = RKnockback;
|
|
||||||
_healthbar.Initialize(CHealth!.CurrentHealth);
|
_healthbar.Initialize(CHealth.CurrentHealth);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetupSignals()
|
public void SetupSignals()
|
||||||
{
|
{
|
||||||
// Anonymous function call to erase return values of ReduceHealth
|
// Anonymous function call to erase return values of ReduceHealth
|
||||||
CDamageable.DamageTaken += (source, record) => ReduceHealth(source, record);
|
CDamageable.DamageTaken += (source, record) => ReduceHealth(source, record);
|
||||||
CDamageable.DamageTaken += (source, record) => RegisterKnockback(new KnockbackRecord(record));
|
CDamageable.DamageTaken += (_, record) => RegisterKnockback(new KnockbackRecord(record));
|
||||||
CHealth.HealthDepleted += Kill;
|
CHealth.HealthDepleted += Kill;
|
||||||
HealthChanged += (source, record) => _healthbar.SetHealth(record.CurrentHealth);
|
HealthChanged += (_, record) => _healthbar.SetHealth(record.CurrentHealth);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _PhysicsProcess(double delta)
|
public override void _PhysicsProcess(double delta)
|
||||||
@@ -187,24 +182,21 @@ public partial class Enemy : CharacterBody3D,
|
|||||||
|
|
||||||
public void RegisterKnockback(KnockbackRecord knockbackRecord)
|
public void RegisterKnockback(KnockbackRecord knockbackRecord)
|
||||||
{
|
{
|
||||||
if (CKnockback is null) return;
|
|
||||||
CKnockback.RegisterKnockback(knockbackRecord);
|
CKnockback.RegisterKnockback(knockbackRecord);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector3 ComputeKnockback()
|
public Vector3 ComputeKnockback()
|
||||||
{
|
{
|
||||||
if (CKnockback is null) return Vector3.Zero;
|
|
||||||
return CKnockback.ComputeKnockback();
|
return CKnockback.ComputeKnockback();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector3 GetTargetGlobalPosition()
|
public Vector3 GetTargetGlobalPosition()
|
||||||
{
|
{
|
||||||
if (_target is null) return GlobalPosition;
|
return _target == null ? GlobalPosition : _target.GlobalPosition;
|
||||||
return _target.GlobalPosition;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stun management
|
// Stun management
|
||||||
public bool IsStunned { get; set; } = false;
|
public bool IsStunned { get; set; }
|
||||||
|
|
||||||
[Export(PropertyHint.Range, "0.1, 2, 0.1, or_greater")]
|
[Export(PropertyHint.Range, "0.1, 2, 0.1, or_greater")]
|
||||||
public float StunDuration { get; set; } = 1f;
|
public float StunDuration { get; set; } = 1f;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ using Movementtests.interfaces;
|
|||||||
[GlobalClass, Icon("res://assets/ui/IconGodotNode/control/icon_text_panel.png")]
|
[GlobalClass, Icon("res://assets/ui/IconGodotNode/control/icon_text_panel.png")]
|
||||||
public partial class PlayerUi : Control
|
public partial class PlayerUi : Control
|
||||||
{
|
{
|
||||||
private TextureRect[] _dashIcons = new TextureRect[3];
|
internal TextureRect[] _dashIcons = new TextureRect[3];
|
||||||
private TextureRect _enemyTarget;
|
private TextureRect _enemyTarget;
|
||||||
private Healthbar _healthbar;
|
private Healthbar _healthbar;
|
||||||
|
|
||||||
|
|||||||
@@ -26,18 +26,18 @@ public partial class DashSystem: Node3D
|
|||||||
public Vector3 PlannedMantleLocation { get; set; }
|
public Vector3 PlannedMantleLocation { get; set; }
|
||||||
public MantleSystem MantleSystem { get; set; }
|
public MantleSystem MantleSystem { get; set; }
|
||||||
|
|
||||||
private HeadSystem _head;
|
internal HeadSystem _head;
|
||||||
public ShapeCast3D DashCast3D;
|
public ShapeCast3D DashCast3D;
|
||||||
private Camera3D _camera;
|
internal Camera3D _camera;
|
||||||
private Vector3 _dashDirection = Vector3.Zero;
|
internal Vector3 _dashDirection = Vector3.Zero;
|
||||||
|
|
||||||
private ShapeCast3D _dashCastDrop;
|
internal ShapeCast3D _dashCastDrop;
|
||||||
private MeshInstance3D _dashDropIndicator;
|
internal MeshInstance3D _dashDropIndicator;
|
||||||
private MeshInstance3D _dashDropLocationIndicator;
|
internal MeshInstance3D _dashDropLocationIndicator;
|
||||||
|
|
||||||
private MeshInstance3D _dashTarget;
|
internal MeshInstance3D _dashTarget;
|
||||||
private CpuParticles3D _dashIndicator;
|
internal CpuParticles3D _dashIndicator;
|
||||||
private AnimationPlayer _dashIndicatorAnim;
|
internal AnimationPlayer _dashIndicatorAnim;
|
||||||
|
|
||||||
[Export]
|
[Export]
|
||||||
public PackedScene DashIndicatorScene { get; set; }
|
public PackedScene DashIndicatorScene { get; set; }
|
||||||
@@ -77,7 +77,7 @@ public partial class DashSystem: Node3D
|
|||||||
_dashIndicatorAnim = GetNode<AnimationPlayer>("DashIndicator/AnimationPlayer");
|
_dashIndicatorAnim = GetNode<AnimationPlayer>("DashIndicator/AnimationPlayer");
|
||||||
}
|
}
|
||||||
|
|
||||||
private DashLocation ComputeDashLocation()
|
internal DashLocation ComputeDashLocation()
|
||||||
{
|
{
|
||||||
var targetLocation = DashCast3D.ToGlobal(DashCast3D.TargetPosition);
|
var targetLocation = DashCast3D.ToGlobal(DashCast3D.TargetPosition);
|
||||||
var hasHit = DashCast3D.IsColliding();
|
var hasHit = DashCast3D.IsColliding();
|
||||||
|
|||||||
@@ -39,10 +39,10 @@ public partial class HeadSystem : Node3D
|
|||||||
float BobbingMultiplier,
|
float BobbingMultiplier,
|
||||||
float FovMultiplier);
|
float FovMultiplier);
|
||||||
|
|
||||||
private Camera3D _camera;
|
internal Camera3D _camera;
|
||||||
private Marker3D _cameraAnchor;
|
internal Marker3D _cameraAnchor;
|
||||||
private AnimationPlayer _animationPlayer;
|
internal AnimationPlayer _animationPlayer;
|
||||||
private AnimationTree _animationTree;
|
internal AnimationTree _animationTree;
|
||||||
|
|
||||||
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
|
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
|
||||||
public float LookSensitivity { get; set; } = 1f;
|
public float LookSensitivity { get; set; } = 1f;
|
||||||
@@ -63,11 +63,11 @@ public partial class HeadSystem : Node3D
|
|||||||
[Export(PropertyHint.Range, "0,1,0.01,or_greater")]
|
[Export(PropertyHint.Range, "0,1,0.01,or_greater")]
|
||||||
public float SlidingJitterAmplitude { get; set; } = 0.1f;
|
public float SlidingJitterAmplitude { get; set; } = 0.1f;
|
||||||
|
|
||||||
private FastNoiseLite _slidingNoise = new FastNoiseLite();
|
internal FastNoiseLite _slidingNoise = new FastNoiseLite();
|
||||||
|
|
||||||
[ExportGroup("Bobbing")]
|
[ExportGroup("Bobbing")]
|
||||||
|
|
||||||
private float _bobbingAccumulator; // Constantly increases when player moves in X or/and Z axis
|
internal float _bobbingAccumulator; // Constantly increases when player moves in X or/and Z axis
|
||||||
[Export(PropertyHint.Range, "0,10,0.01,or_greater")]
|
[Export(PropertyHint.Range, "0,10,0.01,or_greater")]
|
||||||
public float BobbingFrequency { set; get; } = 2.4f;
|
public float BobbingFrequency { set; get; } = 2.4f;
|
||||||
[Export(PropertyHint.Range, "0,0.4,0.01,or_greater")]
|
[Export(PropertyHint.Range, "0,0.4,0.01,or_greater")]
|
||||||
@@ -84,11 +84,11 @@ public partial class HeadSystem : Node3D
|
|||||||
public float FovMaxedOutSpeed { get; set; } = 20f;
|
public float FovMaxedOutSpeed { get; set; } = 20f;
|
||||||
|
|
||||||
[ExportGroup("First Person rig")]
|
[ExportGroup("First Person rig")]
|
||||||
private Node3D _fpRig;
|
internal Node3D _fpRig;
|
||||||
private Node3D _rightHandedWeapon;
|
internal Node3D _rightHandedWeapon;
|
||||||
private Node3D _leftHandedWeapon;
|
internal Node3D _leftHandedWeapon;
|
||||||
private Node3D _fpDisplacedRig;
|
internal Node3D _fpDisplacedRig;
|
||||||
private Vector3 _fpDisplacedRigInitialRotation;
|
internal Vector3 _fpDisplacedRigInitialRotation;
|
||||||
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
|
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
|
||||||
public float WeaponSway { get; set; } = 5f;
|
public float WeaponSway { get; set; } = 5f;
|
||||||
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
|
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
|
||||||
@@ -190,8 +190,8 @@ public partial class HeadSystem : Node3D
|
|||||||
EmitSignalHitboxDeactivated();
|
EmitSignalHitboxDeactivated();
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool _footstepEmitted;
|
internal bool _footstepEmitted;
|
||||||
private bool _isPlayingForcingAnim;
|
internal bool _isPlayingForcingAnim;
|
||||||
|
|
||||||
public void ResetHeadBobbing()
|
public void ResetHeadBobbing()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -265,8 +265,8 @@ public partial class PlayerController : CharacterBody3D,
|
|||||||
private float _inputRotateFloorplane;
|
private float _inputRotateFloorplane;
|
||||||
|
|
||||||
// Basic falling
|
// Basic falling
|
||||||
private float _targetSpeed;
|
internal float _targetSpeed;
|
||||||
private float _gravity;
|
internal float _gravity;
|
||||||
|
|
||||||
// Jump stuff
|
// Jump stuff
|
||||||
private int _currentInputBufferFrames;
|
private int _currentInputBufferFrames;
|
||||||
@@ -290,7 +290,7 @@ public partial class PlayerController : CharacterBody3D,
|
|||||||
private Vector3 _currentWallContactPoint = Vector3.Zero;
|
private Vector3 _currentWallContactPoint = Vector3.Zero;
|
||||||
|
|
||||||
// Dash stuff
|
// Dash stuff
|
||||||
private bool _canDash = true;
|
internal bool _canDash = true;
|
||||||
private bool _canDashAirborne = true;
|
private bool _canDashAirborne = true;
|
||||||
private float _playerHeight;
|
private float _playerHeight;
|
||||||
private float _playerRadius;
|
private float _playerRadius;
|
||||||
|
|||||||
59
tests/components/DamageComponentUnitTest.cs
Normal file
59
tests/components/DamageComponentUnitTest.cs
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
using Godot;
|
||||||
|
using GdUnit4;
|
||||||
|
using static GdUnit4.Assertions;
|
||||||
|
using Movementtests.interfaces;
|
||||||
|
using Movementtests.systems.damage;
|
||||||
|
|
||||||
|
namespace Movementtests.tests;
|
||||||
|
|
||||||
|
[TestSuite, RequireGodotRuntime]
|
||||||
|
public class DamageComponentUnitTest
|
||||||
|
{
|
||||||
|
[TestCase]
|
||||||
|
public void DamageModifier_Applies_WhenTypeMatches()
|
||||||
|
{
|
||||||
|
var modifier = new RDamageModifier(EDamageTypes.Normal, 2.0f);
|
||||||
|
var input = new DamageRecord(Vector3.Zero, new RDamage(10.0f, EDamageTypes.Normal));
|
||||||
|
|
||||||
|
var result = modifier.TakeDamage(input);
|
||||||
|
AssertFloat(result.Damage.DamageDealt).IsEqual(20.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase]
|
||||||
|
public void DamageModifier_Ignores_WhenTypeDifferent()
|
||||||
|
{
|
||||||
|
var modifier = new RDamageModifier(EDamageTypes.Fire, 3.0f);
|
||||||
|
var input = new DamageRecord(Vector3.Zero, new RDamage(10.0f, EDamageTypes.Normal));
|
||||||
|
|
||||||
|
var result = modifier.TakeDamage(input);
|
||||||
|
AssertFloat(result.Damage.DamageDealt).IsEqual(0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase]
|
||||||
|
public void CDamageable_Sums_All_Modifiers()
|
||||||
|
{
|
||||||
|
var mod1 = new RDamageModifier(EDamageTypes.Normal, 1.0f);
|
||||||
|
var mod2 = new RDamageModifier(EDamageTypes.Normal, 0.5f);
|
||||||
|
|
||||||
|
var cDamageable = new CDamageable();
|
||||||
|
cDamageable.DamageModifiers = new[] { mod1, mod2 };
|
||||||
|
|
||||||
|
var input = new DamageRecord(Vector3.Zero, new RDamage(10.0f, EDamageTypes.Normal));
|
||||||
|
var result = cDamageable.TakeDamage(input);
|
||||||
|
|
||||||
|
// 10*1.0 + 10*0.5 = 15
|
||||||
|
AssertFloat(result.Damage.DamageDealt).IsEqual(15.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase]
|
||||||
|
public void CDamageable_ComputeDamage_DoesNotEmit()
|
||||||
|
{
|
||||||
|
var mod = new RDamageModifier(EDamageTypes.Normal, 2.0f);
|
||||||
|
var cDamageable = new CDamageable();
|
||||||
|
cDamageable.DamageModifiers = new[] { mod };
|
||||||
|
|
||||||
|
var input = new DamageRecord(Vector3.Zero, new RDamage(5.0f, EDamageTypes.Normal));
|
||||||
|
var result = cDamageable.ComputeDamage(input);
|
||||||
|
AssertFloat(result.Damage.DamageDealt).IsEqual(10.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
1
tests/components/DamageComponentUnitTest.cs.uid
Normal file
1
tests/components/DamageComponentUnitTest.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://db6rva7uccppc
|
||||||
56
tests/components/HealthComponentUnitTest.cs
Normal file
56
tests/components/HealthComponentUnitTest.cs
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
using Godot;
|
||||||
|
using GdUnit4;
|
||||||
|
using static GdUnit4.Assertions;
|
||||||
|
using Movementtests.interfaces;
|
||||||
|
using Movementtests.systems.damage;
|
||||||
|
|
||||||
|
namespace Movementtests.tests;
|
||||||
|
|
||||||
|
[TestSuite, RequireGodotRuntime]
|
||||||
|
public class HealthComponentUnitTest
|
||||||
|
{
|
||||||
|
[TestCase]
|
||||||
|
public void ReadyInitializesCurrentHealth()
|
||||||
|
{
|
||||||
|
var cHealth = new CHealth();
|
||||||
|
cHealth.RHealth = new RHealth(150.0f);
|
||||||
|
// Simulate Godot ready
|
||||||
|
cHealth._Ready();
|
||||||
|
AssertFloat(cHealth.CurrentHealth).IsEqual(150.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase]
|
||||||
|
public void ReduceHealthDecreasesAndDoesNotDeplete()
|
||||||
|
{
|
||||||
|
var cHealth = new CHealth();
|
||||||
|
cHealth.RHealth = new RHealth(100.0f);
|
||||||
|
cHealth.CurrentHealth = 100.0f;
|
||||||
|
|
||||||
|
var damage = new DamageRecord(Vector3.Zero, new RDamage(25.0f, EDamageTypes.Normal));
|
||||||
|
var record = cHealth.ReduceHealth(source: null!, damageRecord: damage);
|
||||||
|
|
||||||
|
AssertFloat(cHealth.CurrentHealth).IsEqual(75.0f);
|
||||||
|
AssertFloat(record.CurrentHealth).IsEqual(75.0f);
|
||||||
|
AssertFloat(record.PreviousHealth).IsEqual(100.0f);
|
||||||
|
AssertFloat(record.MaxHealth).IsEqual(100.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase]
|
||||||
|
public void ReduceHealthTriggersDepletionToZero()
|
||||||
|
{
|
||||||
|
var cHealth = new CHealth();
|
||||||
|
cHealth.RHealth = new RHealth(50.0f);
|
||||||
|
cHealth.CurrentHealth = 50.0f;
|
||||||
|
|
||||||
|
bool depleted = false;
|
||||||
|
cHealth.HealthDepleted += _ => depleted = true;
|
||||||
|
|
||||||
|
var damage = new DamageRecord(Vector3.Zero, new RDamage(100.0f, EDamageTypes.Normal));
|
||||||
|
var record = cHealth.ReduceHealth(source: null!, damageRecord: damage);
|
||||||
|
|
||||||
|
AssertBool(depleted).IsTrue();
|
||||||
|
AssertFloat(cHealth.CurrentHealth).IsEqual(0.0f);
|
||||||
|
AssertFloat(record.CurrentHealth).IsEqual(-50.0f);
|
||||||
|
AssertFloat(record.MaxHealth).IsEqual(50.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
1
tests/components/HealthComponentUnitTest.cs.uid
Normal file
1
tests/components/HealthComponentUnitTest.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://bd52i51hncgmf
|
||||||
31
tests/components/KnockbackComponentUnitTest.cs
Normal file
31
tests/components/KnockbackComponentUnitTest.cs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
using Godot;
|
||||||
|
using GdUnit4;
|
||||||
|
using static GdUnit4.Assertions;
|
||||||
|
using Movementtests.interfaces;
|
||||||
|
|
||||||
|
namespace Movementtests.tests;
|
||||||
|
|
||||||
|
[TestSuite, RequireGodotRuntime]
|
||||||
|
public class KnockbackComponentUnitTest
|
||||||
|
{
|
||||||
|
[TestCase]
|
||||||
|
public void RegisterAndComputeKnockback_Works_And_Resets()
|
||||||
|
{
|
||||||
|
var cKnock = new CKnockback();
|
||||||
|
cKnock.RKnockback = new RKnockback(2.0f);
|
||||||
|
cKnock.GlobalPosition = Vector3.Zero;
|
||||||
|
|
||||||
|
var damage = new DamageRecord(new Vector3(10, 0, 0), new RDamage(0, Movementtests.systems.damage.EDamageTypes.Normal));
|
||||||
|
var record = new KnockbackRecord(damage, 1.5f);
|
||||||
|
|
||||||
|
cKnock.RegisterKnockback(record);
|
||||||
|
var force = cKnock.ComputeKnockback();
|
||||||
|
|
||||||
|
// Direction from source(10,0,0) to target(0,0,0) is (-1,0,0), scaled by modifier(2) and multiplier(1.5) => (-3,0,0)
|
||||||
|
AssertVector(force).IsEqual(new Vector3(-3, 0, 0));
|
||||||
|
|
||||||
|
// Second call returns zero since internal state resets
|
||||||
|
var second = cKnock.ComputeKnockback();
|
||||||
|
AssertVector(second).IsEqual(Vector3.Zero);
|
||||||
|
}
|
||||||
|
}
|
||||||
1
tests/components/KnockbackComponentUnitTest.cs.uid
Normal file
1
tests/components/KnockbackComponentUnitTest.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://bv0eionbgbig5
|
||||||
32
tests/components/MovementSystemUnitTest.cs
Normal file
32
tests/components/MovementSystemUnitTest.cs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
using Godot;
|
||||||
|
using GdUnit4;
|
||||||
|
using static GdUnit4.Assertions;
|
||||||
|
using Movementtests.interfaces;
|
||||||
|
using Movementtests.scenes.movement;
|
||||||
|
|
||||||
|
namespace Movementtests.tests;
|
||||||
|
|
||||||
|
[TestSuite, RequireGodotRuntime]
|
||||||
|
public class MovementSystemUnitTest
|
||||||
|
{
|
||||||
|
[TestCase]
|
||||||
|
public void GroundedMovement_Accelerates_And_Applies_Gravity()
|
||||||
|
{
|
||||||
|
var move = new CGroundedMovement();
|
||||||
|
move.RMovement = new RMovement(speed: 10.0f, acceleration: 1.0f, gravityModifier: 0.5f, targetHeight: 0.0f);
|
||||||
|
move.WallInFrontRayCast = new RayCast3D();
|
||||||
|
move.GlobalPosition = Vector3.Zero;
|
||||||
|
|
||||||
|
var inputs = new MovementInputs(
|
||||||
|
Velocity: Vector3.Zero,
|
||||||
|
TargetLocation: new Vector3(10, 0, 0),
|
||||||
|
isOnFloor: false,
|
||||||
|
gravity: Vector3.Down * 9.8f,
|
||||||
|
delta: 1.0
|
||||||
|
);
|
||||||
|
|
||||||
|
var v = move.ComputeVelocity(inputs);
|
||||||
|
|
||||||
|
AssertVector(v).IsEqualApprox(new Vector3(10, -4.9f, 0), new Vector3(0.0001f, 0.0001f, 0.0001f));
|
||||||
|
}
|
||||||
|
}
|
||||||
1
tests/components/MovementSystemUnitTest.cs.uid
Normal file
1
tests/components/MovementSystemUnitTest.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://cofj5s4x74ay
|
||||||
78
tests/enemies/EnemyUnitTest.cs
Normal file
78
tests/enemies/EnemyUnitTest.cs
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
using Godot;
|
||||||
|
using GdUnit4;
|
||||||
|
using static GdUnit4.Assertions;
|
||||||
|
using Movementtests.interfaces;
|
||||||
|
using Movementtests.systems.damage;
|
||||||
|
|
||||||
|
namespace Movementtests.tests;
|
||||||
|
|
||||||
|
[TestSuite, RequireGodotRuntime]
|
||||||
|
public class EnemyUnitTest
|
||||||
|
{
|
||||||
|
[TestCase]
|
||||||
|
public void ComputeDamage_NoComponent_ReturnsZero()
|
||||||
|
{
|
||||||
|
var enemy = new Enemy();
|
||||||
|
var input = new DamageRecord(Vector3.Zero, new RDamage(10.0f, EDamageTypes.Normal));
|
||||||
|
|
||||||
|
var result = enemy.ComputeDamage(input);
|
||||||
|
AssertFloat(result.Damage.DamageDealt).IsEqual(0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase]
|
||||||
|
public void TakeDamage_WithCDamageable_AggregatesDamage()
|
||||||
|
{
|
||||||
|
var enemy = new Enemy();
|
||||||
|
var cDamage = new CDamageable();
|
||||||
|
cDamage.DamageModifiers = new[]
|
||||||
|
{
|
||||||
|
new RDamageModifier(EDamageTypes.Normal, 1.0f),
|
||||||
|
new RDamageModifier(EDamageTypes.Normal, 2.0f)
|
||||||
|
};
|
||||||
|
enemy.CDamageable = cDamage;
|
||||||
|
|
||||||
|
var input = new DamageRecord(Vector3.Zero, new RDamage(10.0f, EDamageTypes.Normal));
|
||||||
|
var result = enemy.TakeDamage(input);
|
||||||
|
AssertFloat(result.Damage.DamageDealt).IsEqual(30.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase]
|
||||||
|
public void ReduceHealth_WithCHealth_Decreases()
|
||||||
|
{
|
||||||
|
var enemy = new Enemy();
|
||||||
|
var health = new CHealth { RHealth = new RHealth(100.0f), CurrentHealth = 100.0f };
|
||||||
|
enemy.CHealth = health;
|
||||||
|
|
||||||
|
var input = new DamageRecord(Vector3.Zero, new RDamage(25.0f, EDamageTypes.Normal));
|
||||||
|
var record = enemy.ReduceHealth(enemy, input);
|
||||||
|
|
||||||
|
AssertFloat(health.CurrentHealth).IsEqual(75.0f);
|
||||||
|
AssertFloat(record.CurrentHealth).IsEqual(75.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase]
|
||||||
|
public void Knockback_Register_And_Compute()
|
||||||
|
{
|
||||||
|
var enemy = new Enemy();
|
||||||
|
var cKnock = new CKnockback { RKnockback = new RKnockback(1.0f) };
|
||||||
|
enemy.CKnockback = cKnock;
|
||||||
|
enemy.GlobalPosition = Vector3.Zero;
|
||||||
|
cKnock.GlobalPosition = Vector3.Zero;
|
||||||
|
|
||||||
|
var dmg = new DamageRecord(new Vector3(5, 0, 0), new RDamage(0, EDamageTypes.Normal));
|
||||||
|
var krec = new KnockbackRecord(dmg, 2.0f);
|
||||||
|
enemy.RegisterKnockback(krec);
|
||||||
|
|
||||||
|
var k = enemy.ComputeKnockback();
|
||||||
|
AssertVector(k).IsEqual(new Vector3(-2, 0, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase]
|
||||||
|
public void Unstun_ResetsFlag()
|
||||||
|
{
|
||||||
|
var enemy = new Enemy();
|
||||||
|
enemy.IsStunned = true;
|
||||||
|
enemy.Unstun();
|
||||||
|
AssertBool(enemy.IsStunned).IsFalse();
|
||||||
|
}
|
||||||
|
}
|
||||||
1
tests/enemies/EnemyUnitTest.cs.uid
Normal file
1
tests/enemies/EnemyUnitTest.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://cojxgcs6xqqoq
|
||||||
55
tests/player/DashSystemUnitTest.cs
Normal file
55
tests/player/DashSystemUnitTest.cs
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
using Godot;
|
||||||
|
using GdUnit4;
|
||||||
|
using static GdUnit4.Assertions;
|
||||||
|
using Movementtests.systems;
|
||||||
|
|
||||||
|
namespace Movementtests.tests;
|
||||||
|
|
||||||
|
[TestSuite, RequireGodotRuntime]
|
||||||
|
public class DashSystemUnitTest
|
||||||
|
{
|
||||||
|
private DashSystem _dashSystem;
|
||||||
|
|
||||||
|
[BeforeTest]
|
||||||
|
public void SetupTest()
|
||||||
|
{
|
||||||
|
_dashSystem = new DashSystem();
|
||||||
|
|
||||||
|
_dashSystem.DashCast3D = new ShapeCast3D();
|
||||||
|
_dashSystem.AddChild(_dashSystem.DashCast3D);
|
||||||
|
|
||||||
|
_dashSystem._dashCastDrop = new ShapeCast3D();
|
||||||
|
_dashSystem.AddChild(_dashSystem._dashCastDrop);
|
||||||
|
|
||||||
|
_dashSystem._dashTarget = new MeshInstance3D();
|
||||||
|
_dashSystem.AddChild(_dashSystem._dashTarget);
|
||||||
|
|
||||||
|
_dashSystem._dashDropIndicator = new MeshInstance3D();
|
||||||
|
_dashSystem.AddChild(_dashSystem._dashDropIndicator);
|
||||||
|
|
||||||
|
_dashSystem._dashDropLocationIndicator = new MeshInstance3D();
|
||||||
|
_dashSystem.AddChild(_dashSystem._dashDropLocationIndicator);
|
||||||
|
}
|
||||||
|
|
||||||
|
[AfterTest]
|
||||||
|
public void CleanupTest()
|
||||||
|
{
|
||||||
|
_dashSystem?.Free();
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase]
|
||||||
|
public void TestStopPreparingDash()
|
||||||
|
{
|
||||||
|
_dashSystem.CanDashThroughTarget = true;
|
||||||
|
_dashSystem._dashTarget.Visible = true;
|
||||||
|
_dashSystem._dashDropIndicator.Visible = true;
|
||||||
|
_dashSystem._dashDropLocationIndicator.Visible = true;
|
||||||
|
|
||||||
|
_dashSystem.StopPreparingDash();
|
||||||
|
|
||||||
|
AssertBool(_dashSystem.CanDashThroughTarget).IsFalse();
|
||||||
|
AssertBool(_dashSystem._dashTarget.Visible).IsFalse();
|
||||||
|
AssertBool(_dashSystem._dashDropIndicator.Visible).IsFalse();
|
||||||
|
AssertBool(_dashSystem._dashDropLocationIndicator.Visible).IsFalse();
|
||||||
|
}
|
||||||
|
}
|
||||||
1
tests/player/DashSystemUnitTest.cs.uid
Normal file
1
tests/player/DashSystemUnitTest.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://pv570go4cxws
|
||||||
91
tests/player/HeadSystemUnitTest.cs
Normal file
91
tests/player/HeadSystemUnitTest.cs
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
using Godot;
|
||||||
|
using GdUnit4;
|
||||||
|
using static GdUnit4.Assertions;
|
||||||
|
using Movementtests.systems;
|
||||||
|
|
||||||
|
namespace Movementtests.tests;
|
||||||
|
|
||||||
|
[TestSuite, RequireGodotRuntime]
|
||||||
|
public class HeadSystemUnitTest
|
||||||
|
{
|
||||||
|
private HeadSystem _head;
|
||||||
|
|
||||||
|
[BeforeTest]
|
||||||
|
public void SetupTest()
|
||||||
|
{
|
||||||
|
_head = new HeadSystem();
|
||||||
|
_head._camera = new Camera3D();
|
||||||
|
_head.AddChild(_head._camera);
|
||||||
|
|
||||||
|
_head._cameraAnchor = new Marker3D();
|
||||||
|
_head.AddChild(_head._cameraAnchor);
|
||||||
|
|
||||||
|
_head._fpRig = new Node3D();
|
||||||
|
_head.AddChild(_head._fpRig);
|
||||||
|
|
||||||
|
_head._fpDisplacedRig = new Node3D();
|
||||||
|
_head.AddChild(_head._fpDisplacedRig);
|
||||||
|
}
|
||||||
|
|
||||||
|
[AfterTest]
|
||||||
|
public void CleanupTest()
|
||||||
|
{
|
||||||
|
_head?.Free();
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase]
|
||||||
|
public void TestResetHeadBobbing()
|
||||||
|
{
|
||||||
|
_head._bobbingAccumulator = 10.0f;
|
||||||
|
_head.ResetHeadBobbing();
|
||||||
|
AssertFloat(_head._bobbingAccumulator).IsEqual(0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase]
|
||||||
|
public void TestComputeHowMuchInputForward()
|
||||||
|
{
|
||||||
|
Vector3 forwardInput = new Vector3(0, 0, -1);
|
||||||
|
AssertFloat(_head.ComputeHowMuchInputForward(forwardInput)).IsEqual(1.0f);
|
||||||
|
|
||||||
|
Vector3 backwardInput = new Vector3(0, 0, 1);
|
||||||
|
AssertFloat(_head.ComputeHowMuchInputForward(backwardInput)).IsEqual(-1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase]
|
||||||
|
public void TestComputeHowMuchInputSideways()
|
||||||
|
{
|
||||||
|
Vector3 rightInput = new Vector3(1, 0, 0);
|
||||||
|
AssertFloat(_head.ComputeHowMuchInputSideways(rightInput)).IsEqual(1.0f);
|
||||||
|
|
||||||
|
Vector3 leftInput = new Vector3(-1, 0, 0);
|
||||||
|
AssertFloat(_head.ComputeHowMuchInputSideways(leftInput)).IsEqual(-1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase]
|
||||||
|
public void TestGetForwardHorizontalVector()
|
||||||
|
{
|
||||||
|
Vector3 forward = _head.GetForwardHorizontalVector();
|
||||||
|
AssertVector(forward).IsEqualApprox(Vector3.Back, new Vector3(0.001f, 0.001f, 0.001f));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase]
|
||||||
|
public void TestLookAroundRotation()
|
||||||
|
{
|
||||||
|
var inputs = new HeadSystem.CameraParameters(
|
||||||
|
Delta: 0.016,
|
||||||
|
LookDir: new Vector2(1, 0),
|
||||||
|
PlayerInput: Vector3.Zero,
|
||||||
|
PlayerVelocity: Vector3.Zero,
|
||||||
|
WallContactPoint: Vector3.Zero,
|
||||||
|
SensitivitMultiplier: 1.0f,
|
||||||
|
WithCameraJitter: false,
|
||||||
|
WithCameraBobbing: false,
|
||||||
|
BobbingMultiplier: 1.0f,
|
||||||
|
FovMultiplier: 1.0f
|
||||||
|
);
|
||||||
|
|
||||||
|
float initialY = _head.Rotation.Y;
|
||||||
|
_head.LookAround(inputs);
|
||||||
|
AssertFloat(_head.Rotation.Y).IsEqual(initialY + 1.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
1
tests/player/HeadSystemUnitTest.cs.uid
Normal file
1
tests/player/HeadSystemUnitTest.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://bp0xn8k3dmfkg
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
using System.Reflection;
|
|
||||||
using Godot;
|
using Godot;
|
||||||
using GdUnit4;
|
using GdUnit4;
|
||||||
using static GdUnit4.Assertions;
|
using static GdUnit4.Assertions;
|
||||||
@@ -16,12 +15,9 @@ public class PlayerControllerUnitTest
|
|||||||
public void SetupTest()
|
public void SetupTest()
|
||||||
{
|
{
|
||||||
_player = new PlayerController();
|
_player = new PlayerController();
|
||||||
// We don't call _Ready() to avoid node dependency issues,
|
_player._targetSpeed = 7.0f;
|
||||||
// but we need to initialize some private fields for unit testing.
|
_player._gravity = 9.8f;
|
||||||
SetPrivateField(_player, "_targetSpeed", 7.0f);
|
|
||||||
SetPrivateField(_player, "_gravity", 9.8f);
|
|
||||||
|
|
||||||
// Setup Combat/Health dependencies
|
|
||||||
var rHealth = new RHealth(100.0f);
|
var rHealth = new RHealth(100.0f);
|
||||||
_player.RHealth = rHealth;
|
_player.RHealth = rHealth;
|
||||||
_player.CHealth = new CHealth { RHealth = rHealth, CurrentHealth = 100.0f };
|
_player.CHealth = new CHealth { RHealth = rHealth, CurrentHealth = 100.0f };
|
||||||
@@ -33,17 +29,11 @@ public class PlayerControllerUnitTest
|
|||||||
_player?.Free();
|
_player?.Free();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetPrivateField(object obj, string fieldName, object value)
|
|
||||||
{
|
|
||||||
var field = typeof(PlayerController).GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
|
|
||||||
field?.SetValue(obj, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestCase]
|
[TestCase]
|
||||||
public void TestCalculateGravityForce()
|
public void TestCalculateGravityForce()
|
||||||
{
|
{
|
||||||
_player.Weight = 3.0f;
|
_player.Weight = 3.0f;
|
||||||
// _gravity is 9.8f
|
// gravity is 9.8f
|
||||||
AssertFloat(_player.CalculateGravityForce()).IsEqualApprox(29.4f, 0.001f);
|
AssertFloat(_player.CalculateGravityForce()).IsEqualApprox(29.4f, 0.001f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,15 +41,15 @@ public class PlayerControllerUnitTest
|
|||||||
public void TestIsPlayerInputtingForward()
|
public void TestIsPlayerInputtingForward()
|
||||||
{
|
{
|
||||||
// Test Keyboard Input
|
// Test Keyboard Input
|
||||||
_player.InputDeviceChanged(false); // isUsingGamepad = false
|
_player.InputDeviceChanged(false);
|
||||||
_player.OnInputMoveKeyboard(new Vector3(0, 0, -1)); // Forward is -Z in Godot
|
_player.OnInputMoveKeyboard(Vector3.Forward);
|
||||||
AssertBool(_player.IsPlayerInputtingForward()).IsTrue();
|
AssertBool(_player.IsPlayerInputtingForward()).IsTrue();
|
||||||
|
|
||||||
_player.OnInputMoveKeyboard(new Vector3(0, 0, 1)); // Backward
|
_player.OnInputMoveKeyboard(Vector3.Back);
|
||||||
AssertBool(_player.IsPlayerInputtingForward()).IsFalse();
|
AssertBool(_player.IsPlayerInputtingForward()).IsFalse();
|
||||||
|
|
||||||
// Test Gamepad Input
|
// Test Gamepad Input
|
||||||
_player.InputDeviceChanged(true); // isUsingGamepad = true
|
_player.InputDeviceChanged(true);
|
||||||
_player.OnInputMove(new Vector3(0, 0, -1));
|
_player.OnInputMove(new Vector3(0, 0, -1));
|
||||||
AssertBool(_player.IsPlayerInputtingForward()).IsTrue();
|
AssertBool(_player.IsPlayerInputtingForward()).IsTrue();
|
||||||
}
|
}
|
||||||
@@ -78,14 +68,8 @@ public class PlayerControllerUnitTest
|
|||||||
_player.Velocity = Vector3.Zero;
|
_player.Velocity = Vector3.Zero;
|
||||||
_player.AccelerationFloor = 10.0f;
|
_player.AccelerationFloor = 10.0f;
|
||||||
|
|
||||||
// Moving forward
|
|
||||||
Vector3 direction = Vector3.Forward; // (0, 0, -1)
|
|
||||||
float delta = 0.1f;
|
float delta = 0.1f;
|
||||||
|
Vector3 newVelocity = _player.ComputeHVelocity(delta, _player.AccelerationFloor, _player.DecelerationFloor, Vector3.Forward);
|
||||||
// _targetSpeed is 7.0f
|
|
||||||
// Expected velocity change: Lerp(0, -7.0, 0.1 * 10.0) -> Lerp(0, -7.0, 1.0) -> -7.0
|
|
||||||
Vector3 newVelocity = _player.ComputeHVelocity(delta, _player.AccelerationFloor, _player.DecelerationFloor, direction);
|
|
||||||
|
|
||||||
AssertVector(newVelocity).IsEqual(new Vector3(0, 0, -7.0f));
|
AssertVector(newVelocity).IsEqual(new Vector3(0, 0, -7.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,12 +80,8 @@ public class PlayerControllerUnitTest
|
|||||||
_player.AccelerationAir = 2.0f;
|
_player.AccelerationAir = 2.0f;
|
||||||
_player.DecelerationAir = 2.0f;
|
_player.DecelerationAir = 2.0f;
|
||||||
|
|
||||||
// No input direction (deceleration)
|
|
||||||
Vector3 direction = Vector3.Zero;
|
|
||||||
float delta = 0.5f;
|
float delta = 0.5f;
|
||||||
|
Vector3 newVelocity = _player.ComputeHVelocity(delta, _player.AccelerationAir, _player.DecelerationAir, Vector3.Zero);
|
||||||
// Expected velocity change: Lerp(5, 0, 0.5 * 2.0) -> Lerp(5, 0, 1.0) -> 0
|
|
||||||
Vector3 newVelocity = _player.ComputeHVelocity(delta, _player.AccelerationAir, _player.DecelerationAir, direction);
|
|
||||||
|
|
||||||
AssertVector(newVelocity).IsEqual(Vector3.Zero);
|
AssertVector(newVelocity).IsEqual(Vector3.Zero);
|
||||||
}
|
}
|
||||||
@@ -109,23 +89,17 @@ public class PlayerControllerUnitTest
|
|||||||
[TestCase]
|
[TestCase]
|
||||||
public void TestReduceHealth()
|
public void TestReduceHealth()
|
||||||
{
|
{
|
||||||
// Initial health is 100
|
|
||||||
var damageRecord = new DamageRecord(Vector3.Zero, new RDamage(25.0f, EDamageTypes.Normal));
|
var damageRecord = new DamageRecord(Vector3.Zero, new RDamage(25.0f, EDamageTypes.Normal));
|
||||||
_player.ReduceHealth(_player, damageRecord);
|
_player.ReduceHealth(_player, damageRecord);
|
||||||
|
|
||||||
AssertFloat(_player.CHealth.CurrentHealth).IsEqual(75.0f);
|
AssertFloat(_player.CHealth.CurrentHealth).IsEqual(75.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestCase]
|
[TestCase]
|
||||||
public void TestEmpoweredActionsLeft()
|
public void TestEmpoweredActionsLeft()
|
||||||
{
|
{
|
||||||
// EmpoweredActionsLeft setter calls PlayerUi.SetNumberOfDashesLeft
|
|
||||||
// PlayerUi.SetNumberOfDashesLeft accesses _dashIcons array, which is null if _Ready() isn't called.
|
|
||||||
// We can initialize _dashIcons via reflection to allow the setter to work.
|
|
||||||
var mockUi = new PlayerUi();
|
var mockUi = new PlayerUi();
|
||||||
var dashIcons = new TextureRect[3] { new TextureRect(), new TextureRect(), new TextureRect() };
|
var dashIcons = new TextureRect[3] { new TextureRect(), new TextureRect(), new TextureRect() };
|
||||||
var field = typeof(PlayerUi).GetField("_dashIcons", BindingFlags.NonPublic | BindingFlags.Instance);
|
mockUi._dashIcons = dashIcons;
|
||||||
field?.SetValue(mockUi, dashIcons);
|
|
||||||
|
|
||||||
_player.PlayerUi = mockUi;
|
_player.PlayerUi = mockUi;
|
||||||
|
|
||||||
@@ -139,23 +113,16 @@ public class PlayerControllerUnitTest
|
|||||||
[TestCase]
|
[TestCase]
|
||||||
public void TestDashCooldownTimeout()
|
public void TestDashCooldownTimeout()
|
||||||
{
|
{
|
||||||
SetPrivateField(_player, "_canDash", false);
|
_player._canDash = false;
|
||||||
_player.DashCooldownTimeout();
|
_player.DashCooldownTimeout();
|
||||||
bool canDash = (bool)GetPrivateField(_player, "_canDash");
|
AssertBool(_player._canDash).IsTrue();
|
||||||
AssertBool(canDash).IsTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
private object GetPrivateField(object obj, string fieldName)
|
|
||||||
{
|
|
||||||
var field = typeof(PlayerController).GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
|
|
||||||
return field?.GetValue(obj);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestCase]
|
[TestCase]
|
||||||
public void TestGetInputLocalHDirection()
|
public void TestGetInputLocalHDirection()
|
||||||
{
|
{
|
||||||
_player.InputDeviceChanged(false); // Keyboard
|
_player.InputDeviceChanged(false);
|
||||||
_player.OnInputMoveKeyboard(new Vector3(1, 0, 1)); // Diagonal
|
_player.OnInputMoveKeyboard(new Vector3(1, 0, 1));
|
||||||
|
|
||||||
Vector3 expected = new Vector3(1, 0, 1).Normalized();
|
Vector3 expected = new Vector3(1, 0, 1).Normalized();
|
||||||
AssertVector(_player.GetInputLocalHDirection()).IsEqualApprox(expected, new Vector3(0.001f, 0.001f, 0.001f));
|
AssertVector(_player.GetInputLocalHDirection()).IsEqualApprox(expected, new Vector3(0.001f, 0.001f, 0.001f));
|
||||||
@@ -168,7 +135,6 @@ public class PlayerControllerUnitTest
|
|||||||
cKnockback.RKnockback = new RKnockback(10.0f);
|
cKnockback.RKnockback = new RKnockback(10.0f);
|
||||||
_player.CKnockback = cKnockback;
|
_player.CKnockback = cKnockback;
|
||||||
|
|
||||||
// Setup knockback record
|
|
||||||
var damageRecord = new DamageRecord(new Vector3(10, 0, 0), new RDamage(0, EDamageTypes.Normal));
|
var damageRecord = new DamageRecord(new Vector3(10, 0, 0), new RDamage(0, EDamageTypes.Normal));
|
||||||
var knockbackRecord = new KnockbackRecord(damageRecord, 1.0f);
|
var knockbackRecord = new KnockbackRecord(damageRecord, 1.0f);
|
||||||
|
|
||||||
@@ -177,10 +143,6 @@ public class PlayerControllerUnitTest
|
|||||||
|
|
||||||
_player.RegisterKnockback(knockbackRecord);
|
_player.RegisterKnockback(knockbackRecord);
|
||||||
|
|
||||||
// Expected direction: GlobalPosition (0,0,0) - SourceLocation (10,0,0) = (-10,0,0)
|
|
||||||
// Normalized: (-1, 0, 0)
|
|
||||||
// finalKnockback: (-1, 0, 0) * 10.0 (Modifier) * 1.0 (ForceMultiplier) = (-10, 0, 0)
|
|
||||||
|
|
||||||
Vector3 knockback = cKnockback.ComputeKnockback();
|
Vector3 knockback = cKnockback.ComputeKnockback();
|
||||||
AssertVector(knockback).IsEqual(new Vector3(-10, 0, 0));
|
AssertVector(knockback).IsEqual(new Vector3(-10, 0, 0));
|
||||||
}
|
}
|
||||||
|
|||||||
51
tests/player/WeaponSystemUnitTest.cs
Normal file
51
tests/player/WeaponSystemUnitTest.cs
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
using Godot;
|
||||||
|
using GdUnit4;
|
||||||
|
using static GdUnit4.Assertions;
|
||||||
|
using Movementtests.systems;
|
||||||
|
using Movementtests.systems.damage;
|
||||||
|
|
||||||
|
namespace Movementtests.tests;
|
||||||
|
|
||||||
|
[TestSuite, RequireGodotRuntime]
|
||||||
|
public class WeaponSystemUnitTest
|
||||||
|
{
|
||||||
|
private WeaponSystem _weapon;
|
||||||
|
|
||||||
|
[BeforeTest]
|
||||||
|
public void SetupTest()
|
||||||
|
{
|
||||||
|
_weapon = new WeaponSystem();
|
||||||
|
_weapon.RDamage = new RDamage(5.0f, EDamageTypes.Normal);
|
||||||
|
|
||||||
|
_weapon.WeaponMesh = new MeshInstance3D();
|
||||||
|
_weapon.AddChild(_weapon.WeaponMesh);
|
||||||
|
_weapon.WeaponLocationIndicator = new MeshInstance3D();
|
||||||
|
_weapon.AddChild(_weapon.WeaponLocationIndicator);
|
||||||
|
}
|
||||||
|
|
||||||
|
[AfterTest]
|
||||||
|
public void CleanupTest()
|
||||||
|
{
|
||||||
|
_weapon?.Free();
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase]
|
||||||
|
public void TestWeaponLeftAndBackVisibility()
|
||||||
|
{
|
||||||
|
_weapon.Visible = false;
|
||||||
|
|
||||||
|
_weapon.WeaponLeft();
|
||||||
|
AssertBool(_weapon.Visible).IsTrue();
|
||||||
|
|
||||||
|
_weapon.WeaponBack();
|
||||||
|
AssertBool(_weapon.Visible).IsFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase]
|
||||||
|
public void TestThrowWeaponOnCurveSetsUnfrozen()
|
||||||
|
{
|
||||||
|
_weapon.Freeze = true;
|
||||||
|
_weapon.ThrowWeaponOnCurve();
|
||||||
|
AssertBool(_weapon.Freeze).IsFalse();
|
||||||
|
}
|
||||||
|
}
|
||||||
1
tests/player/WeaponSystemUnitTest.cs.uid
Normal file
1
tests/player/WeaponSystemUnitTest.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://vkv8aderakcb
|
||||||
Reference in New Issue
Block a user