diff --git a/State/Character/PlayerState.cs b/State/Character/PlayerState.cs index b780fa0..3bfe666 100644 --- a/State/Character/PlayerState.cs +++ b/State/Character/PlayerState.cs @@ -68,13 +68,23 @@ public abstract partial class PlayerState : CharacterState if (!weapon.ShouldHideIdle || isAttack1On) { - if (joystick.IsZeroApprox()) + var inputMethod = Utils.World.Instance.GlobalState + .Settings.InputMethod; + switch (inputMethod) { - Character.Target = Character.Direction; - } - else - { - Character.Target = joystick; + case Global.InputMethod.Joystick: + if (joystick.IsZeroApprox()) + { + Character.Target = Character.Direction; + } + else + { + Character.Target = joystick; + } + break; + default: + Character.Target = dirToMouse; + break; } } diff --git a/State/Global/GameSettings.cs b/State/Global/GameSettings.cs new file mode 100644 index 0000000..baf8174 --- /dev/null +++ b/State/Global/GameSettings.cs @@ -0,0 +1,16 @@ +using Godot; + +namespace SupaLidlGame.State.Global; + +public enum InputMethod +{ + Mouse, + Joystick, + MouseCentered, +} + +public partial class GameSettings : Resource +{ + [Export] + public InputMethod InputMethod { get; set; } +} diff --git a/State/Global/GlobalState.cs b/State/Global/GlobalState.cs index 51b42a4..5471371 100644 --- a/State/Global/GlobalState.cs +++ b/State/Global/GlobalState.cs @@ -14,12 +14,44 @@ public partial class GlobalState : Node [Export] public Stats Stats { get; set; } = new(); + [Export] + public GameSettings Settings { get; set; } = new(); + [Signal] public delegate void SummonBossEventHandler(string bossName); public override void _Ready() { ProcessMode = ProcessModeEnum.Always; + LoadSettings(); + } + + public override void _Notification(int what) + { + if (what == NotificationWMCloseRequest) + { + // TODO: quit prompt + GetTree().Root + .PropagateNotification((int)NotificationWMCloseRequest); + SaveSettings(); + } + } + + private void LoadSettings() + { + if (ResourceLoader.Exists("user://settings.tres")) + { + Settings = ResourceLoader.Load("user://settings.tres"); + } + else + { + Settings = new GameSettings(); + } + } + + public void SaveSettings() + { + ResourceSaver.Save(Settings, "user://settings.tres"); } public void ImportFromSave(Save save)