internally switch input methods; closes #11

controller-support
HumanoidSandvichDispenser 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,13 +68,23 @@ public abstract partial class PlayerState : CharacterState
if (!weapon.ShouldHideIdle || isAttack1On) if (!weapon.ShouldHideIdle || isAttack1On)
{ {
if (joystick.IsZeroApprox()) var inputMethod = Utils.World.Instance.GlobalState
.Settings.InputMethod;
switch (inputMethod)
{ {
Character.Target = Character.Direction; case Global.InputMethod.Joystick:
} if (joystick.IsZeroApprox())
else {
{ Character.Target = Character.Direction;
Character.Target = joystick; }
else
{
Character.Target = joystick;
}
break;
default:
Character.Target = dirToMouse;
break;
} }
} }

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] [Export]
public Stats Stats { get; set; } = new(); public Stats Stats { get; set; } = new();
[Export]
public GameSettings Settings { get; set; } = new();
[Signal] [Signal]
public delegate void SummonBossEventHandler(string bossName); public delegate void SummonBossEventHandler(string bossName);
public override void _Ready() public override void _Ready()
{ {
ProcessMode = ProcessModeEnum.Always; 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) public void ImportFromSave(Save save)