internally switch input methods; closes #11

pull/6/head
John Montagu, the 4th Earl of Sandvich 2023-08-29 22:24:20 -07:00
parent 0662c558e0
commit 5ef3229e93
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
3 changed files with 64 additions and 6 deletions

View File

@ -68,6 +68,11 @@ public abstract partial class PlayerState : CharacterState
if (!weapon.ShouldHideIdle || isAttack1On)
{
var inputMethod = Utils.World.Instance.GlobalState
.Settings.InputMethod;
switch (inputMethod)
{
case Global.InputMethod.Joystick:
if (joystick.IsZeroApprox())
{
Character.Target = Character.Direction;
@ -76,6 +81,11 @@ public abstract partial class PlayerState : CharacterState
{
Character.Target = joystick;
}
break;
default:
Character.Target = dirToMouse;
break;
}
}
if (isAttack1On)

View File

@ -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; }
}

View File

@ -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<GameSettings>("user://settings.tres");
}
else
{
Settings = new GameSettings();
}
}
public void SaveSettings()
{
ResourceSaver.Save(Settings, "user://settings.tres");
}
public void ImportFromSave(Save save)