-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlc-js-timer.html
164 lines (159 loc) · 5.25 KB
/
lc-js-timer.html
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.4.min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/3.0.3/handlebars.js" type="text/javascript"></script>
<script src="lc-speech-synth.js" type="text/javascript"></script>
<script src="lc-js-timer.js" type="text/javascript"></script>
<!-- <script src="lc-js-timer_test.js" type="text/javascript"></script> -->
<link rel="stylesheet" type="text/css" href="styles.css">
<link href='http://fonts.googleapis.com/css?family=VT323' rel='stylesheet' type='text/css'>
<script>
$(function(){
var T = {};
T.timer = Handlebars.compile($("#timer-template").html());
var AlertBox = {
alertNum: 0,
pushNewAlert: function(msg) {
LCSpeechSynth.tryMessage(msg);
var alertMsgDomId = 'alertMsg' + AlertBox.alertNum++;
$("#alerts").prepend($("<li id='" + alertMsgDomId + "'>" + msg + "</li>"));
$("#" + alertMsgDomId).addClass("blink");
window.setInterval(function(){
$("#" + alertMsgDomId).removeClass("blink");
}, 4*1000);
window.setInterval(function(){
$("#" + alertMsgDomId).fadeOut(1000, function(){
$("#" + alertMsgDomId).remove();
});
}, 15*1000);
}
};
var app = new LcJsTimerApp({
onStateChange: function(domain, oldState, newState) {
if (domain == 'game') {
$("body").toggleClass(
"game-started",
((newState == LcJsTimerApp.STATES_ENUM.IN_PROGRESS) ||
(newState == LcJsTimerApp.STATES_ENUM.PAUSED)));
$("body").toggleClass(
"game-paused",
(newState == LcJsTimerApp.STATES_ENUM.PAUSED));
}
if (domain == 'travel') {
$("body").toggleClass(
"game-travelling",
((newState == LcJsTimerApp.STATES_TRAVEL_ENUM.TRAVEL_TRANSIT) ||
(newState == LcJsTimerApp.STATES_TRAVEL_ENUM.TRAVEL_ARRIVED)));
if (newState == LcJsTimerApp.STATES_TRAVEL_ENUM.TRAVEL_NO) {
$("#travel-timer").html("");
}
}
},
onGameTimerTick: function(seconds) {
$("#game-timer").html(T.timer(Util.secondsToMinutesAndSecondsAsPaddedStrings(seconds)));
switch(seconds) {
case 10 * 60:
case 5 * 60:
case 2 * 60:
AlertBox.pushNewAlert((seconds / 60) + " minutes left in game");
break;
case 60:
case 30:
AlertBox.pushNewAlert(seconds + " seconds left in game");
break;
case 0:
AlertBox.pushNewAlert("Game clock ended. Reveal endgame. Start travel now.");
break;
}
},
onTravelTimerTick: function(seconds) {
$("#travel-timer").html(T.timer(Util.secondsToMinutesAndSecondsAsPaddedStrings(seconds)));
switch(seconds) {
case 60:
case 30:
case 10:
AlertBox.pushNewAlert(seconds + " seconds until arrival.");
break;
case 0:
AlertBox.pushNewAlert("We have arrived. Game clock paused. Start mission now.");
app.stopTravelTimer();
app.pauseGame();
break;
}
}
});
$("#start-game").click(function() {
app.promptAndConfirmAndStartGameTimer();
AlertBox.pushNewAlert("Welcome, Commander!");
});
$("#start-travel").click(function() {
app.promptAndConfirmAndPrimeTravelTimer();
AlertBox.pushNewAlert("Warp drive engaged. En route.");
});
$("#stop-travel").click(function() {
app.confirmStopTravelTimer();
});
$("#pause").click(app.pauseGame.bind(app));
$("#resume").click(app.resumeGame.bind(app));
// Style toggles
var font = -1, maxFont = 2, palette = -1, maxPalette = 1;
function togglePalette(){
$("body").removeClass("palette-" + palette);
palette = (palette + 1) % (maxPalette + 1)
$("body").addClass("palette-" + palette);
}
function toggleFont(){
$("body").removeClass("font-" + font);
font = (font + 1) % (maxFont + 1)
$("body").addClass("font-" + font);
};
$("#togglePalette").click(togglePalette);
$("#toggleFont").click(toggleFont);
$("#configureVoice").click(LCSpeechSynth.configureVoice);
$("#testVoice").click(LCSpeechSynth.testCurrentVoice);
togglePalette();
toggleFont();
});
</script>
</head>
<body>
<div id="title">
<h1>Love Commander</h1>
<button id="togglePalette">Toggle Palette</button>
<button id="toggleFont">Toggle Font</button>
<button id="testVoice">Test Voice</button>
<button id="configureVoice">Configure Voice</button>
</div>
<div class="control-panel alerts-control-panel">
<div class="control-panel-label inverse">Alerts</div>
<ul id="alerts">
</ul>
</div>
<div class="control-panel">
<div class="control-panel-label inverse">Game Clock</div>
<div class="button-bar">
<button id="start-game" class="show-unless-game-started">Start Game</button>
<div class="show-if-game-started">
<button id="pause" class="show-unless-game-paused">Pause Game</button>
<button id="resume" class="show-if-game-paused">Resume Game</button>
</div>
</div>
<div id="game-timer" class="timer"></div>
</div>
<div class="control-panel">
<div class="control-panel-label inverse">Travel Clock</div>
<div class="button-bar">
<div class="show-if-game-started">
<button id="start-travel" class="show-unless-game-travelling">Start Travel</button>
<button id="stop-travel" class="show-if-game-travelling">Stop Travel (DEBUG)</button>
</div>
</div>
<div id="travel-timer" class="timer"></div>
</div>
<div id="footer">
</div>
<script id="timer-template" type="text/x-handlebars-template">
{{minutes}}:{{seconds}}
</script>
</body>
</html>