added play sound on error

This commit is contained in:
Jack 2020-08-13 23:11:53 +01:00
parent 2223df1b4b
commit ba1fc7748d
6 changed files with 44 additions and 1 deletions

View file

@ -898,7 +898,10 @@ exports.saveConfig = functions.https.onCall((request, response) => {
{ merge: true }
)
.then((e) => {
return 1;
return {
returnCode: 1,
message: "Saved",
};
})
.catch((e) => {
console.error(

View file

@ -1509,6 +1509,21 @@
</div>
</div>
</div>
<div class="section playSoundOnError">
<h1>play sound on error</h1>
<div class="text">
Plays a short sound if you press an incorrect key or press space
too early.
</div>
<div class="buttons">
<div class="button off" tabindex="0" onclick="this.blur();">
off
</div>
<div class="button on" tabindex="0" onclick="this.blur();">
on
</div>
</div>
</div>
<div class="section tags">
<h1>tags</h1>
<div class="text">

View file

@ -59,6 +59,8 @@ let keypressStats = {
},
};
let errorSound = new Audio("../sound/error.wav");
let customText = "The quick brown fox jumps over the lazy dog".split(" ");
let customTextIsRandom = false;
let customTextWordCount = 1;
@ -3055,6 +3057,12 @@ function hideCustomMode2Popup() {
}
}
function playErrorSound() {
if (!config.playSoundOnError) return;
errorSound.currentTime = 0;
errorSound.play();
}
$("#customMode2PopupWrapper").click((e) => {
if ($(e.target).attr("id") === "customMode2PopupWrapper") {
hideCustomMode2Popup();
@ -3331,6 +3339,7 @@ $(document).keypress(function (event) {
accuracyStats.incorrect++;
currentErrorCount++;
thisCharCorrect = false;
playErrorSound();
} else {
accuracyStats.correct++;
thisCharCorrect = true;
@ -3632,6 +3641,7 @@ $(document).keydown((event) => {
updateCaretPosition();
currentKeypressCount++;
} else {
playErrorSound();
accuracyStats.incorrect++;
if (config.stopOnError) {
if (config.difficulty == "expert" || config.difficulty == "master") {

View file

@ -151,6 +151,10 @@ settingsGroups.colorfulMode = new SettingsGroup(
);
settingsGroups.randomTheme = new SettingsGroup("randomTheme", setRandomTheme);
settingsGroups.stopOnError = new SettingsGroup("stopOnError", setStopOnError);
settingsGroups.stopOnError = new SettingsGroup(
"playSoundOnError",
setPlaySoundOnError
);
settingsGroups.showAllLines = new SettingsGroup(
"showAllLines",
setShowAllLines

View file

@ -46,6 +46,7 @@ let defaultConfig = {
smoothLineScroll: false,
alwaysShowDecimalPlaces: false,
alwaysShowWordsHistory: false,
playSoundOnError: false,
};
let cookieConfig = null;
@ -82,6 +83,7 @@ async function saveConfigToDB() {
accountIconLoading(true);
saveConfig({ uid: firebase.auth().currentUser.uid, obj: config }).then(
(d) => {
console.log(d.data);
accountIconLoading(false);
if (d.data.returnCode === 1) {
// showNotification('config saved to db',1000);
@ -159,6 +161,7 @@ function applyConfig(configObj) {
setShowTimerProgress(configObj.showTimerProgress, true);
setAlwaysShowDecimalPlaces(config.alwaysShowDecimalPlaces, true);
setAlwaysShowWordsHistory(config.alwaysShowWordsHistory, true);
setPlaySoundOnError(config.playSoundOnError, true);
// if (
// configObj.resultFilters !== null &&
// configObj.resultFilters !== undefined
@ -193,6 +196,14 @@ function hideTestConfig() {
$("#top .config").css("opacity", 0).addClass("hidden");
}
function setPlaySoundOnError(val, nosave) {
if (val == undefined) {
val = false;
}
config.playSoundOnError = val;
if (!nosave) saveConfigToCookie();
}
//difficulty
function setDifficulty(diff, nosave) {
if (

BIN
public/sound/error.wav Normal file

Binary file not shown.