Skip to content

Commit 5c4ff1a

Browse files
committed
Left stick = DPad + delay + interval for both
1 parent 39a6a20 commit 5c4ff1a

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "emulsion",
3-
"version": "0.10.32",
3+
"version": "0.10.33",
44
"summary": "Better gaming throught chemistry",
55
"description": "Display your games collection into responsive galleries, manage game metadata, cover art and emulator configuration. Launch your games in style.",
66
"homepage": "https://yphil.gitlab.io/emulsion",

src/js/slideshow.js

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -846,8 +846,8 @@ export function initGamepad() {
846846

847847
const longPressTimeouts = {};
848848
const longPressIntervals = {};
849-
const repeatDelay = 500;
850-
const repeatInterval = 150;
849+
const repeatDelay = 250;
850+
const repeatInterval = 50;
851851

852852
// Listen for gamepad connection events
853853
window.addEventListener('gamepadconnected', (event) => {
@@ -887,37 +887,89 @@ export function initGamepad() {
887887
if (!buttonStates['leftStickLeft']) {
888888
buttonStates['leftStickLeft'] = true;
889889
handleGameControllerButtonPress(14); // Left
890+
longPressTimeouts['leftStickLeft'] = setTimeout(() => {
891+
longPressIntervals['leftStickLeft'] = setInterval(() => {
892+
handleGameControllerButtonPress(14);
893+
}, repeatInterval);
894+
}, repeatDelay);
890895
}
891896
} else if (buttonStates['leftStickLeft']) {
892897
buttonStates['leftStickLeft'] = false;
898+
if (longPressTimeouts['leftStickLeft']) {
899+
clearTimeout(longPressTimeouts['leftStickLeft']);
900+
delete longPressTimeouts['leftStickLeft'];
901+
}
902+
if (longPressIntervals['leftStickLeft']) {
903+
clearInterval(longPressIntervals['leftStickLeft']);
904+
delete longPressIntervals['leftStickLeft'];
905+
}
893906
}
894907

895908
if (leftStickX > threshold) {
896909
if (!buttonStates['leftStickRight']) {
897910
buttonStates['leftStickRight'] = true;
898911
handleGameControllerButtonPress(15); // Right
912+
longPressTimeouts['leftStickRight'] = setTimeout(() => {
913+
longPressIntervals['leftStickRight'] = setInterval(() => {
914+
handleGameControllerButtonPress(15);
915+
}, repeatInterval);
916+
}, repeatDelay);
899917
}
900918
} else if (buttonStates['leftStickRight']) {
901919
buttonStates['leftStickRight'] = false;
920+
if (longPressTimeouts['leftStickRight']) {
921+
clearTimeout(longPressTimeouts['leftStickRight']);
922+
delete longPressTimeouts['leftStickRight'];
923+
}
924+
if (longPressIntervals['leftStickRight']) {
925+
clearInterval(longPressIntervals['leftStickRight']);
926+
delete longPressIntervals['leftStickRight'];
927+
}
902928
}
903929

904930
// Left stick vertical (up/down)
905931
if (leftStickY < -threshold) {
906932
if (!buttonStates['leftStickUp']) {
907933
buttonStates['leftStickUp'] = true;
908934
handleGameControllerButtonPress(12); // Up
935+
longPressTimeouts['leftStickUp'] = setTimeout(() => {
936+
longPressIntervals['leftStickUp'] = setInterval(() => {
937+
handleGameControllerButtonPress(12);
938+
}, repeatInterval);
939+
}, repeatDelay);
909940
}
910941
} else if (buttonStates['leftStickUp']) {
911942
buttonStates['leftStickUp'] = false;
943+
if (longPressTimeouts['leftStickUp']) {
944+
clearTimeout(longPressTimeouts['leftStickUp']);
945+
delete longPressTimeouts['leftStickUp'];
946+
}
947+
if (longPressIntervals['leftStickUp']) {
948+
clearInterval(longPressIntervals['leftStickUp']);
949+
delete longPressIntervals['leftStickUp'];
950+
}
912951
}
913952

914953
if (leftStickY > threshold) {
915954
if (!buttonStates['leftStickDown']) {
916955
buttonStates['leftStickDown'] = true;
917956
handleGameControllerButtonPress(13); // Down
957+
longPressTimeouts['leftStickDown'] = setTimeout(() => {
958+
longPressIntervals['leftStickDown'] = setInterval(() => {
959+
handleGameControllerButtonPress(13);
960+
}, repeatInterval);
961+
}, repeatDelay);
918962
}
919963
} else if (buttonStates['leftStickDown']) {
920964
buttonStates['leftStickDown'] = false;
965+
if (longPressTimeouts['leftStickDown']) {
966+
clearTimeout(longPressTimeouts['leftStickDown']);
967+
delete longPressTimeouts['leftStickDown'];
968+
}
969+
if (longPressIntervals['leftStickDown']) {
970+
clearInterval(longPressIntervals['leftStickDown']);
971+
delete longPressIntervals['leftStickDown'];
972+
}
921973
}
922974

923975
[0,1,2,3,4,5,8,12,13,14,15].forEach((buttonIndex) => {

0 commit comments

Comments
 (0)