handle unhandled input for `CharacterState`

godot-4.3
John Montagu, the 4th Earl of Sandvich 2024-01-06 14:13:11 -08:00
parent b79c2d0e3a
commit 05ae280785
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
2 changed files with 7 additions and 3 deletions

View File

@ -70,4 +70,6 @@ public abstract partial class CharacterState : Node, IState<CharacterState>
} }
public virtual CharacterState Input(InputEvent @event) => null; public virtual CharacterState Input(InputEvent @event) => null;
public virtual CharacterState UnhandledInput(InputEvent @event) => null;
} }

View File

@ -13,7 +13,7 @@ public abstract partial class PlayerState : CharacterState
[Export] [Export]
public PlayerMaxLevelState MaxLevelState { get; set; } public PlayerMaxLevelState MaxLevelState { get; set; }
public override CharacterState Input(InputEvent @event) public override CharacterState UnhandledInput(InputEvent @event)
{ {
var inventory = Character.Inventory; var inventory = Character.Inventory;
var player = _player; var player = _player;
@ -60,16 +60,16 @@ public abstract partial class PlayerState : CharacterState
} }
} }
return base.Input(@event); return base.UnhandledInput(@event);
} }
public override CharacterState Process(double delta) public override CharacterState Process(double delta)
{ {
Character.Direction = Godot.Input.GetVector("left", "right", Character.Direction = Godot.Input.GetVector("left", "right",
"up", "down"); "up", "down");
Character.LookTowardsDirection();
var player = _player; var player = _player;
var desiredTarget = player.GetDesiredInputFromInput(); var desiredTarget = player.GetDesiredInputFromInput();
if (!desiredTarget.IsZeroApprox()) if (!desiredTarget.IsZeroApprox())
{ {
@ -77,6 +77,8 @@ public abstract partial class PlayerState : CharacterState
player.DesiredTarget = desiredTarget; player.DesiredTarget = desiredTarget;
} }
Character.LookTowardsDirection();
if (Character.Inventory.SelectedItem is Items.Weapon weapon) if (Character.Inventory.SelectedItem is Items.Weapon weapon)
{ {
var isAttack1On = Godot.Input.IsActionPressed("attack1"); var isAttack1On = Godot.Input.IsActionPressed("attack1");