Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add keyboard controls for battle speed when viewing replays #2287

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
36 changes: 36 additions & 0 deletions replay.pokemonshowdown.com/src/replays-battle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export class BattlePanel extends preact.Component<{id: string}> {
}
// @ts-ignore
if (e.target?.tagName === 'INPUT' || e.target?.tagName === 'SELECT') return;
let target;
switch (e.keyCode) {
case 75: // k
if (this.battle?.atQueueEnd) {
Expand Down Expand Up @@ -195,6 +196,11 @@ export class BattlePanel extends preact.Component<{id: string}> {
case 191: // / (?)
if (e.shiftKey) {
alert(
'h = hyperfast speed\n' +
'f = fast speed\n' +
'n = normal speed\n' +
's = slow speed\n' +
'r = really slow speed\n' +
'k = play/pause\n' +
'j = previous turn\n' +
'l = next turn\n' +
Expand All @@ -219,6 +225,36 @@ export class BattlePanel extends preact.Component<{id: string}> {
case 77: // m
this.toggleMute();
break;
case 72: // h
target = this.base?.querySelector<HTMLSelectElement>('select[name=speed]');
if (!target) return;
target.value = 'hyperfast';
this.changeSpeed({target});
break;
case 70: // f
target = this.base?.querySelector<HTMLSelectElement>('select[name=speed]');
if (!target) return;
target.value = 'fast';
this.changeSpeed({target});
break;
case 78: // n
target = this.base?.querySelector<HTMLSelectElement>('select[name=speed]');
if (!target) return;
target.value = 'normal';
this.changeSpeed({target});
break;
case 83: // s
target = this.base?.querySelector<HTMLSelectElement>('select[name=speed]');
if (!target) return;
target.value = 'slow';
this.changeSpeed({target});
break;
case 82: // r
target = this.base?.querySelector<HTMLSelectElement>('select[name=speed]');
if (!target) return;
target.value = 'reallyslow';
this.changeSpeed({target});
break;
}
this.forceUpdate();
};
Expand Down
Loading