using System.Numerics; namespace Godosa.Core.Input; [Flags] public enum PadButtons { None = 0, A = 1 << 0, B = 1 << 1, X = 1 << 2, Y = 1 << 3, Back = 1 << 4, Start = 1 << 5, LeftShoulder = 1 << 6, RightShoulder = 1 << 7, DpadUp = 1 << 8, DpadDown = 1 << 9, DpadLeft = 1 << 10, DpadRight = 1 << 11, } /// Raw held pad state, no game meaning: sticks −1…1 (SDL convention, stick up = /// −Y), triggers 0…1. Each game maps it to its own input frame. public readonly record struct GamepadState(Vector2 LeftStick, Vector2 RightStick, float LeftTrigger, float RightTrigger, PadButtons Buttons) { public bool Held(PadButtons button) => (Buttons & button) != 0; } /// Input-script pad events (PadA PadB PadX PadY PadBack PadStart PadUp PadDown /// PadLeft PadRight PadLB PadRB PadLT PadRT, case-insensitive): triggers go full on/off. public static class GamepadScript { public static GamepadState? Apply(GamepadState state, string name, bool down) { string key = name.ToLowerInvariant(); if (key == "padlt") return state with { LeftTrigger = down ? 1f : 0f }; if (key == "padrt") return state with { RightTrigger = down ? 1f : 0f }; PadButtons button = key switch { "pada" => PadButtons.A, "padb" => PadButtons.B, "padx" => PadButtons.X, "pady" => PadButtons.Y, "padback" => PadButtons.Back, "padstart" => PadButtons.Start, "padup" => PadButtons.DpadUp, "paddown" => PadButtons.DpadDown, "padleft" => PadButtons.DpadLeft, "padright" => PadButtons.DpadRight, "padlb" => PadButtons.LeftShoulder, "padrb" => PadButtons.RightShoulder, _ => PadButtons.None, }; if (button == PadButtons.None) return null; return state with { Buttons = down ? state.Buttons | button : state.Buttons & ~button }; } }