-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtable.html
More file actions
851 lines (730 loc) · 33 KB
/
Copy pathtable.html
File metadata and controls
851 lines (730 loc) · 33 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Le Tableur — MKWii Competitive Tabling Helper</title>
<style>
/* Ensure Played tracks rows are single-line and tidy */
.section.tracks .row { flex-wrap: nowrap; align-items: center; }
.section.tracks .row .mono { flex: 0 0 auto; } /* index stays compact */
.section.tracks .track { flex: 1 1 0; min-width: 0; }
.section.notes {
display: flex;
flex-direction: column;
display: flex;
flex-direction: column;
}
:root {
--bg: #0e1117;
--panel: #0b0f1a;
--card: #111625;
--border: #1f2937;
--muted: #93a1b1;
--text: #e6edf3;
--accent: #3b82f6;
--red: #dc2626;
--green: #22c55e;
--orange: #ff6a00;
--violet: #8b5cf6;
--blue: #3b82f6;
--yellow: #ffd400;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
.header { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; background: #111827; border-bottom: 1px solid var(--border); }
.title { font-weight: 800; letter-spacing: .2px; }
.controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.button { border: 1px solid var(--border); background: var(--panel); color: var(--text); padding: 10px 14px; border-radius: 10px; cursor: pointer; font-weight: 600; }
.button[disabled] { opacity: .55; cursor: not-allowed; }
.button.primary { background: var(--accent); border-color: var(--accent); color: white; }
.button.ghost { background: transparent; }
.button.small { padding: 6px 10px; font-size: 12px; }
.danger { color: #f87171; }
.container { max-width: 1200px; margin: 0 auto; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 12px; }
.grid { display: grid; gap: 12px; }
.grid-start { grid-template-columns: 1fr; }
.format-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; }
.format { display: flex; gap: 8px; align-items: center; background: var(--panel); border: 1px solid var(--border); padding: 10px 12px; border-radius: 10px; }
.row {display:flex; gap:10px; align-items:center; flex-wrap:wrap;}
.row:last-child { border-bottom: 0; }
.input, select { width: 100%; background: var(--panel); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 8px 10px; }
textarea.input { resize: vertical; min-height: 36px; }
label { font-size: 12px; color: var(--muted); }
.muted { color: var(--muted); }
.mono { min-width: 20px; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; }
.stack { display: grid; gap: 8px; }
.stack-tight { gap: 6px; }
.teams { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px; }
.team-card { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-items: start; background: var(--panel); border: 1px solid var(--border); padding: 10px; border-radius: 10px; }
.team-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; border: 1px solid var(--border); background: var(--panel); }
.dot { inline-size: 10px; block-size: 10px; border-radius: 999px; display: inline-block; border: 1px solid rgba(255,255,255,.25); }
.workspace {display:grid; gap:12px; grid-template-columns:3fr 1fr; align-items: stretch;}
.section h3 { margin: 0 0 6px 0; }
.copybar { display: flex; flex-wrap: wrap; gap: 8px; }
.players .row { flex-wrap: wrap; grid-template-columns: 28px 1fr 130px; }
.notes .row { flex-wrap: wrap; grid-template-columns: 28px 1fr; }
.tracks .row { flex-wrap: wrap; grid-template-columns: 28px 1fr; }
.leftbar { border-left: 4px solid transparent; padding-left: 8px; border-radius: 8px; }
.footer { margin-top: 12px; text-align: center; font-size: 12px; color: var(--muted); }
.toast { position: fixed; right: 16px; bottom: 16px; background: #111827; border: 1px solid var(--border); color: var(--text); padding: 10px 14px; border-radius: 10px; opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s; pointer-events: none; }
.toast.show { opacity: 1; transform: none; }
.hidden { display: none !important; }
@media (max-width: 1000px) {
.workspace { grid-template-columns: 1fr; }
}
.section.tracks {grid-column:1 / -1;}
.sep{ opacity:.6; user-select:none; padding:0 6px; }
.comma{ opacity:.5; user-select:none; padding:0 4px; }
.player-team{ min-width: 100px; flex: 0 1 120px; width: 120px; }
.player-cc{ min-width: 64px; flex: 0 0 70px; width: 70px; }
.gp{ width:64px; }
.group{ display:flex; align-items:center; gap:6px; flex-wrap:wrap; }
.divider{ width:1px; height:28px; background:var(--border); }
.group{ display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
.player-team{ min-width: 100px; flex: 0 1 120px; width: 120px; }
.player-cc{ min-width: 64px; flex: 0 0 70px; width: 70px; }
.gp{ width:64px; }
.total{ width:80px; }
.team-country .input { padding-left: 8px; padding-right: 8px; }
.team-country .player-team { padding-left: 6px; padding-right: 6px; }
.section.players .row {flex-wrap: nowrap; overflow: hidden; align-items: center;}
.section.players .group {flex-wrap: nowrap;}
.section.notes .row {flex-wrap: nowrap; align-items: center;}
.note-text{ flex:1 1 0; min-width:0; line-height: 17px; }
.section.notes #notesList { margin-top: auto; margin-bottom: 0;
margin-bottom: 0;
}
/* Make Player name inputs match other boxes and grow */
.section.players .player-name{
opacity: 1;
user-select: text;
padding: 8px 10px; /* same as .input */
flex: 1 1 0;
min-width: 0;
width: auto;
}
.validation { font-size: 12px; color: var(--muted); }
.validation .row { display: flex; justify-content: space-between; gap: 8px; }
.validation .ok { color: var(--green); }
.validation .bad { color: var(--red); }
.validation .warn { color: var(--orange); }
.input.invalid { border-color: var(--red); box-shadow: inset 0 0 0 1px var(--red); }
.section.validation { grid-column: 1 / -1; }
</style>
</head>
<body>
<header class="header">
<div class="title">Le Tableur - MKWii Competitive Tabling Helper</div>
<div class="controls">
<button class="hidden button ghost" id="btnBackToStart" hidden aria-hidden="true" tabindex="-1">Change format</button>
<button class="button" id="btnReset">Reset</button>
<a class="button ghost" href="#" id="btnDownload" download="mkw-table.html" title="Download this page as a single file">Download</a>
</div>
</header>
<main class="container">
<!-- Start screen -->
<section id="start" class="grid grid-start">
<div class="card stack">
<h2 style="margin:0">Choose a format (12 players)</h2>
<div class="format-options" role="group" aria-label="Format options">
<label class="format"><input type="radio" name="format" value="FFA" checked> FFA (no teams)</label>
<label class="format"><input type="radio" name="format" value="T2"> Teams of 2 (6 teams)</label>
<label class="format"><input type="radio" name="format" value="T3"> Teams of 3 (4 teams)</label>
<label class="format"><input type="radio" name="format" value="T4"> Teams of 4 (3 teams)</label>
<label class="format"><input type="radio" name="format" value="T6"> Teams of 6 (2 teams)</label>
</div>
<div class="stack-tight">
<label for="importNames">Optional — import player names (comma-space separated):</label>
<input id="importNames" class="input" placeholder="Player 1, Player 2, Player 3, …" />
</div>
<div class="controls">
<button class="button primary" id="btnStart">Continue</button>
<span class="muted">You can change format later at the top.</span>
</div>
</div>
<div class="card muted" style="font-size:13px">
<strong>Tips</strong>
<ul>
<li>Player, note, and track fields are all separate inputs for fast copy-paste.</li>
<li>Team tags are limited to 10 characters. Colors (ordered): Red, Orange, Yellow, Green, Blue, Violet.</li>
<li>Use the three copy buttons to export: current table, all mod notes, or played tracks.</li>
</ul>
</div>
</section>
<!-- Workspace -->
<section id="workspace" class="stack hidden" aria-live="polite">
<!-- Teams config appears when applicable -->
<div id="teamsPanel" class="card stack hidden">
<div class="team-head">
<h2 style="margin:0">Teams</h2>
<div class="muted">Set tag (≤ 10 chars) and color</div>
</div>
<div id="teamsGrid" class="teams"></div>
</div>
<!-- Copy bar -->
<div class="card copybar">
<button class="button primary" id="copyTable">Copy current table</button>
<button class="button" id="copyNotes">Copy all mod notes</button>
<button class="button" id="copyTracks">Copy played tracks</button>
</div>
<!-- Main 3-column workspace -->
<div class="workspace">
<section class="card section players">
<h3>Players <i>(Name | Team, Country | GP1, GP2, GP3, Total)</i></h3>
<div class="stack-tight" style="margin-bottom:8px">
<label for="importInline">Import / overwrite players (comma-space separated)</label>
<input id="importInline" class="input" placeholder="Player 1, Player 2, …" />
<div class="controls">
<button class="button small" id="btnImportInline">Import</button>
</div>
</div>
<div id="playersList"></div>
</section><section class="card section notes">
<h3>Mod notes</h3>
<div id="notesList"></div>
</section>
<section class="card section" validation id="validationSection">
<h3>Validation</h3>
<div id="validationPanel" class="validation"></div>
</section>
<section class="card section tracks">
<h3>Played tracks (12)</h3>
<div class="controls" style="margin-bottom:6px">
<button class="button small" id="btnClearTracks">Clear tracks</button>
</div>
<div id="tracksList"></div>
</section>
</div>
<div class="footer">
Offline single‑file tool • Your data stays in this tab. Use the copy buttons to export. • Follows Lorenzi's table format. • Made with ChatGPT 5 Thinking.
</div>
</section>
</main>
<div id="toast" class="toast" role="status" aria-live="polite"></div>
<script>
(function(){
const COLORS = [
{name:'Red', var:'--red'},
{name:'Orange', var:'--orange'},
{name:'Yellow', var:'--yellow'},
{name:'Green', var:'--green'},
{name:'Blue', var:'--blue'},
{name:'Violet', var:'--violet'},
];
const COLOR_MAP = Object.fromEntries(COLORS.map(c => [c.name, getCSSVar(c.var)]));
// --- ISO 3166-1 alpha-2 country codes ---
const ISO2 = [
"", "AF","AX","AL","DZ","AS","AD","AO","AI","AQ","AG","AR","AM","AW","AU","AT","AZ","BS","BH","BD","BB","BY","BE","BZ","BJ","BM","BT","BO","BQ","BA","BW","BV","BR","IO","BN","BG","BF","BI","CV","KH","CM","CA","KY","CF","TD","CL","CN","CX","CC","CO","KM","CG","CD","CK","CR","CI","HR","CU","CW","CY","CZ","DK","DJ","DM","DO","EC","EG","SV","GQ","ER","EE","SZ","ET","FK","FO","FJ","FI","FR","GF","PF","TF","GA","GM","GE","DE","GH","GI","GR","GL","GD","GP","GU","GT","GG","GN","GW","GY","HT","HM","VA","HN","HK","HU","IS","IN","ID","IR","IQ","IE","IM","IL","IT","JM","JP","JE","JO","KZ","KE","KI","KP","KR","KW","KG","LA","LV","LB","LS","LR","LY","LI","LT","LU","MO","MG","MW","MY","MV","ML","MT","MH","MQ","MR","MU","YT","MX","FM","MD","MC","MN","ME","MS","MA","MZ","MM","NA","NR","NP","NL","NC","NZ","NI","NE","NG","NU","NF","MK","MP","NO","OM","PK","PW","PS","PA","PG","PY","PE","PH","PN","PL","PT","PR","QA","RE","RO","RU","RW","BL","SH","KN","LC","MF","PM","VC","WS","SM","ST","SA","SN","RS","SC","SL","SG","SX","SK","SI","SB","SO","ZA","GS","SS","ES","LK","SD","SR","SJ","SE","CH","SY","TW","TJ","TZ","TH","TL","TG","TK","TO","TT","TN","TR","TM","TC","TV","UG","UA","AE","GB","US","UM","UY","UZ","VU","VE","VN","VG","VI","WF","EH","YE","ZM","ZW"
];
// Build datalist for country codes (allows free typing with suggestions)
(function ensureCountryDatalist(){
let dl = document.getElementById('iso2');
if(!dl){
dl = document.createElement('datalist');
dl.id = 'iso2';
dl.innerHTML = ISO2.filter(Boolean).map(cc => `<option value="${cc}">`).join('');
document.body.appendChild(dl);
}
})();
function playerTotal(p){
const g = p.gp || [0,0,0];
return (parseInt(g[0]||0,10) + parseInt(g[1]||0,10) + parseInt(g[2]||0,10));
}
function teamTotal(ti){
return state.players.filter(p=>p.teamIndex===ti).reduce((s,p)=>s+playerTotal(p),0);
}
// --- Enforce color-first ordering of teams and players ---
const COLOR_ORDER = COLORS.map(c=>c.name); // ['Red','Orange','Yellow','Green','Blue','Violet']
const COLOR_RANK = Object.fromEntries(COLOR_ORDER.map((n,i)=>[n,i]));
function orderedTeamIndices(){
// Sort teams by their selected color according to COLOR_ORDER; uncolored go last in numeric order
return state.teams.map((_,i)=>i).sort((a,b)=>{
const ca = state.teams[a]?.color || '';
const cb = state.teams[b]?.color || '';
const ra = (ca in COLOR_RANK) ? COLOR_RANK[ca] : Number.POSITIVE_INFINITY;
const rb = (cb in COLOR_RANK) ? COLOR_RANK[cb] : Number.POSITIVE_INFINITY;
if(ra!==rb) return ra - rb;
return a - b; // stable fallback by numeric index
});
}
function orderedPlayerIndices(){
// In FFA, keep existing order; otherwise group players by their team's color rank
if(state.format==='FFA') return state.players.map((_,i)=>i);
const tOrder = orderedTeamIndices();
const buckets = new Map(tOrder.map(ti=>[ti,[]]));
state.players.forEach((p, idx)=>{
const ti = p.teamIndex;
if(!buckets.has(ti)) buckets.set(ti, []);
buckets.get(ti).push(idx); // preserve original relative order within a team
});
const out = [];
tOrder.forEach(ti=>{ (buckets.get(ti)||[]).forEach(i=>out.push(i)); });
return out;
}
function getCSSVar(v){ return getComputedStyle(document.documentElement).getPropertyValue(v).trim(); }
const els = {
start: document.getElementById('start'),
workspace: document.getElementById('workspace'),
btnStart: document.getElementById('btnStart'),
btnBackToStart: document.getElementById('btnBackToStart'),
btnReset: document.getElementById('btnReset'),
btnDownload: document.getElementById('btnDownload'),
importNames: document.getElementById('importNames'),
importInline: document.getElementById('importInline'),
btnImportInline: document.getElementById('btnImportInline'),
teamsPanel: document.getElementById('teamsPanel'),
teamsGrid: document.getElementById('teamsGrid'),
playersList: document.getElementById('playersList'),
notesList: document.getElementById('notesList'),
tracksList: document.getElementById('tracksList'),
copyTable: document.getElementById('copyTable'),
copyNotes: document.getElementById('copyNotes'),
copyTracks: document.getElementById('copyTracks'),
btnClearTracks: document.getElementById('btnClearTracks'),
toast: document.getElementById('toast'),
};
const defaultNames = Array(12).fill('');
const state = {
format: 'FFA',
teamSize: 1,
teamCount: 12,
teams: [],
players: Array(12).fill('').map((_, i)=>({ name:'', teamIndex: 0, country: '', gp: [0,0,0] })),
notes: Array(12).fill(''),
tracks: Array(12).fill(''),
};
function setFormat(f){
state.format = f;
const size = f === 'FFA' ? 1 : parseInt(f.slice(1), 10); // T2 -> 2
state.teamSize = size;
state.teamCount = 12 / size;
// Init teams with defaults
state.teams = Array.from({length: state.teamCount}, ()=>({
color: '',
tag: '',
}));
// Auto-assign players to teams in blocks
state.players.forEach((p, idx)=>{ p.teamIndex = Math.floor(idx / state.teamSize); });
renderAll();
}
function defaultTag(idx, count){
const tagSets = {
2: ['RED','BLU'],
3: ['RED','BLU','GRN'],
4: ['RED','BLU','GRN','PUR'],
6: ['RED','GRN','ONG','PUR','BLU','YLW'],
12:['P1','P2','P3','P4','P5','P6','P7','P8','P9','P10','P11','P12']
};
const base = tagSets[count] || ['TEAM'];
return (base[idx] || `T${idx+1}`).slice(0,10);
}
function parseNames(raw){
if(!raw) return [];
// Accept comma OR comma-space; trim empties
return raw.split(',').map(s=>s.trim()).filter(Boolean).slice(0,12);
}
function importNames(raw){
const names = parseNames(raw);
if(!names.length) return;
for(let i=0;i<12;i++){
state.players[i].name = names[i] || `Player ${i+1}`;
}
renderPlayersAndNotes();
}
function show(section){
if(section==='start'){
els.start.classList.remove('hidden');
els.workspace.classList.add('hidden');
} else {
els.start.classList.add('hidden');
els.workspace.classList.remove('hidden');
}
}
// --- Validation (MKWii 12p: 15-12-10-8-7-6-5-4-3-2-1-0 per race) ---
const MKW_RACE_POINTS = [15,12,10,8,7,6,5,4,3,2,1,0];
const MKW_POINTS_PER_GP = MKW_RACE_POINTS.reduce((a,b)=>a+b,0) * 4; // 73 * 4 = 292
function updateValidationUI(){
const panel = document.getElementById('validationPanel');
if(!panel) return;
// Per-GP totals across all players
const totals = [0,0,0];
state.players.forEach(p => {
const g = p.gp || [0,0,0];
for(let i=0;i<3;i++) totals[i] += parseInt(g[i]||0,10) || 0;
});
// Build rows with status
panel.innerHTML = ['',1,2,3].slice(1).map(i=>{
const t = totals[i-1];
const diff = t - MKW_POINTS_PER_GP;
const cls = diff===0 ? 'ok' : (diff>0 ? 'bad' : 'warn');
const label = diff===0 ? 'OK' : (diff>0 ? `+${diff} too high` : `${-diff} too low`);
return `<div class="row"><div>GP ${i} total</div><div class="${cls}">${t} / ${MKW_POINTS_PER_GP} (${label})</div></div>`;
}).join('');
}
function renderAll(){
// Teams panel visibility
if(state.format==='FFA'){
els.teamsPanel.classList.add('hidden');
} else {
els.teamsPanel.classList.remove('hidden');
renderTeams();
}
renderPlayersAndNotes();
renderTracks();
updateValidationUI();
}
// Enforce uniqueness of team colors: disable taken options in other selects
function updateColorOptionStates(){
const used = new Set(state.teams.map(t=>t.color).filter(Boolean));
els.teamsGrid.querySelectorAll('.team-color').forEach(sel=>{
const idx = parseInt(sel.dataset.idx,10);
const current = state.teams[idx]?.color || '';
sel.querySelectorAll('option').forEach(opt=>{
if(!opt.value) return; // allow blank
opt.disabled = used.has(opt.value) && opt.value !== current;
});
});
}
function renderTeams(){
els.teamsGrid.innerHTML = '';
orderedTeamIndices().forEach((idx)=>{ const team = state.teams[idx];
const card = document.createElement('div');
card.className = 'team-card';
card.innerHTML = `
<div class="stack" style="grid-column: 1 / -1">
<div class="team-head">
<div class="badge"><span class="dot" style="background:${COLOR_MAP[team.color]}"></span> Team ${idx+1}</div>
<span class="muted">${membersOf(idx).length} / ${state.teamSize} players · Team total: <b>${teamTotal(idx)}</b></span>
</div>
</div>
<div class="stack">
<label>Tag (≤10)</label>
<input class="input team-tag" maxlength="10" value="${escapeHtml(team.tag)}" data-idx="${idx}" />
</div>
<div class="stack">
<label>Color</label>
<select class=\"input team-color\" data-idx=\"${idx}\">
<option value=\"\" ${team.color?'':'selected'}>—</option>
${COLORS.map(c=>`<option value=\"${c.name}\" ${c.name===team.color?'selected':''}>${c.name}</option>`).join('')}
</select>
</div>`;
els.teamsGrid.appendChild(card);
});
els.teamsGrid.querySelectorAll('.team-tag').forEach(inp=>{
inp.addEventListener('input', e=>{
const i = parseInt(e.target.dataset.idx,10);
state.teams[i].tag = e.target.value.slice(0,10);
});
});
els.teamsGrid.querySelectorAll('.team-color').forEach(sel=>{
// remember previous value on focus
sel.addEventListener('focus', e=>{
const i = parseInt(e.target.dataset.idx,10);
e.target.dataset.prev = state.teams[i]?.color || '';
});
sel.addEventListener('change', e=>{
const i = parseInt(e.target.dataset.idx,10);
const prev = e.target.dataset.prev || (state.teams[i]?.color || '');
const val = e.target.value;
// If chosen color is already used by another team (non-empty), reject
if (val && state.teams.some((t,idx)=> idx!==i && t.color === val)){
toast('That color is already used by another team.');
e.target.value = prev;
return;
}
state.teams[i].color = val;
// Update the dot in the header without a full re-render
const card = e.target.closest('.team-card');
const dot = card && card.querySelector('.team-head .dot');
if (dot) dot.style.background = COLOR_MAP[state.teams[i].color] || 'transparent';
// Disable colors already taken in other selects and refresh dependent views
updateColorOptionStates();
renderPlayersAndNotes();
});
});
updateColorOptionStates();
}
function membersOf(teamIndex){
return state.players.filter(p=>p.teamIndex===teamIndex);
}
function renderPlayersAndNotes(){
// Players
els.playersList.innerHTML = '';
orderedPlayerIndices().forEach((idx)=>{
const player = state.players[idx];
const color = (state.format==='FFA') ? 'transparent' : (COLOR_MAP[state.teams[player.teamIndex]?.color] || 'transparent');
const row = document.createElement('div');
row.className = 'row';
row.innerHTML = `
<div class="muted mono">${idx+1}</div>
<input class="input leftbar player-name" style="border-left:4px solid ${color}" value="${escapeHtml(player.name)}" data-idx="${idx}" />
<div class="divider"></div>
<div class="group team-country">
${state.format==='FFA' ? '' : `<select class="input player-team" data-idx="${idx}">
${orderedTeamIndices().map((ti)=>{ const t = state.teams[ti];
const label = `${escapeHtml(t.tag||('T'+(ti+1)))} (${t.color})`;
return `<option value="${ti}" ${ti===player.teamIndex?'selected':''}>${label}</option>`;
}).join('')}
</select>`}
<input class="input player-cc" data-idx="${idx}" title="Country (ISO-3166-1 alpha-2)" list="iso2" placeholder="CC" maxlength="2" value="${escapeHtml(player.country)}" />
</div>
<div class="divider"></div>
<div class="group scores">
<input class="input gp" type="number" max="60" min="0" step="1" placeholder="GP1" value="${(player.gp||[0,0,0])[0]||0}" data-idx="${idx}" data-gp="0" />
<input class="input gp" type="number" max="60" min="0" step="1" placeholder="GP2" value="${(player.gp||[0,0,0])[1]||0}" data-idx="${idx}" data-gp="1" />
<input class="input gp" type="number" max="60" min="0" step="1" placeholder="GP3" value="${(player.gp||[0,0,0])[2]||0}" data-idx="${idx}" data-gp="2" />
<input class="input total" type="number" readonly value="${playerTotal(player)}" title="Player total" />
</div>
`;
els.playersList.appendChild(row);
});
// Name changes
els.playersList.querySelectorAll('.player-name').forEach(inp=>{
inp.addEventListener('input', e=>{
const i = parseInt(e.target.dataset.idx,10);
state.players[i].name = e.target.value;
});
});
// Team changes
els.playersList.querySelectorAll('.player-team').forEach(sel=>{
sel.addEventListener('change', e=>{
const i = parseInt(e.target.dataset.idx,10);
state.players[i].teamIndex = parseInt(e.target.value,10);
renderPlayersAndNotes();
renderTeams();
});
});
// Country input (free-typed with suggestions via datalist)
els.playersList.querySelectorAll('.player-cc').forEach(inp=>{
const commit = (v)=>{
const i = parseInt(inp.dataset.idx,10);
// Uppercase, letters only, max 2 chars
let cc = (v||'').toUpperCase().replace(/[^A-Z]/g,'').slice(0,2);
inp.value = cc;
state.players[i].country = cc;
};
inp.addEventListener('input', e=>{ commit(e.target.value); });
inp.addEventListener('change', e=>{
commit(e.target.value);
renderPlayersAndNotes();
renderTeams();
});
});
// GP inputs
els.playersList.querySelectorAll('.gp').forEach(inp=>{
// Update state + inline invalid state on input (no rerender to preserve focus)
inp.addEventListener('input', e=>{
const i = parseInt(e.target.dataset.idx,10);
const g = parseInt(e.target.dataset.gp,10);
let v = parseInt(e.target.value||'0',10);
if(!Array.isArray(state.players[i].gp)) state.players[i].gp = [0,0,0];
if(isNaN(v) || v < 0) v = 0;
// Mark invalid > 60
if(v > 60){
e.target.classList.add('invalid');
} else {
e.target.classList.remove('invalid');
}
state.players[i].gp[g] = v;
updateValidationUI();
});
// Re-render dependent UI on change (blur/enter)
inp.addEventListener('change', e=>{
renderPlayersAndNotes();
renderTeams();
updateValidationUI();
});
});
// Notes
els.notesList.innerHTML = '';
orderedPlayerIndices().forEach((idx)=>{ const player = state.players[idx];
const row = document.createElement('div');
row.className = 'row';
row.innerHTML = `
<div class="muted mono">${idx+1}</div>
<input class="input note-text" type="text" data-idx="${idx}" placeholder="Type moderator notes for this player…" value="${escapeHtml(state.notes[idx]||'')}" />
`;
els.notesList.appendChild(row);
});
els.notesList.querySelectorAll('.note-text').forEach(area=>{
area.addEventListener('input', e=>{
const i = parseInt(e.target.dataset.idx,10);
state.notes[i] = e.target.value;
});
});
}
function renderTracks(){
els.tracksList.innerHTML = '';
for(let i=0;i<12;i++){
const row = document.createElement('div');
row.className = 'row';
row.innerHTML = `
<div class="muted mono">${i+1}</div>
<input class="input track" data-idx="${i}" placeholder="Track name…" value="${escapeHtml(state.tracks[i]||'')}" />
`;
els.tracksList.appendChild(row);
}
els.tracksList.querySelectorAll('.track').forEach(inp=>{
inp.addEventListener('input', e=>{
const i = parseInt(e.target.dataset.idx,10);
state.tracks[i] = e.target.value;
});
});
}
function copyTable(){
let out = '';
if(state.format==='FFA'){
out += 'FFA\n';
state.players.forEach(p=>{ const cc=(p.country||'').toLowerCase(); const g=p.gp||[0,0,0]; out += `${(p.name||'').trim()} [${cc}] ${parseInt(g[0]||0,10)}|${parseInt(g[1]||0,10)}|${parseInt(g[2]||0,10)}
`; });
} else {
// Group by teams in index order
Array.from({length: state.teamCount}, (_, ti) => ti).forEach((ti)=>{ const t = state.teams[ti];
const header = (t.tag||`T${ti+1}`).slice(0,10);
out += header + '\n';
state.players.filter(p=>p.teamIndex===ti).forEach(p=>{
const cc = (p.country||'').toLowerCase();
const g = p.gp||[0,0,0];
out += `${(p.name||'').trim()} [${cc}] ${parseInt(g[0]||0,10)}|${parseInt(g[1]||0,10)}|${parseInt(g[2]||0,10)}
`;
});
out += '\n';
});
}
copyToClipboard(out.trimEnd());
toast(`Copied table${state.format==='FFA'?' (FFA)':''} to clipboard`);
}
function copyNotes(){
const lines = [];
state.players.forEach((p, i)=>{
const note = (state.notes[i]||'').trim();
if(note){
lines.push(`${p.name}: ${note}`);
}
});
copyToClipboard(lines.join('\n'));
toast(`Copied ${lines.length} mod note${lines.length===1?'':'s'}`);
}
function copyTracks(){
const lines = [];
state.tracks.forEach((t,i)=>{ if((t||'').trim()) lines.push(`${i+1}. ${t.trim()}`); });
copyToClipboard(lines.join('\n'));
toast(`Copied ${lines.length} track${lines.length===1?'':'s'}`);
}
function copyToClipboard(text){
if(navigator.clipboard && navigator.clipboard.writeText){
navigator.clipboard.writeText(text).catch(()=>fallbackCopy(text));
} else {
fallbackCopy(text);
}
}
function fallbackCopy(text){
const ta = document.createElement('textarea');
ta.value = text; document.body.appendChild(ta); ta.select();
try { document.execCommand('copy'); } catch(e){}
ta.remove();
}
function toast(msg){
els.toast.textContent = msg;
els.toast.classList.add('show');
clearTimeout(els.toast._t);
els.toast._t = setTimeout(()=>els.toast.classList.remove('show'), 1500);
}
function resetAll(){
setFormat('FFA');
state.players = Array(12).fill('').map((_, i)=>({name:'', teamIndex:0, country:'', gp:[0,0,0]}));
state.notes = Array(12).fill('');
state.tracks = Array(12).fill('');
document.querySelector('input[name="format"][value="FFA"]').checked = true;
els.importNames.value = '';
els.importInline.value = '';
show('start');
renderAll();
}
function downloadSelf(){
// Serialize current DOM as a new single file preserving state by embedding a small state script
const doctype = '<!DOCTYPE html>';
const html = document.documentElement.cloneNode(true);
// Inject a script tag to rehydrate state on load
const script = document.createElement('script');
script.type = 'application/json';
script.id = 'saved-state';
script.textContent = JSON.stringify(state);
html.querySelector('body').appendChild(script);
const serializer = new XMLSerializer();
const blob = new Blob([doctype + '\n' + serializer.serializeToString(html)], {type:'text/html'});
const url = URL.createObjectURL(blob);
els.btnDownload.href = url;
// file name is set via download attribute
}
function escapeHtml(s){
return (s||'').replace(/[&<>"']/g, (m)=>({
'&':'&','<':'<','>':'>','"':'"','\'':'''
})[m]);
}
// Event wiring
els.btnStart.addEventListener('click', ()=>{
const selected = document.querySelector('input[name="format"]:checked').value;
setFormat(selected);
// Optional import from start
const raw = els.importNames.value.trim();
if(raw) importNames(raw);
show('workspace');
});
els.btnBackToStart.addEventListener('click', ()=>{
show('start');
});
document.querySelectorAll('input[name="format"]').forEach(r=>{
r.addEventListener('change', (e)=>{
setFormat(e.target.value);
});
});
els.btnImportInline.addEventListener('click', ()=>{
importNames(els.importInline.value.trim());
els.importInline.value='';
});
els.copyTable.addEventListener('click', copyTable);
els.copyNotes.addEventListener('click', copyNotes);
els.copyTracks.addEventListener('click', copyTracks);
els.btnClearTracks.addEventListener('click', ()=>{
state.tracks = Array(12).fill('');
renderTracks();
});
els.btnReset.addEventListener('click', resetAll);
// Prepare download link on hover/click to ensure current state is embedded
['mouseenter','focus','click','touchstart'].forEach(evt=>{
els.btnDownload.addEventListener(evt, downloadSelf, {passive:true});
});
// Rehydrate from embedded state if present (for downloaded/self-opened file)
(function rehydrate(){
const saved = document.getElementById('saved-state');
if(!saved) return;
try{
const s = JSON.parse(saved.textContent||'{}');
if(!s || !Array.isArray(s.players) || s.players.every(p => !p || !p.name)) { return; }
if(s && Array.isArray(s.players) && s.players.length===12){
Object.assign(state, s);
// Coerce numbers just in case
state.teamSize = Number(state.teamSize)||1;
state.teamCount = Number(state.teamCount)|| (state.format==='FFA'?12:12/state.teamSize);
// Ensure teams array
if(!Array.isArray(state.teams) || !state.teams.length){
state.teams = Array.from({length: state.teamCount}, (_,i)=>({color: COLORS[i%COLORS.length].name, tag: defaultTag(i, state.teamCount)}));
}
renderAll();
show('workspace');
}
}catch(e){ /* ignore */ }
})();
// Initialize defaults
setFormat('FFA');
renderAll();
show('start');
})();
</script>
</body>
</html>