-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpokemon-match-control.html
More file actions
2078 lines (1789 loc) · 92.6 KB
/
pokemon-match-control.html
File metadata and controls
2078 lines (1789 loc) · 92.6 KB
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
<!DOCTYPE html>
<html lang="en" data-theme="cardcast">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CardCast - Pokemon Match Control</title>
<link href="/css/style.css" rel="stylesheet">
<script src="https://cdn.tailwindcss.com"></script>
<style>
/* Minimal custom styles for specific needs */
.pokemon-card-aspect {
aspect-ratio: 63/88;
}
.prize-card-taken {
opacity: 0.5;
background: #374151 !important;
}
.search-overlay {
display: none;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.8);
z-index: 1000;
padding: 2rem;
}
.search-overlay.active {
display: flex;
align-items: center;
justify-content: center;
}
/* Stadium card cropping styles */
.stadium-card-display {
width: 120px;
height: 40px;
overflow: hidden;
position: relative;
border-radius: 0.375rem;
background: #1f2937;
}
.stadium-card-display img {
position: absolute;
width: 100%;
top: -15%;
left: 0;
transform: scale(1.2);
}
.stadium-mini-display {
display: flex;
align-items: center;
gap: 0.75rem;
padding: 0.5rem;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border-radius: 0.5rem;
min-height: 3.5rem;
}
/* Drag and Drop Styles */
.draggable {
cursor: move;
transition: transform 0.2s;
}
.draggable:hover {
transform: scale(1.02);
}
.dragging {
opacity: 0.5;
transform: scale(0.95);
}
.drag-over {
border: 2px solid #3b82f6 !important;
background-color: rgba(59, 130, 246, 0.1) !important;
}
.drop-zone {
min-height: 112px;
transition: all 0.3s;
}
.active-drop-zone {
min-height: 112px;
position: relative;
}
.bench-drop-zone {
position: relative;
}
/* Visual feedback during drag */
.drag-placeholder {
border: 3px dashed #3b82f6;
background: rgba(59, 130, 246, 0.05);
display: flex;
align-items: center;
justify-content: center;
color: #3b82f6;
font-weight: bold;
}
/* Stadium search results - FIXED Z-INDEX */
.stadium-search-results {
position: absolute;
top: 100%;
left: 0;
right: 0;
background: #1f2937;
border: 1px solid #374151;
border-radius: 0.5rem;
margin-top: 0.25rem;
max-height: 300px;
overflow-y: auto;
z-index: 99999 !important; /* Maximum z-index with !important */
box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
}
.card {
overflow: visible !important;
}
.card-body {
overflow: visible !important;
}
/* Make sure the stadium card specifically doesn't clip */
.card:has(#stadiumDisplay) {
overflow: visible !important;
z-index: 9999 !important;
}
/* Ensure the relative container is high enough */
#stadiumDisplay {
position: relative;
z-index: 9998 !important;
}
#emptyStadium {
position: relative;
z-index: 9997 !important;
}
#stadiumDisplay {
position: relative;
z-index: 100;
}
/* Make sure the card containing the stadium doesn't have overflow hidden */
.card-body {
overflow: visible !important;
}
.stadium-search-item {
display: flex;
align-items: center;
gap: 0.75rem;
padding: 0.5rem;
cursor: pointer;
transition: background 0.2s;
}
.stadium-search-item:hover {
background: #374151;
}
.stadium-search-item img {
width: 60px;
height: 84px;
object-fit: cover;
border-radius: 0.25rem;
}
/* Deck selector styles */
.deck-selector {
display: flex;
align-items: center;
gap: 0.5rem;
padding: 0.5rem;
background: rgba(59, 130, 246, 0.1);
border-radius: 0.5rem;
margin-bottom: 0.5rem;
}
.deck-selector select {
flex: 1;
}
.deck-info {
display: flex;
align-items: center;
gap: 0.5rem;
font-size: 0.875rem;
color: #9ca3af;
}
</style>
</head>
<body class="min-h-screen bg-gradient-to-br from-base-100 via-base-200 to-base-100">
<div class="animated-bg"></div>
<div class="orb orb-1"></div>
<div class="orb orb-2"></div>
<div class="orb orb-3"></div>
<!-- Header -->
<div class="navbar glass-card border-b-0 fixed top-0 z-50">
<div class="flex-1">
<h1 class="text-xl font-bold">CardCast - Pokemon Match Control</h1>
<a href="/" class="btn btn-ghost btn-sm ml-4">← Back to Main</a>
</div>
<div class="flex-none">
<div class="badge badge-lg" id="overlayStatus">
<span class="badge badge-error">Overlay Not Connected</span>
</div>
</div>
</div>
<!-- Main Container -->
<div class="container mx-auto px-4 pt-20 pb-8">
<!-- Stadium Control -->
<div class="card bg-base-100 shadow-xl mb-6">
<div class="card-body py-4">
<div class="flex items-center justify-between">
<div class="flex items-center gap-4 flex-1">
<label class="text-sm font-semibold whitespace-nowrap">Stadium in Play:</label>
<!-- Stadium Display Area -->
<div id="stadiumDisplay" class="flex-1">
<!-- Empty state -->
<div id="emptyStadium" class="flex items-center gap-4">
<div class="relative flex-1 max-w-md">
<input type="text"
id="stadiumSearch"
placeholder="Search for a Stadium card..."
class="input input-bordered input-sm w-full"
autocomplete="off">
<div id="stadiumSearchResults" class="stadium-search-results hidden"></div>
</div>
</div>
<!-- Active stadium display (hidden by default) -->
<div id="activeStadium" class="stadium-mini-display hidden">
<div class="stadium-card-display">
<img id="stadiumCardImage" src="" alt="Stadium">
</div>
<div class="flex-1">
<div id="stadiumCardName" class="font-bold text-white"></div>
<div id="stadiumCardSet" class="text-xs text-white/70"></div>
</div>
<button class="btn btn-error btn-sm" onclick="clearStadium()">Remove</button>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="grid lg:grid-cols-2 gap-6">
<!-- Player 1 Controls -->
<div class="card bg-base-100 shadow-xl border-t-4 border-primary">
<div class="card-body">
<div class="flex items-center justify-between mb-2">
<input type="text" id="player1Name" value="Player 1"
class="input input-ghost text-xl font-bold w-40">
<div class="flex items-center gap-2">
<span class="text-sm">Record:</span>
<input type="number" id="player1Wins" value="0" min="0" class="input input-bordered input-xs w-12">
<span>/</span>
<input type="number" id="player1Losses" value="0" min="0" class="input input-bordered input-xs w-12">
<span>/</span>
<input type="number" id="player1Ties" value="0" min="0" class="input input-bordered input-xs w-12">
<button class="btn btn-xs" onclick="updatePlayerRecord(1)">Set</button>
</div>
</div>
<!-- Deck Selector -->
<div class="deck-selector">
<label class="text-sm font-semibold">Deck:</label>
<select id="player1Deck" class="select select-bordered select-sm" onchange="updatePlayerDeck(1)">
<option value="">No Deck (Search All Cards)</option>
</select>
<div class="deck-info" id="player1DeckInfo"></div>
</div>
<div class="flex items-center gap-4 mb-2">
<span class="text-sm">Games Won in Match:</span>
<div class="join">
<button class="btn btn-xs join-item" onclick="updateMatchScore(1, -1)">-</button>
<span class="join-item bg-base-200 px-3 py-1 text-sm" id="player1MatchScore">0</span>
<button class="btn btn-xs join-item" onclick="updateMatchScore(1, 1)">+</button>
</div>
</div>
<!-- Active Pokemon -->
<div class="divider">Active Pokemon</div>
<div class="flex items-center gap-4 p-4 bg-base-200 rounded-lg active-drop-zone"
id="player1Active"
data-player="1"
data-slot="active">
<div class="w-20 h-28 bg-base-300 border-2 border-dashed border-base-content/20 rounded flex items-center justify-center">
<span class="text-base-content/50">Empty</span>
</div>
<div class="flex-1">
<button class="btn btn-primary btn-sm" onclick="selectPokemonFor('player1', 'active')">
Select Pokemon
</button>
</div>
</div>
<!-- HP Control -->
<div class="flex items-center gap-2 mt-2">
<span class="text-sm">HP:</span>
<input type="number" id="player1ActiveHp" class="input input-bordered input-sm w-20" value="0" min="0">
<span>/</span>
<input type="number" id="player1ActiveMaxHp" class="input input-bordered input-sm w-20" value="0" min="0">
<button class="btn btn-sm" onclick="updateActiveHp(1)">Update</button>
</div>
<!-- Bench -->
<div class="divider">Bench</div>
<div class="flex items-center gap-2 mb-2">
<span class="text-sm">Bench Size:</span>
<select id="player1BenchSize" class="select select-bordered select-sm" onchange="updateBenchSize(1)">
<option value="5">5 (Standard)</option>
<option value="7">7 (Stadium/Ability)</option>
</select>
</div>
<div class="grid grid-cols-4 gap-2" id="player1Bench">
<!-- Bench slots will be generated by JavaScript -->
</div>
<!-- Prize Cards -->
<div class="divider">Prize Cards</div>
<div class="grid grid-cols-6 gap-2" id="player1Prizes">
<div class="pokemon-card-aspect bg-gradient-to-br from-primary to-secondary rounded cursor-pointer hover:scale-110 transition-transform flex items-center justify-center text-white font-bold"
onclick="togglePrize(1, 0)">1</div>
<div class="pokemon-card-aspect bg-gradient-to-br from-primary to-secondary rounded cursor-pointer hover:scale-110 transition-transform flex items-center justify-center text-white font-bold"
onclick="togglePrize(1, 1)">2</div>
<div class="pokemon-card-aspect bg-gradient-to-br from-primary to-secondary rounded cursor-pointer hover:scale-110 transition-transform flex items-center justify-center text-white font-bold"
onclick="togglePrize(1, 2)">3</div>
<div class="pokemon-card-aspect bg-gradient-to-br from-primary to-secondary rounded cursor-pointer hover:scale-110 transition-transform flex items-center justify-center text-white font-bold"
onclick="togglePrize(1, 3)">4</div>
<div class="pokemon-card-aspect bg-gradient-to-br from-primary to-secondary rounded cursor-pointer hover:scale-110 transition-transform flex items-center justify-center text-white font-bold"
onclick="togglePrize(1, 4)">5</div>
<div class="pokemon-card-aspect bg-gradient-to-br from-primary to-secondary rounded cursor-pointer hover:scale-110 transition-transform flex items-center justify-center text-white font-bold"
onclick="togglePrize(1, 5)">6</div>
</div>
<!-- Turn Actions -->
<div class="divider">Turn Actions</div>
<div class="grid grid-cols-3 gap-2">
<div>
<label class="text-xs">Energy</label>
<div class="flex items-center gap-1">
<input type="checkbox" id="player1Energy" class="checkbox checkbox-sm" onchange="updateTurnActions(1)">
<span class="text-xs">Attached</span>
</div>
</div>
<div>
<label class="text-xs">Supporter</label>
<div class="flex items-center gap-1">
<input type="checkbox" id="player1Supporter" class="checkbox checkbox-sm" onchange="updateTurnActions(1)">
<span class="text-xs">Played</span>
</div>
</div>
<div>
<label class="text-xs">Retreat</label>
<div class="flex items-center gap-1">
<input type="checkbox" id="player1Retreat" class="checkbox checkbox-sm" onchange="updateTurnActions(1)">
<span class="text-xs">Used</span>
</div>
</div>
</div>
</div>
</div>
<!-- Player 2 Controls -->
<div class="card bg-base-100 shadow-xl border-t-4 border-error">
<div class="card-body">
<div class="flex items-center justify-between mb-2">
<input type="text" id="player2Name" value="Player 2"
class="input input-ghost text-xl font-bold w-40">
<div class="flex items-center gap-2">
<span class="text-sm">Record:</span>
<input type="number" id="player2Wins" value="0" min="0" class="input input-bordered input-xs w-12">
<span>/</span>
<input type="number" id="player2Losses" value="0" min="0" class="input input-bordered input-xs w-12">
<span>/</span>
<input type="number" id="player2Ties" value="0" min="0" class="input input-bordered input-xs w-12">
<button class="btn btn-xs" onclick="updatePlayerRecord(2)">Set</button>
</div>
</div>
<!-- Deck Selector -->
<div class="deck-selector">
<label class="text-sm font-semibold">Deck:</label>
<select id="player2Deck" class="select select-bordered select-sm" onchange="updatePlayerDeck(2)">
<option value="">No Deck (Search All Cards)</option>
</select>
<div class="deck-info" id="player2DeckInfo"></div>
</div>
<div class="flex items-center gap-4 mb-2">
<span class="text-sm">Games Won in Match:</span>
<div class="join">
<button class="btn btn-xs join-item" onclick="updateMatchScore(2, -1)">-</button>
<span class="join-item bg-base-200 px-3 py-1 text-sm" id="player2MatchScore">0</span>
<button class="btn btn-xs join-item" onclick="updateMatchScore(2, 1)">+</button>
</div>
</div>
<!-- Active Pokemon -->
<div class="divider">Active Pokemon</div>
<div class="flex items-center gap-4 p-4 bg-base-200 rounded-lg active-drop-zone"
id="player2Active"
data-player="2"
data-slot="active">
<div class="w-20 h-28 bg-base-300 border-2 border-dashed border-base-content/20 rounded flex items-center justify-center">
<span class="text-base-content/50">Empty</span>
</div>
<div class="flex-1">
<button class="btn btn-primary btn-sm" onclick="selectPokemonFor('player2', 'active')">
Select Pokemon
</button>
</div>
</div>
<!-- HP Control -->
<div class="flex items-center gap-2 mt-2">
<span class="text-sm">HP:</span>
<input type="number" id="player2ActiveHp" class="input input-bordered input-sm w-20" value="0" min="0">
<span>/</span>
<input type="number" id="player2ActiveMaxHp" class="input input-bordered input-sm w-20" value="0" min="0">
<button class="btn btn-sm" onclick="updateActiveHp(2)">Update</button>
</div>
<!-- Bench -->
<div class="divider">Bench</div>
<div class="flex items-center gap-2 mb-2">
<span class="text-sm">Bench Size:</span>
<select id="player2BenchSize" class="select select-bordered select-sm" onchange="updateBenchSize(2)">
<option value="5">5 (Standard)</option>
<option value="7">7 (Stadium/Ability)</option>
</select>
</div>
<div class="grid grid-cols-4 gap-2" id="player2Bench">
<!-- Bench slots will be generated by JavaScript -->
</div>
<!-- Prize Cards -->
<div class="divider">Prize Cards</div>
<div class="grid grid-cols-6 gap-2" id="player2Prizes">
<div class="pokemon-card-aspect bg-gradient-to-br from-primary to-secondary rounded cursor-pointer hover:scale-110 transition-transform flex items-center justify-center text-white font-bold"
onclick="togglePrize(2, 0)">1</div>
<div class="pokemon-card-aspect bg-gradient-to-br from-primary to-secondary rounded cursor-pointer hover:scale-110 transition-transform flex items-center justify-center text-white font-bold"
onclick="togglePrize(2, 1)">2</div>
<div class="pokemon-card-aspect bg-gradient-to-br from-primary to-secondary rounded cursor-pointer hover:scale-110 transition-transform flex items-center justify-center text-white font-bold"
onclick="togglePrize(2, 2)">3</div>
<div class="pokemon-card-aspect bg-gradient-to-br from-primary to-secondary rounded cursor-pointer hover:scale-110 transition-transform flex items-center justify-center text-white font-bold"
onclick="togglePrize(2, 3)">4</div>
<div class="pokemon-card-aspect bg-gradient-to-br from-primary to-secondary rounded cursor-pointer hover:scale-110 transition-transform flex items-center justify-center text-white font-bold"
onclick="togglePrize(2, 4)">5</div>
<div class="pokemon-card-aspect bg-gradient-to-br from-primary to-secondary rounded cursor-pointer hover:scale-110 transition-transform flex items-center justify-center text-white font-bold"
onclick="togglePrize(2, 5)">6</div>
</div>
<!-- Turn Actions -->
<div class="divider">Turn Actions</div>
<div class="grid grid-cols-3 gap-2">
<div>
<label class="text-xs">Energy</label>
<div class="flex items-center gap-1">
<input type="checkbox" id="player2Energy" class="checkbox checkbox-sm" onchange="updateTurnActions(2)">
<span class="text-xs">Attached</span>
</div>
</div>
<div>
<label class="text-xs">Supporter</label>
<div class="flex items-center gap-1">
<input type="checkbox" id="player2Supporter" class="checkbox checkbox-sm" onchange="updateTurnActions(2)">
<span class="text-xs">Played</span>
</div>
</div>
<div>
<label class="text-xs">Retreat</label>
<div class="flex items-center gap-1">
<input type="checkbox" id="player2Retreat" class="checkbox checkbox-sm" onchange="updateTurnActions(2)">
<span class="text-xs">Used</span>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Match Controls -->
<div class="card bg-base-100 shadow-xl mt-6">
<div class="card-body">
<!-- Match Setup -->
<div class="border-b border-base-300 pb-4">
<h3 class="text-sm uppercase tracking-wider text-primary font-semibold mb-3">Match Setup</h3>
<div class="flex flex-wrap items-center gap-4">
<div class="form-control">
<label class="label">
<span class="label-text text-xs">Format</span>
</label>
<select id="matchFormat" class="select select-bordered select-sm">
<option value="Best of 1">Best of 1</option>
<option value="Best of 3" selected>Best of 3</option>
</select>
</div>
<div class="form-control">
<label class="label">
<span class="label-text text-xs">Game</span>
</label>
<select id="gameNumber" class="select select-bordered select-sm">
<option value="1">Game 1</option>
<option value="2">Game 2</option>
<option value="3">Game 3</option>
</select>
</div>
<button class="btn btn-primary btn-sm mt-6" onclick="updateMatchSettings()">Apply Settings</button>
</div>
</div>
<!-- Timer Control -->
<div class="border-b border-base-300 py-4">
<h3 class="text-sm uppercase tracking-wider text-primary font-semibold mb-3">Timer Control</h3>
<div class="flex flex-wrap items-center gap-4">
<div class="text-5xl font-mono font-bold text-primary bg-base-200 px-6 py-3 rounded-lg" id="timerDisplay">50:00</div>
<div class="flex gap-2">
<button class="btn btn-success" onclick="startTimer()">▶ Start</button>
<button class="btn btn-warning" onclick="pauseTimer()">⏸ Pause</button>
<button class="btn btn-neutral" onclick="resetTimer()">↺ Reset</button>
</div>
</div>
</div>
<!-- Turn Control -->
<div class="border-b border-base-300 py-4">
<h3 class="text-sm uppercase tracking-wider text-primary font-semibold mb-3">Turn Control</h3>
<div class="flex flex-wrap items-center gap-4">
<div class="badge badge-lg badge-primary p-4" id="turnDisplay">Player 1's Turn</div>
<button class="btn btn-primary" onclick="switchTurn()">Switch Turn</button>
<button class="btn btn-warning btn-sm" onclick="resetTurnActions()">Reset Turn Actions</button>
</div>
</div>
<!-- Overlay Display -->
<div class="border-b border-base-300 py-4">
<h3 class="text-sm uppercase tracking-wider text-primary font-semibold mb-3">Overlay Display</h3>
<div class="flex gap-2">
<button class="btn btn-success" onclick="showPokemonOverlay()">Show Overlay</button>
<button class="btn btn-warning" onclick="hidePokemonOverlay()">Hide Overlay</button>
</div>
</div>
<!-- Match Reset -->
<div class="pt-4">
<h3 class="text-sm uppercase tracking-wider text-primary font-semibold mb-3">Match Reset</h3>
<div class="flex items-center gap-4">
<button class="btn btn-error" onclick="resetMatch()">🔄 Reset Entire Match</button>
<span class="text-xs text-error opacity-70 italic">This will clear all Pokemon, prizes, and timer</span>
</div>
</div>
</div>
</div>
</div>
<!-- Updated Search Overlay -->
<div class="search-overlay" id="searchOverlay">
<div class="card w-full max-w-5xl bg-base-100">
<div class="card-body">
<div class="flex justify-between items-center mb-4">
<h2 class="card-title">Select Pokemon</h2>
<button class="btn btn-circle btn-ghost" onclick="closeSearch()">✕</button>
</div>
<!-- Search mode indicator -->
<div id="searchModeIndicator" class="alert alert-info mb-4 hidden">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="stroke-current shrink-0 w-6 h-6"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
<span id="searchModeText"></span>
</div>
<div class="flex gap-2 mb-4">
<input type="text" id="pokemonSearch" placeholder="Filter cards..."
class="input input-bordered flex-1">
<!-- Toggle for searching all cards vs deck -->
<div class="form-control">
<label class="label cursor-pointer flex gap-2">
<span class="label-text whitespace-nowrap">Search all cards</span>
<input type="checkbox" id="searchAllCards" class="toggle toggle-primary" onchange="toggleSearchMode()">
</label>
</div>
</div>
<!-- Increased grid size and max height for better viewing -->
<div class="grid grid-cols-3 sm:grid-cols-4 md:grid-cols-5 lg:grid-cols-6 xl:grid-cols-8 gap-3 max-h-[600px] overflow-y-auto p-2"
id="searchResults">
<!-- Search results will appear here -->
</div>
</div>
</div>
</div>
<!-- Socket.io -->
<script src="/socket.io/socket.io.js"></script>
<script>
const socket = io();
let matchState = {
player1: {
name: 'Player 1',
active: null,
benchSize: 5,
bench: [null, null, null, null, null, null, null],
prizes: [false, false, false, false, false, false],
record: { wins: 0, losses: 0, ties: 0 },
matchScore: 0,
turnActions: { energy: false, supporter: false, retreat: false },
deckId: null,
deckName: null
},
player2: {
name: 'Player 2',
active: null,
benchSize: 5,
bench: [null, null, null, null, null, null, null],
prizes: [false, false, false, false, false, false],
record: { wins: 0, losses: 0, ties: 0 },
matchScore: 0,
turnActions: { energy: false, supporter: false, retreat: false },
deckId: null,
deckName: null
},
currentTurn: 1,
timer: { minutes: 50, seconds: 0 },
timerInterval: null,
gameNumber: 1,
matchFormat: 'Best of 3',
stadium: null
};
let currentSelection = null;
let draggedPokemon = null;
let draggedFrom = null;
let stadiumSearchTimeout = null;
let availableDecks = [];
let playerDeckCards = {
player1: [],
player2: []
};
// Initialize
document.addEventListener('DOMContentLoaded', () => {
// Load available decks
loadAvailableDecks();
// Load saved state if any
loadMatchState();
// Initialize bench displays
updateBenchDisplay(1);
updateBenchDisplay(2);
// Setup drag and drop for active zones
setupActiveZoneDragDrop(1);
setupActiveZoneDragDrop(2);
// Setup search with updated function
document.getElementById('pokemonSearch').addEventListener('input', debounce(searchPokemon, 300));
// Setup stadium search
document.getElementById('stadiumSearch').addEventListener('input', debounce(searchStadiums, 300));
document.getElementById('stadiumSearch').addEventListener('focus', () => {
const results = document.getElementById('stadiumSearchResults');
if (results.children.length > 0) {
results.classList.remove('hidden');
}
});
// Close stadium search when clicking outside
document.addEventListener('click', (e) => {
if (!e.target.closest('#stadiumSearch') && !e.target.closest('#stadiumSearchResults')) {
document.getElementById('stadiumSearchResults').classList.add('hidden');
}
});
// Update player names on change
document.getElementById('player1Name').addEventListener('change', updatePlayerNames);
document.getElementById('player2Name').addEventListener('change', updatePlayerNames);
// Register with server
socket.emit('register-control', 'pokemon-match');
// Listen for overlay connections
socket.on('overlay-connected', (type) => {
if (type === 'pokemon-match') {
updateOverlayStatus(true);
}
});
socket.on('overlay-disconnected', (type) => {
if (type === 'pokemon-match') {
updateOverlayStatus(false);
}
});
socket.on('connect', () => {
console.log('Control panel connected to server');
socket.emit('register-control', 'pokemon-match');
// Request overlay status
socket.emit('check-overlay-status', 'pokemon-match');
});
});
// Populate deck cards when opening search
async function populateDeckCards() {
const searchAllCards = document.getElementById('searchAllCards').checked;
if (!currentSelection) return;
const playerNum = currentSelection.player === 'player1' ? 1 : 2;
const deckCardNames = playerDeckCards[`player${playerNum}`];
// If no deck selected or searching all cards, don't pre-populate
if (deckCardNames.length === 0 || searchAllCards) {
document.getElementById('searchResults').innerHTML = '<div class="col-span-full text-center text-base-content/50">Search for Pokemon cards to add...</div>';
return;
}
// Get unique card names from deck
const uniqueCardNames = [...new Set(deckCardNames)];
// Fetch card data for all unique cards in the deck
const allCards = [];
const loadingIndicator = document.getElementById('searchResults');
loadingIndicator.innerHTML = '<div class="col-span-full text-center"><span class="loading loading-spinner loading-md"></span> Loading Pokemon from deck...</div>';
for (const cardName of uniqueCardNames) {
try {
const response = await fetch(`/api/search/pokemon?q=${encodeURIComponent(cardName)}`);
const results = await response.json();
// FIXED: Only add cards that EXACTLY match the deck card name
// Filter to Pokemon cards first
const pokemonResults = results.filter(card => isPokemonCard(card));
// Look for exact name match (case-insensitive)
const exactMatch = pokemonResults.find(card =>
card.name.toLowerCase() === cardName.toLowerCase()
);
// IMPORTANT: Only add the card if we found an exact match
// Don't fall back to "first result" as that causes incorrect cards to appear
if (exactMatch) {
allCards.push(exactMatch);
}
// If no exact match found, we simply don't show that card
// This prevents wrong cards from appearing in the list
} catch (error) {
console.error(`Error fetching card: ${cardName}`, error);
}
}
// Display all Pokemon cards from deck that we found exact matches for
displaySearchResults(allCards);
}
// Helper function to determine if a card is a Pokemon
function isPokemonCard(card) {
// Primary check: Pokemon cards have HP
if (card.hp && parseInt(card.hp) > 0) {
return true;
}
// Check card type/supertype if available
if (card.supertype) {
const supertype = card.supertype.toLowerCase();
if (supertype === 'pokemon' || supertype === 'pokémon') {
return true;
}
if (supertype === 'trainer' || supertype === 'energy') {
return false;
}
}
// Check category
if (card.category) {
const category = card.category.toLowerCase();
if (category.includes('pokemon') || category.includes('pokémon')) {
return true;
}
if (category.includes('trainer') || category.includes('energy')) {
return false;
}
}
// Check card type field
if (card.type) {
const type = card.type.toLowerCase();
// Trainer and Energy exclusions
if (type.includes('trainer') || type.includes('supporter') ||
type.includes('item') || type.includes('tool') ||
type.includes('stadium') || type.includes('energy')) {
return false;
}
}
// Name-based exclusions for common non-Pokemon cards
const cardNameLower = card.name.toLowerCase();
const nonPokemonKeywords = [
'energy', 'trainer', 'professor', 'boss', 'stadium',
'ball', 'potion', 'switch', 'catcher', 'belt', 'tool'
];
for (const keyword of nonPokemonKeywords) {
if (cardNameLower.includes(keyword)) {
// But allow cards like "Energy Switch Pikachu" if they have HP
if (!card.hp || parseInt(card.hp) === 0) {
return false;
}
}
}
// If we still can't determine, and it doesn't have HP, it's likely not a Pokemon
return false;
}
// Deck Management Functions
async function loadAvailableDecks() {
try {
// Load decks from localStorage (same as main index.html)
const savedDecks = JSON.parse(localStorage.getItem('savedDecks')) || {};
availableDecks = [];
// Convert saved decks to flat array for easier use
Object.keys(savedDecks).forEach(game => {
if (game === 'pokemon') { // Only show Pokemon decks
savedDecks[game].forEach(deck => {
availableDecks.push({
id: `${game}-${deck.name}`,
name: deck.name,
game: game,
...deck
});
});
}
});
// Update both player deck selectors
updateDeckSelectors();
} catch (error) {
console.error('Error loading decks:', error);
}
}
function updateDeckSelectors() {
const player1Select = document.getElementById('player1Deck');
const player2Select = document.getElementById('player2Deck');
// Create options HTML
let optionsHTML = '<option value="">No Deck (Search All Cards)</option>';
availableDecks.forEach(deck => {
optionsHTML += `<option value="${deck.id}">${deck.name}</option>`;
});
// Preserve current selections
const player1Current = player1Select.value;
const player2Current = player2Select.value;
player1Select.innerHTML = optionsHTML;
player2Select.innerHTML = optionsHTML;
// Restore selections if they still exist
if (player1Current && availableDecks.find(d => d.id == player1Current)) {
player1Select.value = player1Current;
}
if (player2Current && availableDecks.find(d => d.id == player2Current)) {
player2Select.value = player2Current;
}
}
async function updatePlayerDeck(playerNum) {
const deckSelect = document.getElementById(`player${playerNum}Deck`);
const deckId = deckSelect.value;
const deckInfo = document.getElementById(`player${playerNum}DeckInfo`);
if (!deckId) {
// No deck selected - search all cards
matchState[`player${playerNum}`].deckId = null;
matchState[`player${playerNum}`].deckName = null;
playerDeckCards[`player${playerNum}`] = [];
deckInfo.innerHTML = '<span class="text-xs">Searching all cards</span>';
} else {
// Load the selected deck from localStorage
try {
const savedDecks = JSON.parse(localStorage.getItem('savedDecks')) || {};
const [game, ...nameParts] = deckId.split('-');
const deckName = nameParts.join('-');
const deck = savedDecks[game]?.find(d => d.name === deckName);
if (!deck) {
throw new Error('Deck not found');
}
matchState[`player${playerNum}`].deckId = deckId;
matchState[`player${playerNum}`].deckName = deck.name;
// Extract all card names from the deck
const cardNames = [];
if (deck.pokemon) {
deck.pokemon.forEach(p => {
for (let i = 0; i < (p.quantity || p.count || 1); i++) {
cardNames.push(p.name);
}
});
}
if (deck.trainers) {
deck.trainers.forEach(t => {
for (let i = 0; i < (t.quantity || t.count || 1); i++) {
cardNames.push(t.name);
}
});
}
if (deck.energy) {
deck.energy.forEach(e => {
for (let i = 0; i < (e.quantity || e.count || 1); i++) {
cardNames.push(e.name);
}
});
}
playerDeckCards[`player${playerNum}`] = cardNames;
// Count unique cards
const uniqueCount = new Set(cardNames).size;
deckInfo.innerHTML = `<span class="text-xs">${cardNames.length} cards (${uniqueCount} unique)</span>`;
} catch (error) {
console.error('Error loading deck:', error);
deckInfo.innerHTML = '<span class="text-xs text-error">Error loading deck</span>';
}
}
saveMatchState();
}
// UPDATED: Toggle search mode with deck card display
function toggleSearchMode() {
const searchAllCards = document.getElementById('searchAllCards').checked;
updateSearchModeIndicator();
const searchInput = document.getElementById('pokemonSearch');
// If search input is empty, populate deck cards or clear
if (searchInput.value.length === 0) {
if (searchAllCards) {
document.getElementById('searchResults').innerHTML = '<div class="col-span-full text-center text-base-content/50">Search for Pokemon cards to add...</div>';
} else {
populateDeckCards();
}
} else if (searchInput.value.length >= 2) {
// Re-trigger search if there's text in the search box
searchPokemon({ target: searchInput });
}
}
function updateSearchModeIndicator() {
const indicator = document.getElementById('searchModeIndicator');
const indicatorText = document.getElementById('searchModeText');
const searchAllCards = document.getElementById('searchAllCards').checked;
if (!currentSelection) return;
const playerNum = currentSelection.player === 'player1' ? 1 : 2;
const deckName = matchState[`player${playerNum}`].deckName;
if (deckName && !searchAllCards) {
indicator.classList.remove('hidden');
indicatorText.textContent = `Searching in deck: ${deckName}`;
} else if (searchAllCards && deckName) {
indicator.classList.remove('hidden');
indicatorText.textContent = `Searching all cards (deck restriction disabled)`;
} else {
indicator.classList.add('hidden');
}
}