Skip to content

Commit

Permalink
update input system again for some reason
Browse files Browse the repository at this point in the history
gamepad support was bugging out a bit so i fixed that, but also refactored the input system
  • Loading branch information
Joalor64GH authored Nov 11, 2024
1 parent a709d8b commit 22c2e56
Showing 1 changed file with 28 additions and 111 deletions.
139 changes: 28 additions & 111 deletions source/backend/Input.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package backend;

import flixel.input.FlxInput.FlxInputState;

typedef Bind = {
key:Array<FlxKey>,
gamepad:Array<FlxGamepadInputID>
Expand Down Expand Up @@ -33,159 +35,74 @@ class Input {
}

public static function resetControls() {
kBinds = [];
gBinds = [];

kBinds = [LEFT, DOWN, UP, RIGHT, A, S, W, D, ENTER, ESCAPE, R];
gBinds = [DPAD_LEFT, DPAD_DOWN, DPAD_UP, DPAD_RIGHT, LEFT_TRIGGER, LEFT_SHOULDER, RIGHT_SHOULDER, RIGHT_TRIGGER, A, B, RIGHT_STICK_CLICK];

SaveData.saveSettings();
refreshControls();
}

public static function justPressed(tag:String):Bool {
var gamepad:FlxGamepad = FlxG.gamepads.lastActive;
public static function justPressed(tag:String):Bool
return checkInput(tag, JUST_PRESSED);

if (gamepad != null) {
if (binds.exists(tag)) {
for (i in 0...binds[tag].gamepad.length)
if (gamepad.checkStatus(binds[tag].gamepad[i], JUST_PRESSED))
return true;
} else {
return gamepad.checkStatus(FlxGamepadInputID.fromString(tag), JUST_PRESSED);
}
} else {
if (binds.exists(tag)) {
for (i in 0...binds[tag].key.length)
if (FlxG.keys.checkStatus(binds[tag].key[i], JUST_PRESSED))
return true;
} else {
return FlxG.keys.checkStatus(FlxKey.fromString(tag), JUST_PRESSED);
}
}
public static function pressed(tag:String):Bool
return checkInput(tag, PRESSED);

return false;
}
public static function justReleased(tag:String):Bool
return checkInput(tag, JUST_RELEASED);

public static function pressed(tag:String):Bool {
var gamepad:FlxGamepad = FlxG.gamepads.lastActive;
public static function anyJustPressed(tags:Array<String>):Bool
return checkAnyInputs(tags, JUST_PRESSED);

if (gamepad != null) {
if (binds.exists(tag)) {
for (i in 0...binds[tag].gamepad.length)
if (gamepad.checkStatus(binds[tag].gamepad[i], PRESSED))
return true;
} else {
return gamepad.checkStatus(FlxGamepadInputID.fromString(tag), PRESSED);
}
} else {
if (binds.exists(tag)) {
for (i in 0...binds[tag].key.length)
if (FlxG.keys.checkStatus(binds[tag].key[i], PRESSED))
return true;
} else {
return FlxG.keys.checkStatus(FlxKey.fromString(tag), PRESSED);
}
}
public static function anyPressed(tags:Array<String>):Bool
return checkAnyInputs(tags, PRESSED);

return false;
}
public static function anyJustReleased(tags:Array<String>):Bool
return checkAnyInputs(tags, JUST_RELEASED);

public static function justReleased(tag:String):Bool {
public static function checkInput(tag:String, state:FlxInputState):Bool {
var gamepad:FlxGamepad = FlxG.gamepads.lastActive;

if (gamepad != null) {
if (binds.exists(tag)) {
for (i in 0...binds[tag].gamepad.length)
if (gamepad.checkStatus(binds[tag].gamepad[i], JUST_RELEASED))
for (i in binds[tag].gamepad)
if (i != FlxGamepadInputID.NONE && gamepad.checkStatus(binds[tag].gamepad[i], state))
return true;
} else {
return gamepad.checkStatus(FlxGamepadInputID.fromString(tag), JUST_RELEASED);
return gamepad.checkStatus(FlxGamepadInputID.fromString(tag), state);
}
} else {
if (binds.exists(tag)) {
for (i in 0...binds[tag].key.length)
if (FlxG.keys.checkStatus(binds[tag].key[i], JUST_RELEASED))
for (i in binds[tag].key)
if (FlxG.keys.checkStatus(binds[tag].key[i], state))
return true;
} else {
return FlxG.keys.checkStatus(FlxKey.fromString(tag), JUST_RELEASED);
}
}

return false;
}

public static function anyJustPressed(tags:Array<String>):Bool {
var gamepad:FlxGamepad = FlxG.gamepads.lastActive;

for (tag in tags) {
if (gamepad != null) {
if (binds.exists(tag)) {
for (i in 0...binds[tag].gamepad.length)
if (gamepad.checkStatus(binds[tag].gamepad[i], JUST_PRESSED))
return true;
} else {
return gamepad.checkStatus(FlxGamepadInputID.fromString(tag), JUST_PRESSED);
}
} else {
if (binds.exists(tag)) {
for (i in 0...binds[tag].key.length)
if (FlxG.keys.checkStatus(binds[tag].key[i], JUST_PRESSED))
return true;
} else {
return FlxG.keys.checkStatus(FlxKey.fromString(tag), JUST_PRESSED);
}
}
}

return false;
}

public static function anyPressed(tags:Array<String>):Bool {
var gamepad:FlxGamepad = FlxG.gamepads.lastActive;

for (tag in tags) {
if (gamepad != null) {
if (binds.exists(tag)) {
for (i in 0...binds[tag].gamepad.length)
if (gamepad.checkStatus(binds[tag].gamepad[i], PRESSED))
return true;
} else {
return gamepad.checkStatus(FlxGamepadInputID.fromString(tag), PRESSED);
}
} else {
if (binds.exists(tag)) {
for (i in 0...binds[tag].key.length)
if (FlxG.keys.checkStatus(binds[tag].key[i], PRESSED))
return true;
} else {
return FlxG.keys.checkStatus(FlxKey.fromString(tag), PRESSED);
}
return FlxG.keys.checkStatus(FlxKey.fromString(tag), state);
}
}

return false;
}

public static function anyJustReleased(tags:Array<String>):Bool {
public static function checkAnyInputs(tags:Array<String>, state:FlxInputState):Bool {
var gamepad:FlxGamepad = FlxG.gamepads.lastActive;

for (tag in tags) {
if (gamepad != null) {
if (binds.exists(tag)) {
for (i in 0...binds[tag].gamepad.length)
if (gamepad.checkStatus(binds[tag].gamepad[i], JUST_RELEASED))
for (i in binds[tag].gamepad)
if (i != FlxGamepadInputID.NONE && gamepad.checkStatus(binds[tag].gamepad[i], state))
return true;
} else {
return gamepad.checkStatus(FlxGamepadInputID.fromString(tag), JUST_RELEASED);
return gamepad.checkStatus(FlxGamepadInputID.fromString(tag), state);
}
} else {
if (binds.exists(tag)) {
for (i in 0...binds[tag].key.length)
if (FlxG.keys.checkStatus(binds[tag].key[i], JUST_RELEASED))
for (i in binds[tag].key)
if (FlxG.keys.checkStatus(binds[tag].key[i], state))
return true;
} else {
return FlxG.keys.checkStatus(FlxKey.fromString(tag), JUST_RELEASED);
return FlxG.keys.checkStatus(FlxKey.fromString(tag), state);
}
}
}
Expand Down

0 comments on commit 22c2e56

Please sign in to comment.