impr(commandline): preview error sound on hover (@Bretis2019) (#5769)

* fix: play sound on error  on hover in settings pop up menu

* name

---------

Co-authored-by: Miodec <jack@monkeytype.com>
This commit is contained in:
Walid Mosbahi 2024-08-12 15:51:16 +01:00 committed by GitHub
parent 2ae398cdaf
commit 38a8529808
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 0 deletions

View file

@ -17,6 +17,9 @@ const subgroup: MonkeyTypes.CommandsSubgroup = {
id: "setPlaySoundOnError1",
display: "damage",
configValue: "1",
hover: (): void => {
void SoundController.previewError("1");
},
exec: (): void => {
UpdateConfig.setPlaySoundOnError("1");
void SoundController.playError();
@ -26,6 +29,9 @@ const subgroup: MonkeyTypes.CommandsSubgroup = {
id: "setPlaySoundOnError2",
display: "triangle",
configValue: "2",
hover: (): void => {
void SoundController.previewError("2");
},
exec: (): void => {
UpdateConfig.setPlaySoundOnError("2");
void SoundController.playError();
@ -35,6 +41,9 @@ const subgroup: MonkeyTypes.CommandsSubgroup = {
id: "setPlaySoundOnError3",
display: "square",
configValue: "3",
hover: (): void => {
void SoundController.previewError("3");
},
exec: (): void => {
UpdateConfig.setPlaySoundOnError("3");
void SoundController.playError();
@ -44,6 +53,9 @@ const subgroup: MonkeyTypes.CommandsSubgroup = {
id: "setPlaySoundOnError3",
display: "punch miss",
configValue: "4",
hover: (): void => {
void SoundController.previewError("4");
},
exec: (): void => {
UpdateConfig.setPlaySoundOnError("4");
void SoundController.playError();

View file

@ -404,6 +404,20 @@ export async function previewClick(val: string): Promise<void> {
safeClickSounds[val][0].sounds[0].play();
}
export async function previewError(val: string): Promise<void> {
if (errorSounds === null) await initErrorSound();
const safeErrorSounds = errorSounds as ErrorSounds;
const errorSoundIds = Object.keys(safeErrorSounds);
if (!errorSoundIds.includes(val)) return;
//@ts-expect-error
errorClickSounds[val][0].sounds[0].seek(0);
//@ts-expect-error
errorClickSounds[val][0].sounds[0].play();
}
let currentCode = "KeyA";
$(document).on("keydown", (event) => {