From 4af654bbecf8a7cd3925e67f0defa421dd696042 Mon Sep 17 00:00:00 2001 From: "Wei-Cheng Yeh (IID)" Date: Tue, 3 Oct 2023 09:38:51 +0800 Subject: [PATCH 1/4] fix(composeExercise.js): fix passed questions not able to be answered again It is possible to input a character from other questions. However, it was not possible to input a character from any passed question, because these characters were removed from the input table. This caused an issue for the last question, since the "next" question of the last question is currently itself. This issue is fixed by separating the input table and the question list. * MapCharacterTable() * add this.questList (init-ed to have the same content as this.table) * MapCharacterTable.prototype.getCharacterAndAlphabet() * make the previous question deleted from this.questList instead --- composeExercise.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/composeExercise.js b/composeExercise.js index 843b1d8..4d46a72 100644 --- a/composeExercise.js +++ b/composeExercise.js @@ -3,9 +3,12 @@ function MapCharacterTable(characterUse) { var characterArray = characterUse.textContent.split('\n'); var table = this.table = {}; + var questList = this.questList = {} for (var i=0, l=characterArray.length; i Date: Tue, 3 Oct 2023 11:42:26 +0800 Subject: [PATCH 2/4] fix(composeExercise.js): make answer field emptied on pressing Enter This prevents the user from wrongly pressing Space right after pressing Enter. * inputBar.oninput() * reset visualBar.node.textContent on pressing Enter --- composeExercise.js | 1 + 1 file changed, 1 insertion(+) diff --git a/composeExercise.js b/composeExercise.js index 4d46a72..8e226ea 100644 --- a/composeExercise.js +++ b/composeExercise.js @@ -265,6 +265,7 @@ inputBar.oninput = function(){ if (allAlphabet.substr(-1) === '\n') { if (respondWindow.say(allAlphabet)) respondRobot.chatBack(); this.value = ''; + visualBar.node.textContent = '_'; } else if (allAlphabet.charAt(0) == ':') ; else if (allAlphabet.substr(-1) === ' ') { From 4a143badd6e2a1f3dbb38e3cec9f41e66db6e224 Mon Sep 17 00:00:00 2001 From: "Wei-Cheng Yeh (IID)" Date: Tue, 3 Oct 2023 10:23:46 +0800 Subject: [PATCH 3/4] fix(composeExercise.js): keep same-Cangjie questions; make question advancing O(1) time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The question 叭 (口金; rc) was inaccessible due to its Cangjie code being the same as 只 (口金; rc). This issue is fixed by using an Array for MapCharacterTable.questList. * MapCharacterTable() * make this.questList an array (LIFO) * reverse the iteration of `this.questList`-building `for` loop * MapCharacterTable.prototype.getCharacterAndAlphabet() * simplify question advancing by using Array.prototype.pop() * overwrite input table with the answer of the current question for handling characters with the same Cangjie code within the same stage --- composeExercise.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/composeExercise.js b/composeExercise.js index 8e226ea..4a008b7 100644 --- a/composeExercise.js +++ b/composeExercise.js @@ -3,12 +3,12 @@ function MapCharacterTable(characterUse) { var characterArray = characterUse.textContent.split('\n'); var table = this.table = {}; - var questList = this.questList = {} - for (var i=0, l=characterArray.length; i= 0; --i) { if (characterArray[i]) { var character = characterArray[i].charAt(0), alphabet = characterArray[i].substr(1); table[alphabet] = character; - questList[alphabet] = character; + questList.push([character, alphabet]); } } } @@ -21,14 +21,9 @@ MapCharacterTable.prototype = { return undefined; }, getCharacterAndAlphabet: function (oldAlphabet) { - var list = this.questList; - list[oldAlphabet] = undefined; - for (var i in list) { - if (typeof(list[i]) == 'string' && list[i].length == 1) { - return [list[i], i]; - } - } - return false; + var res = this.questList.pop(); + this.table[res[1]] = res[0]; + return res; }, findCharacter: function (alphabet) { return this.table[alphabet] From e5370ac3d1ddaacb5e9ad2978182d7891ab6265b Mon Sep 17 00:00:00 2001 From: "Wei-Cheng Yeh (IID)" Date: Tue, 3 Oct 2023 10:43:47 +0800 Subject: [PATCH 4/4] perf(composeExercise.js): make hint revealing O(1) time * initialize hintBar with attrs hintState & hideState * hintBar.newHintState() * initialize this.hintState & this.hideState * hintBar.hintCharacter() * cache hintState into `this` * cache hideState into `this` * avoid string comparisons by accessing & modifying this.hideState instead --- composeExercise.js | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/composeExercise.js b/composeExercise.js index 4a008b7..b354e10 100644 --- a/composeExercise.js +++ b/composeExercise.js @@ -76,27 +76,35 @@ var respondWindow = { var visualBar = {node: document.getElementById('visual')}; var inputBar = document.getElementById('input'); var questCharacter = {node: document.getElementById('quest')}; -var hintBar = {node: document.getElementById('hint')}; +var hintBar = { + node: document.getElementById('hint'), + hintState: [], + hideState: [], +}; hintBar.newHintState = function() { var answerAlphabetLength = questCharacter.node.title.length; - var hintState = []; - for (var i=0, l=answerAlphabetLength; i