forked from Clones/Controlify
refactor button guide, bindings and controller identification
This commit is contained in:
@ -10,23 +10,25 @@ import dev.isxander.controlify.gui.DrawSize;
|
||||
|
||||
public interface IBind<S extends ControllerState> {
|
||||
float state(S state);
|
||||
default boolean held(S state, Controller<S, ?> controller) {
|
||||
return state(state) > controller.config().buttonActivationThreshold;
|
||||
default boolean held(S state) {
|
||||
return state(state) > controller().config().buttonActivationThreshold;
|
||||
}
|
||||
|
||||
void draw(PoseStack matrices, int x, int centerY, Controller<S, ?> controller);
|
||||
void draw(PoseStack matrices, int x, int centerY);
|
||||
DrawSize drawSize();
|
||||
|
||||
JsonObject toJson();
|
||||
|
||||
Controller<S, ?> controller();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static <T extends ControllerState> IBind<T> fromJson(JsonObject json, Controller<T, ?> controller) {
|
||||
var type = json.get("type").getAsString();
|
||||
if (type.equals(EmptyBind.BIND_ID))
|
||||
return new EmptyBind<>();
|
||||
|
||||
if (controller instanceof GamepadController && type.equals(GamepadBind.BIND_ID)) {
|
||||
return (IBind<T>) GamepadBind.fromJson(json);
|
||||
if (controller instanceof GamepadController gamepad && type.equals(GamepadBinds.BIND_ID)) {
|
||||
return GamepadBinds.fromJson(json).map(bind -> (IBind<T>) bind.forGamepad(gamepad)).orElse(new EmptyBind<>());
|
||||
} else if (controller instanceof JoystickController joystick) {
|
||||
return (IBind<T>) switch (type) {
|
||||
case JoystickButtonBind.BIND_ID -> JoystickButtonBind.fromJson(json, joystick);
|
||||
|
Reference in New Issue
Block a user