| 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320 |
1×
1×
1×
148×
57×
42×
1×
99×
99×
99×
42×
28×
27×
99×
57×
30×
34×
1×
30×
30×
30×
30×
30×
8×
30×
13×
3×
30×
16×
30×
2×
30×
30×
29×
1×
13×
5×
8×
8×
8×
1×
28×
28×
28×
7×
28×
28×
28×
1×
27×
27×
27×
6×
27×
1×
34×
34×
34×
34×
34×
6×
34×
11×
1×
11×
6×
11×
6×
6×
6×
11×
4×
4×
34×
6×
6×
6×
34×
2×
2×
34×
34×
1×
39×
1×
39×
1×
119×
119×
119×
286×
265×
286×
1×
78×
235×
352×
1×
352×
1181×
186×
1×
92×
249×
1×
118×
118×
118×
284×
275×
275×
141×
1×
78×
78×
390×
235×
1×
64×
64×
64×
64×
64×
64×
64×
1×
30×
30×
30×
1×
30×
30×
30×
1×
34×
1×
34×
1×
256×
1×
64×
1×
64×
| /**
* @ngdoc service
* @name app.scores.scoreboardAnimate
* @description
* Change flags on the scoreboard object to trigger animations.
* For example, when the win_game action is executed, the old set
* score should fade out and the new set score should fade in.
* So before the scoreboardController's scoreboard object is updated, flags
* are changed to cause the old set score to fade out. After the
* scoreboardControllers's scoreboard object is updated, flags are changed to
* cause the new set score to fade in.
*/
(function () {
'use strict';
angular
.module('app.scores')
.factory('scoreboardAnimate', factory);
/** @ngInject */
function factory(animationTimers) {
return {
animateAction: function (sb, action, param) {
return new Animations(sb, animationTimers).animateAction(action, param);
},
animateKeepScore: function (sb, keepScore) {
return new Animations(sb, animationTimers).animateKeepScore(keepScore);
}
}
}
// Set and clear flags on the scoreboard object to trigger animation while
// hiding and showing elements of the scoreboard view.
// The scoreboard object must be prepared using the scoreboardPrep service, prior
// to using this class.
function Animations(_sb_, _animationTimers_) {
var sb = _sb_;
var animationTimers = _animationTimers_;
/**
* @ngdoc function
* @name animateKeepScore
* @methodOf app.scores.scoreboardAnimate
* @description
* Hide and show elements while changing the scoreboard view between showing
* score keeper command and hiding score keeper commands
* @param {Boolean} keepScore
* Truthy if showing score keeper commands
*/
this.animateKeepScore = function (keepScore) {
return {
hideChanging: function () {
keepScoreHideChanging(keepScore);
},
hideChanged: function () {
keepScoreHideChanged(!keepScore);
},
showChanged: showChanged,
reset: resetHideAndShow
}
};
/**
* @ngdoc function
* @name animateAction
* @methodOf app.scores.scoreboardAnimate
* @description
* Hide and show elements while positing an action, such as
* win_game
* @param {String} action
* Action such as 'win_game'
* @param {Object} param
* Action parameter
*/
this.animateAction = function (action, param) {
return {
hideChanging: function () {
actionHideChanging(action, param);
},
hideChanged: function () {
actionHideChanged(action, param)
},
showChanged: showChanged,
reset: resetHideAndShow
}
};
function actionHideChanging(action, param) {
var transitions = new ScoreTransitions(action, param, {before: true});
var list = new AnimationList();
list.add('Progress', sb.matchFlags);
list.add('Server', sb.matchFlags);
if (transitions.winningSet)
list.add('Result', sb.matchFlags);
if (sb.currentGame && sb.currentSet)
if (transitions.winningGame && !transitions.winningSet)
list.add('Title', sb.currentGame);
if (transitions.winningGame)
list.add('Result', sb.currentSet);
if (transitions.startingGame && sb.firstServers)
list.add('ServersForm', sb.currentGame);
enableAnimation(list);
// Allow ng-class of elements to apply before hiding elements
animationTimers.digest().then(function () {
hideForAnimation(list, {leftmost: transitions.leftmost});
});
}
function addKeepScoreGameAnimations(list, keepScore, game) {
if (game.newGame) {
list.add('', game, keepScore);
} else Eif (!sb.currentGame.winner) {
list.add('WinButton', game, keepScore);
list.add('RowStatus', game, !keepScore);
}
}
function keepScoreHideChanging(keepScore) {
var list = new AnimationList();
list.add('Progress', sb.matchFlags);
if (sb.currentGame)
addKeepScoreGameAnimations(list, keepScore, sb.currentGame);
enableAnimation(list);
// Allow ng-class to be applied
animationTimers.digest().then(function () {
hideForAnimation(list);
});
}
function keepScoreHideChanged(keepScore) {
var list = new AnimationList();
list.add('Progress', sb.matchFlags);
if (sb.currentGame)
addKeepScoreGameAnimations(list, keepScore, sb.currentGame);
hideForAnimation(list)
}
function actionHideChanged(action, param) {
var transitions = new ScoreTransitions(action, param, {before: false});
var list = new AnimationList();
list.add('Progress', sb.matchFlags);
list.add('Server', sb.matchFlags);
if (transitions.winningSet)
list.add('Result', sb.matchFlags);
if (sb.currentGame && sb.currentSet) {
if (transitions.startingGame)
list.add('WinButton', sb.currentGame);
if (transitions.winningGame && sb.firstServers)
list.add('ServersForm', sb.currentGame);
if (transitions.winningGame && !transitions.winningSet) {
list.add('Title', sb.currentGame);
list.add('StartGameButton', sb.currentGame);
list.add('Result', sb.currentSet);
}
// Hide a newly created set and set's first game
if ((transitions.startingSet || transitions.startingMatch) &&
(!sb.currentGame.winner && sb.currentSet.games.length == 1)) {
list.add('', sb.currentGame);
list.add('', sb.currentSet);
}
}
if (sb.currentGame && sb.previousGame) {
// Hide game that just got a winner
Eif (transitions.winningGame && sb.currentGame.newGame) {
list.add('Title', sb.currentGame);
list.add('', sb.previousGame);
}
}
if (sb.previousSet) {
Eif (transitions.winningSet)
list.add('Result', sb.previousSet);
}
enableAnimation(list);
hideForAnimation(list, {leftmost: transitions.leftmost});
}
function showChanged() {
clearFlags(['hidden']);
}
function resetHideAndShow() {
clearFlags(['hidden', 'animating']);
}
function AnimationList() {
var items = [];
this.items = items;
this.add = function (key, value, hide) {
if (angular.isUndefined(hide))
hide = true;
items.push({key: key, value: value, hide: hide});
}
}
function clearFlags(prefixes) {
eachFlaggedObject(
function (item) {
angular.forEach(prefixes, function (prefix) {
clear(item, prefix)
});
});
// Clear all properties that start with a prefix like "animating"
function clear(item, prefix) {
angular.forEach(item, function (value, key) {
if (key.startsWith(prefix)) {
item[key] = false;
}
});
}
}
function enableAnimation(list) {
angular.forEach(list.items, function (item) {
// Set property such as animatingServersForm
item.value['animating' + item.key] = true;
});
}
function hideForAnimation(list, options) {
options = options || {};
var leftmost = options.leftmost;
angular.forEach(list.items, function (item) {
if (item.hide) {
// Set property such as hiddenServersForm
item.value['hidden' + item.key] = true;
if (angular.isDefined(leftmost))
item.value.hiddenLeftmost = leftmost;
}
});
}
// Enumerate all the objects that may have animating* and hidden* flags.
function eachFlaggedObject(fn) {
var items = [sb.previousGame, sb.currentGame, sb.currentSet, sb.previousSet, sb.matchFlags];
angular.forEach(items,
function (item) {
if (item)
fn(item)
});
}
// Collect some information about the state of the scoreboard before or after executing
// an action
function ScoreTransitions(action, param, stateOf) {
this.winningGame = winningGame(action);
this.winningSet = stateOf.before ? predictWinningSet() : winningSet();
this.winningMatch = stateOf.before ? predictWinningMatch() : winningMatch();
this.startingGame = startingGame(action);
this.startingSet = startingSet(action);
this.startingMatch = action == 'start_play';
this.leftmost = winningGame(action) ? param == 0 : undefined;
function predictWinningSet() {
var nearWinners = sb.near_winners.set;
var opponent = sb.opponents[param];
return winningGame() && nearWinners.indexOf(opponent) >= 0;
}
function predictWinningMatch() {
var nearWinners = sb.near_winners.match;
var opponent = sb.opponents[param];
return winningGame() && nearWinners.indexOf(opponent) >= 0
}
function winningSet() {
// if match is finished then must have won a set.
// Otherwise, if there is a new set then the previous set was won
return winningGame() && (sb.winner ||
(sb.currentSet && sb.currentSet.newSet && sb.previousSet));
}
function winningMatch() {
return winningGame() && sb.winner;
}
function winningGame() {
return action && action.startsWith('win');
}
function startingSet() {
return ['start_set', 'start_match_tiebreak', 'start_match'].indexOf(action) >= 0;
}
function startingGame() {
return ['start_game', 'start_tiebreak'].indexOf(action) >= 0;
}
}
}
})
();
|