diff --git a/static/index.html b/static/index.html index 97a7a81..d2da711 100644 --- a/static/index.html +++ b/static/index.html @@ -5,6 +5,7 @@ סמנטעל + @@ -55,7 +56,8 @@

סמנטעל

- + + diff --git a/static/js/semantle.js b/static/js/semantle.js index 035256d..bcebd21 100644 --- a/static/js/semantle.js +++ b/static/js/semantle.js @@ -61,6 +61,8 @@ let Semantle = (function() { let guessed = new Set(); let firstGuess = true; let guesses = []; + let guessesByID = []; + let progress_view = false; let guessCount = 0; let gameOver = false; const handleStats = false; @@ -186,14 +188,20 @@ let Semantle = (function() { $("#settings-close")[0].focus(); } - function updateGuesses(guess) { - let inner = ` - # - ניחוש - קרבה - מתחמם?`; - /* This is dumb: first we find the most-recent word, and put - it at the top. Then we do the rest. */ + function toggleProgressView(event) { + var element = event.target; + if (element.className.includes("progress-button")){ + progress_view = !progress_view + updateGuesses() + } + } + + function showGuesses(){ + let inner = '' + if (guessesByID.length == 0){ + return inner; + } + let guess = guessesByID[guessesByID.length - 1][1] for (let entry of guesses) { let [similarity, oldGuess, guessNumber, percentile, egg] = entry; if (oldGuess == guess) { @@ -207,6 +215,41 @@ let Semantle = (function() { inner += guessRow(similarity, oldGuess, percentile, guessNumber, guess, egg); } } + return inner + } + + function showProgress(){ + let highest_simlirity = Number.MIN_SAFE_INTEGER + let gusses = []; + for (let entry of guessesByID) { + let [similarity, oldGuess, guessNumber, percentile, egg] = entry; + if (similarity < highest_simlirity) { + continue + } + highest_simlirity = similarity + gusses.push(guessRow(similarity, oldGuess, percentile, guessNumber, guess, egg)); + } + return gusses.reverse().join("") + } + + function updateGuesses() { + let header = ` + # + ניחוש + קרבה + מתחמם? + + `; + let inner = ''; + if (!progress_view){ + inner += showGuesses() + } + else{ + inner += showProgress() + } + if (inner != ''){ + inner = header + inner; + } $('#guesses')[0].innerHTML = inner; } @@ -226,6 +269,8 @@ let Semantle = (function() { $("#rules-button")[0].addEventListener('click', openRules); $("#settings-button")[0].addEventListener('click', openSettings); + $("#guesses")[0].addEventListener('click', toggleProgressView); + [$("#rules-underlay"), $("#rules-close")].forEach((el) => { el[0].addEventListener('click', () => { @@ -303,6 +348,7 @@ let Semantle = (function() { const newEntry = [similarity, guess, guessCount, distance, egg]; guesses.push(newEntry); + guessesByID.push(newEntry); if (distance == 1000){ endGame(true, true); } @@ -313,7 +359,7 @@ let Semantle = (function() { } - updateGuesses(guess); + updateGuesses(); firstGuess = false; // if (guess.toLowerCase() === secret && !gameOver) {