-
Notifications
You must be signed in to change notification settings - Fork 2
/
innovation.js
5411 lines (4744 loc) · 272 KB
/
innovation.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 <gisabelli@boardgamearena.com> & Emmanuel Colin <ecolin@boardgamearena.com>
* Innovation implementation : © Jean Portemer <jportemer@gmail.com>
*
* 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.
* -----
*
* innovation.js
*
* Innovation user interface script
*
* In this file, you are describing the logic of your user interface, in Javascript language.
*
*/
define([
"dojo","dojo/_base/declare",
"ebg/core/gamegui",
"ebg/counter",
"ebg/zone"
],
function (dojo, declare) {
return declare("bgagame.innovation", ebg.core.gamegui, {
constructor: function(){
console.log('innovation constructor');
// Global variables of your user interface
this.zone = {};
this.counter = {};
this.card_dimensions = { // Dimensions in the CSS + 2
"S recto" : {"width" : 33, "height" : 47},
"S card" : {"width" : 47, "height" : 33},
"M card" : {"width" : 182, "height" : 126},
"L recto" : {"width" : 316, "height" : 456},
"L card" : {"width" : 456, "height" : 316},
};
this.my_hand_padding = 5; // Must be consistent to what is declared in CSS
this.overlap_for_unsplayed = 3;
this.overlap_for_splay = {
"M card" : {"compact": 3, "expanded": 52}
};
this.HTML_class = {};
this.HTML_class.my_hand = "M card";
this.HTML_class.opponent_hand = "S recto";
this.HTML_class.display = "M card";
this.HTML_class.deck = "S recto";
this.HTML_class.board = "M card";
this.HTML_class.forecast = "S recto";
this.HTML_class.my_forecast_verso = "M card";
this.HTML_class.score = "S recto";
this.HTML_class.my_score_verso = "M card";
this.HTML_class.revealed = "M card";
this.HTML_class.relics = "S recto"
this.HTML_class.achievements = "S recto"
this.HTML_class.special_achievements = "S card"
this.num_cards_in_row = {};
this.num_cards_in_row.my_hand = null; // Will be computed dynamically
this.num_cards_in_row.opponent_hand = null;
this.num_cards_in_row.display = 1;
this.num_cards_in_row.deck = 15;
this.num_cards_in_row.forecast = null;
this.num_cards_in_row.my_forecast_verso = 3;
this.num_cards_in_row.score = null;
this.num_cards_in_row.my_score_verso = 3;
// For board, this.num_cards_in_row is not defined because it's managed by the splay system: the width is defined dynamically
this.num_cards_in_row.revealed = 1;
this.num_cards_in_row.achievements = null; // This is not defined because it has a custom pattern
this.delta = {};
this.delta.my_hand = {"x": 189, "y": 133}; // +7
this.delta.opponent_hand = {"x": 35, "y": 49}; // + 2
this.delta.display = {"x": 189, "y": 133}; // +7
this.delta.deck = {"x": 3, "y": 3}; // overlap
this.delta.forecast = {"x": 35, "y": 49}; // + 2
this.delta.my_forecast_verso = {"x": 189, "y": 133}; // +7
this.delta.score = {"x": 35, "y": 49}; // + 2
this.delta.my_score_verso = {"x": 189, "y": 133}; // +7
// For board, this.delta is not defined because it's managed by the splay system: the width is defined dynamically
this.delta.revealed = {"x": 189, "y": 133}; // +7;
this.delta.achievements = {"x": 35, "y": 49}; // + 2
this.incremental_id = 0;
this.selected_card = null;
this.display_mode = null;
this.view_full = null;
// Counters used to track progress of the Monument special achievement
this.number_of_tucked_cards = 0;
this.number_of_scored_cards = 0;
this.arrows_for_expanded_mode = ">> <<"; // >> <<
this.arrows_for_compact_mode = "<< >>"; // << >>
this.number_of_splayed_piles = null;
this.players = null;
this.saved_HTML_cards = {};
this.initializing = null;
// Special flags used for Publication
this.publication_permuted_zone = null;
this.publication_permutations_done = null;
this.publication_original_items = null;
// Special flag used when a selection has to be made within a stack
this.color_pile = null;
// Special flags to indicate that multiple colors must be chosen
this.choose_two_colors = null;
this.choose_three_colors = null;
this.first_chosen_color = null;
this.second_chosen_color = null;
// Special flag used by Mona Lisa
this.choose_integer = null;
// System to remember what node where last offed and what was their handlers to restore if needed
this.deactivated_cards = null;
this.deactivated_cards_mid_dogma = null;
this.deactivated_cards_can_endorse = null;
this.erased_pagemaintitle_text = null;
},
//****** CODE FOR DEBUG MODE
debug_draw: function() {
var debug_card_list = document.getElementById("debug_card_list");
this.ajaxcall("/innovation/innovation/debug_draw.html",
{
lock: true,
card_id: debug_card_list.value
},
this, function(result){}, function(is_error){},
);
},
debug_meld: function() {
var debug_card_list = document.getElementById("debug_card_list");
this.ajaxcall("/innovation/innovation/debug_meld.html",
{
lock: true,
card_id: debug_card_list.value
},
this, function(result){}, function(is_error){},
);
},
debug_tuck: function() {
var debug_card_list = document.getElementById("debug_card_list");
this.ajaxcall("/innovation/innovation/debug_tuck.html",
{
lock: true,
card_id: debug_card_list.selectedIndex
},
this, function(result){}, function(is_error){},
);
},
debug_score: function () {
var debug_card_list = document.getElementById("debug_card_list");
this.ajaxcall("/innovation/innovation/debug_score.html",
{
lock: true,
card_id: debug_card_list.value
},
this, function (result) { }, function (is_error) {}
);
},
debug_achieve: function () {
var debug_card_list = document.getElementById("debug_card_list");
this.ajaxcall("/innovation/innovation/debug_achieve.html",
{
lock: true,
card_id: debug_card_list.value
},
this, function (result) { }, function (is_error) {}
);
},
debug_return: function () {
var debug_card_list = document.getElementById("debug_card_list");
this.ajaxcall("/innovation/innovation/debug_return.html",
{
lock: true,
card_id: debug_card_list.value
},
this, function (result) { }, function (is_error) {}
);
},
debug_topdeck: function () {
var debug_card_list = document.getElementById("debug_card_list");
this.ajaxcall("/innovation/innovation/debug_topdeck.html",
{
lock: true,
card_id: debug_card_list.value
},
this, function (result) { }, function (is_error) {}
);
},
debug_dig: function () {
var debug_card_list = document.getElementById("debug_card_list");
this.ajaxcall("/innovation/innovation/debug_dig.html",
{
lock: true,
card_id: debug_card_list.value
},
this, function (result) { }, function (is_error) {}
);
},
debug_foreshadow: function () {
var debug_card_list = document.getElementById("debug_card_list");
this.ajaxcall("/innovation/innovation/debug_foreshadow.html",
{
lock: true,
card_id: debug_card_list.value
},
this, function (result) { }, function (is_error) {}
);
},
debug_unsplay: function() {
var debug_color_list = document.getElementById("debug_color_list");
this.ajaxcall("/innovation/innovation/debug_splay.html",
{
lock: true,
color: debug_color_list.value,
direction: 0
},
this, function (result) { }, function (is_error) {}
);
},
debug_splay_left: function() {
var debug_color_list = document.getElementById("debug_color_list");
this.ajaxcall("/innovation/innovation/debug_splay.html",
{
lock: true,
color: debug_color_list.value,
direction: 1
},
this, function (result) { }, function (is_error) {}
);
},
debug_splay_right: function() {
var debug_color_list = document.getElementById("debug_color_list");
this.ajaxcall("/innovation/innovation/debug_splay.html",
{
lock: true,
color: debug_color_list.value,
direction: 2
},
this, function (result) { }, function (is_error) {}
);
},
debug_splay_up: function() {
var debug_color_list = document.getElementById("debug_color_list");
this.ajaxcall("/innovation/innovation/debug_splay.html",
{
lock: true,
color: debug_color_list.value,
direction: 3
},
this, function (result) { }, function (is_error) {}
);
},
//******
/*
setup:
This method must set up the game user interface according to current game situation specified
in parameters.
The method is called each time the game interface is displayed to a player, ie:
_ when the game starts
_ when a player refreshes the game page (F5)
"gamedatas" argument contains all datas retrieved by your "getAllDatas" PHP method.
*/
setup: function (gamedatas) {
dojo.destroy('debug_output');
//****** CODE FOR DEBUG MODE
if (!this.isSpectator && gamedatas.debug_mode == 1) {
var main_area = $('main_area');
// Prepend UI elements for debug area
main_area.innerHTML =
"</br><select id='debug_color_list'></select>"
+ "<button id='debug_unsplay' class='action-button debug_button bgabutton bgabutton_red'>UNSPLAY</button>"
+ "<button id='debug_splay_left' class='action-button debug_button bgabutton bgabutton_red'>SPLAY LEFT</button>"
+ "<button id='debug_splay_right' class='action-button debug_button bgabutton bgabutton_red'>SPLAY RIGHT</button>"
+ "<button id='debug_splay_up' class='action-button debug_button bgabutton bgabutton_red'>SPLAY UP</button>"
+ main_area.innerHTML;
if (gamedatas.echoes_expansion_enabled) {
main_area.innerHTML = "<button id='debug_foreshadow' class='action-button debug_button bgabutton bgabutton_red'>FORESHADOW</button>" + main_area.innerHTML;
}
if (gamedatas.artifacts_expansion_enabled) {
main_area.innerHTML = "<button id='debug_dig' class='action-button debug_button bgabutton bgabutton_red'>DIG</button>" + main_area.innerHTML;
}
main_area.innerHTML =
"<select id='debug_card_list'></select>"
+ "<button id='debug_draw' class='action-button debug_button bgabutton bgabutton_red'>DRAW</button>"
+ "<button id='debug_meld' class='action-button debug_button bgabutton bgabutton_red'>MELD</button>"
+ "<button id='debug_tuck' class='action-button debug_button bgabutton bgabutton_red'>TUCK</button>"
+ "<button id='debug_score' class='action-button debug_button bgabutton bgabutton_red'>SCORE</button>"
+ "<button id='debug_achieve' class='action-button debug_button bgabutton bgabutton_red'>ACHIEVE</button>"
+ "<button id='debug_return' class='action-button debug_button bgabutton bgabutton_red'>RETURN</button>"
+ "<button id='debug_topdeck' class='action-button debug_button bgabutton bgabutton_red'>TOPDECK</button>"
+ main_area.innerHTML;
// Populate dropdown lists
for (var i = 0; i < Object.keys(gamedatas.cards).length; i++) {
var key = Object.keys(gamedatas.cards)[i];
var card = gamedatas.cards[key];
// NOTE: The colors do not need to be translated because they only appear in the Studio anyway.
var color = card.color == 0 ? "blue" : card.color == 1 ? "red" : card.color == 2 ? "green" : card.color == 3 ? "yellow" : "purple";
if (this.isFountain(card.id)) {
$('debug_card_list').innerHTML += `<option value='${card.id}'> ${card.id} - Fountain (${color})</option>`;
} else if (this.isFlag(card.id)) {
$('debug_card_list').innerHTML += `<option value='${card.id}'> ${card.id} - Flag (${color})</option>`;
} else {
$('debug_card_list').innerHTML += `<option value='${card.id}'> ${card.id} - ${card.name} (Age ${card.age})</option>`;
}
}
$('debug_color_list').innerHTML += `<option value='0'>Blue</option>`;
$('debug_color_list').innerHTML += `<option value='1'>Red</option>`;
$('debug_color_list').innerHTML += `<option value='2'>Green</option>`;
$('debug_color_list').innerHTML += `<option value='3'>Yellow</option>`;
$('debug_color_list').innerHTML += `<option value='4'>Purple</option>`;
// Trigger events when buttons are clicked
dojo.connect($('debug_draw'), 'onclick', this, 'debug_draw');
dojo.connect($('debug_meld'), 'onclick', this, 'debug_meld');
dojo.connect($('debug_tuck'), 'onclick', this, 'debug_tuck');
dojo.connect($('debug_score'), 'onclick', this, 'debug_score');
dojo.connect($('debug_achieve'), 'onclick', this, 'debug_achieve');
dojo.connect($('debug_return'), 'onclick', this, 'debug_return');
dojo.connect($('debug_topdeck'), 'onclick', this, 'debug_topdeck');
if (gamedatas.artifacts_expansion_enabled) {
dojo.connect($('debug_dig'), 'onclick', this, 'debug_dig');
}
if (gamedatas.echoes_expansion_enabled) {
dojo.connect($('debug_foreshadow'), 'onclick', this, 'debug_foreshadow');
}
dojo.connect($('debug_unsplay'), 'onclick', this, 'debug_unsplay');
dojo.connect($('debug_splay_left'), 'onclick', this, 'debug_splay_left');
dojo.connect($('debug_splay_right'), 'onclick', this, 'debug_splay_right');
dojo.connect($('debug_splay_up'), 'onclick', this, 'debug_splay_up');
}
//******
this.my_score_verso_window = new dijit.Dialog({ 'title': _("Cards in your score pile (opponents cannot see this)") });
this.my_forecast_verso_window = new dijit.Dialog({ 'title': _("Cards in your forecast (opponents cannot see this)") });
this.text_for_expanded_mode = _("Show compact");
this.text_for_compact_mode = _("Show expanded");
this.text_for_view_normal = _("Look at all cards in piles");
this.text_for_view_full = _("Resume normal view");
// GENERAL INFO
this.cards = gamedatas.cards;
this.players = gamedatas.players;
this.number_of_achievements_needed_to_win = gamedatas.number_of_achievements_needed_to_win;
// PLAYER PANELS
for (var player_id in this.players) {
dojo.place(`<span class='achievements_to_win'>/${this.number_of_achievements_needed_to_win}<span>`, $('player_score_' + player_id), "after");
dojo.place(this.format_block('jstpl_player_panel', {'player_id':player_id}), $('player_board_' + player_id));
for (var icon=1; icon<=6; icon++) {
var infos = {'player_id':player_id, 'icon': icon};
dojo.place(this.format_block('jstpl_ressource_icon', infos), $('symbols_' + player_id));
dojo.place(this.format_block('jstpl_ressource_count', infos), $('ressource_counts_' + player_id));
}
}
this.addCustomTooltipToClass("score_count", _("Score"), "");
this.addCustomTooltipToClass("hand_count", _("Number of cards in hand"), "");
this.addCustomTooltipToClass("max_age_on_board", _("Max age on board top cards"), "");
this.addCustomTooltipToClass("forecast_count", _("Number of cards in forecast"), "");
for (var icon=1; icon<=6; icon++) {
this.addCustomTooltipToClass("ressource_" + icon, _("Number of visible ${icons} on the board").replace('${icons}', this.square('P', 'icon', icon, 'in_tooltip')), "");
}
// Counters for score
this.counter.score = {};
for(var player_id in this.players) {
this.counter.score[player_id] = new ebg.counter();
this.counter.score[player_id].create($("score_count_" + player_id));
this.counter.score[player_id].setValue(gamedatas.score[player_id]);
}
// Counters for max age on board
this.counter.max_age_on_board = {};
for(var player_id in this.players) {
this.counter.max_age_on_board[player_id] = new ebg.counter();
this.counter.max_age_on_board[player_id].create($("max_age_on_board_" + player_id));
this.counter.max_age_on_board[player_id].setValue(gamedatas.max_age_on_board[player_id]);
}
// Counters for ressources
this.counter.ressource_count = {};
for (var player_id in this.players) {
this.counter.ressource_count[player_id] = {};
for (var icon = 1; icon <= 6; icon++) {
this.counter.ressource_count[player_id][icon] = new ebg.counter();
this.counter.ressource_count[player_id][icon].create($("ressource_count_" + player_id + "_" + icon));
this.counter.ressource_count[player_id][icon].setValue(gamedatas.ressource_counts[player_id][icon]);
}
}
if (gamedatas.artifact_on_display_icons != null && gamedatas.artifact_on_display_icons.resource_icon != null) {
this.updateResourcesForArtifactOnDisplay(
gamedatas.active_player,
gamedatas.artifact_on_display_icons.resource_icon,
gamedatas.artifact_on_display_icons.resource_count_delta);
}
// Action indicator
for(var player_id in this.players) {
dojo.place("<div id='action_indicator_" + player_id + "' class='action_indicator'></div>", $('ressources_' + player_id), 'after');
}
if (gamedatas.active_player !== null) {
this.givePlayerActionCard(gamedatas.active_player, gamedatas.action_number);
}
this.artifacts_expansion_enabled = gamedatas.artifacts_expansion_enabled;
this.relics_enabled = gamedatas.relics_enabled;
this.cities_expansion_enabled = gamedatas.cities_expansion_enabled;
this.echoes_expansion_enabled = gamedatas.echoes_expansion_enabled;
this.figures_expansion_enabled = gamedatas.figures_expansion_enabled;
this.num_sets_in_play = 1 + this.artifacts_expansion_enabled + this.cities_expansion_enabled + this.echoes_expansion_enabled + this.figures_expansion_enabled;
if (this.num_sets_in_play > 2) {
this.delta.deck = {"x": 0.25, "y": 0.25}; // overlap
}
// DECKS
this.zone.deck = {};
for (var type = 0; type <= 4; type++) {
this.zone.deck[type] = {};
for (var age = 1; age <= 10; age++) {
// Creation of the zone
this.zone.deck[type][age] = this.createZone('deck', 0, type, age, null, grouped_by_age_type_and_is_relic=false, counter_method="COUNT", counter_display_zero=false)
this.setPlacementRules(this.zone.deck[type][age], left_to_right=true)
// Add cards to zone according to the current situation
var num_cards = gamedatas.deck_counts[type][age];
for (var i=0; i<num_cards; i++) {
this.createAndAddToZone(this.zone.deck[type][age], i, age, type, /*is_relic=*/ 0, null, dojo.body(), null);
}
// TODO(FIGURES): Handle the case where there are 5 sets.
if (this.num_sets_in_play == 3) {
dojo.addClass(`deck_count_${type}_${age}`, 'three_sets');
dojo.addClass(`deck_pile_${type}_${age}`, 'three_sets');
} else if (this.num_sets_in_play == 4) {
dojo.addClass(`deck_count_${type}_${age}`, 'four_sets');
dojo.addClass(`deck_pile_${type}_${age}`, 'four_sets');
}
}
}
if (!gamedatas.artifacts_expansion_enabled) {
dojo.byId('deck_set_2_1').style.display = 'none';
dojo.byId('deck_set_2_2').style.display = 'none';
}
if (!gamedatas.cities_expansion_enabled) {
dojo.byId('deck_set_3_1').style.display = 'none';
dojo.byId('deck_set_3_2').style.display = 'none';
}
if (!gamedatas.echoes_expansion_enabled) {
dojo.byId('deck_set_4_1').style.display = 'none';
dojo.byId('deck_set_4_2').style.display = 'none';
}
if (!gamedatas.figures_expansion_enabled) {
dojo.byId('deck_set_5_1').style.display = 'none';
dojo.byId('deck_set_5_2').style.display = 'none';
}
// AVAILABLE RELICS
this.zone.relics = {};
this.zone.relics["0"] = this.createZone('relics', 0, null, null, null, grouped_by_age_type_and_is_relic = true);
this.setPlacementRulesForRelics();
if (gamedatas.relics_enabled) {
for (var i = 0; i < gamedatas.unclaimed_relics.length; i++) {
var relic = gamedatas.unclaimed_relics[i];
this.createAndAddToZone(this.zone.relics["0"], i, relic.age, relic.type, relic.is_relic, null, dojo.body(), null);
if (this.canShowCardTooltip(relic['id'])) {
this.addTooltipForCard(relic);
}
}
} else {
dojo.byId('available_relics_container').style.display = 'none';
}
// AVAILABLE ACHIEVEMENTS
// Creation of the zone
this.zone.achievements = {};
// Add cards to zone according to the current situation
if (gamedatas.unclaimed_standard_achievement_counts !== null) {
this.zone.achievements["0"] = this.createZone('achievements', 0, null, null, null, grouped_by_age_type_and_is_relic = true);
this.setPlacementRulesForAchievements();
for (var type = 0; type <= 4; type++) {
for (var is_relic = 0; is_relic <= 1; is_relic++) {
for (var age = 1; age <= 10; age++) {
var num_cards = gamedatas.unclaimed_standard_achievement_counts[type][is_relic][age];
for (var i = 0; i < num_cards; i++) {
this.createAndAddToZone(this.zone.achievements["0"], i, age, type, is_relic, null, dojo.body(), null);
if (!this.isSpectator) {
// Construct card object so that we can add a tooltip to the achievement
// TODO(LATER): Simplify addTooltipForStandardAchievement once the other callsite is removed.
var achievement = {'location': 'achievements', 'owner': 0, 'type': type, 'age': age, 'is_relic': is_relic};
this.addTooltipForStandardAchievement(achievement);
}
}
}
}
}
} else {
// TODO(LATER): Remove this once it is safe to do so.
this.zone.achievements["0"] = this.createZone('achievements', 0);
this.setPlacementRulesForAchievements();
for(var i=0; i<gamedatas.unclaimed_achievements.length; i++) {
var achievement = gamedatas.unclaimed_achievements[i];
if (achievement.age === null) {
continue;
}
this.createAndAddToZone(this.zone.achievements["0"], i, achievement.age, achievement.type, achievement.is_relic, null, dojo.body(), null);
if (!this.isSpectator) {
this.addTooltipForStandardAchievement(achievement);
}
}
}
// AVAILABLE SPECIAL ACHIEVEMENTS
// Creation of the zone
this.zone.special_achievements = {};
this.zone.special_achievements["0"] = this.createZone('special_achievements', 0);
this.setPlacementRulesForSpecialAchievements();
// Add cards to zone according to the current situation
for (var i=0; i<gamedatas.unclaimed_achievements.length; i++) {
var achievement = gamedatas.unclaimed_achievements[i];
if (achievement.age !== null) {
continue;
}
this.createAndAddToZone(this.zone.special_achievements["0"], i, null, achievement.type, achievement.is_relic, achievement.id, dojo.body(), null);
this.addTooltipForCard(achievement);
}
// Add another button here to open up the special achievements popup
var button = this.format_string_recursive("<i id='browse_special_achievements_button' class='bgabutton bgabutton_gray'>${button_text}</i>", {'button_text': _("Browse"), 'i18n': ['button_text']});
dojo.place(button, 'special_achievements', 'after');
this.on(dojo.query('#browse_special_achievements_button'), 'onclick', 'click_open_special_achievement_browsing_window');
// PLAYERS' HANDS
this.zone.hand = {};
for (var player_id in this.players) {
// Creation of the zone
var zone = this.createZone('hand', player_id, null, null, null, grouped_by_age_type_and_is_relic=true, counter_method="COUNT", counter_display_zero=true);
this.zone.hand[player_id] = zone;
this.setPlacementRules(zone, left_to_right=true);
// Add cards to zone according to the current situation
if (player_id == this.player_id) {
for (var i=0; i<gamedatas.my_hand.length; i++) {
var card = gamedatas.my_hand[i];
this.createAndAddToZone(zone, card.position, card.age, card.type, card.is_relic, card.id, dojo.body(), card);
if (gamedatas.turn0 && card.selected == 1) {
this.selected_card = card;
}
// Add tooltip
this.addTooltipForCard(card);
}
} else {
for (var type = 0; type <= 4; type++) {
for (var is_relic = 0; is_relic <= 1; is_relic++) {
for (var age = 1; age <= 10; age++) {
var num_cards = gamedatas.hand_counts[player_id][type][is_relic][age];
for (var i = 0; i < num_cards; i++) {
this.createAndAddToZone(zone, i, age, type, is_relic, null, dojo.body(), null);
if (is_relic) {
// Construct card object so that we can add a tooltip to the relic
var relic = {'location': 'hand', 'owner': player_id, 'type': type, 'age': age, 'is_relic': is_relic, 'id': 212 + age};
if (this.canShowCardTooltip(relic['id'])) {
this.addTooltipForCard(relic);
}
}
}
}
}
}
}
}
// PLAYERS' ARTIFACTS ON DISPLAY
this.zone.display = {};
for (var player_id in this.players) {
if (!gamedatas.artifacts_expansion_enabled) {
dojo.byId('display_container_' + player_id).style.display = 'none';
continue;
}
// Creation of the zone
var zone = this.createZone('display', player_id, null, null, null);
this.zone.display[player_id] = zone;
this.setPlacementRules(zone, left_to_right=true);
// Add card to zone if it exists
var card = gamedatas.artifacts_on_display[player_id];
if (card != null) {
this.createAndAddToZone(zone, card.position, card.age, card.type, card.is_relic, card.id, dojo.body(), card);
this.addTooltipForCard(card);
}
}
// PLAYERS' FORECAST
this.zone.forecast = {};
for (var player_id in this.players) {
// Creation of the zone
this.zone.forecast[player_id] = this.createZone('forecast', player_id, null, null, null, grouped_by_age_type_and_is_relic=true, counter_method="COUNT", counter_display_zero=true);
this.setPlacementRules(this.zone.forecast[player_id], left_to_right=true);
// Add cards to zone according to the current situation
for (var type = 0; type <= 4; type++) {
for (var is_relic = 0; is_relic <= 1; is_relic++) {
var forecast_count = gamedatas.forecast_counts[player_id][type][is_relic];
for (var age = 1; age <= 10; age++) {
var num_cards = forecast_count[age];
for(var i = 0; i < num_cards; i++) {
this.createAndAddToZone(this.zone.forecast[player_id], i, age, type, is_relic, null, dojo.body(), null);
}
}
}
}
if (!this.echoes_expansion_enabled) {
dojo.byId('forecast_text_' + player_id).style.display = 'none';
dojo.byId('forecast_count_container_' + player_id).style.display = 'none';
}
}
// PLAYERS' SCORE
this.zone.score = {};
for (var player_id in this.players) {
// Creation of the zone
this.zone.score[player_id] = this.createZone('score', player_id, null, null, null, grouped_by_age_type_and_is_relic=true);
this.setPlacementRules(this.zone.score[player_id], left_to_right=false);
// Add cards to zone according to the current situation
for (var type = 0; type <= 4; type++) {
for (var is_relic = 0; is_relic <= 1; is_relic++) {
var score_count = gamedatas.score_counts[player_id][type][is_relic];
for (var age = 1; age <= 10; age++) {
var num_cards = score_count[age];
for(var i = 0; i < num_cards; i++) {
this.createAndAddToZone(this.zone.score[player_id], i, age, type, is_relic, null, dojo.body(), null);
if (is_relic) {
// Construct card object so that we can add a tooltip to the relic
var relic = {'location': 'hand', 'owner': player_id, 'type': type, 'age': age, 'is_relic': is_relic, 'id': 212 + age};
if (this.canShowCardTooltip(relic['id'])) {
this.addTooltipForCard(relic);
}
}
}
}
}
}
}
// My forecast: create an extra zone to show the versos of the cards at will in a windows
if (!this.isSpectator && this.echoes_expansion_enabled) {
this.my_forecast_verso_window.attr("content", "<div id='my_forecast_verso'></div><a id='forecast_close_window' class='bgabutton bgabutton_blue'>" + _("Close") + "</a>");
this.zone.my_forecast_verso = this.createZone('my_forecast_verso', this.player_id, null, null, null, grouped_by_age_type_and_is_relic=true);
this.setPlacementRules(this.zone.my_forecast_verso, left_to_right=true);
for (var i = 0; i < gamedatas.my_forecast.length; i++) {
var card = gamedatas.my_forecast[i];
this.createAndAddToZone(this.zone.my_forecast_verso, card.position, card.age, card.type, card.is_relic, card.id, dojo.body(), card);
this.addTooltipForCard(card);
}
// Provide links to get access to that window and close it
dojo.connect($('forecast_text_' + this.player_id), 'onclick', this, 'click_display_forecast_window');
dojo.connect($('forecast_close_window'), 'onclick', this, 'click_close_forecast_window');
}
// My score: create an extra zone to show the versos of the cards at will in a windows
if (!this.isSpectator) {
this.my_score_verso_window.attr("content", "<div id='my_score_verso'></div><a id='score_close_window' class='bgabutton bgabutton_blue'>" + _("Close") + "</a>");
this.zone.my_score_verso = this.createZone('my_score_verso', this.player_id, null, null, null, grouped_by_age_type_and_is_relic=true);
this.setPlacementRules(this.zone.my_score_verso, left_to_right=true);
for (var i = 0; i < gamedatas.my_score.length; i++) {
var card = gamedatas.my_score[i];
this.createAndAddToZone(this.zone.my_score_verso, card.position, card.age, card.type, card.is_relic, card.id, dojo.body(), card);
this.addTooltipForCard(card);
}
// Provide links to get access to that window and close it
dojo.connect($('score_text_' + this.player_id), 'onclick', this, 'click_display_score_window');
dojo.connect($('score_close_window'), 'onclick', this, 'click_close_score_window');
}
// PLAYERS' ACHIEVEMENTS
for (var player_id in this.players) {
// Creation of the zone
this.zone.achievements[player_id] = this.createZone('achievements', player_id);
this.setPlacementRules(this.zone.achievements[player_id], left_to_right=true);
// Add cards to zone according to the current situation
var achievements = gamedatas.claimed_achievements[player_id];
for(var i = 0; i < achievements.length; i++){
var achievement = achievements[i];
if (this.isFlag(parseInt(achievement.id)) || this.isFountain(parseInt(achievement.id))) {
this.createAndAddToZone(this.zone.achievements[player_id], i, null, achievement.type, achievement.is_relic, achievement.id, dojo.body(), achievement);
this.addTooltipForCard(achievement);
} else if (achievement.age == null) { // Special achievement
this.createAndAddToZone(this.zone.achievements[player_id], i, null, achievement.type, achievement.is_relic, achievement.id, dojo.body(), null);
this.addTooltipForCard(achievement);
} else {
// Normal achievement or relic
this.createAndAddToZone(this.zone.achievements[player_id], i, achievement.age, achievement.type, achievement.is_relic, null, dojo.body(), null);
if (achievement.is_relic && this.canShowCardTooltip(achievement.id)) {
this.addTooltipForCard(achievement);
}
}
}
}
if (!this.isSpectator) {
if (this.echoes_expansion_enabled) {
dojo.query('#progress_' + this.player_id + ' .forecast_container > p, #progress_' + this.player_id + ' .achievement_container > p').addClass('two_lines');
dojo.query('#progress_' + this.player_id + ' .forecast_container > p')[0].innerHTML += '<br /><span class="minor_information">' + _('(view cards)') + '</span>';
}
dojo.query('#progress_' + this.player_id + ' .score_container > p, #progress_' + this.player_id + ' .achievement_container > p').addClass('two_lines');
dojo.query('#progress_' + this.player_id + ' .score_container > p')[0].innerHTML += '<br /><span class="minor_information">' + _('(view cards)') + '</span>';
}
// PLAYER BOARD
// Display mode
if (this.isSpectator) { // The wishes for splaying can't be saved if the spectator refreshes
// We set manually a default value
// The spectator can later change this using the buttons, the same way the players do
this.display_mode = true; // Show expanded by default
this.view_full = false; // Don't show view full by default
}
else {
this.display_mode = gamedatas.display_mode;
this.view_full = gamedatas.view_full;
}
// Stacks
this.zone.board = {};
this.number_of_splayed_piles = 0;
for (var player_id in this.players) {
this.zone.board[player_id] = {};
var player_board = gamedatas.board[player_id];
var player_splay_directions = gamedatas.board_splay_directions[player_id];
var player_splay_directions_in_clear = gamedatas.board_splay_directions_in_clear[player_id];
for(var color = 0; color < 5; color++){
var splay_direction = player_splay_directions[color];
var splay_direction_in_clear = player_splay_directions_in_clear[color];
// Creation of the zone
this.zone.board[player_id][color] = this.createZone('board', player_id, null, null, color, grouped_by_age_type_and_is_relic=false, counter_method="COUNT", counter_display_zero=false);
// Disable pile counters
if (this.prefs[113].value == 1) {
dojo.style(`pile_count_${player_id}_${color}`, 'display', 'none');
}
// Splay indicator
dojo.addClass('splay_indicator_' + player_id + '_' + color, 'splay_' + splay_direction);
if (splay_direction > 0) {
this.number_of_splayed_piles++;
this.addCustomTooltip('splay_indicator_' + player_id + '_' + color, dojo.string.substitute(_('This stack is splayed ${direction}.'), {'direction': '<b>' + splay_direction_in_clear + '</b>'}), '')
}
// Add cards to zone according to the current situation
var cards_in_pile = player_board[color];
for(var i = 0; i < cards_in_pile.length; i++){
var card = cards_in_pile[i];
this.createAndAddToZone(this.zone.board[player_id][color], card.position, card.age, card.type, card.is_relic, card.id, dojo.body(), card)
// Add tooltip
this.addTooltipForCard(card);
}
this.refreshSplay(this.zone.board[player_id][color], splay_direction)
}
}
// REVEALED ZONE
this.zone.revealed = {};
for (var player_id in this.players) {
var zone = this.createZone('revealed', player_id, null, null, null);
this.zone.revealed[player_id] = zone;
dojo.style(zone.container_div, 'display', 'none');
this.setPlacementRules(zone, left_to_right=true);
var revealed_cards = gamedatas.revealed[player_id];
for(var i = 0; i < revealed_cards.length; i++){
var card = revealed_cards[i];
this.createAndAddToZone(zone, card.position, card.age, card.type, card.is_relic, card.id, dojo.body(), card)
// Add tooltip
this.addTooltipForCard(card);
}
}
// Button for view full
this.addButtonForViewFull();
// Button for display mode
this.addButtonForSplayMode();
if (this.number_of_splayed_piles > 0) { // If at least there is one splayed color on any player board
this.enableButtonForSplayMode();
}
// Button for looking at cards (including special achievements)
this.addButtonForBrowsingCards();
for (var i = 0; i < gamedatas.unclaimed_achievements.length; i++) {
var achievement = gamedatas.unclaimed_achievements[i];
if (achievement.age === null) {
dojo.query('#special_achievement_summary_' + achievement.id).addClass('unclaimed');
}
}
if (!this.isSpectator) {
this.number_of_tucked_cards = gamedatas.monument_counters.number_of_tucked_cards;
this.number_of_scored_cards = gamedatas.monument_counters.number_of_tucked_cards;
this.refreshSpecialAchievementProgression();
}
// REFERENCE CARD
this.addTooltipForReferenceCard();
// CURRENT DOGMA CARD EFFECT
if (gamedatas.JSCardEffectQuery !== null) {
// Highlight the current effect if visible
dojo.query(gamedatas.JSCardEffectQuery).addClass('current_effect');
}
// Hide player's area if they have been eliminated from the game (e.g. Exxon Valdez)
for (var player_id in this.players) {
if (this.players[player_id].player_eliminated == 1) {
dojo.byId('player_' + player_id).style.display = 'none';
}
}
this.default_viewport = "width=640"; // 640 is set in game_interface_width.min in gameinfos.inc.php
this.onScreenWidthChange();
this.refreshLayout();
// Force refresh page on resize if width changes
var window_width = dojo.window.getBox().w;
var self = this;
window.onresize = function() {
if (window.RT) {
clearTimeout(window.RT);
}
window.RT = setTimeout(function() {
if (window_width != dojo.window.getBox().w) { // If there is an actual change of the width of the viewport
self.refreshLayout();
}
}, 100);
}
// Setup game notifications to handle (see "setupNotifications" method below)
this.setupNotifications();
this.initializing = true;
console.log("Ending game setup");
},
/* [Undocumented] Override BGA framework functions to call onLoadingComplete when loading is done */
setLoader(value, max) {
this.inherited(arguments);
if (!this.isLoadingComplete && value >= 100) {
this.isLoadingComplete = true;
this.onLoadingComplete();
}
},
onLoadingComplete() {
// Add card tooltips to existing game log messages
for (var i = 0; i < this.cards.length; i++) {
var card_id = this.cards[i].id;
// For some reason, after a page refresh, each entry in the game log is located in two diffferent
// spots on the page, meaning that each span holding a card name no longer has a unique ID (since
// it appears exactly twice), and BGA's framework to add a tooltip requires that it has a unique ID.
// The workaround here is to first remove the extra IDs, before trying to add the tooltips.
dojo.query("#chatbar .card_id_" + card_id).removeAttr('id');
var elements = dojo.query(".card_id_" + card_id);
if (elements.length > 0 && this.canShowCardTooltip(card_id)) {
this.addCustomTooltipToClass("card_id_" + card_id, this.getTooltipForCard(card_id), "");
}
}
},
onScreenWidthChange: function () {
// Remove broken "zoom" property added by BGA framework
this.gameinterface_zoomFactor = 1;
$("page-content").style.removeProperty("zoom");
$("page-title").style.removeProperty("zoom");
$("right-side-first-part").style.removeProperty("zoom");
},
refreshLayout : function () {
var on_mobile = dojo.hasClass('ebd-body', 'mobile_version');
var window_width = Math.max(dojo.window.getBox().w, 640); // 640 is set in game_interface_width.min in gameinfos.inc.php
var player_panel_width = on_mobile ? 0 : dojo.position('right-side').w + 10;
var decks_width = 214;
var decks_on_right = this.prefs[112].value == 1;
if (decks_on_right) {
var main_area_width = window_width - player_panel_width - decks_width;
} else if (on_mobile) {
var main_area_width = window_width;
} else {
var main_area_width = window_width - player_panel_width;
}
dojo.style('main_area', 'width', main_area_width + 'px');
if (decks_on_right) {
dojo.style('main_area_wrapper', 'flex-direction', 'row');
dojo.style('decks_and_available_achievements', 'flex-direction', 'column');
dojo.style('available_relics_and_achievements_container', 'display', 'unset');
} else {
dojo.style('main_area_wrapper', 'flex-direction', 'column');
dojo.style('decks_and_available_achievements', 'flex-direction', 'row');
dojo.style('available_relics_and_achievements_container', 'display', 'inline-block');
}
if (this.num_sets_in_play == 1) {
dojo.style('decks', 'display', 'flex');
} else {
dojo.style('decks', 'display', 'inline-block');
}
// NOTE: This is used to get a reference on an arbitrary player. This is important because
// targeting this.player_id doesn't work in spectator mode.
var any_player_id = Object.keys(this.players)[0];
var main_area_inner_width = main_area_width - 14;
var reference_card_width = dojo.position('reference_card_' + any_player_id).w;
var buffer = this.echoes_expansion_enabled ? 10 : 0;
// Calculation relies on this.delta.forecast.x == this.delta.score.x == this.delta.achievements.x
var num_forecast_score_achievements_cards = Math.floor((main_area_inner_width - reference_card_width - buffer) / this.delta.score.x);
this.num_cards_in_row.achievements = Math.floor(num_forecast_score_achievements_cards / 3);
if (this.num_cards_in_row.achievements < 1) {
this.num_cards_in_row.achievements = 1;
}
if (this.num_cards_in_row.achievements > this.number_of_achievements_needed_to_win) {
this.num_cards_in_row.achievements = this.number_of_achievements_needed_to_win;
}
// If we're splitting the achievements across two rows, let's make the rows as even as possible
if (this.number_of_achievements_needed_to_win / 2 < this.num_cards_in_row.achievements && this.num_cards_in_row.achievements < this.number_of_achievements_needed_to_win) {
this.num_cards_in_row.achievements = Math.ceil(this.number_of_achievements_needed_to_win / 2);
}
if (this.echoes_expansion_enabled) {
this.num_cards_in_row.forecast = Math.floor((num_forecast_score_achievements_cards - this.num_cards_in_row.achievements) / 2);
this.num_cards_in_row.score = this.num_cards_in_row.forecast;
} else {
this.num_cards_in_row.forecast = null;
this.num_cards_in_row.score = num_forecast_score_achievements_cards - this.num_cards_in_row.achievements;
}
var forecast_container_width = this.num_cards_in_row.forecast == null ? 0 : this.num_cards_in_row.forecast * this.delta.forecast.x;
var achievement_container_width = this.num_cards_in_row.achievements * this.delta.achievements.x;
var score_container_width = main_area_inner_width - forecast_container_width - reference_card_width - achievement_container_width;
for (var player_id in this.players) {
dojo.style('forecast_container_' + player_id, 'width', forecast_container_width + 'px');
dojo.style('forecast_' + player_id, 'width', forecast_container_width + 'px');
dojo.setStyle(this.zone.forecast[player_id].container_div, 'width', forecast_container_width + "px");
dojo.style('score_container_' + player_id, 'width', score_container_width + 'px');
dojo.style('score_' + player_id, 'width', score_container_width + 'px');
dojo.setStyle(this.zone.score[player_id].container_div, 'width', score_container_width + "px");
dojo.style('achievement_container_' + player_id, 'width', achievement_container_width + 'px');
dojo.style('achievements_' + player_id, 'width', achievement_container_width + 'px');
dojo.setStyle(this.zone.achievements[player_id].container_div, 'width', achievement_container_width + "px");
dojo.style('progress_' + player_id, 'width', main_area_inner_width + 'px');
}
// Defining the number of cards hand zone can host
this.num_cards_in_row.my_hand = Math.floor(main_area_inner_width / this.delta.my_hand.x);
this.num_cards_in_row.opponent_hand = Math.floor(main_area_inner_width / this.delta.opponent_hand.x);
// TODO(LATER): Figure out how to disable the animations while resizing the zones.
for (var player_id in this.players) {
this.zone.forecast[player_id].updateDisplay();
this.zone.score[player_id].updateDisplay();
this.zone.achievements[player_id].updateDisplay();
this.zone.hand[player_id].updateDisplay();