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; // store number of falling elements for each level | ||
37 | var items; | 37 | var items; | ||
38 | var uppercaseOnly; | 38 | var uppercaseOnly; | ||
39 | var mode; | 39 | var mode; | ||
40 | 40 | var levelData; // array to store levelwords | |||
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 | ||
44 | var incFallSpeed = 1000; // how much drop rate increases per sublevel | 44 | var incFallSpeed = 1000; // how much drop rate increases per sublevel | ||
45 | var incSpeed = 10; // how much speed increases per sublevel | 45 | var incSpeed = 10; // how much speed increases per sublevel | ||
46 | // gletters: | 46 | // gletters: | ||
47 | var fallRateBase = 40; // default for how fast letters fall (smaller is faster) | 47 | var fallRateBase = 40; // default for how fast letters fall (smaller is faster) | ||
48 | var fallRateMult = 80; // default for how much falling speed increases per level (smaller is faster) | 48 | var fallRateMult = 80; // default for how much falling speed increases per level (smaller is faster) | ||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Line(s) | 117 | function initLevel() { | |||
120 | items.audioVoices.clearQueue() | 120 | items.audioVoices.clearQueue() | ||
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 | /* for smallnumbers2, maxSubLevel will take value of sublevels attribute from json which represent number of | ||||
129 | falling elements in each level and for other activities it will be 0 here.*/ | ||||
128 | maxSubLevel = items.wordlist.getMaxSubLevel(currentLevel + 1); | 130 | maxSubLevel = items.wordlist.getMaxSubLevel(currentLevel + 1); | ||
131 | levelData = new Array(); | ||||
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. | |||||
132 | | ||||
133 | // for smallnumbers2 and smallnumbers activities levelData will contain random data, while for other activity it contains same data as level.words | ||||
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… | |||||
134 | if(items.ourActivity.useDataset === true) | ||||
shubhammishra: this will restrict the number of dominoes in each level to 15. | |||||
echarruau: See previous comment. | |||||
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… | |||||
135 | setLevelData(); | ||||
136 | else | ||||
137 | levelData = level.words | ||||
129 | 138 | | |||
130 | if (maxSubLevel == 0) { | 139 | if (maxSubLevel == 0) { | ||
131 | // If "sublevels" length is not set in wordlist, use the words length | 140 | // If "sublevels" length is not set in wordlist, use the words length | ||
132 | maxSubLevel = level.words.length | 141 | maxSubLevel = levelData.length | ||
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… | |||||
133 | } | 142 | } | ||
134 | items.score.numberOfSubLevels = maxSubLevel; | 143 | items.score.numberOfSubLevels = maxSubLevel; | ||
135 | setSpeed(); | 144 | setSpeed(); | ||
136 | /*console.log("Gletters: initializing level " + (currentLevel + 1) | 145 | /*console.log("Gletters: initializing level " + (currentLevel + 1) | ||
137 | + " maxSubLvl=" + maxSubLevel | 146 | + " maxSubLvl=" + maxSubLevel | ||
138 | + " wordCount=" + level.words.length | 147 | + " wordCount=" + level.words.length | ||
139 | + " speed=" + speed + " fallspeed=" + fallSpeed);*/ | 148 | + " speed=" + speed + " fallspeed=" + fallSpeed);*/ | ||
140 | 149 | | |||
141 | { | 150 | { | ||
142 | /* populate VirtualKeyboard for mobile: | 151 | /* populate VirtualKeyboard for mobile: | ||
143 | * 1. for < 10 letters print them all in the same row | 152 | * 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 | 153 | * 2. for > 10 letters create 3 rows with equal amount of keys per row | ||
145 | * if possible, otherwise more keys in the upper rows | 154 | * if possible, otherwise more keys in the upper rows | ||
146 | * 3. if we have both upper- and lowercase letters activate the shift | 155 | * 3. if we have both upper- and lowercase letters activate the shift | ||
147 | * key*/ | 156 | * key*/ | ||
148 | // first generate a map of needed letters | 157 | // first generate a map of needed letters | ||
149 | var letters = new Array(); | 158 | var letters = new Array(); | ||
150 | items.keyboard.shiftKey = false; | 159 | items.keyboard.shiftKey = false; | ||
151 | for (var i = 0; i < level.words.length; i++) { | 160 | for (var i = 0; i < levelData.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') { | 161 | if(mode ==='letter') { | ||
153 | // The word is a letter, even if it has several chars (digraph) | 162 | // The word is a letter, even if it has several chars (digraph) | ||
154 | var letter = level.words[i]; | 163 | var letter = levelData[i]; | ||
155 | var isUpper = (letter == letter.toLocaleUpperCase()); | 164 | var isUpper = (letter == letter.toLocaleUpperCase()); | ||
156 | if (isUpper && letters.indexOf(letter.toLocaleLowerCase()) !== -1) | 165 | var isDigit = letter.toLocaleLowerCase() === letter.toLocaleUpperCase() | ||
166 | 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; | 167 | items.keyboard.shiftKey = true; | ||
158 | else if (!isUpper && letters.indexOf(letter.toLocaleUpperCase()) !== -1) | 168 | else if (!isDigit && !isUpper && letters.indexOf(letter.toLocaleUpperCase()) !== -1) | ||
159 | items.keyboard.shiftKey = true; | 169 | items.keyboard.shiftKey = true; | ||
160 | else if (letters.indexOf(letter) === -1) | 170 | else if (letters.indexOf(letter) === -1) | ||
161 | letters.push(level.words[i]); | 171 | letters.push(levelData[i]); | ||
162 | } else { | 172 | } else { | ||
163 | // We split each word in char to create the keyboard | 173 | // We split each word in char to create the keyboard | ||
164 | for (var j = 0; j < level.words[i].length; j++) { | 174 | for (var j = 0; j < levelData[i].length; j++) { | ||
165 | var letter = level.words[i].charAt(j); | 175 | var letter = levelData[i].charAt(j); | ||
166 | var isUpper = (letter == letter.toLocaleUpperCase()); | 176 | var isUpper = (letter == letter.toLocaleUpperCase()); | ||
167 | if (isUpper && letters.indexOf(letter.toLocaleLowerCase()) !== -1) | 177 | if (isUpper && letters.indexOf(letter.toLocaleLowerCase()) !== -1) | ||
168 | items.keyboard.shiftKey = true; | 178 | items.keyboard.shiftKey = true; | ||
169 | else if (!isUpper && letters.indexOf(letter.toLocaleUpperCase()) !== -1) | 179 | else if (!isUpper && letters.indexOf(letter.toLocaleUpperCase()) !== -1) | ||
170 | items.keyboard.shiftKey = true; | 180 | items.keyboard.shiftKey = true; | ||
171 | else if (letters.indexOf(letter) === -1) | 181 | else if (letters.indexOf(letter) === -1) | ||
172 | letters.push(level.words[i].charAt(j)); | 182 | letters.push(levelData[i].charAt(j)); | ||
173 | } | 183 | } | ||
174 | } | 184 | } | ||
175 | } | 185 | } | ||
176 | letters = GCompris.ApplicationInfo.localeSort(letters, items.locale); | 186 | letters = GCompris.ApplicationInfo.localeSort(letters, items.locale); | ||
177 | // generate layout from letter map | 187 | // generate layout from letter map | ||
178 | var layout = new Array(); | 188 | var layout = new Array(); | ||
179 | var row = 0; | 189 | var row = 0; | ||
180 | var offset = 0; | 190 | var offset = 0; | ||
181 | while (offset < letters.length-1) { | 191 | while (offset < letters.length) { | ||
182 | var cols = letters.length <= 10 ? letters.length : (Math.ceil((letters.length-offset) / (3 - row))); | 192 | var cols = letters.length <= 10 ? letters.length : (Math.ceil((letters.length-offset) / (3 - row))); | ||
183 | layout[row] = new Array(); | 193 | layout[row] = new Array(); | ||
184 | for (var j = 0; j < cols; j++) | 194 | for (var j = 0; j < cols; j++) | ||
185 | layout[row][j] = { label: letters[j+offset] }; | 195 | layout[row][j] = { label: letters[j+offset] }; | ||
186 | offset += j; | 196 | offset += j; | ||
187 | row++; | 197 | row++; | ||
188 | } | 198 | } | ||
189 | items.keyboard.layout = layout; | 199 | items.keyboard.layout = layout; | ||
190 | } | 200 | } | ||
201 | if(items.ourActivity.useDataset === true) | ||||
202 | items.wordlist.randomWordList = levelData | ||||
203 | else | ||||
191 | items.wordlist.initRandomWord(currentLevel + 1) | 204 | 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() | 205 | initSubLevel() | ||
193 | } | 206 | } | ||
194 | 207 | | |||
208 | // function to create array of random data | ||||
209 | function setLevelData() { | ||||
210 | | ||||
211 | /* algorithm will add 50% of previous level elements to levelData and 50% times new 2 elements but we can't use | ||||
jjazeix: algorithm | |||||
212 | this for data size of 2 and 3 so handling them separately */ | ||||
jjazeix: separately | |||||
213 | if(level.words.length === 2){ | ||||
214 | for(var i = 0; i < maxSubLevel; i++) | ||||
215 | levelData.push(addNewElement()) | ||||
jjazeix: remove useless spaces before/after parenthesis | |||||
216 | } else if(level.words.length === 3) { | ||||
217 | for(var i = 0; i < maxSubLevel; i++) { | ||||
jjazeix: for(var i = 0 ...) | |||||
jjazeix: add { } | |||||
218 | if(Math.floor(Math.random() * 5) < 1) // adds previous element with probability of 1/5 and rest two with 2/5 | ||||
jjazeix: probability | |||||
jjazeix: remove space before ) | |||||
219 | levelData.push(level.words[1]); | ||||
220 | else | ||||
221 | levelData.push(addNewElement()) | ||||
222 | } | ||||
223 | } else { | ||||
jjazeix: add { } | |||||
224 | for(var i = 0; i < maxSubLevel; i++) { | ||||
jjazeix: remove space before ) | |||||
225 | if(Math.floor(Math.random() * 2) == 0) | ||||
226 | levelData.push(addNewElement()) | ||||
227 | else { | ||||
jjazeix: an element | |||||
228 | // generate a random index for an element (excluding first and last element) to be added in levelData | ||||
jjazeix: indentation | |||||
229 | var index = Math.floor(Math.random() * (level.words.length - 2)) +1; | ||||
230 | levelData.push(level.words[index]) | ||||
231 | } | ||||
232 | } | ||||
233 | } | ||||
234 | } | ||||
235 | | ||||
236 | // function will return any one of new number which we aim to teach in this level | ||||
237 | function addNewElement() { | ||||
jjazeix: remove space before ) | |||||
238 | // if generated random number is 0, it will return first element otherwise last | ||||
239 | if(Math.floor(Math.random()*2) === 0) | ||||
240 | return level.words[0]; | ||||
241 | else | ||||
242 | return level.words[level.words.length-1]; | ||||
243 | } | ||||
244 | | ||||
195 | function initSubLevel() { | 245 | function initSubLevel() { | ||
196 | currentWord = null; | 246 | currentWord = null; | ||
197 | if (currentSubLevel != 0) { | 247 | if (currentSubLevel != 0) { | ||
198 | // increase speed | 248 | // increase speed | ||
199 | speed = Math.max(speed - incSpeed, wgMinSpeed); | 249 | speed = Math.max(speed - incSpeed, wgMinSpeed); | ||
200 | items.wordDropTimer.interval = fallSpeed = Math.max(fallSpeed - incFallSpeed, wgMinFallSpeed); | 250 | items.wordDropTimer.interval = fallSpeed = Math.max(fallSpeed - incFallSpeed, wgMinFallSpeed); | ||
201 | } | 251 | } | ||
202 | items.score.currentSubLevel = currentSubLevel + 1; | 252 | items.score.currentSubLevel = currentSubLevel + 1; | ||
▲ Show 20 Lines • Show All 222 Lines • Show Last 20 Lines |
as seen in our discussion you do not need this value