-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cortana.js
51 lines (37 loc) · 1.56 KB
/
Cortana.js
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
/*global Windows:true, FlightArcade: true */
// Handle Cortana activation adding the event listener before DOM Content Loaded
// parse out the command type and call the respective game APIs
(function() {
if (typeof Windows !== 'undefined') {
Windows.UI.WebUI.WebUIApplication.addEventListener("activated", function (args) {
var activation = Windows.ApplicationModel.Activation;
if (args.kind === activation.ActivationKind.voiceCommand) {
var speechRecognitionResult = args.result;
var textSpoken = speechRecognitionResult.text;
// Determine the command type {level, waypoint} defined in vcd
if (speechRecognitionResult.rulePath[0] === "level") {
// Determine level {tin, bronze, gold}
if (textSpoken.search("tin") >= 0) {
toastNotification("Achievement unlocked 100G - Using Cortana");
FlightArcade.startBronzeLevel();
}
else if (textSpoken.search("bronze") >= 0) {
toastNotification("Achievement unlocked 100G - Using Cortana");
FlightArcade.startTinLevel()
}
else if (textSpoken.search("gold") >= 0) {
toastNotification("Achievement unlocked 100G - Using Cortana");
FlightArcade.startGoldLevel();
}
else {
// No level specified by user
}
}
else if (speechRecognitionResult.rulePath[0] === "waypoint") {
// Call waypoints api
FlightArcade.goToNamedPosition('alphaBravo');
}
}
});
}
})();