-
Notifications
You must be signed in to change notification settings - Fork 1
/
resistance.js
1933 lines (1569 loc) · 60.1 KB
/
resistance.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
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["Resistance"] = factory();
else
root["Resistance"] = factory();
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
__webpack_require__(1);
module.exports = __webpack_require__(31);
/***/ },
/* 1 */
/***/ function(module, exports) {
// removed by extract-text-webpack-plugin
/***/ },
/* 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 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
var _interopRequireDefault = __webpack_require__(32)['default'];
var _libSha256 = __webpack_require__(33);
var _libSha2562 = _interopRequireDefault(_libSha256);
var _servicesGameClient = __webpack_require__(34);
var _servicesGameClient2 = _interopRequireDefault(_servicesGameClient);
var _servicesMasterClient = __webpack_require__(51);
var _servicesMasterClient2 = _interopRequireDefault(_servicesMasterClient);
var HASHED_PW = 'f00a787f7492a95e165b470702f4fe9373583fbdc025b2c8bdf0262cc48fcff4';
var MASTER = 'fc613b4dfd6736a7bd268c8a0e74ed0d1c04a959f59dd74ef2874983fd443fc9';
var password = prompt('Password?');
var gameClient = undefined;
switch (_libSha2562['default'].hash(password)) {
case HASHED_PW:
gameClient = new _servicesGameClient2['default']('https://shining-fire-2823.firebaseio.com/');
break;
case MASTER:
gameClient = new _servicesMasterClient2['default']('https://shining-fire-2823.firebaseio.com/');
break;
}
if (gameClient) {
window.gameClient = gameClient;
window.onbeforeunload = function () {
return 'La Resistance';
};
}
/***/ },
/* 32 */
/***/ function(module, exports) {
"use strict";
exports["default"] = function (obj) {
return obj && obj.__esModule ? obj : {
"default": obj
};
};
exports.__esModule = true;
/***/ },
/* 33 */
/***/ function(module, exports, __webpack_require__) {
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* SHA-256 implementation in JavaScript (c) Chris Veness 2002-2014 / MIT Licence */
/* */
/* - see http://csrc.nist.gov/groups/ST/toolkit/secure_hashing.html */
/* http://csrc.nist.gov/groups/ST/toolkit/examples.html */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* jshint node:true */ /* global define, escape, unescape */
'use strict';
/**
* SHA-256 hash function reference implementation.
*
* @namespace
*/
var Sha256 = {};
/**
* Generates SHA-256 hash of string.
*
* @param {string} msg - String to be hashed
* @returns {string} Hash of msg as hex character string
*/
Sha256.hash = function (msg) {
// convert string to UTF-8, as SHA only deals with byte-streams
msg = msg.utf8Encode();
// constants [§4.2.2]
var K = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
// initial hash value [§5.3.1]
var H = [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19];
// PREPROCESSING
msg += String.fromCharCode(0x80); // add trailing '1' bit (+ 0's padding) to string [§5.1.1]
// convert string msg into 512-bit/16-integer blocks arrays of ints [§5.2.1]
var l = msg.length / 4 + 2; // length (in 32-bit integers) of msg + ‘1’ + appended length
var N = Math.ceil(l / 16); // number of 16-integer-blocks required to hold 'l' ints
var M = new Array(N);
for (var i = 0; i < N; i++) {
M[i] = new Array(16);
for (var j = 0; j < 16; j++) {
// encode 4 chars per integer, big-endian encoding
M[i][j] = msg.charCodeAt(i * 64 + j * 4) << 24 | msg.charCodeAt(i * 64 + j * 4 + 1) << 16 | msg.charCodeAt(i * 64 + j * 4 + 2) << 8 | msg.charCodeAt(i * 64 + j * 4 + 3);
} // note running off the end of msg is ok 'cos bitwise ops on NaN return 0
}
// add length (in bits) into final pair of 32-bit integers (big-endian) [§5.1.1]
// note: most significant word would be (len-1)*8 >>> 32, but since JS converts
// bitwise-op args to 32 bits, we need to simulate this by arithmetic operators
M[N - 1][14] = (msg.length - 1) * 8 / Math.pow(2, 32);M[N - 1][14] = Math.floor(M[N - 1][14]);
M[N - 1][15] = (msg.length - 1) * 8 & 0xffffffff;
// HASH COMPUTATION [§6.1.2]
var W = new Array(64);var a, b, c, d, e, f, g, h;
for (var i = 0; i < N; i++) {
// 1 - prepare message schedule 'W'
for (var t = 0; t < 16; t++) W[t] = M[i][t];
for (var t = 16; t < 64; t++) W[t] = Sha256.Sig1(W[t - 2]) + W[t - 7] + Sha256.Sig0(W[t - 15]) + W[t - 16] & 0xffffffff;
// 2 - initialise working variables a, b, c, d, e, f, g, h with previous hash value
a = H[0];b = H[1];c = H[2];d = H[3];e = H[4];f = H[5];g = H[6];h = H[7];
// 3 - main loop (note 'addition modulo 2^32')
for (var t = 0; t < 64; t++) {
var T1 = h + Sha256.Sigma1(e) + Sha256.Ch(e, f, g) + K[t] + W[t];
var T2 = Sha256.Sigma0(a) + Sha256.Maj(a, b, c);
h = g;
g = f;
f = e;
e = d + T1 & 0xffffffff;
d = c;
c = b;
b = a;
a = T1 + T2 & 0xffffffff;
}
// 4 - compute the new intermediate hash value (note 'addition modulo 2^32')
H[0] = H[0] + a & 0xffffffff;
H[1] = H[1] + b & 0xffffffff;
H[2] = H[2] + c & 0xffffffff;
H[3] = H[3] + d & 0xffffffff;
H[4] = H[4] + e & 0xffffffff;
H[5] = H[5] + f & 0xffffffff;
H[6] = H[6] + g & 0xffffffff;
H[7] = H[7] + h & 0xffffffff;
}
return Sha256.toHexStr(H[0]) + Sha256.toHexStr(H[1]) + Sha256.toHexStr(H[2]) + Sha256.toHexStr(H[3]) + Sha256.toHexStr(H[4]) + Sha256.toHexStr(H[5]) + Sha256.toHexStr(H[6]) + Sha256.toHexStr(H[7]);
};
/**
* Rotates right (circular right shift) value x by n positions [§3.2.4].
* @private
*/
Sha256.ROTR = function (n, x) {
return x >>> n | x << 32 - n;
};
/**
* Logical functions [§4.1.2].
* @private
*/
Sha256.Sigma0 = function (x) {
return Sha256.ROTR(2, x) ^ Sha256.ROTR(13, x) ^ Sha256.ROTR(22, x);
};
Sha256.Sigma1 = function (x) {
return Sha256.ROTR(6, x) ^ Sha256.ROTR(11, x) ^ Sha256.ROTR(25, x);
};
Sha256.Sig0 = function (x) {
return Sha256.ROTR(7, x) ^ Sha256.ROTR(18, x) ^ x >>> 3;
};
Sha256.Sig1 = function (x) {
return Sha256.ROTR(17, x) ^ Sha256.ROTR(19, x) ^ x >>> 10;
};
Sha256.Ch = function (x, y, z) {
return x & y ^ ~x & z;
};
Sha256.Maj = function (x, y, z) {
return x & y ^ x & z ^ y & z;
};
/**
* Hexadecimal representation of a number.
* @private
*/
Sha256.toHexStr = function (n) {
// note can't use toString(16) as it is implementation-dependant,
// and in IE returns signed numbers when used on full words
var s = "",
v;
for (var i = 7; i >= 0; i--) {
v = n >>> i * 4 & 0xf;s += v.toString(16);
}
return s;
};
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/** Extend String object with method to encode multi-byte string to utf8
* - monsur.hossa.in/2012/07/20/utf-8-in-javascript.html */
if (typeof String.prototype.utf8Encode == 'undefined') {
String.prototype.utf8Encode = function () {
return unescape(encodeURIComponent(this));
};
}
/** Extend String object with method to decode utf8 string to multi-byte */
if (typeof String.prototype.utf8Decode == 'undefined') {
String.prototype.utf8Decode = function () {
try {
return decodeURIComponent(escape(this));
} catch (e) {
return this; // invalid UTF-8? return as-is
}
};
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
if (typeof module != 'undefined' && module.exports) module.exports = Sha256; // CommonJs export
if (true) !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = function () {
return Sha256;
}.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); // AMD
/***/ },
/* 34 */
/***/ function(module, exports, __webpack_require__) {
// todo: separate player sign in events from game instance events
'use strict';
var _createClass = __webpack_require__(35)['default'];
var _classCallCheck = __webpack_require__(39)['default'];
var _Object$keys = __webpack_require__(40)['default'];
var _interopRequireDefault = __webpack_require__(32)['default'];
Object.defineProperty(exports, '__esModule', {
value: true
});
var _modelsPlayer = __webpack_require__(50);
var _modelsPlayer2 = _interopRequireDefault(_modelsPlayer);
var USE_COOKIE = false;
var GameClient = (function () {
function GameClient(url) {
var _this = this;
_classCallCheck(this, GameClient);
var db = this.db = new Firebase(url);
this.players = [];
db.once('value', function (snapshot) {
_this.init(snapshot.val() || {});
db.on('child_added', function (msg) {
return _this.handleEvent(msg.val());
});
_this.signIn();
});
}
_createClass(GameClient, [{
key: 'init',
value: function init(events) {
var _this2 = this;
this.READ_ONLY = true;
_Object$keys(events).forEach(function (key) {
_this2.handleEvent(events[key]);
});
// READ_ONLY should be false for last event?
this.READ_ONLY = false;
}
}, {
key: 'handleEvent',
value: function handleEvent(_ref) {
var name = _ref.name;
var data = _ref.data;
var eventHandler = this['on' + name];
if (eventHandler) {
eventHandler.call(this, data);
}
}
}, {
key: 'push',
value: function push(event) {
this.db.push(event);
}
}, {
key: 'signIn',
value: function signIn() {
var _this3 = this;
var id = Number(document.cookie || NaN);
if (isNaN(id) || !USE_COOKIE) {
document.cookie = id = this.id = this.players.length + 1;
var _name = this.name = prompt('Please enter your name');
this.push({
name: 'PlayerSignIn',
data: {
id: id,
name: _name
}
});
} else {
this.id = id;
}
var chatInput = document.querySelector('.chat__input');
var onKeyPress = function onKeyPress(e) {
var keyCode = e.keyCode;
var target = e.target;
if (keyCode !== 13) {
return;
}
_this3.push({
name: 'ChatMessage',
data: {
name: _this3.name,
message: target.value
}
});
target.value = '';
};
chatInput.addEventListener('keypress', onKeyPress, false);
}
}, {
key: 'onPlayerSignIn',
value: function onPlayerSignIn(_ref2) {
var id = _ref2.id;
var name = _ref2.name;
var players = this.players;
if (players[id - 1]) {
return;
}
players.push(new _modelsPlayer2['default'](id, name));
}
}, {
key: 'onSetRole',
value: function onSetRole(_ref3) {
var id = _ref3.id;
var role = _ref3.role;
var imageNumber = _ref3.imageNumber;
if (id !== this.id) {
return;
}
var roleClass = 'player__role--' + role;
var roleCardClass = roleClass + '--' + imageNumber;
var roleCard = document.querySelector('.player--current .player__role');
roleCard.classList.add(roleClass);
roleCard.classList.add(roleCardClass);
roleCard.classList.remove('player__role--face-down');
}
}, {
key: 'onSpiesHeadsUp',
value: function onSpiesHeadsUp() {
// todo: display spies heads up phase for a while
}
}, {
key: 'onSetMerlin',
value: function onSetMerlin(_ref4) {
var id = _ref4.id;
var roles = _ref4.roles;
if (id !== this.id) {
return;
}
this.gamePlayers.forEach(function (player) {
var id = player.id;
var _roles$id = roles[id];
var role = _roles$id.role;
var imageNumber = _roles$id.imageNumber;
var roleClass = 'player__role--' + role;
var roleCardClass = roleClass + '--' + imageNumber;
var roleCard = document.querySelector('.player--' + id + ' .player__role');
var faceDown = 'player__role--face-down';
roleCard.classList.add(roleClass);
roleCard.classList.add(roleCardClass);
roleCard.classList.remove(faceDown);
});
}
}, {
key: 'onLeaderChange',
value: function onLeaderChange(_ref5) {
var id = _ref5.id;
var oldLeader = this.leader;
var token = '.player__leader-token';
var hidden = 'player__leader-token--hidden';
var newLeaderSelector = '.player--' + id + ' ' + token;
if (oldLeader) {
var oldLeaderSelector = '.player--' + oldLeader + ' ' + token;
document.querySelector(oldLeaderSelector).classList.add(hidden);
}
document.querySelector(newLeaderSelector).classList.remove(hidden);
this.leader = id;
// todo: highlight current mission
}
}, {
key: 'onBuildTeam',
value: function onBuildTeam(_ref6) {
var _this4 = this;
var numPlayers = _ref6.numPlayers;
if (this.leader !== this.id || this.READ_ONLY) {
return;
}
var selected = {};
var panel = document.querySelector('.game__table__decision-panel');
var submit = document.querySelector('.submit');
var icons = document.querySelectorAll('.player__icon');
var teamCount = 0;
var onClick = function onClick(e) {
var target = e.target;
if (target.classList.contains('player__icon--selected')) {
target.classList.remove('player__icon--selected');
selected[target.id] = false;
teamCount--;
} else {
if (teamCount === numPlayers) {
return;
}
target.classList.add('player__icon--selected');
selected[target.id] = true;
teamCount++;
}
if (teamCount === numPlayers) {
submit.removeAttribute('disabled');
} else {
submit.setAttribute('disabled', 'true');
}
};
[].forEach.call(icons, function (icon) {
icon.addEventListener('click', onClick, false);
});
panel.classList.add('game__table__decision-panel--open');
panel.classList.add('game__table__decision-panel--team');
var onSubmit = function onSubmit() {
submit.removeEventListener('click', onSubmit, false);
[].forEach.call(icons, function (icon) {
icon.removeEventListener('click', onClick, false);
});
panel.classList.remove('game__table__decision-panel--open');
panel.classList.remove('game__table__decision-panel--team');
submit.setAttribute('disabled', 'true');
_this4.push({
name: 'TeamChosen',
data: {
team: _Object$keys(selected).reduce(function (team, id) {
if (selected[id]) {
team.push(id);
}
return team;
}, [])
}
});
var chosen = document.querySelectorAll('.player__icon--selected');
[].forEach.call(chosen, function (icon) {
icon.classList.remove('player__icon--selected');
});
};
submit.addEventListener('click', onSubmit, false);
}
}, {
key: 'onTeamChosen',
value: function onTeamChosen(_ref7) {
var team = _ref7.team;
var onTeam = 'player__icon--on-team';
team.forEach(function (id) {
var playerIcon = '.player--' + id + ' .player__icon';
document.querySelector(playerIcon).classList.add(onTeam);
});
this.team = team;
}
}, {
key: 'onTeamVote',
value: function onTeamVote() {
var _this5 = this;
if (this.READ_ONLY) {
return;
}
this.votes = [];
var panel = document.querySelector('.game__table__decision-panel');
var submit = document.querySelector('.submit');
var approveToken = document.querySelector('.vote-token--approve');
var rejectToken = document.querySelector('.vote-token--reject');
var onClick = function onClick(e) {
var prev = document.querySelector('.vote-token--selected');
var target = e.target;
if (prev && prev !== target) {
prev.classList.remove('vote-token--selected');
}
target.classList.add('vote-token--selected');
submit.removeAttribute('disabled');
};
approveToken.addEventListener('click', onClick, false);
rejectToken.addEventListener('click', onClick, false);
panel.classList.add('game__table__decision-panel--open');
panel.classList.add('game__table__decision-panel--vote');
var onSubmit = function onSubmit() {
submit.removeEventListener('click', onSubmit, false);
approveToken.removeEventListener('click', onClick, false);
rejectToken.removeEventListener('click', onClick, false);
panel.classList.remove('game__table__decision-panel--open');
panel.classList.remove('game__table__decision-panel--vote');
submit.setAttribute('disabled', 'true');
var selected = document.querySelector('.vote-token--selected');
var approve = selected.classList.contains('vote-token--approve');
selected.classList.remove('vote-token--selected');
_this5.push({
name: 'Vote',
data: { approve: approve, id: _this5.id }
});
};
submit.addEventListener('click', onSubmit, false);
}
}, {
key: 'onVote',
value: function onVote(data) {
this.votes.push(data);
}
}, {
key: 'onVotingResults',
value: function onVotingResults(_ref8) {
var approved = _ref8.approved;
if (approved) {
// todo: display approved message
// todo: reset failed vote token
// todo: team tokens
this.team.forEach(function (id) {
var playerClass = '.player--' + id;
var missionCardSelector = playerClass + ' .player__mission-card';
var hidden = 'player__mission-card--hidden';
[].forEach.call(document.querySelectorAll(missionCardSelector), function (el) {
el.classList.remove(hidden);
});
});
} else {
// todo: display rejected message
// todo: move failed vote token
var team = document.querySelectorAll('.player__icon--on-team');
[].forEach.call(team, function (icon) {
icon.classList.remove('player__icon--on-team');
});
this.team = [];
}
var revealedTokens = [];
var faceDown = 'player__vote--face-down';
this.votes.forEach(function (vote) {
var player = '.player--' + vote.id;
var token = '.player__vote--' + (vote.approve ? 'approve' : 'reject');
var selected = document.querySelector(player + ' ' + token);
selected.classList.remove(faceDown);
revealedTokens.push(selected);
});
this.votes = [];
setTimeout(function () {
revealedTokens.forEach(function (token) {
return token.classList.add(faceDown);
});
}, 10000);
}
}, {
key: 'onConductMission',
value: function onConductMission(_ref9) {
var _this6 = this;
var team = _ref9.team;
if (!team[this.id] || this.READ_ONLY) {
return;
}
var panel = document.querySelector('.game__table__decision-panel');
var submit = document.querySelector('.submit');
var successCard = document.querySelector('.mission-card--success');
var failCard = document.querySelector('.mission-card--fail');
var onClick = function onClick(e) {
var prev = document.querySelector('.mission-card--selected');
var target = e.target;
if (prev && prev !== target) {
prev.classList.remove('mission-card--selected');
}
target.classList.add('mission-card--selected');
submit.removeAttribute('disabled');
};
successCard.addEventListener('click', onClick, false);
failCard.addEventListener('click', onClick, false);
panel.classList.add('game__table__decision-panel--open');
panel.classList.add('game__table__decision-panel--mission');
var onSubmit = function onSubmit() {
submit.removeEventListener('click', onSubmit, false);
successCard.removeEventListener('click', onClick, false);
failCard.removeEventListener('click', onClick, false);
panel.classList.remove('game__table__decision-panel--open');
panel.classList.remove('game__table__decision-panel--mission');
submit.setAttribute('disabled', 'true');
var selected = document.querySelector('.mission-card--selected');
var success = selected.classList.contains('mission-card--success');
selected.classList.remove('mission-card--selected');
_this6.push({
name: 'MissionCardChosen',
data: { success: success }
});
};
submit.addEventListener('click', onSubmit, false);
}
}, {
key: 'onMissionResults',
value: function onMissionResults(_ref10) {
var success = _ref10.success;
var missionCards = _ref10.missionCards;
var els = [];
var message = document.querySelector('.message');
missionCards.forEach(function (successCard) {
var el = document.createElement('div');
el.classList.add('mission-card');
if (successCard) {
el.classList.add('mission-card--success');
} else {
el.classList.add('mission-card--fail');
}
message.appendChild(el);
els.push(el);
});
setTimeout(function () {
els.forEach(function (el) {
message.removeChild(el);
});
}, 10000);
var wins = document.querySelector('.wins');
var win = document.createElement('div');
win.classList.add('win');
if (success) {
win.classList.add('win--resistance');
} else {
win.classList.add('win--spy');
}
wins.appendChild(win);
var missionCardEls = document.querySelectorAll('.player__mission-card');
[].forEach.call(missionCardEls, function (missionCard) {
missionCard.classList.add('player__mission-card--hidden');
});
var team = document.querySelectorAll('.player__icon--on-team');
[].forEach.call(team, function (icon) {
icon.classList.remove('player__icon--on-team');
});
this.team = [];
}
}, {
key: 'onGameStart',
value: function onGameStart(_ref11) {
var players = _ref11.players;
var positions = _ref11.positions;
// todo: setup board
// todo: add player icon / info to room display
var numPlayers = players.length;
var gameClass = 'game--' + numPlayers + '-players';
var offset = positions[this.id];
this.gamePlayers = players;
players.forEach(function (player, idx) {
var position = idx - offset + 1;
if (position < 1) {
position += numPlayers;
}
var id = player.id;
var playerClass = 'player--' + id;
var seat = document.querySelector('.player--position-' + position);
seat.classList.add(playerClass);
seat.querySelector('.player__name').textContent = player.name;
seat.querySelector('.player__icon').id = id;
});
document.querySelector('.game').classList.add(gameClass);
}
}, {
key: 'onGameOver',
value: function onGameOver(_ref12) {
var winners = _ref12.winners;
var roles = _ref12.roles;
// todo: display winners message
this.gamePlayers.forEach(function (player) {
var id = player.id;
var _roles$id2 = roles[id];
var role = _roles$id2.role;
var imageNumber = _roles$id2.imageNumber;
var roleClass = 'player__role--' + role;
var roleCardClass = roleClass + '--' + imageNumber;
var roleCard = document.querySelector('.player--' + id + ' .player__role');
var faceDown = 'player__role--face-down';
roleCard.classList.add(roleClass);
roleCard.classList.add(roleCardClass);
roleCard.classList.remove(faceDown);
});
}
}, {
key: 'onGameEnd',
value: function onGameEnd() {
// l33t hacks, remove
document.querySelector('.game').outerHTML = '\n <div class="game">\n <div class="player player--position-1 player--current">\n <div class="player__name"></div>\n <div class="player__icon"></div>\n <div class="player__role player__role--face-down"></div>\n <div class="player__vote player__vote--approve player__vote--face-down"></div>\n <div class="player__vote player__vote--reject player__vote--face-down"></div>\n <div class="player__leader-token player__leader-token--hidden"></div>\n <div class="player__mission-card player__mission-card--hidden"></div>\n <div class="player__mission-card player__mission-card--hidden"></div>\n </div>\n <div class="player player--position-2">\n <div class="player__name"></div>\n <div class="player__icon"></div>\n <div class="player__role player__role--face-down"></div>\n <div class="player__vote player__vote--approve player__vote--face-down"></div>\n <div class="player__vote player__vote--reject player__vote--face-down"></div>\n <div class="player__leader-token player__leader-token--hidden"></div>\n <div class="player__mission-card player__mission-card--hidden"></div>\n <div class="player__mission-card player__mission-card--hidden"></div>\n </div>\n <div class="player player--position-3">\n <div class="player__name"></div>\n <div class="player__icon"></div>\n <div class="player__role player__role--face-down"></div>\n <div class="player__vote player__vote--approve player__vote--face-down"></div>\n <div class="player__vote player__vote--reject player__vote--face-down"></div>\n <div class="player__leader-token player__leader-token--hidden"></div>\n <div class="player__mission-card player__mission-card--hidden"></div>\n <div class="player__mission-card player__mission-card--hidden"></div>\n </div>\n <div class="player player--position-4">\n <div class="player__name"></div>\n <div class="player__icon"></div>\n <div class="player__role player__role--face-down"></div>\n <div class="player__vote player__vote--approve player__vote--face-down"></div>\n <div class="player__vote player__vote--reject player__vote--face-down"></div>\n <div class="player__leader-token player__leader-token--hidden"></div>\n <div class="player__mission-card player__mission-card--hidden"></div>\n <div class="player__mission-card player__mission-card--hidden"></div>\n </div>\n <div class="player player--position-5">\n <div class="player__name"></div>\n <div class="player__icon"></div>\n <div class="player__role player__role--face-down"></div>\n <div class="player__vote player__vote--approve player__vote--face-down"></div>\n <div class="player__vote player__vote--reject player__vote--face-down"></div>\n <div class="player__leader-token player__leader-token--hidden"></div>\n <div class="player__mission-card player__mission-card--hidden"></div>\n <div class="player__mission-card player__mission-card--hidden"></div>\n </div>\n <div class="player player--position-6">\n <div class="player__name"></div>\n <div class="player__icon"></div>\n <div class="player__role player__role--face-down"></div>\n <div class="player__vote player__vote--approve player__vote--face-down"></div>\n <div class="player__vote player__vote--reject player__vote--face-down"></div>\n <div class="player__leader-token player__leader-token--hidden"></div>\n <div class="player__mission-card player__mission-card--hidden"></div>\n <div class="player__mission-card player__mission-card--hidden"></div>\n </div>\n <div class="player player--position-7">\n <div class="player__name"></div>\n <div class="player__icon"></div>\n <div class="player__role player__role--face-down"></div>\n <div class="player__vote player__vote--approve player__vote--face-down"></div>\n <div class="player__vote player__vote--reject player__vote--face-down"></div>\n <div class="player__leader-token player__leader-token--hidden"></div>\n <div class="player__mission-card player__mission-card--hidden"></div>\n <div class="player__mission-card player__mission-card--hidden"></div>\n </div>\n <div class="player player--position-8">\n <div class="player__name"></div>\n <div class="player__icon"></div>\n <div class="player__role player__role--face-down"></div>\n <div class="player__vote player__vote--approve player__vote--face-down"></div>\n <div class="player__vote player__vote--reject player__vote--face-down"></div>\n <div class="player__leader-token player__leader-token--hidden"></div>\n <div class="player__mission-card player__mission-card--hidden"></div>\n <div class="player__mission-card player__mission-card--hidden"></div>\n </div>\n <div class="player player--position-9">\n <div class="player__name"></div>\n <div class="player__icon"></div>\n <div class="player__role player__role--face-down"></div>\n <div class="player__vote player__vote--approve player__vote--face-down"></div>\n <div class="player__vote player__vote--reject player__vote--face-down"></div>\n <div class="player__leader-token player__leader-token--hidden"></div>\n <div class="player__mission-card player__mission-card--hidden"></div>\n <div class="player__mission-card player__mission-card--hidden"></div>\n </div>\n <div class="player player--position-10">\n <div class="player__name"></div>\n <div class="player__icon"></div>\n <div class="player__role player__role--face-down"></div>\n <div class="player__vote player__vote--approve player__vote--face-down"></div>\n <div class="player__vote player__vote--reject player__vote--face-down"></div>\n <div class="player__leader-token player__leader-token--hidden"></div>\n <div class="player__mission-card player__mission-card--hidden"></div>\n <div class="player__mission-card player__mission-card--hidden"></div>\n </div>\n <div class="game__area">\n <div class="game__table">\n <div class="game__table__top">\n <div class="game__table__top__display"></div>\n </div>\n <div class="game__table__middle">\n <div class="game__table__middle__strip"></div>\n <div class="game__board">\n <div class="game__board__panel"></div>\n <div class="game__board__results"></div>\n </div>\n <div class="display">\n <div class="message"></div>\n <div class="wins"></div>\n </div>\n </div>\n <div class="game__table__bottom">\n <div class="game__table__bottom__results"></div>\n </div>\n </div>\n <div class="game__table__decision-panel">\n <div class="team"></div>\n <div class="vote-tokens">\n <div class="vote-token vote-token--approve"></div>\n <div class="vote-token vote-token--reject"></div>\n </div>\n <div class="mission-cards">\n <div class="mission-card mission-card--success"></div>\n <div class="mission-card mission-card--fail"></div>\n </div>\n <button class="submit" disabled="true">Submit</button>\n </div>\n </div>\n </div>'.replace(/>\s+/g, '>');
this.gamePlayers = [];
}
}, {
key: 'onChatMessage',
value: function onChatMessage(_ref13) {
var name = _ref13.name;
var message = _ref13.message;
var nameEl = document.createElement('strong');
var messageEl = document.createElement('li');
var chatHistory = document.querySelector('.chat__history');
nameEl.classList.add('chat__message__name');
nameEl.textContent = name + ': ';
messageEl.classList.add('chat__message');
messageEl.textContent = message;
messageEl.insertBefore(nameEl, messageEl.firstChild);
chatHistory.appendChild(messageEl);
chatHistory.scrollTop = chatHistory.scrollHeight;
}
}]);
return GameClient;
})();
exports['default'] = GameClient;
module.exports = exports['default'];
/***/ },
/* 35 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
var _Object$defineProperty = __webpack_require__(36)["default"];
exports["default"] = (function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
_Object$defineProperty(target, descriptor.key, descriptor);
}
}
return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
})();
exports.__esModule = true;
/***/ },
/* 36 */
/***/ function(module, exports, __webpack_require__) {
module.exports = { "default": __webpack_require__(37), __esModule: true };
/***/ },
/* 37 */
/***/ function(module, exports, __webpack_require__) {
var $ = __webpack_require__(38);
module.exports = function defineProperty(it, key, desc){
return $.setDesc(it, key, desc);
};
/***/ },
/* 38 */
/***/ function(module, exports) {
var $Object = Object;
module.exports = {
create: $Object.create,
getProto: $Object.getPrototypeOf,
isEnum: {}.propertyIsEnumerable,
getDesc: $Object.getOwnPropertyDescriptor,
setDesc: $Object.defineProperty,
setDescs: $Object.defineProperties,
getKeys: $Object.keys,
getNames: $Object.getOwnPropertyNames,
getSymbols: $Object.getOwnPropertySymbols,
each: [].forEach
};
/***/ },
/* 39 */
/***/ function(module, exports) {