This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
99 lines (86 loc) · 2.17 KB
/
app.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
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
/* globals angular */
(function(){
"use strict";
var app = angular.module("snake", ["ui.router", "ui.bootstrap.modal"]);
app.config(["$stateProvider", function($stateProvider){
$stateProvider.state("mainmenu", {
templateUrl: "template/mainmenu.html"
}).state("lobby", {
templateUrl: "template/lobby.html",
controller: "lobby",
params: ["local"]
}).state("lobby.create", {
controller: "lobbycreate"
}).state("lobby.join", {
controller: "lobbyjoin",
params: ["id", "local"]
}).state("browse", {
templateUrl: "template/browse.html",
controller: "browse"
}).state("game", {
template: " ",
controller: "game",
params: ["settings", "players"]
}).state("scoreboard", {
templateUrl: "template/scoreboard.html",
controller: "scoreboard",
params: ["data", "local"]
});
}]);
app.filter("snakeColor", function(){
return function(input){
var map = ["?", "Green", "Yellow", "Red", "Fuchsia", "Cerulean", "Aquamarine"];
return map[parseInt(input, 10)];
};
});
app.filter("yesno", function(){
return function(input){
return input ? "Yes" : "No";
};
});
app.filter("ucfirst", function(){
return function(input){
return input.charAt(0).toUpperCase() + input.slice(1);
};
});
app.filter("timehumanize", function(){
return function(input){
input /= 1000;
var min = Math.floor(input/60);
var sec = Math.ceil(input - min*60);
if(sec.toString().length < 2){
sec = "0" + sec;
}
return min+":"+sec;
};
});
app.factory("netcode", function(){
var netcode = new Netcode();
netcode.connect();
return netcode;
});
app.factory("handleRtcKey", ["netcode", function(){
return function($scope){
var onKeyDown = function(e){
if(e.which == 86){
netcode.rtc.muteMic(false);
}
};
var onKeyUp = function(e){
if(e.which == 86){
netcode.rtc.muteMic(true);
}
};
document.addEventListener("keydown", onKeyDown, false);
document.addEventListener("keyup", onKeyUp, false);
$scope.$on("$destroy", function(){
document.removeEventListener("keydown", onKeyDown, false);
document.removeEventListener("keyup", onKeyUp, false);
netcode.rtc.muteMic(true);
});
};
}]);
app.run(["$state", function($state){
$state.go("mainmenu");
}]);
})();