gd: state getters

This commit is contained in:
2025-06-08 15:49:47 +02:00
parent 7924bec78d
commit 70c70264cc
2 changed files with 40 additions and 20 deletions

View File

@ -137,6 +137,8 @@ transform = Transform3D(1, 0, 0, 0, 0.173648, -0.984808, 0, 0.984808, 0.173648,
ThrowForce = 25.0 ThrowForce = 25.0
StraightThrowDuration = 0.07 StraightThrowDuration = 0.07
[node name="CoyoteTime" type="Timer" parent="."]
[node name="StateChart" type="Node" parent="."] [node name="StateChart" type="Node" parent="."]
script = ExtResource("25_wv70j") script = ExtResource("25_wv70j")
metadata/_custom_type_script = "uid://couw105c3bde4" metadata/_custom_type_script = "uid://couw105c3bde4"

View File

@ -41,11 +41,20 @@ public partial class PlayerController : CharacterBody3D
private bool _dashCanceled; private bool _dashCanceled;
private StateChart _playerState; private StateChart _playerState;
// Actions state
private StateChartState _weaponInHand; private StateChartState _weaponInHand;
private StateChartState _aiming; private StateChartState _aiming;
private StateChartState _dashing; private StateChartState _dashing;
private StateChartState _weaponThrown; private StateChartState _weaponThrown;
private StateChartState _hanging; private StateChartState _actionHanging;
// Movement state
private StateChartState _grounded;
private StateChartState _movHanging;
private StateChartState _wallHugging;
private StateChartState _airborne;
private StateChartState _coyoteEnabled;
private StateChartState _doubleJumpEnabled;
private StateChartState _falling;
public override void _Ready() public override void _Ready()
{ {
@ -93,11 +102,20 @@ public partial class PlayerController : CharacterBody3D
// State management // State management
_playerState = StateChart.Of(GetNode("StateChart")); _playerState = StateChart.Of(GetNode("StateChart"));
_weaponInHand = StateChartState.Of(GetNode("StateChart/Root/WeaponInHand")); // Actions states
_aiming = StateChartState.Of(GetNode("StateChart/Root/Aiming")); _weaponInHand = StateChartState.Of(GetNode("StateChart/Root/Actions/WeaponInHand"));
_dashing = StateChartState.Of(GetNode("StateChart/Root/Dashing")); _aiming = StateChartState.Of(GetNode("StateChart/Root/Actions/Aiming"));
_weaponThrown = StateChartState.Of(GetNode("StateChart/Root/WeaponThrown")); _dashing = StateChartState.Of(GetNode("StateChart/Root/Actions/Dashing"));
_hanging = StateChartState.Of(GetNode("StateChart/Root/Hanging")); _weaponThrown = StateChartState.Of(GetNode("StateChart/Root/Actions/WeaponThrown"));
_actionHanging = StateChartState.Of(GetNode("StateChart/Root/Actions/Hanging"));
// Movement states
_grounded = StateChartState.Of(GetNode("StateChart/Root/Movement/Grounded"));
_movHanging = StateChartState.Of(GetNode("StateChart/Root/Movement/Hanging"));
_wallHugging = StateChartState.Of(GetNode("StateChart/Root/Movement/WallHugging"));
_airborne = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne"));
_coyoteEnabled = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne/CoyoteEnabled"));
_doubleJumpEnabled = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne/DoubleJumpEnabled"));
_falling = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne/Falling"));
/////////////////////////// ///////////////////////////
// Initialize components // // Initialize components //
@ -162,19 +180,6 @@ public partial class PlayerController : CharacterBody3D
_dashDirection = (DashSystem.DashResolve.DashLocation - GlobalPosition).Normalized(); _dashDirection = (DashSystem.DashResolve.DashLocation - GlobalPosition).Normalized();
DashSystem.Dash(); DashSystem.Dash();
} }
public void OnWeaponThrown()
{
RemoveChild(WeaponRoot);
GetTree().GetRoot().AddChild(WeaponRoot);
WeaponRoot.SetGlobalPosition(GlobalPosition);
var (hasHit, location, collisionPoint, collisionNormal) = DashSystem.DashComputation;
var (endWithMantle, dashLocation, mantleLocation) = DashSystem.DashResolve;
DashSystem.CancelDash();
WeaponSystem.ThrowWeapon(location, hasHit, collisionPoint, collisionNormal);
}
public void OnDashEnded() public void OnDashEnded()
{ {
@ -215,6 +220,19 @@ public partial class PlayerController : CharacterBody3D
_playerState.SendEvent("dash_ended"); _playerState.SendEvent("dash_ended");
} }
public void OnWeaponThrown()
{
RemoveChild(WeaponRoot);
GetTree().GetRoot().AddChild(WeaponRoot);
WeaponRoot.SetGlobalPosition(GlobalPosition);
var (hasHit, location, collisionPoint, collisionNormal) = DashSystem.DashComputation;
var (endWithMantle, dashLocation, mantleLocation) = DashSystem.DashResolve;
DashSystem.CancelDash();
WeaponSystem.ThrowWeapon(location, hasHit, collisionPoint, collisionNormal);
}
public void OnInputMove(Vector3 value) public void OnInputMove(Vector3 value)
{ {
_inputMove = value; _inputMove = value;
@ -277,7 +295,7 @@ public partial class PlayerController : CharacterBody3D
isOnFloorCustom(), isOnFloorCustom(),
isPlayerDead, isPlayerDead,
isHeadTouchingCeiling, isHeadTouchingCeiling,
_hanging.Active); _actionHanging.Active);
MoveSystem.MoveAround(moveAroundParams); MoveSystem.MoveAround(moveAroundParams);
Vector2 inputLookDir = new Vector2(_inputRotateY, _inputRotateFloorplane); Vector2 inputLookDir = new Vector2(_inputRotateY, _inputRotateFloorplane);