gd: basic weapon and readability refacto

This commit is contained in:
2025-06-06 16:09:39 +02:00
parent bbcc3d0867
commit 579b523a37
15 changed files with 263 additions and 201 deletions

View File

@ -2,9 +2,9 @@
namespace Movementtests.systems;
public record DashComputation(bool HasHit, Vector3 Location, Vector3 CollisionPoint, Vector3 CollisionNormal);
public record DashComputationRecord(bool HasHit, Vector3 Location, Vector3 CollisionPoint, Vector3 CollisionNormal);
public record DashResolve(bool EndWithMantle, Vector3 DashLocation, Vector3 MantleLocation);
public record DashResolveRecord(bool EndWithMantle, Vector3 DashLocation, Vector3 MantleLocation);
public partial class DashSystem: Node3D
{
@ -19,7 +19,9 @@ public partial class DashSystem: Node3D
private MantleSystem _mantleSystem;
private MeshInstance3D _dashTarget;
private DashResolve _dashResolve;
public DashResolveRecord DashResolve { get; set; }
public DashComputationRecord DashComputation { get; set; }
[Signal]
public delegate void DashStartedEventHandler();
@ -40,20 +42,20 @@ public partial class DashSystem: Node3D
_dashTarget.SetVisible(false);
}
private DashComputation ComputeDashLocation()
private DashComputationRecord ComputeDashLocation()
{
if (!_dashCast3D.IsColliding())
{
return new DashComputation(false, _dashCast3D.ToGlobal(_dashCast3D.TargetPosition), Vector3.Zero, Vector3.Zero);
return new DashComputationRecord(false, _dashCast3D.ToGlobal(_dashCast3D.TargetPosition), Vector3.Zero, Vector3.Zero);
}
var collisionPoint = _dashCast3D.GetCollisionPoint(0);
var collisionNormal = _dashCast3D.GetCollisionNormal(0);
var collisionShape = (SphereShape3D) _dashCast3D.GetShape();
var centerSphereLocation = collisionPoint + collisionNormal * collisionShape.Radius;
return new DashComputation(true, centerSphereLocation, collisionPoint, collisionNormal);
return new DashComputationRecord(true, centerSphereLocation, collisionPoint, collisionNormal);
}
public DashResolve PrepareDash()
public void PrepareDash()
{
_dashTarget.SetVisible(false);
@ -62,7 +64,8 @@ public partial class DashSystem: Node3D
_head.Rotation.Y,
_camera.Rotation.Z));
var (hasHit, location, collisionPoint, collisionNormal) = ComputeDashLocation();
DashComputation = ComputeDashLocation();
var (hasHit, location, collisionPoint, collisionNormal) = DashComputation;
var shouldMantle = false;
var mantleLocation = Vector3.Zero;
@ -78,8 +81,7 @@ public partial class DashSystem: Node3D
_dashTarget.SetVisible(true);
_dashTarget.SetGlobalPosition(location);
_dashResolve = new DashResolve(shouldMantle, location, mantleLocation);
return _dashResolve;
DashResolve = new DashResolveRecord(shouldMantle, location, mantleLocation);
}
public void CancelDash()
@ -96,12 +98,12 @@ public partial class DashSystem: Node3D
{
EmitSignal(SignalName.DashStarted);
_dashTarget.SetVisible(false);
var dashTweenInputs = new TweenQueueSystem.TweenInputs(_dashResolve.DashLocation, 0.1f);
var dashTweenInputs = new TweenQueueSystem.TweenInputs(DashResolve.DashLocation, 0.1f);
var dashTween = _tweenQueueSystem.TweenToLocation(dashTweenInputs);
dashTween.Finished += DashTweenEnded;
if (_dashResolve.EndWithMantle)
if (DashResolve.EndWithMantle)
{
_tweenQueueSystem.QueueTween(_dashResolve.MantleLocation, 0.2f);
_tweenQueueSystem.QueueTween(DashResolve.MantleLocation, 0.2f);
}
}
}