Skip to content

Commit 8b0a9be

Browse files
committed
added difficulty setting
fixed a bug where the settings page would be displayed in two columns if key tips are enabled
1 parent fec8e83 commit 8b0a9be

6 files changed

Lines changed: 88 additions & 8 deletions

File tree

public/index.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,18 @@ <h1>support</h1>
242242
</div>
243243
</div>
244244
<div class="page pageSettings hidden">
245-
<div class="tip" style="grid-column: 1/3;">tip: You can also change all these settings quickly using the command line (<key>esc</key>)</div>
245+
<div class="tip">tip: You can also change all these settings quickly using the command line (<key>esc</key>)</div>
246+
<div class="section difficulty">
247+
<h1>test difficulty</h1>
248+
<div class="text">Normal is the classic type test experience. Expert fails the test if you submit (press space) an incorrect word.
249+
Master fails if you press a single incorrect key (meaning you have to achieve 100% accuracy).
250+
</div>
251+
<div class="buttons">
252+
<div class="button" difficulty="normal" tabindex="0" onclick="this.blur();">normal</div>
253+
<div class="button" difficulty="expert" tabindex="0" onclick="this.blur();">expert</div>
254+
<div class="button" difficulty="master" tabindex="0" onclick="this.blur();">master</div>
255+
</div>
256+
</div>
246257
<div class="section smoothCaret" section="">
247258
<h1>smooth caret</h1>
248259
<div class="text">The caret will move smoothly between letters and words.</div>

public/js/commandline.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ let commands = {
4949
toggleFreedomMode();
5050
}
5151
},
52+
{
53+
id: "changeDifficulty",
54+
display: "Change difficulty...",
55+
subgroup: true,
56+
exec: () => {
57+
currentCommands.push(commandsDifficulty);
58+
showCommandLine();
59+
}
60+
},
5261
{
5362
id: "changeTheme",
5463
display: "Change theme...",
@@ -152,6 +161,33 @@ let commandsSendDevMessage = {
152161
]
153162
}
154163

164+
let commandsDifficulty = {
165+
title: "Change difficulty...",
166+
list: [
167+
{
168+
id: "setDifficultyNormal",
169+
display: "Normal",
170+
exec: () => {
171+
setDifficulty('normal');
172+
}
173+
},
174+
{
175+
id: "setDifficultyExpert",
176+
display: "Expert",
177+
exec: () => {
178+
setDifficulty('expert');
179+
}
180+
},
181+
{
182+
id: "setDifficultyMaster",
183+
display: "Master",
184+
exec: () => {
185+
setDifficulty('master');
186+
}
187+
}
188+
]
189+
}
190+
155191

