-
Notifications
You must be signed in to change notification settings - Fork 0
/
velonimo.js
3455 lines (3276 loc) · 157 KB
/
velonimo.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
/**
*------
* BGA framework: © Gregory Isabelli <[email protected]> & Emmanuel Colin <[email protected]>
* Velonimo implementation : © Oliver THEBAULT (a.k.a. Oliboy50)
*
* This code has been produced on the BGA studio platform for use on http://boardgamearena.com.
* See http://en.boardgamearena.com/#!doc/Studio for more information.
* -----
*
* velonimo.js
*
* Velonimo user interface script
*
* In this file, you are describing the logic of your user interface, in Javascript language.
*
*/
/**
* Velonimo JS coding rules
*
* Since this JS file is not transpiled,
* we cannot use the latest ecmascript features,
* so we target the following browsers:
* - "Edge" 15+
* - "Firefox" 54+
* - "Chrome" 51+
* - "Safari" 10+
* - "Opera" 38+
* - "Opera Mobile" 64+
* - "Samsung Internet" 5+
*
* Use https://caniuse.com/ to see if you can use a feature.
*/
// Cards color ID
const COLOR_BLUE = 10;
const COLOR_BROWN = 20;
const COLOR_GRAY = 30;
const COLOR_GREEN = 40;
const COLOR_PINK = 50;
const COLOR_RED = 60;
const COLOR_YELLOW = 70;
const COLOR_ADVENTURER = 80;
const COLOR_SPECIAL = 90;
const SIMPLE_COLORS = [COLOR_BLUE, COLOR_BROWN, COLOR_GRAY, COLOR_GREEN, COLOR_PINK, COLOR_RED, COLOR_YELLOW];
// Cards value
const VALUE_1 = 1;
const VALUE_2 = 2;
const VALUE_3 = 3;
const VALUE_4 = 4;
const VALUE_5 = 5;
const VALUE_6 = 6;
const VALUE_7 = 7;
const VALUE_25 = 25;
const VALUE_30 = 30;
const VALUE_35 = 35;
const VALUE_40 = 40;
const VALUE_45 = 45;
const VALUE_50 = 50;
const VALUE_JERSEY_PLUS_TEN = 10;
const VALUE_LEGENDS_BROOM_WAGON_PLUS_FIVE = 5;
const VALUE_LEGENDS_EAGLE_ADD_ONE_OTHER_NUMBER = -4;
const VALUE_LEGENDS_PANDA_ADD_ONE_OTHER_COLOR = -5;
const VALUE_LEGENDS_SHARK_ONE_RED_MULTIPLY_TEN = -6;
const VALUE_LEGENDS_BADGER_ANY_NUMBER_OF_EACH_COLOR = -7;
const VALUE_LEGENDS_ELEPHANT_STOP = -8;
// Special cards ID
const CARD_ID_JERSEY_PLUS_TEN = -2;
const CARD_ID_LEGENDS_BROOM_WAGON_PLUS_FIVE = -3;
const CARD_ID_LEGENDS_EAGLE_ADD_ONE_OTHER_NUMBER = -4;
const CARD_ID_LEGENDS_PANDA_ADD_ONE_OTHER_COLOR = -5;
const CARD_ID_LEGENDS_SHARK_ONE_RED_MULTIPLY_TEN = -6;
const CARD_ID_LEGENDS_BADGER_ANY_NUMBER_OF_EACH_COLOR = -7;
const CARD_ID_LEGENDS_ELEPHANT_STOP = -8;
// Sprites
const NUMBER_OF_COLUMNS_IN_CARDS_SPRITE = 7;
const NUMBER_OF_ROWS_IN_CARDS_SPRITE = 9;
// DOM IDs
const DOM_ID_APP = 'velonimo-game';
const DOM_ID_BOARD_CARPET = 'board-carpet';
const DOM_ID_CARDS_DECK = 'cards-deck';
const DOM_ID_CARDS_DECK_CARDS = 'cards-deck-cards';
const DOM_ID_ATTACK_REWARD_CARD = 'attack-reward-card';
const DOM_ID_PLAYED_CARDS_WRAPPER = 'played-cards';
const DOM_ID_LAST_PLAYED_CARDS = 'last-played-cards';
const DOM_ID_PREVIOUS_LAST_PLAYED_CARDS = 'previous-last-played-cards';
const DOM_ID_PLAYER_HAND = 'my-hand';
const DOM_ID_PLAYER_HAND_TITLE_WRAPPER = 'my-hand-title-wrapper';
const DOM_ID_PLAYER_HAND_TITLE_WRAPPER_LEFT = 'my-hand-title-wrapper-left';
const DOM_ID_PLAYER_HAND_TITLE_WRAPPER_RIGHT = 'my-hand-title-wrapper-right';
const DOM_ID_PLAYER_HAND_TITLE = 'my-hand-title';
const DOM_ID_PLAYER_HAND_TOGGLE_SORT_BUTTON = 'toggle-sort-button';
const DOM_ID_PLAYER_HAND_TOGGLE_SORT_BUTTON_LABEL = 'toggle-sort-button-label';
const DOM_ID_PLAYER_HAND_GROUP_CARDS_BUTTON = 'group-cards-button';
const DOM_ID_PLAYER_HAND_UNGROUP_CARDS_BUTTON = 'ungroup-cards-button';
const DOM_ID_PLAYER_HAND_SELECTED_CARDS = 'my-hand-selected-cards';
const DOM_ID_CURRENT_ROUND = 'current-round';
const DOM_ID_ACTION_BUTTON_PLAY_CARDS = 'action-button-play-cards';
const DOM_ID_ACTION_BUTTON_PASS_TURN = 'action-button-pass-turn';
const DOM_ID_ACTION_BUTTON_SELECT_PLAYER = 'action-button-select-player';
const DOM_ID_ACTION_BUTTON_GIVE_CARDS = 'action-button-give-cards';
// DOM classes
const DOM_CLASS_PLAYER_TABLE = 'player-table';
const DOM_CLASS_PLAYER_JERSEY = 'player-table-jersey';
const DOM_CLASS_PLAYER_LEGENDS_BROOM_WAGON = 'player-table-legends-broom-wagon';
const DOM_CLASS_PLAYER_LEGENDS_COACH = 'player-table-legends-coach';
const DOM_CLASS_PLAYER_HAS_JERSEY = 'has-jersey';
const DOM_CLASS_PLAYER_HAS_LEGENDS_BROOM_WAGON = 'has-legends-broom-wagon';
const DOM_CLASS_PLAYER_HAS_LEGENDS_EAGLE = 'has-legends-coach-eagle';
const DOM_CLASS_PLAYER_HAS_LEGENDS_PANDA = 'has-legends-coach-panda';
const DOM_CLASS_PLAYER_HAS_LEGENDS_SHARK = 'has-legends-coach-shark';
const DOM_CLASS_PLAYER_HAS_LEGENDS_BADGER = 'has-legends-coach-badger';
const DOM_CLASS_PLAYER_HAS_LEGENDS_ELEPHANT = 'has-legends-coach-elephant';
const DOM_CLASS_PLAYER_HAS_USED_JERSEY = 'has-used-jersey';
const DOM_CLASS_PLAYER_HAS_USED_LEGENDS_BROOM_WAGON = 'has-used-legends-broom-wagon';
const DOM_CLASS_PLAYER_HAS_USED_LEGENDS_EAGLE = 'has-used-legends-coach-eagle';
const DOM_CLASS_PLAYER_HAS_USED_LEGENDS_PANDA = 'has-used-legends-coach-panda';
const DOM_CLASS_PLAYER_HAS_USED_LEGENDS_SHARK = 'has-used-legends-coach-shark';
const DOM_CLASS_PLAYER_HAS_USED_LEGENDS_BADGER = 'has-used-legends-coach-badger';
const DOM_CLASS_PLAYER_HAS_USED_LEGENDS_ELEPHANT = 'has-used-legends-coach-elephant';
const DOM_CLASS_PLAYER_PANEL_CONTAINER = 'player-panel-velonimo-wrapper';
const DOM_CLASS_PLAYER_PANEL_LEFT = 'player-panel-velonimo-left';
const DOM_CLASS_PLAYER_PANEL_RIGHT = 'player-panel-velonimo-right';
const DOM_CLASS_JERSEY_IN_PLAYER_PANEL = 'player-panel-jersey';
const DOM_CLASS_LEGENDS_BROOM_WAGON_IN_PLAYER_PANEL = 'player-panel-legends-broom-wagon';
const DOM_CLASS_LEGENDS_EAGLE_IN_PLAYER_PANEL = 'player-panel-legends-coach-eagle';
const DOM_CLASS_LEGENDS_PANDA_IN_PLAYER_PANEL = 'player-panel-legends-coach-panda';
const DOM_CLASS_LEGENDS_SHARK_IN_PLAYER_PANEL = 'player-panel-legends-coach-shark';
const DOM_CLASS_LEGENDS_BADGER_IN_PLAYER_PANEL = 'player-panel-legends-coach-badger';
const DOM_CLASS_LEGENDS_ELEPHANT_IN_PLAYER_PANEL = 'player-panel-legends-coach-elephant';
const DOM_CLASS_NUMBER_OF_REMAINING_CARDS_IN_PLAYER_PANEL = 'player-panel-number-of-remaining-cards';
const DOM_CLASS_CARDS_STACK = 'cards-stack';
const DOM_CLASS_CARDS_STACK_PREVIOUS_PLAYED = 'previous-last-played-cards';
const DOM_CLASS_DISABLED_ACTION_BUTTON = 'disabled';
const DOM_CLASS_ACTIVE_PLAYER = 'active';
const DOM_CLASS_SELECTABLE_PLAYER = 'selectable';
const DOM_CLASS_NON_SELECTABLE_CARD = 'non-selectable-player-card';
const DOM_CLASS_PLAYER_SPEECH_BUBBLE_SHOW = 'show-bubble';
const DOM_CLASS_SPEECH_BUBBLE = 'player-table-speech-bubble';
const DOM_CLASS_SPEECH_BUBBLE_LEFT = 'speech-bubble-on-left';
const DOM_CLASS_SPEECH_BUBBLE_RIGHT = 'speech-bubble-on-right';
const DOM_CLASS_CARDS_GROUP_CARD = 'cards-group-card';
const DOM_CLASS_CARDS_GROUP_CARD_LEFT = 'cards-group-card-left';
const DOM_CLASS_CARDS_GROUP_CARD_RIGHT = 'cards-group-card-right';
const DOM_CLASS_VELONIMO_CARD = 'velonimo-card';
const DOM_CLASS_CARD_FRONT_SIDE = 'front-side';
const DOM_CLASS_CARD_BACK_SIDE = 'back-side';
const DOM_CLASS_MOVING_CARD = 'moving-card';
// Player hand sorting modes
const PLAYER_HAND_SORT_BY_COLOR = 'color';
const PLAYER_HAND_SORT_BY_VALUE = 'value';
// Style
const BOARD_CARPET_WIDTH = 740;
const CARD_WIDTH = 90;
const CARD_HEIGHT = 126;
const PLAYER_TABLE_WIDTH = 200;
const PLAYER_TABLE_HEIGHT = CARD_HEIGHT;
const PLAYER_TABLE_HORIZONTAL_MIDDLE_MARGIN = 100;
const TABLE_STYLE_HORIZONTAL_LEFT = `left: 0;`;
const TABLE_STYLE_HORIZONTAL_MIDDLE_LEFT = `left: ${PLAYER_TABLE_HORIZONTAL_MIDDLE_MARGIN}px;`;
const TABLE_STYLE_HORIZONTAL_CENTER = `left: ${(BOARD_CARPET_WIDTH / 2) - (PLAYER_TABLE_WIDTH / 2)}px;`;
const TABLE_STYLE_HORIZONTAL_MIDDLE_RIGHT = `left: ${BOARD_CARPET_WIDTH - (PLAYER_TABLE_WIDTH + PLAYER_TABLE_HORIZONTAL_MIDDLE_MARGIN)}px;`;
const TABLE_STYLE_HORIZONTAL_RIGHT = `left: ${BOARD_CARPET_WIDTH - PLAYER_TABLE_WIDTH}px;`;
const TABLE_STYLE_VERTICAL_TOP = `top: 0;`;
const TABLE_STYLE_VERTICAL_BOTTOM = `bottom: 0;`;
// the current player (index 0 == current player) place is always at the bottom of the board, in a way that players always stay closed to their hand
const PLAYERS_PLACES_BY_NUMBER_OF_PLAYERS = {
2: {
0: {
tableStyle: `${TABLE_STYLE_VERTICAL_BOTTOM} ${TABLE_STYLE_HORIZONTAL_CENTER}`,
bubbleClass: DOM_CLASS_SPEECH_BUBBLE_LEFT,
},
1: {
tableStyle: `${TABLE_STYLE_VERTICAL_TOP} ${TABLE_STYLE_HORIZONTAL_CENTER}`,
bubbleClass: DOM_CLASS_SPEECH_BUBBLE_RIGHT,
},
},
3: {
0: {
tableStyle: `${TABLE_STYLE_VERTICAL_BOTTOM} ${TABLE_STYLE_HORIZONTAL_CENTER}`,
bubbleClass: DOM_CLASS_SPEECH_BUBBLE_LEFT,
},
1: {
tableStyle: `${TABLE_STYLE_VERTICAL_TOP} ${TABLE_STYLE_HORIZONTAL_MIDDLE_LEFT}`,
bubbleClass: DOM_CLASS_SPEECH_BUBBLE_LEFT,
},
2: {
tableStyle: `${TABLE_STYLE_VERTICAL_TOP} ${TABLE_STYLE_HORIZONTAL_MIDDLE_RIGHT}`,
bubbleClass: DOM_CLASS_SPEECH_BUBBLE_RIGHT,
},
},
4: {
0: {
tableStyle: `${TABLE_STYLE_VERTICAL_BOTTOM} ${TABLE_STYLE_HORIZONTAL_CENTER}`,
bubbleClass: DOM_CLASS_SPEECH_BUBBLE_LEFT,
},
1: {
tableStyle: `${TABLE_STYLE_VERTICAL_TOP} ${TABLE_STYLE_HORIZONTAL_LEFT}`,
bubbleClass: DOM_CLASS_SPEECH_BUBBLE_RIGHT,
},
2: {
tableStyle: `${TABLE_STYLE_VERTICAL_TOP} ${TABLE_STYLE_HORIZONTAL_CENTER}`,
bubbleClass: DOM_CLASS_SPEECH_BUBBLE_RIGHT,
},
3: {
tableStyle: `${TABLE_STYLE_VERTICAL_TOP} ${TABLE_STYLE_HORIZONTAL_RIGHT}`,
bubbleClass: DOM_CLASS_SPEECH_BUBBLE_LEFT,
},
},
5: {
0: {
tableStyle: `${TABLE_STYLE_VERTICAL_BOTTOM} ${TABLE_STYLE_HORIZONTAL_MIDDLE_LEFT}`,
bubbleClass: DOM_CLASS_SPEECH_BUBBLE_LEFT,
},
1: {
tableStyle: `${TABLE_STYLE_VERTICAL_TOP} ${TABLE_STYLE_HORIZONTAL_LEFT}`,
bubbleClass: DOM_CLASS_SPEECH_BUBBLE_RIGHT,
},
2: {
tableStyle: `${TABLE_STYLE_VERTICAL_TOP} ${TABLE_STYLE_HORIZONTAL_CENTER}`,
bubbleClass: DOM_CLASS_SPEECH_BUBBLE_RIGHT,
},
3: {
tableStyle: `${TABLE_STYLE_VERTICAL_TOP} ${TABLE_STYLE_HORIZONTAL_RIGHT}`,
bubbleClass: DOM_CLASS_SPEECH_BUBBLE_LEFT,
},
4: {
tableStyle: `${TABLE_STYLE_VERTICAL_BOTTOM} ${TABLE_STYLE_HORIZONTAL_MIDDLE_RIGHT}`,
bubbleClass: DOM_CLASS_SPEECH_BUBBLE_RIGHT,
},
},
};
define([
'dojo','dojo/_base/declare',
'ebg/core/gamegui',
'ebg/counter',
'ebg/stock',
],
function (dojo, declare) {
return declare('bgagame.velonimo', ebg.core.gamegui, {
constructor: function () {
this.resetCurrentState();
this.currentRound = 0;
this.currentPlayerHasJersey = false;
this.currentPlayerHasLegendsBroomWagon = false;
this.currentPlayerHasLegendsEagle = false;
this.currentPlayerHasLegendsPanda = false;
this.currentPlayerHasLegendsShark = false;
this.currentPlayerHasLegendsBadger = false;
this.currentPlayerHasLegendsElephant = false;
this.jerseyIsNotPlayable = false;
this.legendsBroomWagonIsNotPlayable = false;
this.legendsEagleIsNotPlayable = false;
this.legendsPandaIsNotPlayable = false;
this.legendsSharkIsNotPlayable = false;
this.legendsBadgerIsNotPlayable = false;
this.legendsElephantIsNotPlayable = false;
this.isExtensionLegendsEnabled = false;
this.howManyRounds = 0;
this.playedCardsValue = 0;
this.howManyCardsToGiveBack = 0;
this.players = {};
this.playerHand = null; // https://en.doc.boardgamearena.com/Stock
// /!\ 2P mode only
this.howManyCardsInDeck = 0;
this.resetDisplayedNumberOfCardsByPlayerId();
this.timeoutToRefreshDisplayedNumberOfCards = null;
this.resetCardsGroups();
},
setup: function (gamedatas) {
this.currentState = gamedatas.gamestate.name;
this.currentRound = gamedatas.currentRound;
this.jerseyIsNotPlayable = gamedatas.jerseyIsNotPlayable;
this.legendsBroomWagonIsNotPlayable = gamedatas.legendsBroomWagonIsNotPlayable;
this.legendsEagleIsNotPlayable = gamedatas.legendsEagleIsNotPlayable;
this.legendsPandaIsNotPlayable = gamedatas.legendsPandaIsNotPlayable;
this.legendsSharkIsNotPlayable = gamedatas.legendsSharkIsNotPlayable;
this.legendsBadgerIsNotPlayable = gamedatas.legendsBadgerIsNotPlayable;
this.legendsElephantIsNotPlayable = gamedatas.legendsElephantIsNotPlayable;
this.howManyRounds = gamedatas.howManyRounds;
this.isExtensionLegendsEnabled = gamedatas.isExtensionLegendsEnabled === true;
// setup board
dojo.place(
`<div id="board">
<div id="${DOM_ID_BOARD_CARPET}">
<div id="${DOM_ID_PLAYED_CARDS_WRAPPER}">
<div id="${DOM_ID_PREVIOUS_LAST_PLAYED_CARDS}"></div>
<div id="${DOM_ID_LAST_PLAYED_CARDS}"></div>
</div>
</div>
<div id="game-info" class="player-board">
${_('Round')}
<div id="${DOM_ID_CURRENT_ROUND}"></div>
</div>
</div>
<div id="my-hand-wrapper" class="whiteblock">
<div id="${DOM_ID_PLAYER_HAND_TITLE_WRAPPER}">
<div id="${DOM_ID_PLAYER_HAND_TITLE_WRAPPER_LEFT}">
<i class="fa fa-hand-paper-o"></i>
<h3 id="${DOM_ID_PLAYER_HAND_TITLE}">${_('My hand')}</h3>
<a href="javascript:void(0)" id="${DOM_ID_PLAYER_HAND_TOGGLE_SORT_BUTTON}" class="bgabutton bgabutton_gray"><span id="${DOM_ID_PLAYER_HAND_TOGGLE_SORT_BUTTON_LABEL}"></span></a>
</div>
<div id="${DOM_ID_PLAYER_HAND_TITLE_WRAPPER_RIGHT}"></div>
</div>
<div id="${DOM_ID_PLAYER_HAND}"></div>
</div>`,
DOM_ID_APP
);
// setup players
this.players = gamedatas.players;
const howManyPlayers = Object.keys(this.players).length;
const playersPlace = PLAYERS_PLACES_BY_NUMBER_OF_PLAYERS[howManyPlayers];
this.sortPlayersToStartWithPlayerIdIfPresent(
this.sortPlayersByTurnOrderPosition(Object.entries(this.players).map((entry) => entry[1])),
gamedatas.currentPlayerId
).forEach((player, index) => {
const playerPosition = playersPlace[index];
const playerColorRGB = `#${player.color}`;
const isPositionTop = playerPosition.tableStyle.indexOf('top') !== -1;
// setup player on board
dojo.place(
`<div id="player-table-${player.id}" class="${DOM_CLASS_PLAYER_TABLE} ${isPositionTop ? 'player-position-top' : 'player-position-bottom'}" style="width: ${PLAYER_TABLE_WIDTH}px; height: ${PLAYER_TABLE_HEIGHT}px; ${playerPosition.tableStyle}">
<div class="player-table-name" style="color: ${playerColorRGB};"><span>${(player.name.length > 20 ? (player.name.substring(0,20) + '...') : player.name)}</span></div>
<div id="player-table-${player.id}-hand" class="player-table-hand"><div id="player-table-${player.id}-hand-cards" class="player-table-hand-cards"></div></div>
<div id="player-table-${player.id}-special-cards" class="player-special-cards"></div>
<div id="player-table-${player.id}-finish-position" class="player-table-finish-position"></div>
<div id="player-table-${player.id}-speech-bubble" class="${DOM_CLASS_SPEECH_BUBBLE} ${playerPosition.bubbleClass}" style="color: ${playerColorRGB};"></div>
</div>`,
DOM_ID_BOARD_CARPET
);
// setup player panel
dojo.place(
`<div class="${DOM_CLASS_PLAYER_PANEL_CONTAINER}">
<div id="player-panel-${player.id}-velonimo-left" class="${DOM_CLASS_PLAYER_PANEL_LEFT}">
<div id="player-panel-${player.id}-remaining-cards" class="${DOM_CLASS_NUMBER_OF_REMAINING_CARDS_IN_PLAYER_PANEL}">
<i class="fa fa-hand-paper-o"></i><span id="player-panel-${player.id}-remaining-cards-number">0</span>
</div>
</div>
<div id="player-panel-${player.id}-velonimo-right" class="${DOM_CLASS_PLAYER_PANEL_RIGHT}"></div>
</div>`,
`player_board_${player.id}`
);
this.addTooltip(`player-panel-${player.id}-remaining-cards`, _('Number of cards in hand'), '');
});
this.setupPlayersFinishPosition();
if (this.isExtensionLegendsEnabled) {
// setup legends coaches
if (gamedatas.legendsEagleIsNotPlayable) {
this.useSpecialCardForCurrentRound(CARD_ID_LEGENDS_EAGLE_ADD_ONE_OTHER_NUMBER);
} else {
this.restoreSpecialCardForCurrentRound(CARD_ID_LEGENDS_EAGLE_ADD_ONE_OTHER_NUMBER);
}
if (gamedatas.legendsPandaIsNotPlayable) {
this.useSpecialCardForCurrentRound(CARD_ID_LEGENDS_PANDA_ADD_ONE_OTHER_COLOR);
} else {
this.restoreSpecialCardForCurrentRound(CARD_ID_LEGENDS_PANDA_ADD_ONE_OTHER_COLOR);
}
if (gamedatas.legendsSharkIsNotPlayable) {
this.useSpecialCardForCurrentRound(CARD_ID_LEGENDS_SHARK_ONE_RED_MULTIPLY_TEN);
} else {
this.restoreSpecialCardForCurrentRound(CARD_ID_LEGENDS_SHARK_ONE_RED_MULTIPLY_TEN);
}
if (gamedatas.legendsBadgerIsNotPlayable) {
this.useSpecialCardForCurrentRound(CARD_ID_LEGENDS_BADGER_ANY_NUMBER_OF_EACH_COLOR);
} else {
this.restoreSpecialCardForCurrentRound(CARD_ID_LEGENDS_BADGER_ANY_NUMBER_OF_EACH_COLOR);
}
if (gamedatas.legendsElephantIsNotPlayable) {
this.useSpecialCardForCurrentRound(CARD_ID_LEGENDS_ELEPHANT_STOP);
} else {
this.restoreSpecialCardForCurrentRound(CARD_ID_LEGENDS_ELEPHANT_STOP);
}
this.moveLegendsCoachToPlayers();
// setup legends broom wagon
if (gamedatas.legendsBroomWagonIsNotPlayable) {
this.useSpecialCardForCurrentRound(CARD_ID_LEGENDS_BROOM_WAGON_PLUS_FIVE);
} else {
this.restoreSpecialCardForCurrentRound(CARD_ID_LEGENDS_BROOM_WAGON_PLUS_FIVE);
}
this.moveLegendsBroomWagonToLastLoser();
}
// setup jersey (if not 2P mode)
if (!this.is2PlayersMode()) {
if (this.jerseyIsNotPlayable) {
this.useSpecialCardForCurrentRound(CARD_ID_JERSEY_PLUS_TEN);
} else {
this.restoreSpecialCardForCurrentRound(CARD_ID_JERSEY_PLUS_TEN);
}
this.moveJerseyToCurrentWinner();
}
// show 2P mode items
if (this.is2PlayersMode()) {
dojo.place(
`<div id="${DOM_ID_CARDS_DECK}"><div id="${DOM_ID_CARDS_DECK_CARDS}"></div></div>
<div id="${DOM_ID_ATTACK_REWARD_CARD}"></div>`,
DOM_ID_BOARD_CARPET
);
this.howManyCardsInDeck = gamedatas.numberOfCardsInDeck;
this.setupDeckOfCards();
this.setupAttackRewardCards(gamedatas.attackRewardCards);
}
// init playerHand "ebg.stock" component
this.playerHand = new ebg.stock();
this.playerHand.create(this, $(DOM_ID_PLAYER_HAND), CARD_WIDTH, CARD_HEIGHT);
this.playerHand.resizeItems(CARD_WIDTH, CARD_HEIGHT, CARD_WIDTH * NUMBER_OF_COLUMNS_IN_CARDS_SPRITE, CARD_HEIGHT * NUMBER_OF_ROWS_IN_CARDS_SPRITE);
this.playerHand.setSelectionAppearance('class');
this.playerHand.image_items_per_row = NUMBER_OF_COLUMNS_IN_CARDS_SPRITE;
// create cards
const cardsImageUrl = g_gamethemeurl+'img/cards.png';
this.execFnForEachCardInGame((color, value) => {
const cardPositionInSprite = this.getCardPositionInSpriteByColorAndValue(color, value);
this.playerHand.addItemType(
cardPositionInSprite, // stock item ID
cardPositionInSprite, // card weight (used for sorting)
cardsImageUrl, // sprite URL
cardPositionInSprite // position in sprite
);
});
dojo.connect(this.playerHand, 'onChangeSelection', this, (_, itemId) => {
if (typeof itemId === 'undefined') {
return;
}
if (
this.isCurrentPlayerActive()
&& this.currentState === 'playerGiveCardsBackAfterPicking'
) {
this.setupGiveCardsBackAfterPickingActionButton();
return;
}
const cardId = parseInt(itemId, 10);
if (this.playerHand.isSelected(cardId)) {
this.onPlayerCardSelected(cardId);
} else {
this.onPlayerCardUnselected(cardId);
}
});
// sort cards
this.onClickOnTogglePlayerHandSortButton();
dojo.connect($(DOM_ID_PLAYER_HAND_TOGGLE_SORT_BUTTON), 'onclick', this, 'onClickOnTogglePlayerHandSortButton');
// setup currentPlayer cards
this.addCardsToPlayerHand(
this.addSpecialCardsToCards(this.getSpecialPlayerCardIds(), gamedatas.currentPlayerCards),
false
);
// setup cards played on table
this.playedCardsValue = gamedatas.playedCardsValue;
this.setupPreviousPlayedCards(
gamedatas.previousPlayedCards.concat(gamedatas.previousPlayedSpecialCards)
);
this.moveCardsFromPlayerHandToTable(
gamedatas.playedCardsPlayerId,
gamedatas.playedCards.concat(gamedatas.playedSpecialCards)
);
this.resetDisplayedNumberOfCardsByPlayerId();
this.setupPlayersHiddenCards();
this.setupTurnPassedBubbles(gamedatas.playedCardsPlayerId, gamedatas.activePlayerId);
// setup players score
this.setupPlayersScore();
// setup rounds info
this.setupRoundsInfo();
// handle game notifications
this.setupNotifications();
},
///////////////////////////////////////////////////
//// Game & client states
///////////////////////////////////////////////////
onEnteringState: function (state, data) {
this.currentState = state;
switch (state) {
case 'firstPlayerTurn':
case 'playerTurn':
dojo.addClass(`player-table-${data.args.activePlayerId}`, DOM_CLASS_ACTIVE_PLAYER);
break;
case 'playerSelectNextPlayer':
dojo.addClass(`player-table-${data.args.activePlayerId}`, DOM_CLASS_ACTIVE_PLAYER);
this.setupSelectPlayerAction(data.args.activePlayerId, data.args.selectablePlayers, this.onSelectNextPlayer);
break;
case 'playerSelectWhoTakeAttackReward':
dojo.addClass(`player-table-${data.args.activePlayerId}`, DOM_CLASS_ACTIVE_PLAYER);
this.setupSelectPlayerAction(data.args.activePlayerId, data.args.selectablePlayers, this.onSelectWhoTakeAttackReward);
break;
case 'playerSelectPlayerToPickCards':
dojo.addClass(`player-table-${data.args.activePlayerId}`, DOM_CLASS_ACTIVE_PLAYER);
this.setupSelectPlayerAction(data.args.activePlayerId, data.args.selectablePlayers, this.onSelectPlayerToPickCards);
break;
case 'playerGiveCardsBackAfterPicking':
dojo.addClass(`player-table-${data.args.activePlayerId}`, DOM_CLASS_ACTIVE_PLAYER);
this.howManyCardsToGiveBack = data.args.numberOfCards;
break;
}
},
onLeavingState: function (state) {
dojo.query(`.${DOM_CLASS_PLAYER_TABLE}`).removeClass(DOM_CLASS_ACTIVE_PLAYER);
switch (state) {
case 'playerSelectNextPlayer':
case 'playerSelectWhoTakeAttackReward':
case 'playerSelectPlayerToPickCards':
Object.entries(this.players).forEach((entry) => {
const player = entry[1];
dojo.removeClass(`player-table-${player.id}`, DOM_CLASS_SELECTABLE_PLAYER);
this.disconnect($(`player-table-${player.id}`), 'onclick');
});
break;
case 'playerGiveCardsBackAfterPicking':
this.howManyCardsToGiveBack = 0;
if (this.isCurrentPlayerActive()) {
this.unselectAllCards();
this.displayCardsAsNonSelectable([]);
}
break;
}
this.resetCurrentState();
},
onUpdateActionButtons: function (state, args) {
this.removeActionButtons();
if (!this.isCurrentPlayerActive()) {
return;
}
this.currentState = state;
switch (state) {
case 'firstPlayerTurn':
this.setupPlayCardsActionButton();
break;
case 'playerTurn':
this.addActionButton(DOM_ID_ACTION_BUTTON_PASS_TURN, _('Pass'), 'onPassTurn');
// add "play cards" button if player can play
if (this.currentPlayerCanPlayCards()) {
this.setupPlayCardsActionButton();
}
break;
case 'playerGiveCardsBackAfterPicking':
this.unselectAllCards();
this.setupGiveCardsBackAfterPickingActionButton();
break;
}
},
///////////////////////////////////////////////////
//// Utility methods
///////////////////////////////////////////////////
/**
* @Override format_string_recursive BGA framework function
* @see https://en.doc.boardgamearena.com/BGA_Studio_Cookbook#Inject_images_and_styled_html_in_the_log
*/
format_string_recursive: function (log, args) {
try {
if (log && args && !args.processed) {
args.processed = true;
for (let key in args) {
switch (key) {
case 'cardsImage':
args[key] = this.getLogHtmlForCards(args[key]);
break;
}
}
}
} catch (e) {
console.error("Custom format_string_recursive thrown", log, args, e.stack);
}
return this.inherited(arguments); // equivalent to "super()"
},
/**
* @param {Object[]} cards
* @returns {string}
*/
getLogHtmlForCards: function (cards) {
return this.sortPlayedCards(cards).map((card) => {
const position = this.getCardPositionInSpriteByColorAndValue(card.color, card.value);
const backgroundX = this.getAbsoluteCardBackgroundPositionXFromCardPosition(position) + this.getLogHtmlBackgroundOffsetXForCard(card);
const backgroundY = this.getAbsoluteCardBackgroundPositionYFromCardPosition(position) + this.getLogHtmlBackgroundOffsetYForCard(card);
return `<div class="${DOM_CLASS_VELONIMO_CARD} ${DOM_CLASS_CARD_FRONT_SIDE}" style="width: ${this.getLogHtmlWidthForCard(card)}px; height: 24px; background-position: -${backgroundX}px -${backgroundY}px;"></div>`;
}).join(' ');
},
getLogHtmlWidthForCard: function (card) {
if (card.color === COLOR_ADVENTURER) {
return 33;
}
if (card.color === COLOR_SPECIAL) {
return 30;
}
return 17;
},
getLogHtmlBackgroundOffsetXForCard: function (card) {
if (card.color === COLOR_ADVENTURER) {
return 3;
}
if (card.value === VALUE_2) {
return 66;
}
if (card.value === VALUE_6) {
return 7;
}
if (card.value === VALUE_7) {
return 7;
}
if (
card.color === COLOR_SPECIAL
&& [
VALUE_JERSEY_PLUS_TEN,
VALUE_LEGENDS_BROOM_WAGON_PLUS_FIVE,
].includes(card.value)
) {
return 1;
}
if (
card.color === COLOR_SPECIAL
&& [
VALUE_LEGENDS_EAGLE_ADD_ONE_OTHER_NUMBER,
VALUE_LEGENDS_PANDA_ADD_ONE_OTHER_COLOR,
VALUE_LEGENDS_SHARK_ONE_RED_MULTIPLY_TEN,
VALUE_LEGENDS_BADGER_ANY_NUMBER_OF_EACH_COLOR,
VALUE_LEGENDS_ELEPHANT_STOP,
].includes(card.value)
) {
return 30;
}
return 8;
},
getLogHtmlBackgroundOffsetYForCard: function (card) {
if (card.color === COLOR_ADVENTURER) {
return 5;
}
if (
card.color === COLOR_SPECIAL
&& card.value === VALUE_JERSEY_PLUS_TEN
) {
return 2;
}
if (
card.color === COLOR_SPECIAL
&& card.value === VALUE_LEGENDS_BROOM_WAGON_PLUS_FIVE
) {
return 1;
}
if (
card.color === COLOR_SPECIAL
&& [
VALUE_LEGENDS_EAGLE_ADD_ONE_OTHER_NUMBER,
VALUE_LEGENDS_PANDA_ADD_ONE_OTHER_COLOR,
VALUE_LEGENDS_SHARK_ONE_RED_MULTIPLY_TEN,
VALUE_LEGENDS_BADGER_ANY_NUMBER_OF_EACH_COLOR,
VALUE_LEGENDS_ELEPHANT_STOP,
].includes(card.value)
) {
return 91;
}
return 4;
},
/**
* @param {Object} card
* @returns {[string, string]|null}
* @see https://en.doc.boardgamearena.com/Game_interface_logic:_yourgamename.js#Tooltips
*/
getTooltipTextsForCard: function (card) {
switch (card.color) {
case COLOR_BLUE:
case COLOR_BROWN:
case COLOR_GRAY:
case COLOR_GREEN:
case COLOR_PINK:
case COLOR_RED:
case COLOR_YELLOW:
if (card.value === VALUE_1) {
return [
_('Leader - Value: 1 - For each leader played, you must randomly pick 1 card from the player hand of your choice, then give this player back 1 card of your choice.'),
'',
];
} else if (
card.value === VALUE_2
&& this.is2PlayersMode()
) {
return [
_('Water carrier - Value: 2 - For each water carrier played, you must draw 1 card from the deck (even if this was your last card).'),
'',
];
} else {
return null;
}
case COLOR_ADVENTURER:
return [
dojo.string.substitute(_('Adventurer - Value: ${v} - This card cannot be played with others, because the adventurers does not belong to a team, they always play solo.'), { v: card.value }),
'',
];
case COLOR_SPECIAL:
switch (card.value) {
case VALUE_JERSEY_PLUS_TEN:
return [
dojo.string.substitute(_('Carrot polka dot Jersey - Given to the current winner of the game - It adds ${v} points to any valid card combinations (one or more colored cards). It cannot be played with adventurers.'), { v: VALUE_JERSEY_PLUS_TEN }),
''
];
case VALUE_LEGENDS_BROOM_WAGON_PLUS_FIVE:
return [
dojo.string.substitute(_('Broom Wagon - Given to the loser of the previous round - It adds ${v} points to any valid card combinations (one or more colored cards). It cannot be played with adventurers.'), { v: VALUE_LEGENDS_BROOM_WAGON_PLUS_FIVE }),
''
];
case VALUE_LEGENDS_EAGLE_ADD_ONE_OTHER_NUMBER:
return [
_('Coach Eagle - Allow to add a card of a different value to card(s) that share the same value.'),
''
];
case VALUE_LEGENDS_PANDA_ADD_ONE_OTHER_COLOR:
return [
_('Coach Panda - Allow to add a card of a different color to card(s) that share the same color.'),
''
];
case VALUE_LEGENDS_SHARK_ONE_RED_MULTIPLY_TEN:
return [
_('Coach Shark - Multiply the value of a single red card by 10 (e.g. a "5 red" played with this coach is equal to "50").'),
''
];
case VALUE_LEGENDS_BADGER_ANY_NUMBER_OF_EACH_COLOR:
return [
_('Coach Badger - Allow to combine a single card of each color, even if they do not share the same value.'),
''
];
case VALUE_LEGENDS_ELEPHANT_STOP:
return [
_('Coach Elephant - The card(s) played with this coach immediately end the current turn (i.e. like if no other players wanted to play on top of it).'),
''
];
default:
return null;
}
default:
return null;
}
},
/**
* @returns {string}
*/
getTranslatedTextForSelectedCardsValue: function () {
return _('Combined value of selected cards');
},
/**
* @param {string} action
* @param {Object} data
*/
requestAction: function (action, data) {
if (
typeof data !== 'object'
|| data.hasOwnProperty('lock')
|| data.hasOwnProperty('action')
|| data.hasOwnProperty('module')
|| data.hasOwnProperty('class')
) {
console.error('[requestAction] Invalid data');
return;
}
this.ajaxcall(
`/velonimo/velonimo/${action}.html`,
Object.assign({}, data, { lock: true }),
this,
() => {}
);
},
/**
* Return true if:
* - the current player is spectator
* - the current player is in replay mode
* - the game has ended (a.k.a. archive mode)
* @see https://en.doc.boardgamearena.com/Game_interface_logic:_yourgamename.js
*
* @returns {boolean}
*/
isReadOnly() {
return this.isSpectator || typeof g_replayFrom !== 'undefined' || g_archive_mode;
},
/**
* @returns {boolean}
*/
is2PlayersMode: function () {
return Object.keys(this.players).length === 2;
},
resetDisplayedNumberOfCardsByPlayerId: function () {
this.displayedNumberOfCardsByPlayerId = {};
Object.entries(this.players).forEach((entry) => {
const player = entry[1];
this.displayedNumberOfCardsByPlayerId[player.id] = player.howManyCards;
});
},
setupRoundsInfo: function () {
$(DOM_ID_CURRENT_ROUND).innerHTML = `${this.currentRound} / ${this.howManyRounds}`;
},
setupPlayersHiddenCards: function () {
const getCardRotateDeg = (numberOfCards, i) => {
if (numberOfCards === 1) {
return 0;
}
const offset = numberOfCards * 2;
return offset + ((i * -1) * 5);
};
Object.entries(this.displayedNumberOfCardsByPlayerId).forEach((entry) => {
const playerId = entry[0];
const howManyCards = entry[1];
const playerCardsHtml = [];
for (let i = 0; i < howManyCards; i++) {
playerCardsHtml.push(`<div id="player-table-${playerId}-card-${i}" class="${DOM_CLASS_VELONIMO_CARD} ${DOM_CLASS_CARD_BACK_SIDE}" style="transform: rotate(${getCardRotateDeg(howManyCards, i)}deg);"></div>`);
}
$(`player-table-${playerId}-hand-cards`).innerHTML = playerCardsHtml.join('');
$(`player-panel-${playerId}-remaining-cards-number`).innerHTML = howManyCards;
});
},
setupPlayersScore: function () {
Object.entries(this.players).forEach((entry) => {
const player = entry[1];
if (this.scoreCtrl.hasOwnProperty(player.id)) {
this.scoreCtrl[player.id].toValue(player.score);
}
});
},
setupPlayersFinishPosition: function () {
Object.entries(this.players).forEach((entry) => {
const player = entry[1];
const playerCurrentRoundRank = this.getCurrentRoundRankFromPlayerRoundsRanking(player.roundsRanking || {});
dojo.removeClass(`player-table-${player.id}`, `has-finished-1`);
dojo.removeClass(`player-table-${player.id}`, `has-finished-2`);
dojo.removeClass(`player-table-${player.id}`, `has-finished-3`);
dojo.removeClass(`player-table-${player.id}`, `has-finished-4`);
if (playerCurrentRoundRank) {
dojo.addClass(`player-table-${player.id}`, `has-finished-${playerCurrentRoundRank}`);
}
});
},
setupPlayCardsActionButtonIfNeeded: function () {
if (
this.isCurrentPlayerActive()
&& (
this.currentState === 'firstPlayerTurn'
|| this.currentState === 'playerTurn'
)
&& this.currentPlayerCanPlayCards()
) {
this.setupPlayCardsActionButton();
}
},
setupPlayCardsActionButton: function () {
const selectedCards = this.getSelectedPlayerCards();
const selectedCardsValue = this.getCardsValue(selectedCards);
// setup play cards button
if (!$(DOM_ID_ACTION_BUTTON_PLAY_CARDS)) {
this.addActionButton(DOM_ID_ACTION_BUTTON_PLAY_CARDS, _('Play selected cards'), 'onPlayCards');
dojo.place(`<span id="${DOM_ID_ACTION_BUTTON_PLAY_CARDS}-value"> (${selectedCardsValue})</span>`, DOM_ID_ACTION_BUTTON_PLAY_CARDS);
this.addTooltip(`${DOM_ID_ACTION_BUTTON_PLAY_CARDS}-value`, this.getTranslatedTextForSelectedCardsValue(), '');
}
dojo.toggleClass(DOM_ID_ACTION_BUTTON_PLAY_CARDS, DOM_CLASS_DISABLED_ACTION_BUTTON, selectedCardsValue <= this.playedCardsValue);
$(`${DOM_ID_ACTION_BUTTON_PLAY_CARDS}-value`).innerText = ` (${selectedCardsValue})`;
},
setupSelectedCardsValueInPlayerHand: function () {
if ($(DOM_ID_PLAYER_HAND_SELECTED_CARDS)) {
dojo.destroy(DOM_ID_PLAYER_HAND_SELECTED_CARDS);
}
const selectedCards = this.getSelectedPlayerCards();
if (!selectedCards.length) {
return;
}
const getIcon = (cardsValue) => {
if (cardsValue < 20) {
return 'battery-empty';
} else if (cardsValue < 30) {
return 'battery-quarter';
} else if (cardsValue < 40) {
return 'battery-half';
} else if (cardsValue < 50) {
return 'battery-three-quarters';
} else {
return 'battery-full';
}
};
const selectedCardsValue = this.getCardsValue(selectedCards);
dojo.place(`<div id="${DOM_ID_PLAYER_HAND_SELECTED_CARDS}"><i class="fa fa-${getIcon(selectedCardsValue)}"></i><span id="${DOM_ID_PLAYER_HAND_SELECTED_CARDS}-value">${selectedCardsValue}</span></div>`, DOM_ID_PLAYER_HAND_TITLE_WRAPPER_RIGHT);
this.addTooltip(DOM_ID_PLAYER_HAND_SELECTED_CARDS, this.getTranslatedTextForSelectedCardsValue(), '');
},
/**
*
* @param {number} activePlayerId
* @param {Object[]} selectablePlayers Indexed by playerId.
* @param {function(number)} onClickOnActionButton The function arg is the selected playerId.
*/
setupSelectPlayerAction: function (activePlayerId, selectablePlayers, onClickOnActionButton) {
if (this.isCurrentPlayerActive()) {
Object.entries(selectablePlayers).forEach((entry) => {
const player = entry[1];
// setup click on player tables
dojo.addClass(`player-table-${player.id}`, DOM_CLASS_SELECTABLE_PLAYER);
this.connect($(`player-table-${player.id}`), 'onclick', () => onClickOnActionButton.bind(this)(player.id));
// setup click on action buttons
this.addActionButton(`${DOM_ID_ACTION_BUTTON_SELECT_PLAYER}-${player.id}`, player.name, () => onClickOnActionButton.bind(this)(player.id), null, false, 'gray');
dojo.style(`${DOM_ID_ACTION_BUTTON_SELECT_PLAYER}-${player.id}`, 'color', `#${player.color}`);
});
}
},
setupGiveCardsBackAfterPickingActionButton: function () {
this.setupPlayerHandSelectableCards();
const selectedCards = this.getSelectedPlayerCards();
if (!$(DOM_ID_ACTION_BUTTON_GIVE_CARDS)) {
this.addActionButton(DOM_ID_ACTION_BUTTON_GIVE_CARDS, _('Give selected cards'), 'onSelectCardsToGiveBack');
}
dojo.toggleClass(DOM_ID_ACTION_BUTTON_GIVE_CARDS, DOM_CLASS_DISABLED_ACTION_BUTTON, (selectedCards.length === 0) || (selectedCards.length !== this.howManyCardsToGiveBack));
},
moveJerseyToCurrentWinner: function () {
const card = this.addSpecialCardsToCards([CARD_ID_JERSEY_PLUS_TEN], [])[0];
const tooltipTexts = this.getTooltipTextsForCard(card);
const position = this.getCardPositionInSpriteByColorAndValue(card.color, card.value);
const backgroundX = this.getAbsoluteCardBackgroundPositionXFromCardPosition(position) + this.getLogHtmlBackgroundOffsetXForCard(card);
const backgroundY = this.getAbsoluteCardBackgroundPositionYFromCardPosition(position) + this.getLogHtmlBackgroundOffsetYForCard(card);
const applyJersey = (playerId) => {
dojo.place(`<div id="player-table-${playerId}-jersey" class="${DOM_CLASS_PLAYER_JERSEY}" style="background-position: -${backgroundX}px -${backgroundY}px;"></div>`, `player-table-${playerId}-special-cards`);
this.addTooltip(`player-table-${playerId}-jersey`, tooltipTexts[0], tooltipTexts[1]);
dojo.addClass(`player-table-${playerId}`, DOM_CLASS_PLAYER_HAS_JERSEY);
dojo.place(`<div id="player-panel-${playerId}-jersey" class="${DOM_CLASS_JERSEY_IN_PLAYER_PANEL} ${DOM_CLASS_VELONIMO_CARD} ${DOM_CLASS_CARD_FRONT_SIDE}" style="width: ${this.getLogHtmlWidthForCard(card)}px; height: 30px; background-position: -${backgroundX}px -${backgroundY}px;"></div>`, `player-panel-${playerId}-velonimo-right`);
this.addTooltip(`player-panel-${playerId}-jersey`, tooltipTexts[0], tooltipTexts[1]);
};
const removeJersey = (playerId) => {
dojo.removeClass(`player-table-${playerId}`, DOM_CLASS_PLAYER_HAS_JERSEY);
this.fadeOutAndDestroy(`player-table-${playerId}-jersey`);
this.fadeOutAndDestroy(`player-panel-${playerId}-jersey`);
};
Object.entries(this.players).forEach((entry) => {
const player = entry[1];
if (player.isWearingJersey) {
this.currentPlayerHasJersey = this.player_id === player.id;
if (!dojo.hasClass(`player-table-${player.id}`, DOM_CLASS_PLAYER_HAS_JERSEY)) {
applyJersey(player.id);
}
} else {
if (dojo.hasClass(`player-table-${player.id}`, DOM_CLASS_PLAYER_HAS_JERSEY)) {
removeJersey(player.id);
}
}
});
},
moveLegendsBroomWagonToLastLoser: function () {
if (!this.isExtensionLegendsEnabled) {
return;
}
const card = this.addSpecialCardsToCards([CARD_ID_LEGENDS_BROOM_WAGON_PLUS_FIVE], [])[0];
const tooltipTexts = this.getTooltipTextsForCard(card);
const position = this.getCardPositionInSpriteByColorAndValue(card.color, card.value);
const backgroundX = this.getAbsoluteCardBackgroundPositionXFromCardPosition(position) + this.getLogHtmlBackgroundOffsetXForCard(card);
const backgroundY = this.getAbsoluteCardBackgroundPositionYFromCardPosition(position) + this.getLogHtmlBackgroundOffsetYForCard(card);
const applyLegendsBroomWagon = (playerId) => {
dojo.place(`<div id="player-table-${playerId}-legends-broom-wagon" class="${DOM_CLASS_PLAYER_LEGENDS_BROOM_WAGON}" style="background-position: -${backgroundX}px -${backgroundY}px;"></div>`, `player-table-${playerId}-special-cards`);
this.addTooltip(`player-table-${playerId}-legends-broom-wagon`, tooltipTexts[0], tooltipTexts[1]);
dojo.addClass(`player-table-${playerId}`, DOM_CLASS_PLAYER_HAS_LEGENDS_BROOM_WAGON);