Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion Backends/HTML5/kha/SystemImpl.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,37 @@ class SystemImpl {
return "unknown";
}

public static function setGamepadRumble(index: Int, leftAmount: Float, rightAmount: Float) {}
public static function setGamepadRumble(index: Int, leftAmount: Float, rightAmount: Float): Void {
final sysGamepads = getGamepads();
if (sysGamepads == null || sysGamepads[index] == null) {
return;
}

final gamepad = sysGamepads[index];
final duration = 10000; // 10 seconds

if (untyped gamepad.vibrationActuator) {
if (leftAmount == 0 && rightAmount == 0) {
untyped gamepad.vibrationActuator.reset();
}
else {
untyped gamepad.vibrationActuator.playEffect('dual-rumble', {
duration: duration,
strongMagnitude: leftAmount,
weakMagnitude: rightAmount
});
}
}
else if (untyped gamepad.hapticActuators && untyped gamepad.hapticActuators.length > 0) {
final hapticActuator = untyped gamepad.hapticActuators[0];
if (leftAmount == 0 && rightAmount == 0) {
untyped gamepad.hapticActuators[0].pulse(0, 0);
}
else {
untyped gamepad.hapticActuators[0].pulse(leftAmount, duration);
}
}
}

static function getGamepads(): Array<js.html.Gamepad> {
if (chrome && kha.vr.VrInterface.instance != null && kha.vr.VrInterface.instance.IsVrEnabled()) {
Expand Down
Loading