Changeset View
Standalone View
src/activities/calendar/calendar.js
Show All 35 Lines | |||||
36 | var monthSelected = 2 | 36 | var monthSelected = 2 | ||
37 | var yearSelected = 2018 | 37 | var yearSelected = 2018 | ||
38 | var dayOfWeekSelected | 38 | var dayOfWeekSelected | ||
39 | var minRange //sum of min. visible month and year on calendar for navigation bar next/prev button visibility. | 39 | var minRange //sum of min. visible month and year on calendar for navigation bar next/prev button visibility. | ||
40 | var maxRange //sum of max. visible month and year on calendar for navigation bar next/prev button visibility. | 40 | var maxRange //sum of max. visible month and year on calendar for navigation bar next/prev button visibility. | ||
41 | var correctAnswer | 41 | var correctAnswer | ||
42 | var mode | 42 | var mode | ||
43 | 43 | | |||
44 | function start(items_, dataset_) { | 44 | function start(items_) { | ||
45 | items = items_ | 45 | items = items_ | ||
46 | dataset = dataset_.get() | 46 | numberOfLevel = items.levels.length | ||
47 | numberOfLevel = dataset.length | | |||
48 | currentLevel = 0 | 47 | currentLevel = 0 | ||
49 | 48 | | |||
50 | if(Qt.locale(GCompris.ApplicationSettings.locale).firstDayOfWeek == Qml.Locale.Monday) { | 49 | if(Qt.locale(GCompris.ApplicationSettings.locale).firstDayOfWeek == Qml.Locale.Monday) { | ||
51 | items.daysOfTheWeekModel.move(0, items.daysOfTheWeekModel.count - 1, 1) | 50 | items.daysOfTheWeekModel.move(0, items.daysOfTheWeekModel.count - 1, 1) | ||
52 | } | 51 | } | ||
53 | initLevel(); | 52 | initLevel(); | ||
54 | } | 53 | } | ||
55 | 54 | | |||
56 | function stop() { | 55 | function stop() { | ||
57 | } | 56 | } | ||
58 | 57 | | |||
59 | function initLevel() { | 58 | function initLevel() { | ||
60 | currentSubLevel = 1; | 59 | currentSubLevel = 1; | ||
61 | items.bar.level = currentLevel + 1 | 60 | items.bar.level = currentLevel + 1 | ||
62 | currentLevelConfig = dataset[currentLevel][0][0] | 61 | currentLevelConfig = items.levels[currentLevel] | ||
63 | setCalendarConfigurations() | 62 | setCalendarConfigurations() | ||
64 | initQuestion(); | 63 | initQuestion(); | ||
65 | } | 64 | } | ||
66 | 65 | | |||
67 | function nextLevel() { | 66 | function nextLevel() { | ||
68 | if(numberOfLevel <= ++currentLevel) { | 67 | if(numberOfLevel <= ++currentLevel) { | ||
69 | currentLevel = 0 | 68 | currentLevel = 0 | ||
70 | } | 69 | } | ||
Show All 16 Lines | 81 | function setCalendarConfigurations() { | |||
87 | items.calendar.minimumDate = currentLevelConfig["minimumDate"] | 86 | items.calendar.minimumDate = currentLevelConfig["minimumDate"] | ||
88 | items.calendar.maximumDate = currentLevelConfig["maximumDate"] | 87 | items.calendar.maximumDate = currentLevelConfig["maximumDate"] | ||
89 | items.calendar.visibleYear = currentLevelConfig["visibleYear"] | 88 | items.calendar.visibleYear = currentLevelConfig["visibleYear"] | ||
90 | yearSelected = currentLevelConfig["visibleYear"] | 89 | yearSelected = currentLevelConfig["visibleYear"] | ||
91 | items.calendar.visibleMonth = currentLevelConfig["visibleMonth"] | 90 | items.calendar.visibleMonth = currentLevelConfig["visibleMonth"] | ||
92 | monthSelected = currentLevelConfig["visibleMonth"] | 91 | monthSelected = currentLevelConfig["visibleMonth"] | ||
93 | items.answerChoices.visible = (mode === "findDayOfWeek") ? true : false | 92 | items.answerChoices.visible = (mode === "findDayOfWeek") ? true : false | ||
94 | items.okButton.visible = !items.answerChoices.visible | 93 | items.okButton.visible = !items.answerChoices.visible | ||
95 | currentDataSet = dataset[currentLevel][1] | 94 | currentDataSet = currentLevelConfig["questionAnswers"] | ||
96 | currentDataSet = Core.shuffle(currentDataSet) | 95 | currentDataSet = Core.shuffle(currentDataSet) | ||
97 | items.score.numberOfSubLevels = currentDataSet.length | 96 | items.score.numberOfSubLevels = currentDataSet.length | ||
98 | items.score.currentSubLevel = currentSubLevel | 97 | items.score.currentSubLevel = currentSubLevel | ||
99 | } | 98 | } | ||
100 | 99 | | |||
100 | function isLeapYear(year) { | ||||
101 | if(year % 100 == 0 && year % 400 != 0) { | ||||
102 | return false | ||||
103 | } else if(year % 4 == 0) { | ||||
104 | return true | ||||
105 | } else { | ||||
106 | return false | ||||
107 | } | ||||
108 | } | ||||
109 | | ||||
110 | function generateRandomYearMonthDay(minimumDate, maximumDate) { | ||||
111 | var daysInMonths = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] | ||||
jjazeix: qsTr() missing | |||||
scagarwal: Do maintain spaces between elements in an array. The formatting is wrong. | |||||
112 | var minYear = Number(minimumDate.slice(0, 4)) | ||||
amankumargupta: Indentation | |||||
113 | var maxYear = Number(maximumDate.slice(0, 4)) | ||||
this should be depending on the country. We may want to display month day year on some locales, it needs to be configurable for the translator (and have a comment) jjazeix: this should be depending on the country. We may want to display month day year on some locales… | |||||
114 | var minMonth = Number(minimumDate.slice(5, 7)) | ||||
115 | var maxMonth = Number(maximumDate.slice(5, 7)) | ||||
116 | var minDate = Number(minimumDate.slice(8, 10)) | ||||
117 | var maxDate = Number(maximumDate.slice(8, 10)) | ||||
118 | var currentYear = minYear + Math.floor(Math.random() * Math.floor((maxYear - minYear))) | ||||
119 | var currentMonth = minMonth + Math.floor(Math.random() * Math.floor((maxMonth - minMonth))) | ||||
120 | var currentDate | ||||
121 | daysInMonths[1] = (isLeapYear(currentYear)) ? 29 : 28; | ||||
122 | currentDate = minDate + Math.floor(Math.random() * Math.floor((daysInMonths[currentMonth - 1] - minMonth))) | ||||
123 | var maxOffset = (maxDate - minDate) + (maxMonth - minMonth) * 28 + (maxYear - minYear) * 365 | ||||
124 | var offset = 1 + Math.floor(Math.random() * Math.floor(maxOffset)) | ||||
Shouldn't Math.floor((maxMonth - minMonth)) be Math.floor(maxMonth - minMonth + 1)? Let's say minMonth is 3 and maxMonth is 5. I should get any random among 0, 1, 2 so that minMonth + Math.floor(Math.random() * Math.floor((maxMonth - minMonth))) can be anything between 3, 4, 5. But, Math.floor(Math.random() * Math.floor((maxMonth - minMonth))) limits the values among 0, 1 (as minMonth - maxMonth = 2 in our case). So you should probably do maxMonth - minMonth + 1? amankumargupta: Shouldn't Math.floor((maxMonth - minMonth)) be Math.floor(maxMonth - minMonth + 1)?
Let's say… | |||||
125 | var currentOffset = offset; | ||||
126 | currentOffset += currentDate | ||||
127 | var answerDate = 1; | ||||
amankumargupta: Same comment about choosing random value as above. | |||||
128 | var answerMonth = currentMonth | ||||
129 | var answerYear = currentYear | ||||
130 | while(currentOffset > 0) { | ||||
131 | if(currentOffset - daysInMonths[answerMonth - 1] > 0) { | ||||
132 | currentOffset -= daysInMonths[answerMonth - 1] | ||||
133 | answerMonth++; | ||||
134 | } else { | ||||
135 | answerDate = currentOffset; | ||||
Why a new variable "currentOffset"? Why not directly use "offset"? It's not used anywhere in this function. amankumargupta: Why a new variable "currentOffset"? Why not directly use "offset"? It's not used anywhere in… | |||||
136 | currentOffset = 0 | ||||
137 | } | ||||
138 | if(answerMonth > 12) { | ||||
139 | answerYear++; | ||||
140 | answerMonth = 1; | ||||
141 | } | ||||
142 | } | ||||
143 | | ||||
144 | var question = "Find the date " + offset.toString() + "days after " + currentYear.toString() + "-" + | ||||
145 | currentMonth.toString() + "-" + currentDate.toString(); | ||||
146 | return { year: answerYear, month: answerMonth - 1, day: answerDate, offset: offset } | ||||
147 | } | ||||
148 | | ||||
149 | function getTemplateQuestionText(mode, date) { | ||||
150 | var questionText | ||||
151 | if(mode == "findDayOfWeek") { | ||||
152 | questionText = "Find the Week Day on " + date.day.toString() | ||||
153 | } else if(mode == "findDay") { | ||||
154 | questionText = "Select Day " + date.day.toString() | ||||
155 | } else if(mode == "findMonthOnly") { | ||||
156 | questionText = "Find the month" + date.month.toString() | ||||
157 | } else { | ||||
158 | "Find the date " + date.offset.toString() + "days after " + date.year.toString() + "-" + | ||||
159 | date.month.toString() + "-" + date.day.toString(); | ||||
jjazeix: no space before ? | |||||
160 | } | ||||
qsTr() + bad format jjazeix: qsTr() + bad format
Can you please check if the format is the same if we change locale? | |||||
@jjazeix When I change the locale only the names of months and years change, not the question text. As we used hardcoded strings for questions. AkshayCHD: @jjazeix When I change the locale only the names of months and years change, not the question… | |||||
161 | return questionText | ||||
162 | } | ||||
163 | | ||||
101 | function initQuestion() { | 164 | function initQuestion() { | ||
102 | if(currentDataSet.length < currentSubLevel) { | 165 | if(currentDataSet.length < currentSubLevel) { | ||
103 | items.bonus.good("lion") | 166 | items.bonus.good("lion") | ||
104 | } | 167 | } | ||
Please add translators comment above explaining what the arguments will be. It'll be easier for them to understand while translating. amankumargupta: Please add translators comment above explaining what the arguments will be. It'll be easier for… | |||||
105 | else { | 168 | else { | ||
169 | if(!currentLevelConfig.questionsExplicitlyGiven) { | ||||
170 | var randomDate = generateRandomYearMonthDay(currentLevelConfig.minimumDate, currentLevelConfig.maximumDate) | ||||
171 | items.score.currentSubLevel = currentSubLevel | ||||
172 | if(currentLevelConfig.mode == "findDayOfWeek") { | ||||
173 | var selectedDate = new Date(randomDate.year, randomDate.month - 1, randomDate.day) | ||||
174 | correctAnswer.dayOfWeek = Number(selectedDate.getDay()) | ||||
175 | } else { | ||||
176 | correctAnswer = randomDate | ||||
177 | } | ||||
178 | items.questionItem.text = getTemplateQuestionText(currentLevelConfig.mode, randomDate) | ||||
179 | } else { | ||||
106 | items.score.currentSubLevel = currentSubLevel | 180 | items.score.currentSubLevel = currentSubLevel | ||
107 | items.questionItem.text = currentDataSet[currentSubLevel-1]["question"] | 181 | items.questionItem.text = currentDataSet[currentSubLevel-1]["question"] | ||
108 | correctAnswer = currentDataSet[currentSubLevel-1]["answer"] | 182 | correctAnswer = currentDataSet[currentSubLevel-1]["answer"] | ||
109 | } | 183 | } | ||
110 | } | 184 | } | ||
185 | } | ||||
111 | 186 | | |||
112 | function updateScore(isCorrectAnswer) { | 187 | function updateScore(isCorrectAnswer) { | ||
113 | if(isCorrectAnswer) { | 188 | if(isCorrectAnswer) { | ||
114 | items.questionDelay.start() | 189 | items.questionDelay.start() | ||
115 | items.okButtonParticles.burst(20) | 190 | items.okButtonParticles.burst(20) | ||
116 | items.score.playWinAnimation() | 191 | items.score.playWinAnimation() | ||
117 | currentSubLevel++; | 192 | currentSubLevel++; | ||
118 | } | 193 | } | ||
Show All 10 Lines | 201 | if(mode === "findDayOfWeek") { | |||
129 | } | 204 | } | ||
130 | } | 205 | } | ||
131 | // For levels having question based on month only. | 206 | // For levels having question based on month only. | ||
132 | else if(mode === "findMonthOnly") { | 207 | else if(mode === "findMonthOnly") { | ||
133 | if(correctAnswer["month"].indexOf(monthSelected) >= 0) { | 208 | if(correctAnswer["month"].indexOf(monthSelected) >= 0) { | ||
134 | isCorrectAnswer = true | 209 | isCorrectAnswer = true | ||
135 | } | 210 | } | ||
136 | } | 211 | } | ||
212 | // For levels having question based on day only. | ||||
213 | else if(mode === "findDay") { | ||||
214 | if(daySelected === correctAnswer["day"]) { | ||||
215 | isCorrectAnswer = true | ||||
216 | } | ||||
217 | } | ||||
137 | // For levels having questions based on dayOfWeek, month and year. | 218 | // For levels having questions based on dayOfWeek, month and year. | ||
138 | else if(mode !== "findDayOfWeek") { | 219 | else { | ||
139 | if(monthSelected === correctAnswer["month"] && daySelected === correctAnswer["day"] && yearSelected === correctAnswer["year"]) { | 220 | if(monthSelected === correctAnswer["month"] && daySelected === correctAnswer["day"] && yearSelected === correctAnswer["year"]) { | ||
140 | isCorrectAnswer = true | 221 | isCorrectAnswer = true | ||
141 | } | 222 | } | ||
142 | } | 223 | } | ||
143 | updateScore(isCorrectAnswer) | 224 | updateScore(isCorrectAnswer) | ||
144 | } | 225 | } | ||
145 | 226 | |
qsTr() missing