1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
// Sounds theme
var soundThemes = [ "audio/theme_piano", "audio/theme_guitar", "audio/theme_violon", "audio/theme_oboe", "audio/theme_trompet", "audio/theme_mallets", "audio/theme_soprano"];
var soundNotesPos = [ 24, 536, 1024, 1536, 2057, 2569, 3048, 4040, 4552, 5032, 5560, 6064, 6349, 6570, 6836, 7072, 8056, 8560, 9072, 10071, 10575, 11071, 12063, 13061, 14063, 15062 ];
// Main app class
enyo.kind({
name: "Abcd.App",
kind: enyo.Control,
classes: "main",
components: [
{components: [
{name: "logo", kind: "Image", classes: "logo", src: "images/logo.png"},
{name: "instrument", kind: "Image", classes: "instrument", src: "images/instrument0.png", ontap: "nextInstrument"},
{name: "letter", content: "", classes: "letter" }
]},
{components: [
{name: "credit", kind: "Image", src: "images/credit.png", classes: "creditButton", ontap: "displayCredits"},
{name: "learn", kind: "Image", src: "images/learn.png", classes: "learnButton", ontap: "learnGame"},
{name: "play", kind: "Image", src: "images/play.png", classes: "playButton", ontap: "playGame"},
{name: "build", kind: "Image", src: "images/build.png", classes: "buildButton", ontap: "buildGame"}
]},
{name: "creditsPopup", kind: "Abcd.CreditsPopup"},
{kind: "Signals", onEndOfSound: "endOfSound", onSoundTimeupdate: "soundTimeupdate"}
],
// Constructor, save home
create: function() {
this.inherited(arguments);
Abcd.context.home = this;
},
// Start the last closed activity if context not null
rendered: function() {
if (Abcd.context.screen != "") {
Abcd.context.object = enyo.create({
kind: Abcd.context.screen,
context: Abcd.context.screenContext
}).renderInto(document.getElementById("body"));
Abcd.context.screen = "";
return true;
}
this.playTheme();
Abcd.context.object = null;
},
// Play theme
playTheme: function() {
this.soundindex = 0;
this.soundpos = 0;
Abcd.sound.play(soundThemes[this.soundindex]);
},
// Launch activities
learnGame: function(e, s) {
Abcd.sound.pause();
Abcd.context.object = new Abcd.Learn().renderInto(document.getElementById("body"));
},
playGame: function(e, s) {
Abcd.sound.pause();
Abcd.context.object = new Abcd.Play().renderInto(document.getElementById("body"));
},
// Display credits page
displayCredits: function(e, s) {
this.$.creditsPopup.show();
},
// Sound ended, play next instrument
endOfSound: function(e, s) {
if (s == soundThemes[this.soundindex])
this.nextInstrument();
},
nextInstrument: function() {
this.soundindex = (this.soundindex + 1) % soundThemes.length;
this.soundpos = 0;
this.$.letter.setContent("");
this.$.instrument.setSrc("images/instrument"+this.soundindex+".png");
Abcd.sound.play(soundThemes[this.soundindex]);
},
soundTimeupdate: function(e, s) {
for (var i = this.soundpos ; i < soundNotesPos.length ; i++) {
var val = soundNotesPos[i];
this.soundpos = i;
if (s >= val - 50 && s < val + 50) {
this.$.letter.setContent(String.fromCharCode(65+i));
return;
}
if (val > s) {
break;
}
}
this.$.letter.setContent("");
}
});
|