Major Player refactor
This commit is contained in:
@@ -1,22 +1,21 @@
|
||||
using Godot;
|
||||
|
||||
namespace GameJamDungeon
|
||||
namespace GameJamDungeon;
|
||||
|
||||
public partial class PlayerLogic
|
||||
{
|
||||
public partial class PlayerLogic
|
||||
public static class Input
|
||||
{
|
||||
public static class Input
|
||||
{
|
||||
public readonly record struct PhysicsTick(double Delta);
|
||||
public readonly record struct PhysicsTick(double Delta);
|
||||
|
||||
public readonly record struct Moved(Vector3 GlobalPosition, Transform3D GlobalTransform);
|
||||
public readonly record struct Moved(Vector3 GlobalPosition, Transform3D GlobalTransform);
|
||||
|
||||
public readonly record struct Enable;
|
||||
public readonly record struct Enable;
|
||||
|
||||
public readonly record struct Attack;
|
||||
public readonly record struct Attack;
|
||||
|
||||
public readonly record struct AttackAnimationFinished;
|
||||
public readonly record struct AttackAnimationFinished;
|
||||
|
||||
public readonly record struct Killed;
|
||||
}
|
||||
public readonly record struct Killed;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,14 @@
|
||||
using Godot;
|
||||
namespace GameJamDungeon;
|
||||
|
||||
namespace GameJamDungeon
|
||||
public partial class PlayerLogic
|
||||
{
|
||||
public partial class PlayerLogic
|
||||
public static class Output
|
||||
{
|
||||
public static class Output
|
||||
public static class Animations
|
||||
{
|
||||
public static class Animations
|
||||
{
|
||||
public readonly record struct Attack;
|
||||
}
|
||||
|
||||
public readonly record struct MovementComputed(Basis Rotation, Vector3 Velocity);
|
||||
|
||||
public readonly record struct ThrowItem;
|
||||
public readonly record struct Attack;
|
||||
}
|
||||
|
||||
public readonly record struct ThrowItem;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
namespace GameJamDungeon
|
||||
namespace GameJamDungeon;
|
||||
|
||||
public partial class PlayerLogic
|
||||
{
|
||||
public partial class PlayerLogic
|
||||
public record Settings
|
||||
{
|
||||
public record Settings
|
||||
{
|
||||
public float MoveSpeed { get; set; }
|
||||
public float MoveSpeed { get; set; }
|
||||
|
||||
public float RotationSpeed { get; set; }
|
||||
public float RotationSpeed { get; set; }
|
||||
|
||||
public float Acceleration { get; set; }
|
||||
}
|
||||
public float Acceleration { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.LogicBlocks;
|
||||
|
||||
namespace GameJamDungeon
|
||||
namespace GameJamDungeon;
|
||||
|
||||
public partial class PlayerLogic
|
||||
{
|
||||
public partial class PlayerLogic
|
||||
{
|
||||
[Meta]
|
||||
public abstract partial record State : StateLogic<State>;
|
||||
}
|
||||
[Meta]
|
||||
public abstract partial record State : StateLogic<State>;
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.LogicBlocks;
|
||||
|
||||
namespace GameJamDungeon
|
||||
{
|
||||
public interface IPlayerLogic : ILogicBlock<PlayerLogic.State>;
|
||||
namespace GameJamDungeon;
|
||||
|
||||
[Meta, Id("player_logic")]
|
||||
[LogicBlock(typeof(State), Diagram = true)]
|
||||
public partial class PlayerLogic : LogicBlock<PlayerLogic.State>, IPlayerLogic
|
||||
{
|
||||
public override Transition GetInitialState() => To<State.Idle>();
|
||||
}
|
||||
public interface IPlayerLogic : ILogicBlock<PlayerLogic.State>;
|
||||
|
||||
[Meta, Id("player_logic")]
|
||||
[LogicBlock(typeof(State), Diagram = true)]
|
||||
public partial class PlayerLogic : LogicBlock<PlayerLogic.State>, IPlayerLogic
|
||||
{
|
||||
public override Transition GetInitialState() => To<State.Idle>();
|
||||
}
|
||||
|
||||
@@ -8,14 +8,12 @@ state "PlayerLogic State" as GameJamDungeon_PlayerLogic_State {
|
||||
state "Disabled" as GameJamDungeon_PlayerLogic_State_Disabled
|
||||
}
|
||||
|
||||
GameJamDungeon_PlayerLogic_State_Alive --> GameJamDungeon_PlayerLogic_State_Alive : Moved
|
||||
GameJamDungeon_PlayerLogic_State_Alive --> GameJamDungeon_PlayerLogic_State_Alive : PhysicsTick
|
||||
GameJamDungeon_PlayerLogic_State_Alive --> GameJamDungeon_PlayerLogic_State_Dead : Killed
|
||||
GameJamDungeon_PlayerLogic_State_Attacking --> GameJamDungeon_PlayerLogic_State_Idle : AttackAnimationFinished
|
||||
GameJamDungeon_PlayerLogic_State_Disabled --> GameJamDungeon_PlayerLogic_State_Idle : Enable
|
||||
GameJamDungeon_PlayerLogic_State_Idle --> GameJamDungeon_PlayerLogic_State_Attacking : Attack
|
||||
|
||||
GameJamDungeon_PlayerLogic_State_Alive : OnPhysicsTick → MovementComputed
|
||||
GameJamDungeon_PlayerLogic_State_Idle : OnAttack → Attack
|
||||
|
||||
[*] --> GameJamDungeon_PlayerLogic_State_Idle
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
using Chickensoft.Introspection;
|
||||
|
||||
namespace GameJamDungeon
|
||||
namespace GameJamDungeon;
|
||||
|
||||
public partial class PlayerLogic
|
||||
{
|
||||
public partial class PlayerLogic
|
||||
public partial record State
|
||||
{
|
||||
public partial record State
|
||||
[Meta]
|
||||
public partial record Attacking : Alive, IGet<Input.AttackAnimationFinished>
|
||||
{
|
||||
[Meta]
|
||||
public partial record Attacking : Alive, IGet<Input.AttackAnimationFinished>
|
||||
public Transition On(in Input.AttackAnimationFinished input)
|
||||
{
|
||||
public Transition On(in Input.AttackAnimationFinished input)
|
||||
{
|
||||
return To<Idle>();
|
||||
}
|
||||
return To<Idle>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
|
||||
namespace GameJamDungeon
|
||||
{
|
||||
public partial class PlayerLogic
|
||||
{
|
||||
public abstract partial record State
|
||||
{
|
||||
[Meta, Id("player_logic_state_alive_idle")]
|
||||
public partial record Idle : Alive, IGet<Input.Attack>
|
||||
{
|
||||
namespace GameJamDungeon;
|
||||
|
||||
public virtual Transition On(in Input.Attack input)
|
||||
{
|
||||
GD.Print("Attacking...");
|
||||
Output(new Output.Animations.Attack());
|
||||
return To<Attacking>();
|
||||
}
|
||||
public partial class PlayerLogic
|
||||
{
|
||||
public abstract partial record State
|
||||
{
|
||||
[Meta, Id("player_logic_state_alive_idle")]
|
||||
public partial record Idle : Alive, IGet<Input.Attack>
|
||||
{
|
||||
|
||||
public virtual Transition On(in Input.Attack input)
|
||||
{
|
||||
GD.Print("Attacking...");
|
||||
Output(new Output.Animations.Attack());
|
||||
return To<Attacking>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,48 +1,27 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
|
||||
namespace GameJamDungeon
|
||||
namespace GameJamDungeon;
|
||||
|
||||
public partial class PlayerLogic
|
||||
{
|
||||
public partial class PlayerLogic
|
||||
public partial record State
|
||||
{
|
||||
public partial record State
|
||||
[Meta, Id("player_logic_alive")]
|
||||
public abstract partial record Alive : State, IGet<Input.PhysicsTick>, IGet<Input.Killed>
|
||||
{
|
||||
[Meta, Id("player_logic_alive")]
|
||||
public abstract partial record Alive : State, IGet<Input.PhysicsTick>, IGet<Input.Moved>, IGet<Input.Killed>
|
||||
public virtual Transition On(in Input.PhysicsTick input)
|
||||
{
|
||||
public virtual Transition On(in Input.PhysicsTick input)
|
||||
{
|
||||
var delta = input.Delta;
|
||||
var player = Get<IPlayer>();
|
||||
var settings = Get<Settings>();
|
||||
var delta = input.Delta;
|
||||
var player = Get<IPlayer>();
|
||||
player.Move((float)delta);
|
||||
return ToSelf();
|
||||
}
|
||||
|
||||
var rawInput = player.GetGlobalInputVector();
|
||||
var strafeLeftInput = player.GetLeftStrafeInputVector();
|
||||
var strafeRightInput = player.GetRightStrafeInputVector();
|
||||
|
||||
var transform = player.Transform;
|
||||
transform.Basis = new Basis(Vector3.Up, settings.RotationSpeed * -rawInput.X * (float)delta) * transform.Basis;
|
||||
var moveDirection = new Vector3(strafeRightInput - strafeLeftInput, 0, rawInput.Z);
|
||||
var velocity = player.Basis * moveDirection * settings.MoveSpeed * settings.Acceleration;
|
||||
|
||||
Output(new Output.MovementComputed(transform.Basis, velocity));
|
||||
|
||||
return ToSelf();
|
||||
}
|
||||
|
||||
public virtual Transition On(in Input.Moved input)
|
||||
{
|
||||
var gameRepo = Get<IGameRepo>();
|
||||
gameRepo.SetPlayerGlobalPosition(input.GlobalPosition);
|
||||
gameRepo.SetPlayerGlobalTransform(input.GlobalTransform);
|
||||
return ToSelf();
|
||||
}
|
||||
|
||||
public Transition On(in Input.Killed input)
|
||||
{
|
||||
GD.Print("Player died");
|
||||
return To<Dead>();
|
||||
}
|
||||
public Transition On(in Input.Killed input)
|
||||
{
|
||||
GD.Print("Player died");
|
||||
return To<Dead>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,23 @@
|
||||
using Chickensoft.Introspection;
|
||||
|
||||
namespace GameJamDungeon
|
||||
namespace GameJamDungeon;
|
||||
|
||||
public partial class PlayerLogic
|
||||
{
|
||||
public partial class PlayerLogic
|
||||
public abstract partial record State
|
||||
{
|
||||
public abstract partial record State
|
||||
[Meta, Id("player_logic_state_disabled")]
|
||||
public partial record Disabled : State, IGet<Input.Enable>
|
||||
{
|
||||
[Meta, Id("player_logic_state_disabled")]
|
||||
public partial record Disabled : State, IGet<Input.Enable>
|
||||
public Disabled()
|
||||
{
|
||||
public Disabled()
|
||||
{
|
||||
OnAttach(() => Get<IAppRepo>().GameEntered += OnGameEntered);
|
||||
OnDetach(() => Get<IAppRepo>().GameEntered -= OnGameEntered);
|
||||
}
|
||||
|
||||
public Transition On(in Input.Enable input) => To<Idle>();
|
||||
|
||||
public void OnGameEntered() => Input(new Input.Enable());
|
||||
OnAttach(() => Get<IAppRepo>().GameEntered += OnGameEntered);
|
||||
OnDetach(() => Get<IAppRepo>().GameEntered -= OnGameEntered);
|
||||
}
|
||||
|
||||
public Transition On(in Input.Enable input) => To<Idle>();
|
||||
|
||||
public void OnGameEntered() => Input(new Input.Enable());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user