156192
let commandsWordCount = {
157193
title: "Change word count...",

public/js/db.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ async function db_getUserResults() {
3232
return ret;
3333
}
3434

35-
async function db_getUserHighestWpm(mode, mode2, punctuation, language) {
35+
async function db_getUserHighestWpm(mode, mode2, punctuation, language, difficulty) {
3636

3737
function cont() {
3838
let topWpm = 0;
3939
dbSnapshot.forEach(result => {
40-
if (result.mode == mode && result.mode2 == mode2 && result.punctuation == punctuation && result.language == language) {
40+
if (result.mode == mode && result.mode2 == mode2 && result.punctuation == punctuation && result.language == language && result.difficulty == difficulty) {
4141
if (result.wpm > topWpm) {
4242
topWpm = result.wpm;
4343
}

public/js/script.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ function compareInput() {
252252
ret += '<letter class="correct">' + currentWord[i] + "</letter>";
253253
// $(letterElems[i]).removeClass('incorrect').addClass('correct');
254254
} else {
255+
if(config.difficulty == "master"){
256+
showResult();
257+
}
255258
if (currentWord[i] == undefined) {
256259
ret +=
257260
'<letter class="incorrect extra">' + currentInput[i] + "</letter>";
@@ -516,9 +519,9 @@ function showResult() {
516519
restartCount: restartCount
517520
};
518521
restartCount = 0;
519-
if (stats.wpm > 0 && stats.wpm < 600 && stats.acc > 50 && stats.acc <= 100) {
522+
if (stats.wpm > 0 && stats.wpm < 350 && stats.acc > 50 && stats.acc <= 100) {
520523
if (firebase.auth().currentUser != null) {
521-
db_getUserHighestWpm(config.mode, mode2, config.punctuation, config.language).then(data => {
524+
db_getUserHighestWpm(config.mode, mode2, config.punctuation, config.language, config.difficulty).then(data => {
522525
// console.log(`highest wpm for this mode is ${data}, current is ${stats.wpm}`);
523526
if (data < stats.wpm) {
524527
hideCrown();
@@ -570,6 +573,11 @@ function showResult() {
570573
if (config.punctuation) {
571574
infoText += "<br>punctuation"
572575
}
576+
if (config.difficulty == "expert") {
577+
infoText += "<br>expert";
578+
}else if(config.difficulty == "master"){
579+
infoText += "<br>master";
580+
}
573581

574582
$("#result .stats .info .bottom").html(infoText);
575583

@@ -1231,7 +1239,7 @@ $(document).keydown((event) => {
12311239
highlightBadWord();
12321240
currentInput = "";
12331241
currentWordIndex++;
1234-
if (currentWordIndex == wordsList.length) {
1242+
if (currentWordIndex == wordsList.length || config.difficulty == "expert") {
12351243
showResult();
12361244
return;
12371245
}

public/js/settings.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ function updateSettingsPage(){
2020
setActiveThemeButton();
2121
setActiveLanguageButton();
2222
setActiveFontSizeButton();
23+
setActiveDifficultyButton();
2324

2425
if (config.showKeyTips) {
2526
$(".pageSettings .tip").removeClass('hidden');
@@ -40,6 +41,11 @@ function setActiveFontSizeButton() {
4041
$(`.pageSettings .section.fontSize .buttons .button[fontsize=`+config.fontSize+`]`).addClass('active');
4142
}
4243

44+
function setActiveDifficultyButton() {
45+
$(`.pageSettings .section.difficulty .buttons .button`).removeClass('active');
46+
$(`.pageSettings .section.difficulty .buttons .button[difficulty=`+config.difficulty+`]`).addClass('active');
47+
}
48+
4349
function setActiveLanguageButton() {
4450
$(`.pageSettings .section.languages .language`).removeClass('active');
4551
$(`.pageSettings .section.languages .language[language=${config.language}]`).addClass('active');
@@ -161,4 +167,12 @@ $(document).on("click",".pageSettings .section.fontSize .button", (e) => {
161167
changeFontSize(fontSize);
162168
showNotification('Font size changed', 1000);
163169
setActiveFontSizeButton();
170+
})
171+
172+
//difficulty
173+
$(document).on("click",".pageSettings .section.difficulty .button", (e) => {
174+
let difficulty = $(e.currentTarget).attr('difficulty');
175+
setDifficulty(difficulty);
176+
showNotification('Difficulty changed', 1000);
177+
setActiveDifficultyButton();
164178
})

public/js/userconfig.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ let config = {
1111
language: "english",
1212
fontSize: 1,
1313
freedomMode: false,
14-
resultFilters: ["all"]
14+
resultFilters: ["all"],
15+
difficulty: "master",
1516
}
1617

1718
//cookies
@@ -42,6 +43,7 @@ function loadConfigFromCookie() {
4243
changeLanguage(newConfig.language,true);
4344
changeFontSize(newConfig.fontSize,true);
4445
setFreedomMode(newConfig.freedomMode,true);
46+
setDifficulty(newConfig.difficulty,true);
4547
if(newConfig.resultFilters == null || newConfig.resultFilters == undefined){
4648
newConfig.resultFilters = ["all"];
4749
}
@@ -55,7 +57,16 @@ function showTestConfig() {
5557

5658
function hideTestConfig() {
5759
$("#top .config").css("opacity",0).addClass('hidden');
58-
60+
}
61+
62+
//difficulty
63+
function setDifficulty(diff, nosave){
64+
if(diff !== "normal" && diff !== "expert" && diff !== "master"){
65+
diff = "normal";
66+
}
67+
config.difficulty = diff;
68+
restartTest();
69+
if(!nosave) saveConfigToCookie();
5970
}
6071

6172
//key tips

0 commit comments

Comments
 (0)