gd: state getters
This commit is contained in:
@ -137,6 +137,8 @@ transform = Transform3D(1, 0, 0, 0, 0.173648, -0.984808, 0, 0.984808, 0.173648,
|
||||
ThrowForce = 25.0
|
||||
StraightThrowDuration = 0.07
|
||||
|
||||
[node name="CoyoteTime" type="Timer" parent="."]
|
||||
|
||||
[node name="StateChart" type="Node" parent="."]
|
||||
script = ExtResource("25_wv70j")
|
||||
metadata/_custom_type_script = "uid://couw105c3bde4"
|
||||
|
@ -41,11 +41,20 @@ public partial class PlayerController : CharacterBody3D
|
||||
private bool _dashCanceled;
|
||||
|
||||
private StateChart _playerState;
|
||||
// Actions state
|
||||
private StateChartState _weaponInHand;
|
||||
private StateChartState _aiming;
|
||||
private StateChartState _dashing;
|
||||
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()
|
||||
{
|
||||
@ -93,11 +102,20 @@ public partial class PlayerController : CharacterBody3D
|
||||
|
||||
// State management
|
||||
_playerState = StateChart.Of(GetNode("StateChart"));
|
||||
_weaponInHand = StateChartState.Of(GetNode("StateChart/Root/WeaponInHand"));
|
||||
_aiming = StateChartState.Of(GetNode("StateChart/Root/Aiming"));
|
||||
_dashing = StateChartState.Of(GetNode("StateChart/Root/Dashing"));
|
||||
_weaponThrown = StateChartState.Of(GetNode("StateChart/Root/WeaponThrown"));
|
||||
_hanging = StateChartState.Of(GetNode("StateChart/Root/Hanging"));
|
||||
// Actions states
|
||||
_weaponInHand = StateChartState.Of(GetNode("StateChart/Root/Actions/WeaponInHand"));
|
||||
_aiming = StateChartState.Of(GetNode("StateChart/Root/Actions/Aiming"));
|
||||
_dashing = StateChartState.Of(GetNode("StateChart/Root/Actions/Dashing"));
|
||||
_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 //
|
||||
@ -163,19 +181,6 @@ public partial class PlayerController : CharacterBody3D
|
||||
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()
|
||||
{
|
||||
// Regular dash
|
||||
@ -215,6 +220,19 @@ public partial class PlayerController : CharacterBody3D
|
||||
_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)
|
||||
{
|
||||
_inputMove = value;
|
||||
@ -277,7 +295,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
isOnFloorCustom(),
|
||||
isPlayerDead,
|
||||
isHeadTouchingCeiling,
|
||||
_hanging.Active);
|
||||
_actionHanging.Active);
|
||||
MoveSystem.MoveAround(moveAroundParams);
|
||||
|
||||
Vector2 inputLookDir = new Vector2(_inputRotateY, _inputRotateFloorplane);
|
||||
|
Reference in New Issue
Block a user