Search in sources :

Example 1 with MouseSourceType

use of io.github.voidzombie.nhglib.input.models.MouseSourceType in project nhglib by VoidZombie.

the class InputConfigurationsJson method parse.

@Override
public void parse(JsonValue jsonValue) {
    inputConfigurations = new InputConfigurations();
    JsonValue configurationsJson = jsonValue.get("configurations");
    JsonValue keysJson = configurationsJson.get("keys");
    JsonValue sticksJson = configurationsJson.get("sticks");
    JsonValue pointersJson = configurationsJson.get("pointers");
    JsonValue controllersJson = configurationsJson.get("controllers");
    JsonValue mouseJson = configurationsJson.get("mouse");
    // Keys
    for (JsonValue keyJson : keysJson) {
        String name = keyJson.getString("name");
        Integer keyCode = keyJson.getInt("keyCode");
        InputMode inputMode = InputMode.fromString(keyJson.getString("inputMode"));
        KeyInputConfiguration keyInputConfiguration = new KeyInputConfiguration();
        keyInputConfiguration.setName(name);
        keyInputConfiguration.setKeyCode(keyCode);
        keyInputConfiguration.setInputMode(inputMode);
        inputConfigurations.keyInputConfigurations.add(keyInputConfiguration);
    }
    // Sticks
    for (JsonValue stickJson : sticksJson) {
        String name = stickJson.getString("name");
        Integer controllerId = stickJson.getInt("controllerId");
        StickType stickType = StickType.fromString(stickJson.getString("stickType"));
        StickInputConfiguration stickInputConfiguration = new StickInputConfiguration();
        stickInputConfiguration.setName(name);
        stickInputConfiguration.setControllerId(controllerId);
        stickInputConfiguration.setStickType(stickType);
        inputConfigurations.stickInputConfigurations.add(stickInputConfiguration);
    }
    // Pointers
    for (JsonValue pointerJson : pointersJson) {
        Integer pointerId = pointerJson.getInt("id");
        String name = pointerJson.getString("name");
        Float horizontalSensitivity = pointerJson.getFloat("horizontalSensitivity");
        Float verticalSensitivity = pointerJson.getFloat("verticalSensitivity");
        PointerSourceType pointerSourceType = PointerSourceType.fromString(pointerJson.getString("sourceType"));
        PointerInputConfiguration pointerInputConfiguration = new PointerInputConfiguration();
        pointerInputConfiguration.setId(pointerId);
        pointerInputConfiguration.setName(name);
        pointerInputConfiguration.setHorizontalSensitivity(horizontalSensitivity);
        pointerInputConfiguration.setVerticalSensitivity(verticalSensitivity);
        pointerInputConfiguration.setPointerSourceType(pointerSourceType);
        inputConfigurations.pointerInputConfigurations.add(pointerInputConfiguration);
    }
    // Controllers
    for (JsonValue controllerJson : controllersJson) {
        Integer id = controllerJson.getInt("id");
        JsonValue leftStickConfigurationJson = controllerJson.get("leftStick");
        JsonValue rightStickConfigurationJson = controllerJson.get("rightStick");
        StickConfiguration leftStick = stickConfigurationFromJson(leftStickConfigurationJson);
        StickConfiguration rightStick = stickConfigurationFromJson(rightStickConfigurationJson);
        ControllerConfiguration controllerConfiguration = new ControllerConfiguration();
        controllerConfiguration.setId(id);
        controllerConfiguration.setLeftStick(leftStick);
        controllerConfiguration.setRightStick(rightStick);
        inputConfigurations.controllerConfigurations.add(controllerConfiguration);
    }
    // Mouse
    for (JsonValue mouse : mouseJson) {
        Float mouseHorizontalSensitivity = mouse.getFloat("horizontalSensitivity", 0f);
        Float mouseVerticalSensitivity = mouse.getFloat("verticalSensitivity", 0f);
        String name = mouse.getString("name");
        MouseSourceType mouseSourceType = MouseSourceType.fromString(mouse.getString("sourceType"));
        MouseInputConfiguration mouseInputConfiguration = new MouseInputConfiguration();
        mouseInputConfiguration.setName(name);
        mouseInputConfiguration.setHorizontalSensitivity(mouseHorizontalSensitivity);
        mouseInputConfiguration.setVerticalSensitivity(mouseVerticalSensitivity);
        mouseInputConfiguration.setMouseSourceType(mouseSourceType);
        inputConfigurations.mouseInputConfigurations.add(mouseInputConfiguration);
    }
}
Also used : InputMode(io.github.voidzombie.nhglib.input.models.InputMode) StickInputConfiguration(io.github.voidzombie.nhglib.input.configuration.impls.StickInputConfiguration) JsonValue(com.badlogic.gdx.utils.JsonValue) StickType(io.github.voidzombie.nhglib.input.models.StickType) InputConfigurations(io.github.voidzombie.nhglib.input.configuration.InputConfigurations) PointerSourceType(io.github.voidzombie.nhglib.input.models.PointerSourceType) MouseInputConfiguration(io.github.voidzombie.nhglib.input.configuration.impls.MouseInputConfiguration) PointerInputConfiguration(io.github.voidzombie.nhglib.input.configuration.impls.PointerInputConfiguration) KeyInputConfiguration(io.github.voidzombie.nhglib.input.configuration.impls.KeyInputConfiguration) ControllerConfiguration(io.github.voidzombie.nhglib.input.controllers.ControllerConfiguration) StickConfiguration(io.github.voidzombie.nhglib.input.controllers.StickConfiguration) MouseSourceType(io.github.voidzombie.nhglib.input.models.MouseSourceType)

Aggregations

JsonValue (com.badlogic.gdx.utils.JsonValue)1 InputConfigurations (io.github.voidzombie.nhglib.input.configuration.InputConfigurations)1 KeyInputConfiguration (io.github.voidzombie.nhglib.input.configuration.impls.KeyInputConfiguration)1 MouseInputConfiguration (io.github.voidzombie.nhglib.input.configuration.impls.MouseInputConfiguration)1 PointerInputConfiguration (io.github.voidzombie.nhglib.input.configuration.impls.PointerInputConfiguration)1 StickInputConfiguration (io.github.voidzombie.nhglib.input.configuration.impls.StickInputConfiguration)1 ControllerConfiguration (io.github.voidzombie.nhglib.input.controllers.ControllerConfiguration)1 StickConfiguration (io.github.voidzombie.nhglib.input.controllers.StickConfiguration)1 InputMode (io.github.voidzombie.nhglib.input.models.InputMode)1 MouseSourceType (io.github.voidzombie.nhglib.input.models.MouseSourceType)1 PointerSourceType (io.github.voidzombie.nhglib.input.models.PointerSourceType)1 StickType (io.github.voidzombie.nhglib.input.models.StickType)1