-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.js
More file actions
104 lines (91 loc) · 3.01 KB
/
init.js
File metadata and controls
104 lines (91 loc) · 3.01 KB
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
101
102
103
// Force Polymer to skip font import
window.polymerSkipLoadingFontRoboto = true;
let gameComponent;
let media;
document.addEventListener('deviceready', () => {
// Cordova fires a 'pause' event when app goes to the background
document.addEventListener('pause', onPause, false);
document.addEventListener('resume', onResume, false);
media = new Media('assets/sounds/background.mp3', null, null, status => {
if (status === 4) {
media.play();
}
});
media.setVolume(0);
media.play();
}, false);
// Pause audio when quitting the app
function onPause() {
gameComponent.stopPlayback();
media.pause();
}
// Resume audio when quitting the app
function onResume() {
media.play();
}
function BlockMove(event) {
event.preventDefault();
}
// When the game component is ready, set up the tutorial
document.addEventListener('pie-game-connected', () => {
gameComponent = document.getElementById('app').getGameComponent();
// If the tutorial has been completed, don't run
if (localStorage.getItem('tutorial-done')) {
return;
}
// Initialize tutorial
gameComponent.tutorial = new Tutorial(gameComponent);
gameComponent.tutorial.stepList = [
{
userTarget: 'play-button',
tooltipText: 'Tap here for a melody!',
tooltipTarget: 'play-button'
},
{
appEvent: 'playback-changed'
},
{
userTarget: 'note-0-container',
tooltipTarget: 'note-0-container',
tooltipText: 'OK, the melody had two notes.<br> Can this be the first?'
},
{
tooltipTarget: 'note-0',
tooltipText: 'That\'s right!',
duration: 1500
},
{
userTarget: 'note-3-container',
tooltipTarget: 'note-3',
tooltipText: 'This the second?'
},
{
tooltipTarget: 'note-3',
tooltipText: 'Excellent! Ready to go!',
duration: 1800
},
];
});
let visibilityHidden, visibilityChange;
if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support
visibilityHidden = "hidden";
visibilityChange = "visibilitychange";
} else if (typeof document.mozHidden !== "undefined") {
visibilityHidden = "mozHidden";
visibilityChange = "mozvisibilitychange";
} else if (typeof document.msHidden !== "undefined") {
visibilityHidden = "msHidden";
visibilityChange = "msvisibilitychange";
} else if (typeof document.webkitHidden !== "undefined") {
visibilityHidden = "webkitHidden";
visibilityChange = "webkitvisibilitychange";
}
window.onpagehide = handleVisibilityChange;
// If the page is hidden, stop the playback
function handleVisibilityChange(e) {
if (document[visibilityHidden]) {
gameComponent.stopPlayback();
}
}
// Handle page visibility change
document.addEventListener(visibilityChange, handleVisibilityChange, false);