allow emulation of modded controller

This commit is contained in:
RandomityGuy 2025-03-23 17:59:11 +05:30
parent e0bd40fc03
commit 0a42f481ca
4 changed files with 52 additions and 1 deletions

View file

@ -2147,6 +2147,25 @@ class Marble extends GameObject {
move.d = new Vector(); move.d = new Vector();
move.d.x = Gamepad.getAxis(Settings.gamepadSettings.moveYAxis); move.d.x = Gamepad.getAxis(Settings.gamepadSettings.moveYAxis);
move.d.y = -Gamepad.getAxis(Settings.gamepadSettings.moveXAxis); move.d.y = -Gamepad.getAxis(Settings.gamepadSettings.moveXAxis);
if (Settings.controlsSettings.moddedController) {
// we need to scale the moves to square instead of circle
var moveLen = Math.sqrt(move.d.x * move.d.x + move.d.y * move.d.y);
if (moveLen > 0.00001) {
// Normalize the vector
var normalizedX = move.d.x / moveLen;
var normalizedY = move.d.y / moveLen;
// Scale to square - this allows diagonal movements to reach the corners
var scaleFactor = Math.max(Math.abs(normalizedX), Math.abs(normalizedY));
if (scaleFactor > 0) {
// Apply square mapping while preserving the original magnitude
move.d.x = normalizedX / scaleFactor * moveLen;
move.d.y = normalizedY / scaleFactor * moveLen;
}
}
}
if (@:privateAccess !MarbleGame.instance.world.playGui.isChatFocused()) { if (@:privateAccess !MarbleGame.instance.world.playGui.isChatFocused()) {
if (Key.isDown(Settings.controlsSettings.forward)) { if (Key.isDown(Settings.controlsSettings.forward)) {
move.d.x -= 1; move.d.x -= 1;

View file

@ -73,6 +73,7 @@ typedef ControlsSettings = {
var rewind:Int; var rewind:Int;
var chat:Int; var chat:Int;
var oobRespawnKeyByPowerup:Bool; var oobRespawnKeyByPowerup:Bool;
var moddedController:Bool;
} }
typedef TouchSettings = { typedef TouchSettings = {
@ -166,7 +167,8 @@ class Settings {
blast: Key.MOUSE_RIGHT, blast: Key.MOUSE_RIGHT,
rewind: Key.R, rewind: Key.R,
chat: Key.T, chat: Key.T,
oobRespawnKeyByPowerup: false oobRespawnKeyByPowerup: false,
moddedController: false
}; };
public static var touchSettings:TouchSettings = { public static var touchSettings:TouchSettings = {
@ -473,6 +475,9 @@ class Settings {
if (controlsSettings.oobRespawnKeyByPowerup == null) { if (controlsSettings.oobRespawnKeyByPowerup == null) {
controlsSettings.oobRespawnKeyByPowerup = false; controlsSettings.oobRespawnKeyByPowerup = false;
} }
if (controlsSettings.moddedController == null) {
controlsSettings.moddedController = false;
}
if (optionsSettings.rewindEnabled == null) { if (optionsSettings.rewindEnabled == null) {
optionsSettings.rewindEnabled = false; optionsSettings.rewindEnabled = false;
} }

View file

@ -102,6 +102,12 @@ class MiscOptionsGui extends GuiImage {
}, 0.5, 118); }, 0.5, 118);
oobResOpt.setCurrentOption(Settings.controlsSettings.oobRespawnKeyByPowerup ? 1 : 0); oobResOpt.setCurrentOption(Settings.controlsSettings.oobRespawnKeyByPowerup ? 1 : 0);
var moddedOpt = optionCollection.addOption(1, "Emulate Modded Controller", ["No", "Yes"], (idx) -> {
Settings.controlsSettings.moddedController = (idx == 1);
return true;
}, 0.5, 118);
moddedOpt.setCurrentOption(Settings.controlsSettings.moddedController ? 1 : 0);
var bottomBar = new GuiControl(); var bottomBar = new GuiControl();
bottomBar.position = new Vector(0, 590); bottomBar.position = new Vector(0, 590);
bottomBar.extent = new Vector(640, 200); bottomBar.extent = new Vector(640, 200);

View file

@ -76,6 +76,25 @@ class MoveManager {
if (!MarbleGame.instance.paused) { if (!MarbleGame.instance.paused) {
move.d.x = Gamepad.getAxis(Settings.gamepadSettings.moveYAxis); move.d.x = Gamepad.getAxis(Settings.gamepadSettings.moveYAxis);
move.d.y = -Gamepad.getAxis(Settings.gamepadSettings.moveXAxis); move.d.y = -Gamepad.getAxis(Settings.gamepadSettings.moveXAxis);
if (Settings.controlsSettings.moddedController) {
// we need to scale the moves to square instead of circle
var moveLen = Math.sqrt(move.d.x * move.d.x + move.d.y * move.d.y);
if (moveLen > 0.00001) {
// Normalize the vector
var normalizedX = move.d.x / moveLen;
var normalizedY = move.d.y / moveLen;
// Scale to square - this allows diagonal movements to reach the corners
var scaleFactor = Math.max(Math.abs(normalizedX), Math.abs(normalizedY));
if (scaleFactor > 0) {
// Apply square mapping while preserving the original magnitude
move.d.x = normalizedX / scaleFactor * moveLen;
move.d.y = normalizedY / scaleFactor * moveLen;
}
}
}
if (@:privateAccess !MarbleGame.instance.world.playGui.isChatFocused()) { if (@:privateAccess !MarbleGame.instance.world.playGui.isChatFocused()) {
if (Key.isDown(Settings.controlsSettings.forward)) { if (Key.isDown(Settings.controlsSettings.forward)) {
move.d.x -= 1; move.d.x -= 1;
@ -89,6 +108,8 @@ class MoveManager {
if (Key.isDown(Settings.controlsSettings.right)) { if (Key.isDown(Settings.controlsSettings.right)) {
move.d.y -= 1; move.d.y -= 1;
} }
move.d.x = Util.clamp(move.d.x, -1, 1);
move.d.y = Util.clamp(move.d.y, -1, 1);
if (Key.isDown(Settings.controlsSettings.jump) if (Key.isDown(Settings.controlsSettings.jump)
|| MarbleGame.instance.touchInput.jumpButton.pressed || MarbleGame.instance.touchInput.jumpButton.pressed
|| Gamepad.isDown(Settings.gamepadSettings.jump)) { || Gamepad.isDown(Settings.gamepadSettings.jump)) {