gd,refacto: added state chart addon and namespace cleanup

This commit is contained in:
2025-06-05 14:47:51 +02:00
parent 8818e77d23
commit 5c36765a36
239 changed files with 10430 additions and 115 deletions

View File

@ -0,0 +1,94 @@
using Godot;
namespace Movementtests.systems;
public record DashComputation(bool HasHit, Vector3 Location, Vector3 CollisionPoint, Vector3 CollisionNormal);
public record DashResolve(bool EndWithMantle, Vector3 DashLocation, Vector3 MantleLocation);
public partial class DashSystem: Node3D
{
[Export(PropertyHint.Range, "0,0.2,0.01,or_greater")]
public float DashSpeed { get; set; } = 0.05f;
private Node3D _head;
private ShapeCast3D _dashCast3D;
private Camera3D _camera;
private TweenQueueSystem _tweenQueueSystem;
private MantleSystem _mantleSystem;
private MeshInstance3D _dashTarget;
private DashResolve _dashResolve;
public void Init(Node3D head, Camera3D camera, TweenQueueSystem tweenQueueSystem)
{
_dashCast3D = GetNode<ShapeCast3D>("DashCast3D");
_head = head;
_camera = camera;
_tweenQueueSystem = tweenQueueSystem;
_mantleSystem = GetNode<MantleSystem>("MantleSystem");
_mantleSystem.Init(this);
_dashTarget = GetNode<MeshInstance3D>("DashTarget");
_dashTarget.SetVisible(false);
}
private DashComputation ComputeDashLocation()
{
if (!_dashCast3D.IsColliding())
{
return new DashComputation(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);
}
public DashResolve PrepareDash()
{
_dashTarget.SetVisible(false);
_dashCast3D.SetRotation(new Vector3(
_camera.Rotation.X,
_head.Rotation.Y,
_camera.Rotation.Z));
var (hasHit, location, collisionPoint, collisionNormal) = ComputeDashLocation();
var shouldMantle = false;
var mantleLocation = Vector3.Zero;
if (hasHit && Mathf.Abs(collisionNormal.Y) < 0.01f)
{
var mantleResult = _mantleSystem.FindMantleLocationAtPoint(collisionPoint, collisionNormal);
shouldMantle = mantleResult.IsSome(out mantleLocation);
}
var targetColor = shouldMantle ? new Color(0.2f, 0.2f, 1f) : new Color(1f, 1f, 1f);
var targetMaterial = (StandardMaterial3D) _dashTarget.GetSurfaceOverrideMaterial(0);
targetMaterial.SetAlbedo(targetColor);
_dashTarget.SetVisible(true);
_dashTarget.SetGlobalPosition(location);
_dashResolve = new DashResolve(shouldMantle, location, mantleLocation);
return _dashResolve;
}
public void CancelDash()
{
_dashTarget.SetVisible(false);
}
public void Dash()
{
_dashTarget.SetVisible(false);
_tweenQueueSystem.QueueTween(_dashResolve.DashLocation, 0.1f);
if (_dashResolve.EndWithMantle)
{
_tweenQueueSystem.QueueTween(_dashResolve.MantleLocation, 0.1f);
}
}
}

View File

@ -0,0 +1 @@
uid://dwoppk8j5fxeg

View File

@ -0,0 +1,29 @@
[gd_scene load_steps=6 format=3 uid="uid://cqduhd4opgwvm"]
[ext_resource type="Script" uid="uid://dwoppk8j5fxeg" path="res://systems/dash/DashSystem.cs" id="1_hwig2"]
[ext_resource type="PackedScene" uid="uid://wq1okogkhc5l" path="res://systems/mantle/mantle_system.tscn" id="2_pff7b"]
[sub_resource type="SphereShape3D" id="SphereShape3D_qu4wy"]
[sub_resource type="SphereMesh" id="SphereMesh_qu4wy"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_v31n3"]
[node name="DashSystem" type="Node3D"]
script = ExtResource("1_hwig2")
[node name="DashCast3D" type="ShapeCast3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.68, 0)
shape = SubResource("SphereShape3D_qu4wy")
target_position = Vector3(0, 0, -20)
max_results = 1
collision_mask = 2
debug_shape_custom_color = Color(0.911631, 0.11884, 0.656218, 1)
[node name="DashTarget" type="MeshInstance3D" parent="."]
mesh = SubResource("SphereMesh_qu4wy")
surface_material_override/0 = SubResource("StandardMaterial3D_v31n3")
[node name="MantleSystem" parent="." instance=ExtResource("2_pff7b")]
MantleEndLocationDistanceFromWall = 1.0
MantleHeightCastStart = 2.0

View File

@ -1,5 +1,7 @@
using Godot;
using System;
using Godot;
namespace Movementtests.systems;
public partial class HeadSystem : Node3D
{
@ -27,4 +29,4 @@ public partial class HeadSystem : Node3D
_camera.Rotation = currentCameraRotation;
}
}
}

View File

@ -1,8 +1,7 @@
using System;
using Godot;
using Godot;
using RustyOptions;
namespace PolarBears.PlayerControllerAddon;
namespace Movementtests.systems;
public partial class MantleSystem: Node3D
{

View File

@ -1,5 +1,7 @@
using Godot;
using PolarBears.PlayerControllerAddon;
using Movementtests.player_controller.Scripts;
namespace Movementtests.systems;
public partial class MoveSystem : Node3D
{
@ -189,4 +191,4 @@ public partial class MoveSystem : Node3D
}
}
}
}

View File

@ -1,5 +1,7 @@
using Godot;
using System.Collections.Generic;
using Godot;
namespace Movementtests.systems;
public partial class TweenQueueSystem : Node3D
{
@ -49,4 +51,4 @@ public partial class TweenQueueSystem : Node3D
TweenToLocation(_tweenInputs.Dequeue());
}
}
}