Changeset View
Standalone View
src/activities/gletters/gletters.js
Show All 26 Lines | |||||
27 | .pragma library | 27 | .pragma library | ||
28 | .import QtQuick 2.6 as Quick | 28 | .import QtQuick 2.6 as Quick | ||
29 | .import GCompris 1.0 as GCompris //for ApplicationInfo | 29 | .import GCompris 1.0 as GCompris //for ApplicationInfo | ||
30 | .import "qrc:/gcompris/src/core/core.js" as Core | 30 | .import "qrc:/gcompris/src/core/core.js" as Core | ||
31 | 31 | | |||
32 | var currentLevel = 0; | 32 | var currentLevel = 0; | ||
33 | var currentSubLevel = 0; | 33 | var currentSubLevel = 0; | ||
34 | var level = null; | 34 | var level = null; | ||
35 | var maxLevel = 0; | 35 | var maxLevel = 0; | ||
echarruau: as seen in our discussion you do not need this value | |||||
36 | var maxSubLevel = 0; | 36 | var maxSubLevel = 0; | ||
37 | var items; | 37 | var items; | ||
38 | var uppercaseOnly; | 38 | var uppercaseOnly; | ||
39 | var mode; | 39 | var mode; | ||
40 | 40 | | |||
41 | //speed calculations, common: | 41 | //speed calculations, common: | ||
42 | var speed = 0; // how fast letters fall | 42 | var speed = 0; // how fast letters fall | ||
43 | var fallSpeed = 0; // how often new letters are dropped | 43 | var fallSpeed = 0; // how often new letters are dropped | ||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Line(s) | 117 | function initLevel() { | |||
121 | items.bar.level = currentLevel + 1; | 121 | items.bar.level = currentLevel + 1; | ||
122 | wgMaxFallingItems = 3 | 122 | wgMaxFallingItems = 3 | ||
123 | successRate = 1.0 | 123 | successRate = 1.0 | ||
124 | 124 | | |||
125 | // initialize level | 125 | // initialize level | ||
126 | deleteWords(); | 126 | deleteWords(); | ||
127 | level = items.wordlist.getLevelWordList(currentLevel + 1); | 127 | level = items.wordlist.getLevelWordList(currentLevel + 1); | ||
128 | maxSubLevel = items.wordlist.getMaxSubLevel(currentLevel + 1); | 128 | maxSubLevel = items.wordlist.getMaxSubLevel(currentLevel + 1); | ||
129 | 129 | | |||
it creates new variable, which is a hard copy not a reference,as we discussed. shubhammishra: it creates new variable, which is a hard copy not a reference,as we discussed. | |||||
130 | if (maxSubLevel == 0) { | 130 | if (maxSubLevel == 0) { | ||
131 | // If "sublevels" length is not set in wordlist, use the words length | 131 | // If "sublevels" length is not set in wordlist, use the words length | ||
Here you are modifying the source itself, this means that next time you come back to a level you already did you will have the concatenation in the data presented and not what is in the json file. echarruau: Here you are modifying the source itself, this means that next time you come back to a level… | |||||
this line will concatenate levelData to itself thrice, so we will get each copy of dominoes three times. shubhammishra: this line will concatenate levelData to itself thrice, so we will get each copy of dominoes… | |||||
we said yesterday that it does not work. If you have 1 data at the beginning you don't obtain 15 data. We said you need to create an array containing 15 data randomly taken from the available data. echarruau: we said yesterday that it does not work. If you have 1 data at the beginning you don't obtain… | |||||
do i have to make data set of 15 for each level regardless of initial data size as current approach is only increasing it size three times? can i use a loop here which randomly pick a element from level.words 15 times and push it into levelData variable. shubhammishra: do i have to make data set of 15 for each level regardless of initial data size as current… | |||||
we need to have a dataset made from data given in levelswords. The data should be randomly chosen but still have abotu equally distributed. echarruau: we need to have a dataset made from data given in levelswords. The data should be randomly… | |||||
132 | maxSubLevel = level.words.length | 132 | maxSubLevel = level.words.length | ||
shubhammishra: this will restrict the number of dominoes in each level to 15. | |||||
echarruau: See previous comment. | |||||
Here can you have a detailed comment to explain what maxSubLevel is used for. Something to say that it gives the number of falling elements presented for each level. ? echarruau: Here can you have a detailed comment to explain what maxSubLevel is used for. Something to say… | |||||
Yes, maxSubLevel stores the number of dominoes to fall down in each level, in previous code it is equals to level.words.length but this time i added attribute sublevels in json to pass it a value. shubhammishra: Yes, maxSubLevel stores the number of dominoes to fall down in each level, in previous code it… | |||||
I mean a comment in the code, not for me :) echarruau: I mean a comment in the code, not for me :)
I understood this part, but it tool me time, a… | |||||
it would be better to have an attribute named useDataset in the Activity.qml that is set to true for smallnumbers and smallnumbers2. jjazeix: it would be better to have an attribute named useDataset in the Activity.qml that is set to… | |||||
133 | } | 133 | } | ||
134 | items.score.numberOfSubLevels = maxSubLevel; | 134 | items.score.numberOfSubLevels = maxSubLevel; | ||
135 | setSpeed(); | 135 | setSpeed(); | ||
136 | /*console.log("Gletters: initializing level " + (currentLevel + 1) | 136 | /*console.log("Gletters: initializing level " + (currentLevel + 1) | ||
137 | + " maxSubLvl=" + maxSubLevel | 137 | + " maxSubLvl=" + maxSubLevel | ||
138 | + " wordCount=" + level.words.length | 138 | + " wordCount=" + level.words.length | ||
139 | + " speed=" + speed + " fallspeed=" + fallSpeed);*/ | 139 | + " speed=" + speed + " fallspeed=" + fallSpeed);*/ | ||
140 | 140 | | |||
141 | { | 141 | { | ||
142 | /* populate VirtualKeyboard for mobile: | 142 | /* populate VirtualKeyboard for mobile: | ||
143 | * 1. for < 10 letters print them all in the same row | 143 | * 1. for < 10 letters print them all in the same row | ||
144 | * 2. for > 10 letters create 3 rows with equal amount of keys per row | 144 | * 2. for > 10 letters create 3 rows with equal amount of keys per row | ||
145 | * if possible, otherwise more keys in the upper rows | 145 | * if possible, otherwise more keys in the upper rows | ||
146 | * 3. if we have both upper- and lowercase letters activate the shift | 146 | * 3. if we have both upper- and lowercase letters activate the shift | ||
147 | * key*/ | 147 | * key*/ | ||
148 | // first generate a map of needed letters | 148 | // first generate a map of needed letters | ||
149 | var letters = new Array(); | 149 | var letters = new Array(); | ||
150 | items.keyboard.shiftKey = false; | 150 | items.keyboard.shiftKey = false; | ||
151 | for (var i = 0; i < level.words.length; i++) { | 151 | for (var i = 0; i < level.words.length; i++) { | ||
in line 137,156,159,167,170,171,178 just replaced the level.words with new variable levelData as we have to do every operation using this concatenated variable. shubhammishra: in line 137,156,159,167,170,171,178 just replaced the level.words with new variable levelData… | |||||
Good, did you make sure it does not breack gletters? It should not but please check. echarruau: Good, did you make sure it does not breack gletters? It should not but please check. | |||||
i test it by playing all falling * activities and even sure with code changes which i have done, is there any more formal way to check? shubhammishra: i test it by playing all falling * activities and even sure with code changes which i have done… | |||||
152 | if(mode ==='letter') { | 152 | if(mode ==='letter') { | ||
153 | // The word is a letter, even if it has several chars (digraph) | 153 | // The word is a letter, even if it has several chars (digraph) | ||
154 | var letter = level.words[i]; | 154 | var letter = level.words[i]; | ||
155 | var isUpper = (letter == letter.toLocaleUpperCase()); | 155 | var isUpper = (letter == letter.toLocaleUpperCase()); | ||
156 | if (isUpper && letters.indexOf(letter.toLocaleLowerCase()) !== -1) | 156 | var isDigit = letter.toLocaleLowerCase() === letter.toLocaleUpperCase() | ||
157 | if (!isDigit && isUpper && letters.indexOf(letter.toLocaleLowerCase()) !== -1) | ||||
echarruau: why is this diff here? | |||||
The previous code is treating all letters like a alphabets, and sometimes enabling shift even for digits. i have just added isDigit variable in if condition to ensure not to enable shift because of digit. counter case here is if levelData=[3,3]. the previous code will enable shift for this array. shubhammishra: The previous code is treating all letters like a alphabets, and sometimes enabling shift even… | |||||
157 | items.keyboard.shiftKey = true; | 158 | items.keyboard.shiftKey = true; | ||
158 | else if (!isUpper && letters.indexOf(letter.toLocaleUpperCase()) !== -1) | 159 | else if (!isDigit && !isUpper && letters.indexOf(letter.toLocaleUpperCase()) !== -1) | ||
159 | items.keyboard.shiftKey = true; | 160 | items.keyboard.shiftKey = true; | ||
160 | else if (letters.indexOf(letter) === -1) | 161 | else if (letters.indexOf(letter) === -1) | ||
161 | letters.push(level.words[i]); | 162 | letters.push(level.words[i]); | ||
162 | } else { | 163 | } else { | ||
163 | // We split each word in char to create the keyboard | 164 | // We split each word in char to create the keyboard | ||
164 | for (var j = 0; j < level.words[i].length; j++) { | 165 | for (var j = 0; j < level.words[i].length; j++) { | ||
165 | var letter = level.words[i].charAt(j); | 166 | var letter = level.words[i].charAt(j); | ||
166 | var isUpper = (letter == letter.toLocaleUpperCase()); | 167 | var isUpper = (letter == letter.toLocaleUpperCase()); | ||
167 | if (isUpper && letters.indexOf(letter.toLocaleLowerCase()) !== -1) | 168 | if (isUpper && letters.indexOf(letter.toLocaleLowerCase()) !== -1) | ||
168 | items.keyboard.shiftKey = true; | 169 | items.keyboard.shiftKey = true; | ||
169 | else if (!isUpper && letters.indexOf(letter.toLocaleUpperCase()) !== -1) | 170 | else if (!isUpper && letters.indexOf(letter.toLocaleUpperCase()) !== -1) | ||
170 | items.keyboard.shiftKey = true; | 171 | items.keyboard.shiftKey = true; | ||
171 | else if (letters.indexOf(letter) === -1) | 172 | else if (letters.indexOf(letter) === -1) | ||
172 | letters.push(level.words[i].charAt(j)); | 173 | letters.push(level.words[i].charAt(j)); | ||
173 | } | 174 | } | ||
174 | } | 175 | } | ||
175 | } | 176 | } | ||
176 | letters = GCompris.ApplicationInfo.localeSort(letters, items.locale); | 177 | letters = GCompris.ApplicationInfo.localeSort(letters, items.locale); | ||
177 | // generate layout from letter map | 178 | // generate layout from letter map | ||
178 | var layout = new Array(); | 179 | var layout = new Array(); | ||
179 | var row = 0; | 180 | var row = 0; | ||
180 | var offset = 0; | 181 | var offset = 0; | ||
181 | while (offset < letters.length-1) { | 182 | while (offset < letters.length) { | ||
182 | var cols = letters.length <= 10 ? letters.length : (Math.ceil((letters.length-offset) / (3 - row))); | 183 | var cols = letters.length <= 10 ? letters.length : (Math.ceil((letters.length-offset) / (3 - row))); | ||
183 | layout[row] = new Array(); | 184 | layout[row] = new Array(); | ||
184 | for (var j = 0; j < cols; j++) | 185 | for (var j = 0; j < cols; j++) | ||
185 | layout[row][j] = { label: letters[j+offset] }; | 186 | layout[row][j] = { label: letters[j+offset] }; | ||
186 | offset += j; | 187 | offset += j; | ||
187 | row++; | 188 | row++; | ||
188 | } | 189 | } | ||
189 | items.keyboard.layout = layout; | 190 | items.keyboard.layout = layout; | ||
190 | } | 191 | } | ||
191 | items.wordlist.initRandomWord(currentLevel + 1) | 192 | items.wordlist.initRandomWord(currentLevel + 1) | ||
in previous code,function initRandomWord(currentLevel + 1) shuffles the items.word, here we have to take care to do every operation with levelData. i checked the defination of this function and generated the random list by shyuffling levelData. shubhammishra: in previous code,function initRandomWord(currentLevel + 1) shuffles the items.word, here we… | |||||
Not sure we need this since you will create our own random list, but here we may have a problem keeping gletters working. echarruau: Not sure we need this since you will create our own random list, but here we may have a problem… | |||||
levelData is already shuffled, and we can't use initRandomWord function for smallumbers2 as it will shuffle level.words, so i can make changes like this? - if(items.ourActivity.activityName !== "smallnumbers2"){ items.wordlist.initRandomWord(currentLevel + 1) else items.wordlist.randomWordList = levelData shubhammishra: levelData is already shuffled, and we can't use initRandomWord function for smallumbers2 as it… | |||||
echarruau: I need to investigate this one furthut is is not clear to me :( | |||||
At the present moment this discussion is not necessary anymore as our current problem will be soved once you will have created your input data array containing the data to give to the user. echarruau: At the present moment this discussion is not necessary anymore as our current problem will be… | |||||
192 | initSubLevel() | 193 | initSubLevel() | ||
193 | } | 194 | } | ||
194 | 195 | | |||
195 | function initSubLevel() { | 196 | function initSubLevel() { | ||
196 | currentWord = null; | 197 | currentWord = null; | ||
197 | if (currentSubLevel != 0) { | 198 | if (currentSubLevel != 0) { | ||
198 | // increase speed | 199 | // increase speed | ||
jjazeix: algorithm | |||||
199 | speed = Math.max(speed - incSpeed, wgMinSpeed); | 200 | speed = Math.max(speed - incSpeed, wgMinSpeed); | ||
jjazeix: separately | |||||
200 | items.wordDropTimer.interval = fallSpeed = Math.max(fallSpeed - incFallSpeed, wgMinFallSpeed); | 201 | items.wordDropTimer.interval = fallSpeed = Math.max(fallSpeed - incFallSpeed, wgMinFallSpeed); | ||
201 | } | 202 | } | ||
202 | items.score.currentSubLevel = currentSubLevel + 1; | 203 | items.score.currentSubLevel = currentSubLevel + 1; | ||
jjazeix: remove useless spaces before/after parenthesis | |||||
203 | if (currentSubLevel == 0 || droppedWords.length <= 1) // note, last word is still fading out | 204 | if (currentSubLevel == 0 || droppedWords.length <= 1) // note, last word is still fading out | ||
204 | dropWord(); | 205 | dropWord(); | ||
jjazeix: for(var i = 0 ...) | |||||
jjazeix: add { } | |||||
205 | //console.log("Gletters: initializing subLevel " + (currentSubLevel + 1) + " words=" + JSON.stringify(level.words)); | 206 | //console.log("Gletters: initializing subLevel " + (currentSubLevel + 1) + " words=" + JSON.stringify(level.words)); | ||
jjazeix: probability | |||||
jjazeix: remove space before ) | |||||
206 | } | 207 | } | ||
207 | 208 | | |||
208 | function processKeyPress(text) { | 209 | function processKeyPress(text) { | ||
209 | var typedText = uppercaseOnly ? text.toLocaleUpperCase() : text; | 210 | var typedText = uppercaseOnly ? text.toLocaleUpperCase() : text; | ||
210 | 211 | | |||
jjazeix: add { } | |||||
211 | if (currentWord !== null) { | 212 | if (currentWord !== null) { | ||
jjazeix: remove space before ) | |||||
212 | // check against a currently typed word | 213 | // check against a currently typed word | ||
213 | if (!currentWord.checkMatch(typedText)) { | 214 | if (!currentWord.checkMatch(typedText)) { | ||
214 | currentWord = null; | 215 | currentWord = null; | ||
jjazeix: an element | |||||
215 | audioCrashPlay() | 216 | audioCrashPlay() | ||
jjazeix: indentation | |||||
216 | } else { | 217 | } else { | ||
217 | playLetter(text) | 218 | playLetter(text) | ||
218 | } | 219 | } | ||
219 | } else { | 220 | } else { | ||
220 | // no current word, check against all available words | 221 | // no current word, check against all available words | ||
221 | var found = false | 222 | var found = false | ||
222 | for (var i = 0; i< droppedWords.length; i++) { | 223 | for (var i = 0; i< droppedWords.length; i++) { | ||
223 | if (droppedWords[i].checkMatch(typedText)) { | 224 | if (droppedWords[i].checkMatch(typedText)) { | ||
224 | // typed correctly | 225 | // typed correctly | ||
jjazeix: remove space before ) | |||||
225 | currentWord = droppedWords[i]; | 226 | currentWord = droppedWords[i]; | ||
226 | playLetter(text) | 227 | playLetter(text) | ||
227 | found = true | 228 | found = true | ||
228 | break; | 229 | break; | ||
229 | } | 230 | } | ||
230 | } | 231 | } | ||
231 | if(!found) { | 232 | if(!found) { | ||
232 | audioCrashPlay() | 233 | audioCrashPlay() | ||
▲ Show 20 Lines • Show All 192 Lines • Show Last 20 Lines |
as seen in our discussion you do not need this value