Skip to content

Commit fbd07ea

Browse files
author
llaske
committed
Fix glitch on iOS when restarting Abecedarium
1 parent 266617b commit fbd07ea

File tree

1 file changed

+57
-55
lines changed
  • activities/Abecedarium.activity

1 file changed

+57
-55
lines changed

activities/Abecedarium.activity/play.js

Lines changed: 57 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@ enyo.kind({
1111
classes: "board",
1212
published: {
1313
context: null,
14-
},
14+
},
1515
components: [
1616
{kind: "Signals", onEndOfSound: "endSound"},
1717
{components: [
18-
{name: "colorBar", classes: "colorBar"},
18+
{name: "colorBar", classes: "colorBar"},
1919
{name: "home", kind: "Abcd.HomeButton"},
2020
{kind: "Abcd.CaseButton"},
2121
{kind: "Abcd.LanguageButton"}
2222
]},
2323
{components: [
2424
{name: "filterLetter", kind: "Abcd.Letter", letter: "", classes: "filterLetter"},
2525
{name: "filterCollection", kind: "Abcd.Collection", index: 0, classes: "filterCollection", showing: false},
26-
{name: "itemCount", content: "-/-", classes: "itemCount", showing: false},
26+
{name: "itemCount", content: "-/-", classes: "itemCount", showing: false},
2727
{name: "back", kind: "Image", src: "images/back.png", showing: false, classes: "standardButton backButton", ontap: "backTaped"},
2828
{name: "filter", kind: "Image", src: "images/filter.png", showing: false, classes: "standardButton filterButton", ontap: "filterTaped"},
2929
{name: "check", kind: "Image", src: "images/check.png", showing: false, classes: "standardButton checkButton", ontap: "checkTaped"},
30-
{name: "gameFinished", kind: "Control", showing: false, classes: "gameFinished",
30+
{name: "gameFinished", kind: "Control", showing: false, classes: "gameFinished",
3131
components: [
3232
{
3333
name: "gameFinishedMsg",
@@ -40,12 +40,12 @@ enyo.kind({
4040
]}
4141
]
4242
}
43-
]},
43+
]},
4444
{name: "box", classes: "playbox", components: [
4545
]},
4646
{name: "filterPopup", kind: "Abcd.FilterPopup", onFilterChanged: "filterChanged"}
4747
],
48-
48+
4949
// Constructor
5050
create: function() {
5151
this.inherited(arguments);
@@ -57,19 +57,19 @@ enyo.kind({
5757
this.selected = null;
5858
this.forbidentry = false;
5959
this.filter = null;
60-
60+
6161
this.restoreContext();
6262
this.filterChanged({filter: this.filter});
6363
if (this.theme != -1)
6464
this.doGame(this.themeButton);
6565
else
6666
this.displayButtons();
67-
67+
6868
if (this.gamecount === entriesByGame){
6969
this.showGameFinished();
7070
}
7171
},
72-
72+
7373
// Context handling
7474
restoreContext: function() {
7575
if (this.context == null || this.context == "")
@@ -81,7 +81,7 @@ enyo.kind({
8181
if (values[4] != "")
8282
this.filter = { kind: values[4], index: values[5], letter: values[5] };
8383
},
84-
84+
8585
saveContext: function() {
8686
var values = [];
8787
values.push(this.theme);
@@ -102,18 +102,18 @@ enyo.kind({
102102
}
103103
return values.join("|");
104104
},
105-
105+
106106
// Delete all the box content
107107
cleanBox: function() {
108108
var items = [];
109109
enyo.forEach(this.$.box.getControls(), function(item) {
110110
items.push(item);
111-
});
111+
});
112112
for (var i = 0 ; i < items.length ; i++) {
113113
items[i].destroy();
114-
}
114+
}
115115
},
116-
116+
117117
// Display game choice buttons
118118
displayButtons: function() {
119119
this.cleanBox();
@@ -123,7 +123,7 @@ enyo.kind({
123123
this.$.colorBar.addClass("themeColor"+this.theme);
124124
if (this.filter == null)
125125
this.$.filterLetter.hide();
126-
126+
127127
// Draw From picture buttons
128128
this.$.box.createComponent(
129129
{kind: "Abcd.PlayTypeButton", from: "picture", to: "letter"+Abcd.context.casevalue, ontap: "doGame", theme: "play-button-color1"},
@@ -133,7 +133,7 @@ enyo.kind({
133133
{kind: "Abcd.PlayTypeButton", from: "picture", to: "listen", ontap: "doGame", theme: "play-button-color1"},
134134
{owner: this}
135135
).render();
136-
136+
137137
// Draw From letter buttons
138138
this.$.box.createComponent(
139139
{kind: "Abcd.PlayTypeButton", from: "letter"+Abcd.context.casevalue, to: "picture", ontap: "doGame", theme: "play-button-color2"},
@@ -152,32 +152,32 @@ enyo.kind({
152152
this.$.box.createComponent(
153153
{ kind: "Abcd.PlayTypeButton", from: "listen", to: "letter"+Abcd.context.casevalue, ontap: "doGame", theme: "play-button-color3" },
154154
{ owner: this }
155-
).render();
155+
).render();
156156
},
157-
157+
158158
// Localization changed
159159
setLocale: function() {
160160
// Remove filter because too risky
161161
this.filter = null;
162-
this.$.filterLetter.hide();
163-
this.$.filterCollection.hide();
164-
162+
this.$.filterLetter.hide();
163+
this.$.filterCollection.hide();
164+
165165
// If playing, change game because could inexist in the current language
166166
if (this.theme != -1)
167167
this.computeGame();
168-
168+
169169
},
170-
170+
171171
// Case changed
172172
setCase: function() {
173173
// Redraw button
174174
enyo.forEach(this.$.box.getControls(), function(item) {
175175
if (item.kind == 'Abcd.Entry')
176176
item.indexChanged();
177177
else
178-
item.setCase();
178+
item.setCase();
179179
});
180-
180+
181181
// Redraw filter letter and filter popup
182182
if (this.filter != null) {
183183
if (this.filter.kind == "Abcd.Letter")
@@ -186,28 +186,28 @@ enyo.kind({
186186
this.$.filterCollection.indexChanged();
187187
}
188188
},
189-
189+
190190
// Display filter dialog
191191
filterTaped: function() {
192192
this.$.filterPopup.display(this.filter);
193193
},
194-
194+
195195
// Process filter change
196196
filterChanged: function(s, e) {
197197
this.filter = s.filter;
198198
this.$.filterLetter.hide();
199-
this.$.filterCollection.hide();
199+
this.$.filterCollection.hide();
200200
if (this.filter != null) {
201201
if (this.filter.kind == "Abcd.Letter") {
202202
this.$.filterLetter.show();
203203
this.$.filterLetter.setLetter(this.filter.letter);
204204
} else {
205205
this.$.filterCollection.show();
206-
this.$.filterCollection.setIndex(this.filter.index);
206+
this.$.filterCollection.setIndex(this.filter.index);
207207
}
208208
}
209209
},
210-
210+
211211
// Convert value to entry option
212212
convertToEntryOption: function(value) {
213213
return {
@@ -216,9 +216,9 @@ enyo.kind({
216216
textonly: value.substr(0, 6) == "letter"
217217
};
218218
},
219-
219+
220220
// Start game
221-
doGame: function(button, event) {
221+
doGame: function(button, event) {
222222
// Redraw bar
223223
Abcd.changeVisibility(this, {home: false, back: true, filter: false, check: true, itemCount: true});
224224
this.themeButton = button;
@@ -227,32 +227,32 @@ enyo.kind({
227227
else this.theme = 6;
228228
this.$.colorBar.removeClass("themeColor-1");
229229
this.$.colorBar.addClass("themeColor"+this.theme);
230-
230+
231231
// Compute game
232232
this.computeGame();
233233
},
234-
234+
235235
// Compute game
236236
computeGame: function() {
237237
// Compute card to find
238238
this.cleanBox();
239239
this.forbidentry = false;
240240
this.$.itemCount.setContent((this.gamecount+1)+"/"+entriesByGame);
241241
var tofind = Abcd.randomEntryIndex(undefined, this.filter);
242-
var options = this.convertToEntryOption(this.themeButton.from);
242+
var options = this.convertToEntryOption(this.themeButton.from);
243243
var fromEntry = this.from = this.$.box.createComponent(
244244
{kind: "Abcd.Entry", index:tofind, soundonly: options["soundonly"], imageonly: options["imageonly"], textonly: options["textonly"], ontap: "entryTaped"},
245245
{owner: this}
246246
);
247247
fromEntry.addClass("entryPlayFrom");
248248
fromEntry.render();
249-
249+
250250
// Play from card if its a sound
251251
if (options["soundonly"]) {
252252
this.playing = fromEntry;
253-
this.playing.play(Abcd.sound);
253+
this.playing.play(Abcd.sound);
254254
}
255-
255+
256256
// Compute cards to choose
257257
var excludes = [];
258258
excludes.push(tofind);
@@ -261,7 +261,7 @@ enyo.kind({
261261
excludes.push(wrong);
262262
}
263263
excludes = Abcd.mix(excludes);
264-
264+
265265
// Draw cards
266266
var len = excludes.length;
267267
for (var i = 0 ; i < len ; i++) {
@@ -273,29 +273,29 @@ enyo.kind({
273273
toEntry.addClass("entryPlayTo");
274274
toEntry.render();
275275
}
276-
276+
277277
// Save context
278-
Abcd.saveContext();
278+
Abcd.saveContext();
279279
},
280-
280+
281281
// Entry taped play sound and/or select entry
282282
entryTaped: function(entry, event) {
283283
// No selection now
284284
if (this.forbidentry)
285285
return;
286-
286+
287287
// Play sound
288288
if (entry.soundonly) {
289289
if (this.playing != null)
290290
this.playing.abort();
291291
this.playing = entry;
292292
this.playing.play(Abcd.sound);
293293
}
294-
294+
295295
// Don't select the from entry
296296
if (entry.hasClass("entryPlayFrom"))
297297
return;
298-
298+
299299
// Select the entry
300300
if (!entry.hasClass("entryPlaySelected")) {
301301
if (this.selected != null)
@@ -310,6 +310,8 @@ enyo.kind({
310310
Abcd.changeVisibility(this, {home: false, back: false, filter: false, check: false, itemCount: false});
311311
Abcd.hideLang();
312312
this.$.caseButton.hide();
313+
this.$.colorBar.removeClass("themeColor"+this.theme);
314+
this.$.colorBar.addClass("themeColor-1");
313315
var playMode = this;
314316
requirejs(["webL10n"], function(webL10n) {
315317
playMode.$.gameFinishedMsg.setContent(webL10n.get("GameFinised"));
@@ -322,7 +324,7 @@ enyo.kind({
322324
Abcd.showLang();
323325
this.$.caseButton.show();
324326
},
325-
327+
326328
replayTaped: function() {
327329
this.hideGameFinished();
328330
Abcd.changeVisibility(this, {home: false, back: true, filter: false, check: true, itemCount: true});
@@ -334,21 +336,21 @@ enyo.kind({
334336
this.hideGameFinished();
335337
this.backTaped();
336338
},
337-
339+
338340
// Go to the home of the game
339341
backTaped: function() {
340342
this.$.colorBar.removeClass("themeColor"+this.theme);
341343
this.theme = -1;
342344
this.gamecount = 0;
343-
this.selected = null;
345+
this.selected = null;
344346
this.displayButtons();
345347
},
346-
348+
347349
// Check taped
348350
checkTaped: function() {
349351
this.forbidentry = true;
350352
if (this.playing != null)
351-
this.playing.abort();
353+
this.playing.abort();
352354
if (this.selected == null) {
353355
Abcd.sound.play("audio/disappointed");
354356
this.selected = this.from;
@@ -363,27 +365,27 @@ enyo.kind({
363365
this.selected.addClass("entryPlayWrong");
364366
}
365367
},
366-
368+
367369
// End sound
368370
endSound: function(e, s) {
369371
// Prematured end
370372
if (this.selected == null)
371373
return;
372-
374+
373375
// Bad check, retry
374376
if (s.sound == "audio/disappointed") {
375377
this.selected.removeClass("entryPlaySelected");
376378
this.selected.removeClass("entryPlayWrong");
377379
this.selected = null;
378380
this.forbidentry = false;
379-
381+
380382
// Good check
381383
} else if (s.sound == "audio/applause") {
382384
// Clean state
383385
this.selected.removeClass("entryPlaySelected");
384386
this.selected.removeClass("entryPlayRight");
385-
this.selected = null;
386-
387+
this.selected = null;
388+
387389
// Next game or try another game
388390
if ( ++this.gamecount == entriesByGame ) {
389391
this.showGameFinished();

0 commit comments

Comments
 (0)