mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-06 23:57:19 +02:00
Move patchPollGamepads code to external file
This commit is contained in:
parent
e18e05589a
commit
22e29e1d92
@ -3,9 +3,10 @@ import { BX_FLAGS } from "@utils/bx-flags";
|
||||
import { getPref, PrefKey } from "@utils/preferences";
|
||||
import { VibrationManager } from "@modules/vibration-manager";
|
||||
import { BxLogger } from "@utils/bx-logger";
|
||||
import { hashCode } from "@utils/utils";
|
||||
import { hashCode, renderString } from "@utils/utils";
|
||||
import { BxEvent } from "@/utils/bx-event";
|
||||
|
||||
import codeControllerShortcuts from "./patches/controller-shortcuts.js" with { type: "text" };
|
||||
import codeLocalCoOpEnable from "./patches/local-co-op-enable.js" with { type: "text" };
|
||||
import codeRemotePlayEnable from "./patches/remote-play-enable.js" with { type: "text" };
|
||||
import codeRemotePlayKeepAlive from "./patches/remote-play-keep-alive.js" with { type: "text" };
|
||||
@ -175,11 +176,10 @@ if (!!window.BX_REMOTE_PLAY_CONFIG) {
|
||||
const match = codeBlock.match(/this\.gamepadTimestamps\.set\((\w+)\.index/);
|
||||
if (match) {
|
||||
const gamepadVar = match[1];
|
||||
const newCode = `
|
||||
if (${gamepadVar}.buttons[17] && ${gamepadVar}.buttons[17].value === 1) {
|
||||
window.dispatchEvent(new Event('${BxEvent.CAPTURE_SCREENSHOT}'));
|
||||
}
|
||||
`;
|
||||
const newCode = renderString(codeControllerShortcuts, {
|
||||
gamepadVar,
|
||||
});
|
||||
|
||||
codeBlock = codeBlock.replace('this.gamepadTimestamps.set', newCode + 'this.gamepadTimestamps.set');
|
||||
}
|
||||
|
||||
|
5
src/modules/patches/controller-shortcuts.js
Normal file
5
src/modules/patches/controller-shortcuts.js
Normal file
@ -0,0 +1,5 @@
|
||||
const currentGamepad = ${gamepadVar};
|
||||
|
||||
if (currentGamepad.buttons[17] && currentGamepad.buttons[17].value === 1) {
|
||||
window.dispatchEvent(new Event(BxEvent.CAPTURE_SCREENSHOT));
|
||||
}
|
@ -61,3 +61,5 @@ export namespace BxEvent {
|
||||
target.dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
(window as any).BxEvent = BxEvent;
|
||||
|
@ -65,3 +65,15 @@ export function hashCode(str: string): number {
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
||||
export function renderString(str: string, obj: any){
|
||||
return str.replace(/\$\{.+?\}/g, match => {
|
||||
const key = match.substring(2, match.length - 1);
|
||||
if (key in obj) {
|
||||
return obj[key];
|
||||
}
|
||||
|
||||
return match;
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user