-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
869 lines (747 loc) · 42.8 KB
/
index.html
File metadata and controls
869 lines (747 loc) · 42.8 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
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Feuille de Personnage GURPS Lite (Fichier)</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Inter', sans-serif;
background-color: #1a202c;
color: #e2e8f0;
}
.container {
max-width: 900px;
}
.input-group input, .input-group select {
background-color: #2d3748;
border: 1px solid #4a5568;
color: #e2e8f0;
}
.section-header {
background-color: #2d3748;
color: #e2e8f0;
}
.button-group button {
transition: all 0.2s ease-in-out;
}
.button-group button:hover {
transform: translateY(-2px);
}
.disabled-input {
opacity: 0.6;
cursor: not-allowed;
}
/* Style pour la modale */
.modal-content {
background-color: #2d3748;
border: 2px solid #4a5568;
}
/* Custom print styling */
@media print {
.button-group, #messageBox, #toggleSecondaryEdit, .input-group button, .section-header, #loadFileInput {
display: none !important;
}
.container {
box-shadow: none;
border: none;
padding: 0;
}
body {
background-color: white;
color: black;
}
.bg-gray-800, .bg-gray-700, .bg-gray-600 {
background-color: white !important;
color: black !important;
}
.text-indigo-400, .text-gray-400, .text-gray-300 {
color: #333 !important;
}
input, select {
border: 1px solid #ccc !important;
background-color: #f9f9f9 !important;
color: black !important;
}
}
</style>
</head>
<body class="p-4 sm:p-8">
<div class="container mx-auto bg-gray-800 rounded-xl shadow-2xl p-6 sm:p-10 border border-gray-700">
<h1 class="text-4xl sm:text-5xl font-bold text-center mb-6 text-indigo-400">Feuille de Personnage GURPS Lite</h1>
<p class="text-center text-gray-400 mb-8">Gérez votre feuille de personnage via des fichiers JSON.</p>
<!-- Section des Informations Générales -->
<div class="bg-gray-700 p-6 rounded-lg mb-8 shadow-inner">
<h2 class="text-2xl font-bold section-header p-3 rounded-lg text-center mb-4">Informations Générales</h2>
<div class="flex flex-col sm:flex-row gap-4 mb-4">
<div class="w-full">
<label for="charSheetName" class="block text-gray-300 font-semibold mb-2">Nom de la Fiche (pour le nom de fichier)</label>
<input type="text" id="charSheetName" class="w-full p-3 rounded-lg border-2 border-gray-600 focus:outline-none focus:ring-2 focus:ring-indigo-500 bg-gray-600 text-gray-200" placeholder="Ex: Mon Guerrier Orque">
</div>
<div class="w-full">
<label for="charPoints" class="block text-gray-300 font-semibold mb-2">Points de Départ</label>
<input type="number" id="charPoints" class="w-full p-3 rounded-lg border-2 border-gray-600 focus:outline-none focus:ring-2 focus:ring-indigo-500 bg-gray-600 text-gray-200" value="100">
</div>
</div>
<div class="flex flex-col sm:flex-row gap-4">
<div class="w-full">
<label for="charName" class="block text-gray-300 font-semibold mb-2">Nom du Personnage</label>
<input type="text" id="charName" class="w-full p-3 rounded-lg border-2 border-gray-600 focus:outline-none focus:ring-2 focus:ring-indigo-500 bg-gray-600 text-gray-200">
</div>
<div class="w-full">
<label for="charRace" class="block text-gray-300 font-semibold mb-2">Race</label>
<input type="text" id="charRace" class="w-full p-3 rounded-lg border-2 border-gray-600 focus:outline-none focus:ring-2 focus:ring-indigo-500 bg-gray-600 text-gray-200">
</div>
</div>
<div class="w-full mt-4">
<label for="charDesc" class="block text-gray-300 font-semibold mb-2">Description</label>
<input type="text" id="charDesc" class="w-full p-3 rounded-lg border-2 border-gray-600 focus:outline-none focus:ring-2 focus:ring-indigo-500 bg-gray-600 text-gray-200">
</div>
</div>
<!-- Section des Caractéristiques -->
<div class="grid grid-cols-1 md:grid-cols-2 gap-8 mb-8">
<!-- Caractéristiques Principales -->
<div class="bg-gray-700 p-6 rounded-lg shadow-inner">
<h2 class="text-2xl font-bold section-header p-3 rounded-lg text-center mb-4">Caractéristiques Principales</h2>
<div class="space-y-4">
<div class="flex items-center input-group">
<label for="st" class="w-1/3 text-gray-300 font-semibold">Force (ST)</label>
<input type="number" id="st" value="10" min="1" class="w-1/3 p-2 rounded-lg text-center">
<span class="w-1/3 text-right text-gray-400 font-bold" id="stCost">0 pts</span>
</div>
<div class="flex items-center input-group">
<label for="dx" class="w-1/3 text-gray-300 font-semibold">Dextérité (DX)</label>
<input type="number" id="dx" value="10" min="1" class="w-1/3 p-2 rounded-lg text-center">
<span class="w-1/3 text-right text-gray-400 font-bold" id="dxCost">0 pts</span>
</div>
<div class="flex items-center input-group">
<label for="iq" class="w-1/3 text-gray-300 font-semibold">Intelligence (IQ)</label>
<input type="number" id="iq" value="10" min="1" class="w-1/3 p-2 rounded-lg text-center">
<span class="w-1/3 text-right text-gray-400 font-bold" id="iqCost">0 pts</span>
</div>
<div class="flex items-center input-group">
<label for="ht" class="w-1/3 text-gray-300 font-semibold">Santé (HT)</label>
<input type="number" id="ht" value="10" min="1" class="w-1/3 p-2 rounded-lg text-center">
<span class="w-1/3 text-right text-gray-400 font-bold" id="htCost">0 pts</span>
</div>
</div>
</div>
<!-- Caractéristiques Secondaires -->
<div class="bg-gray-700 p-6 rounded-lg shadow-inner">
<h2 class="text-2xl font-bold section-header p-3 rounded-lg text-center mb-4">Caractéristiques Secondaires</h2>
<div class="space-y-4">
<div class="flex items-center input-group">
<label for="hp" class="w-1/3 text-gray-300 font-semibold">Points de Vie (PV)</label>
<input type="number" id="hp" value="10" min="1" class="w-1/3 p-2 rounded-lg text-center disabled-input" disabled>
<span class="w-1/3 text-right text-gray-400 font-bold" id="hpCost">0 pts</span>
</div>
<div class="flex items-center input-group">
<label for="fp" class="w-1/3 text-gray-300 font-semibold">Points de Fatigue (PF)</label>
<input type="number" id="fp" value="10" min="1" class="w-1/3 p-2 rounded-lg text-center disabled-input" disabled>
<span class="w-1/3 text-right text-gray-400 font-bold" id="fpCost">0 pts</span>
</div>
<div class="flex items-center input-group">
<label for="per" class="w-1/3 text-gray-300 font-semibold">Perception (PER)</label>
<input type="number" id="per" value="10" min="1" class="w-1/3 p-2 rounded-lg text-center disabled-input" disabled>
<span class="w-1/3 text-right text-gray-400 font-bold" id="perCost">0 pts</span>
</div>
<div class="flex items-center input-group">
<label for="will" class="w-1/3 text-gray-300 font-semibold">Volonté (VOL)</label>
<input type="number" id="will" value="10" min="1" class="w-1/3 p-2 rounded-lg text-center disabled-input" disabled>
<span class="w-1/3 text-right text-gray-400 font-bold" id="willCost">0 pts</span>
</div>
</div>
<div class="mt-4 text-center text-gray-400">
<button id="toggleSecondaryEdit" class="text-indigo-400 hover:text-indigo-300">Modifier les caractéristiques secondaires</button>
</div>
</div>
</div>
<!-- Section des Statistiques Dérivées -->
<div class="bg-gray-700 p-6 rounded-lg mb-8 shadow-inner">
<h2 class="text-2xl font-bold section-header p-3 rounded-lg text-center mb-4">Statistiques Dérivées</h2>
<div class="grid grid-cols-2 gap-4">
<div class="flex items-center">
<label class="w-2/3 text-gray-300 font-semibold">Vitesse de Base (Basic Speed)</label>
<span id="basicSpeed" class="w-1/3 text-right text-indigo-400 font-extrabold text-xl">5.00</span>
</div>
<div class="flex items-center">
<label class="w-2/3 text-gray-300 font-semibold">Mouvement de Base (Basic Move)</label>
<span id="basicMove" class="w-1/3 text-right text-indigo-400 font-extrabold text-xl">5</span>
</div>
</div>
</div>
<!-- Avantages et Désavantages -->
<div class="bg-gray-700 p-6 rounded-lg mb-8 shadow-inner">
<h2 class="text-2xl font-bold section-header p-3 rounded-lg text-center mb-4">Avantages et Désavantages</h2>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div id="advantages-container" class="space-y-4">
<h3 class="text-xl font-bold text-gray-300 mb-2">Avantages</h3>
<!-- Avantages remplis par JS au chargement -->
</div>
<div id="disadvantages-container" class="space-y-4">
<h3 class="text-xl font-bold text-gray-300 mb-2">Désavantages</h3>
<!-- Désavantages remplis par JS au chargement -->
</div>
</div>
<div class="flex justify-center gap-4 mt-6">
<button onclick="addEntry('advantage')" class="bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-2 px-4 rounded-full shadow-lg">Ajouter un Avantage</button>
<button onclick="addEntry('disadvantage')" class="bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-2 px-4 rounded-full shadow-lg">Ajouter un Désavantage</button>
</div>
</div>
<!-- Section des Compétences (Skills) -->
<div class="bg-gray-700 p-6 rounded-lg mb-8 shadow-inner">
<h2 class="text-2xl font-bold section-header p-3 rounded-lg text-center mb-4">Compétences (Skills)</h2>
<div class="flex text-sm font-semibold text-gray-400 mb-2 p-2 border-b border-gray-600">
<span class="w-1/3">Nom</span>
<span class="w-1/6 text-center">Base</span>
<span class="w-1/6 text-center">Achat</span>
<span class="w-1/6 text-center">Niveau</span>
<span class="w-1/6 text-right">Coût</span>
</div>
<div id="skills-container" class="space-y-2">
<!-- Compétences remplies par JS au chargement -->
</div>
<div class="flex justify-center mt-6">
<button onclick="addSkillEntry()" class="bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-2 px-4 rounded-full shadow-lg">Ajouter une Compétence</button>
</div>
</div>
<!-- Section du Total des Points -->
<div class="bg-gray-700 p-6 rounded-lg mb-8 text-center shadow-inner">
<h2 class="text-3xl font-bold text-gray-300 mb-4">Total des Points</h2>
<div class="flex justify-center items-baseline mb-4">
<span class="text-xl font-semibold text-gray-400 mr-2">Points utilisés :</span>
<span id="pointsUsed" class="text-3xl font-extrabold text-white">0</span>
</div>
<div class="flex justify-center items-baseline">
<span class="text-xl font-semibold text-gray-400 mr-2">Points restants :</span>
<span id="pointsRemaining" class="text-3xl font-extrabold text-white">0</span>
</div>
</div>
<!-- Section des Actions Fichier -->
<div class="button-group flex flex-wrap justify-center items-center gap-4 border-t border-gray-700 pt-6">
<button id="exportButton" class="bg-green-600 hover:bg-green-700 text-white font-bold py-3 px-6 rounded-full shadow-lg">Exporter en JSON</button>
<!-- Conteneur pour l'importation -->
<label for="loadFileInput" class="bg-amber-500 hover:bg-amber-600 text-white font-bold py-3 px-6 rounded-full shadow-lg cursor-pointer inline-block text-center">
Importer depuis JSON
</label>
<input type="file" id="loadFileInput" accept=".json" class="hidden">
<button onclick="window.print()" class="bg-blue-500 hover:bg-blue-600 text-white font-bold py-3 px-6 rounded-full shadow-lg">Imprimer la Fiche</button>
</div>
</div>
<!-- Message box for alerts -->
<div id="messageBox" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden z-50">
<div class="modal-content p-6 rounded-lg shadow-xl text-center max-w-sm w-full mx-4">
<p id="messageText" class="text-gray-200 mb-4"></p>
<button onclick="hideMessage()" class="bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-2 px-4 rounded-full">OK</button>
</div>
</div>
<script>
// Clé unique pour le stockage local (Gardé pour la compatibilité initiale si besoin, mais non utilisé pour la sauvegarde principale)
const mainAttributes = ['st', 'dx', 'iq', 'ht'];
const secondaryAttributes = ['hp', 'fp', 'per', 'will'];
const attributeInputs = mainAttributes.concat(secondaryAttributes);
const attributeCosts = {
st: 10, dx: 20, iq: 20, ht: 10,
hp: 2, fp: 3, per: 5, will: 5
};
// --- GURPS LITE DATA ---
const GURPS_TRAITS = {
"Richesse (Wealth)": 10, "Chance (Luck)": 15, "Beauté (Attractive)": 4, "Contacts (Contact)": 5,
"Vision Nocturne (Night Vision)": 10, "Santé de Fer (Hard to Kill)": 5, "Allié (Ally)": 5,
"Alerte +1 (Alertness +1)": 5, "Seuil de Douleur Élevé (High Pain Threshold)": 10,
"Résistance aux Poisons +1 (Poison Resist +1)": 5,
"Curiosité (Curiosity)": -5, "Code de l'Honneur": -10, "Gourmandise (Gluttony)": -5,
"Honnêteté (Honesty)": -10, "Mauvais tempérament (Bad Temper)": -10, "Borgne (One Eye)": -15,
"Secret (Secret)": -10, "Pauvreté (Poverty)": -10, "Vœu (Mineur) (Minor Vow)": -5,
"Surpoids (Overweight)": -1, "Ennemi (Régulier) (Enemy)": -10,
"Devoir (Rare) (Duty)": -5, "Phobie (Mineure) (Minor Phobia)": -10,
};
const ADVANTAGES = Object.keys(GURPS_TRAITS).filter(key => GURPS_TRAITS[key] > 0);
const DISADVANTAGES = Object.keys(GURPS_TRAITS).filter(key => GURPS_TRAITS[key] < 0);
const GURPS_SKILLS = {
"Bagarre (Brawling)": { attr: 'dx', diff: 'E' },
"Lancer (Throwing)": { attr: 'dx', diff: 'A' },
"Escalade (Climbing)": { attr: 'dx', diff: 'A' },
"Pistolet (Pistol)": { attr: 'dx', diff: 'A' },
"Arc (Bow)": { attr: 'dx', diff: 'A' },
"Épée (Sword)": { attr: 'dx', diff: 'A' },
"Arme contondante (Melee Weapon)": { attr: 'dx', diff: 'A' },
"Natation (Swimming)": { attr: 'ht', diff: 'E' },
"Discrétion (Stealth)": { attr: 'dx', diff: 'A' },
"Médecine (First Aid)": { attr: 'iq', diff: 'E' },
"Conduite (Driving)": { attr: 'iq', diff: 'A' },
"Informatique (Computer Operation)": { attr: 'iq', diff: 'E' },
"Pilotage (Piloting)": { attr: 'iq', diff: 'H' },
"Langue Étrangère (Language)": { attr: 'iq', diff: 'A' },
"Savoir-faire (Area Knowledge)": { attr: 'iq', diff: 'E' },
"Survie (Survival)": { attr: 'per', diff: 'A' },
"Poche (Pickpocket)": { attr: 'dx', diff: 'H' }
};
const SKILL_COSTS = { 1: 1, 2: 2, 3: 4 };
// ---------------------------------------------------------------------------------
// Cache DOM elements
const dom = {};
attributeInputs.forEach(id => dom[id] = document.getElementById(id));
dom.charPoints = document.getElementById('charPoints');
dom.toggleSecondaryEdit = document.getElementById('toggleSecondaryEdit');
dom.basicSpeed = document.getElementById('basicSpeed');
dom.basicMove = document.getElementById('basicMove');
dom.charSheetName = document.getElementById('charSheetName');
// --- Utility functions ---
function showMessage(message) {
document.getElementById('messageText').innerText = message;
document.getElementById('messageBox').classList.remove('hidden');
}
window.hideMessage = function() {
document.getElementById('messageBox').classList.add('hidden');
}
function calculateCost(attribute, value) {
const baseValue = 10;
return (value - baseValue) * attributeCosts[attribute];
}
function getAttributeValue(attr) {
return parseInt(document.getElementById(attr).value) || 10;
}
function getSkillBaseLevel(attr, diff) {
const baseAttr = getAttributeValue(attr);
switch (diff) {
case 'E': return baseAttr;
case 'A': return baseAttr - 1;
case 'H': return baseAttr - 2;
case 'VH': return baseAttr - 3;
default: return baseAttr;
}
}
function calculateSkillCost(skillName, buyLevel) {
if (buyLevel === 0) return 0;
return SKILL_COSTS[buyLevel] || 0;
}
function getSkillOptionsHtml(selectedSkillName = '') {
const skills = Object.keys(GURPS_SKILLS);
let options = `<option value="">--- Choisir ou Personnaliser ---</option>`;
skills.forEach(skill => {
const selected = skill === selectedSkillName ? 'selected' : '';
const { attr, diff } = GURPS_SKILLS[skill];
options += `<option value="${skill}" data-attr="${attr}" data-diff="${diff}" ${selected}>${skill} (${attr}/${diff})</option>`;
});
options += `<option value="custom" ${selectedSkillName === 'custom' ? 'selected' : ''}>-- Entrée personnalisée --</option>`;
return options;
}
function updateSkillRow(skillItem) {
const select = skillItem.querySelector('.skill-select-input');
const buyLevelInput = skillItem.querySelector('.skill-buy-level-input');
const baseAttributeSpan = skillItem.querySelector('.skill-base-attr');
const totalLevelSpan = skillItem.querySelector('.skill-total-level');
const costSpan = skillItem.querySelector('.skill-cost');
const customNameInput = skillItem.querySelector('.skill-name-input');
const skillName = select ? select.value : 'custom';
const buyLevel = parseInt(buyLevelInput.value) || 0;
let baseAttr = '';
let totalLevel = 'N/A';
let cost = 0;
if (skillName === 'custom' || !select || select.value === '') {
baseAttr = 'N/A';
totalLevel = 'N/A';
cost = calculateSkillCost('custom', buyLevel);
} else {
const selectedOption = select.options[select.selectedIndex];
const attr = selectedOption.getAttribute('data-attr');
const diff = selectedOption.getAttribute('data-diff');
const baseLevel = getSkillBaseLevel(attr.toLowerCase(), diff);
totalLevel = baseLevel + buyLevel;
cost = calculateSkillCost(skillName, buyLevel);
baseAttr = `${attr}/${diff} (${baseLevel})`;
}
baseAttributeSpan.textContent = baseAttr;
totalLevelSpan.textContent = totalLevel;
costSpan.textContent = `${cost} pts`;
updateCostsAndTotal();
}
window.updateSkillRow = updateSkillRow;
function addSkillEntry(skillName = '', buyLevel = 0) {
const container = document.getElementById('skills-container');
const newItem = document.createElement('div');
newItem.className = `skill-item flex gap-2 items-center`;
newItem.setAttribute('data-skill', skillName);
const isCustom = skillName && !GURPS_SKILLS.hasOwnProperty(skillName);
const selectHtml = `
<select class="skill-select-input w-1/3 p-2 rounded-lg bg-gray-600 text-gray-200 ${isCustom ? 'hidden' : ''}"
onchange="updateSkillRow(this.closest('.skill-item'))">
${getSkillOptionsHtml(isCustom ? '' : skillName)}
</select>
`;
const customNameInputHtml = `
<input type="text" placeholder="Nom compétence" value="${isCustom ? skillName : ''}"
class="skill-name-input w-1/3 p-2 rounded-lg bg-gray-600 text-gray-200 ${isCustom ? '' : 'hidden'}">
`;
newItem.innerHTML = `
${selectHtml}
${customNameInputHtml}
<span class="skill-base-attr w-1/6 text-center text-gray-300 font-medium text-sm">N/A</span>
<input type="number" value="${buyLevel}" min="0" max="3" class="skill-buy-level-input w-1/6 p-2 rounded-lg text-center bg-gray-600 text-gray-200" oninput="updateSkillRow(this.closest('.skill-item'))">
<span class="skill-total-level w-1/6 text-center text-indigo-400 font-extrabold text-lg">N/A</span>
<span class="skill-cost w-1/6 text-right text-gray-400 font-bold">0 pts</span>
<button onclick="removeEntry(this, 'skill')" class="bg-red-500 hover:bg-red-600 text-white font-bold py-2 px-3 rounded-full text-sm">-</button>
`;
container.appendChild(newItem);
const selectElement = newItem.querySelector('.skill-select-input');
const customInput = newItem.querySelector('.skill-name-input');
selectElement.addEventListener('change', (e) => {
const item = e.target.closest('.skill-item');
const isNowCustom = e.target.value === 'custom';
if (isNowCustom) {
customInput.classList.remove('hidden');
e.target.classList.add('hidden');
customInput.value = '';
} else {
customInput.classList.add('hidden');
e.target.classList.remove('hidden');
}
updateSkillRow(item);
});
customInput.addEventListener('input', (e) => updateSkillRow(e.target.closest('.skill-item')));
updateSkillRow(newItem);
}
window.addSkillEntry = addSkillEntry;
function updateCostsAndTotal() {
let totalPoints = 0;
// 1. Attributes Costs
const stValue = parseInt(dom.st.value) || 10;
const dxValue = parseInt(dom.dx.value) || 10;
const iqValue = parseInt(dom.iq.value) || 10;
const htValue = parseInt(dom.ht.value) || 10;
const primaryValues = { st: stValue, dx: dxValue, iq: iqValue, ht: htValue };
mainAttributes.forEach(attr => {
const cost = calculateCost(attr, primaryValues[attr]);
document.getElementById(`${attr}Cost`).textContent = `${cost} pts`;
totalPoints += cost;
});
const secondaryMappings = {
hp: { source: 'st', input: dom.hp },
fp: { source: 'ht', input: dom.fp },
per: { source: 'iq', input: dom.per },
will: { source: 'iq', input: dom.will }
};
secondaryAttributes.forEach(attr => {
const { source, input } = secondaryMappings[attr];
const baseAttrValue = primaryValues[source];
if (input.disabled) {
input.value = baseAttrValue;
document.getElementById(`${attr}Cost`).textContent = `0 pts`;
} else {
const value = parseInt(input.value) || baseAttrValue;
const difference = value - baseAttrValue;
const cost = difference * attributeCosts[attr];
document.getElementById(`${attr}Cost`).textContent = `${cost} pts`;
totalPoints += cost;
}
});
// 2. Update Derived Statistics
const basicSpeed = (dxValue + htValue) / 4;
const basicMove = Math.floor(basicSpeed);
dom.basicSpeed.textContent = basicSpeed.toFixed(2);
dom.basicMove.textContent = basicMove;
// 3. Advantages and Disadvantages
document.querySelectorAll('#advantages-container .trait-cost-input').forEach(input => {
totalPoints += parseInt(input.value) || 0;
});
document.querySelectorAll('#disadvantages-container .trait-cost-input').forEach(input => {
totalPoints += parseInt(input.value) || 0;
});
// 4. Skills Costs
document.querySelectorAll('#skills-container .skill-item').forEach(item => {
const buyLevel = parseInt(item.querySelector('.skill-buy-level-input').value) || 0;
const cost = calculateSkillCost(item.getAttribute('data-skill'), buyLevel);
const select = item.querySelector('.skill-select-input');
if (select && select.value !== '' && select.value !== 'custom') {
const selectedOption = select.options[select.selectedIndex];
const attr = selectedOption.getAttribute('data-attr');
const diff = selectedOption.getAttribute('data-diff');
const baseLevel = getSkillBaseLevel(attr.toLowerCase(), diff);
item.querySelector('.skill-base-attr').textContent = `${attr}/${diff} (${baseLevel})`;
item.querySelector('.skill-total-level').textContent = baseLevel + buyLevel;
} else if (select && select.value === 'custom') {
item.querySelector('.skill-base-attr').textContent = `N/A`;
item.querySelector('.skill-total-level').textContent = `N/A`;
}
totalPoints += cost;
});
// 5. Final calculation
const startingPoints = parseInt(dom.charPoints.value) || 0;
const pointsRemaining = startingPoints - totalPoints;
document.getElementById('pointsUsed').textContent = totalPoints;
document.getElementById('pointsRemaining').textContent = pointsRemaining;
}
// --- Avantages/Désavantages Functions ---
function getTraitOptionsHtml(type, selectedTraitName = '') {
const traits = type === 'advantage' ? ADVANTAGES : DISADVANTAGES;
let options = `<option value="">--- Choisir ou Personnaliser ---</option>`;
traits.forEach(trait => {
const selected = trait === selectedTraitName ? 'selected' : '';
options += `<option value="${trait}" ${selected}>${trait} (${GURPS_TRAITS[trait]} pts)</option>`;
});
options += `<option value="custom" ${selectedTraitName === 'custom' ? 'selected' : ''}>-- Entrée personnalisée --</option>`;
return options;
}
function updateTraitCost(selectElement, costInput) {
const traitName = selectElement.value;
const isCustom = traitName === 'custom';
const customNameInput = selectElement.nextElementSibling;
if (isCustom) {
customNameInput.classList.remove('hidden');
customNameInput.value = '';
costInput.value = '';
selectElement.classList.add('hidden');
} else {
customNameInput.classList.add('hidden');
if (traitName && GURPS_TRAITS.hasOwnProperty(traitName)) {
costInput.value = GURPS_TRAITS[traitName];
} else {
costInput.value = '';
}
selectElement.classList.remove('hidden');
}
updateCostsAndTotal();
}
function addEntry(type, traitName = '', traitCost = '') {
const containerId = `${type}s-container`;
const container = document.getElementById(containerId);
const newItem = document.createElement('div');
newItem.className = `${type}-item flex gap-2 items-center`;
const isCustom = traitName && !GURPS_TRAITS.hasOwnProperty(traitName);
const selectHtml = `
<select class="trait-select-input flex-grow p-2 rounded-lg bg-gray-600 text-gray-200 ${isCustom ? 'hidden' : ''}"
onchange="updateTraitCost(this, this.parentNode.querySelector('.trait-cost-input'))">
${getTraitOptionsHtml(type, isCustom ? '' : traitName)}
</select>
`;
const customNameInputHtml = `
<input type="text" placeholder="Nom personnalisé" value="${isCustom ? traitName : ''}"
class="trait-name-input flex-grow p-2 rounded-lg bg-gray-600 text-gray-200 ${isCustom ? '' : 'hidden'}">
`;
newItem.innerHTML = `
${selectHtml}
${customNameInputHtml}
<input type="number" placeholder="Coût" value="${traitCost}" class="trait-cost-input w-20 p-2 rounded-lg text-center bg-gray-600 text-gray-200" oninput="updateCostsAndTotal()">
<button onclick="removeEntry(this, '${type}')" class="bg-red-500 hover:bg-red-600 text-white font-bold py-2 px-3 rounded-full text-sm">-</button>
`;
container.appendChild(newItem);
const selectElement = newItem.querySelector('.trait-select-input');
const costInput = newItem.querySelector('.trait-cost-input');
if (!isCustom && selectElement && traitName) {
selectElement.value = traitName;
}
selectElement.addEventListener('change', (e) => updateTraitCost(e.target, costInput));
costInput.addEventListener('input', updateCostsAndTotal);
newItem.querySelector('.trait-name-input').addEventListener('input', updateCostsAndTotal);
updateCostsAndTotal();
}
function removeEntry(button, type) {
const item = button.closest(`.${type}-item`);
item.remove();
updateCostsAndTotal();
}
window.removeEntry = removeEntry;
window.addEntry = addEntry;
window.updateTraitCost = updateTraitCost;
// --- Core Data Collection/Loading Logic ---
function collectCharacterData() {
const characterData = {
charSheetName: dom.charSheetName.value || "Fiche sans nom",
general: {
name: document.getElementById('charName').value,
points: parseInt(document.getElementById('charPoints').value) || 0,
race: document.getElementById('charRace').value,
description: document.getElementById('charDesc').value
},
primary: {},
secondary: {},
advantages: [],
disadvantages: [],
skills: [],
secondaryEditable: !dom.hp.disabled
};
mainAttributes.forEach(attr => {
characterData.primary[attr] = parseInt(dom[attr].value) || 10;
});
secondaryAttributes.forEach(attr => {
characterData.secondary[attr] = parseInt(dom[attr].value) || 10;
});
['advantage', 'disadvantage'].forEach(type => {
document.querySelectorAll(`#${type}s-container .${type}-item`).forEach(item => {
const select = item.querySelector('.trait-select-input');
const customInput = item.querySelector('.trait-name-input');
const cost = parseInt(item.querySelector('.trait-cost-input').value) || 0;
let name = '';
if (select && !select.classList.contains('hidden')) {
name = select.value;
} else if (customInput && !customInput.classList.contains('hidden')) {
name = customInput.value;
}
if (name) {
characterData[`${type}s`].push({ name: name, cost });
}
});
});
document.querySelectorAll('#skills-container .skill-item').forEach(item => {
const select = item.querySelector('.skill-select-input');
const customInput = item.querySelector('.skill-name-input');
const buyLevel = parseInt(item.querySelector('.skill-buy-level-input').value) || 0;
let name = '';
if (select && !select.classList.contains('hidden')) {
name = select.value;
} else if (customInput && !customInput.classList.contains('hidden')) {
name = customInput.value;
}
if (name || buyLevel > 0) { // Save the entry if named or points were spent
characterData.skills.push({ name: name, buyLevel: buyLevel });
}
});
return characterData;
}
function loadCharacterData(data) {
if (!data || !data.general || !data.primary || !data.secondary) {
showMessage("Erreur de format du fichier : Les données de base du personnage sont manquantes ou incorrectes.");
return;
}
document.getElementById('charSheetName').value = data.charSheetName || 'Fiche Chargée';
document.getElementById('charName').value = data.general.name || '';
document.getElementById('charPoints').value = data.general.points || 100;
document.getElementById('charRace').value = data.general.race || '';
document.getElementById('charDesc').value = data.general.description || '';
mainAttributes.forEach(attr => {
dom[attr].value = data.primary[attr] || 10;
});
const isEditable = data.secondaryEditable;
// Force l'état d'édition si besoin
if (dom.hp.disabled === isEditable) {
toggleSecondaryEdit(isEditable);
}
secondaryAttributes.forEach(attr => {
dom[attr].value = data.secondary[attr] || 10;
});
// Clear existing entries
const advContainer = document.getElementById('advantages-container');
const disadvContainer = document.getElementById('disadvantages-container');
const skillsContainer = document.getElementById('skills-container');
advContainer.innerHTML = '<h3 class="text-xl font-bold text-gray-300 mb-2">Avantages</h3>';
disadvContainer.innerHTML = '<h3 class="text-xl font-bold text-gray-300 mb-2">Désavantages</h3>';
skillsContainer.innerHTML = '';
// Load entries
(data.advantages || []).forEach(adv => { addEntry('advantage', adv.name, adv.cost); });
(data.disadvantages || []).forEach(disadv => { addEntry('disadvantage', disadv.name, disadv.cost); });
(data.skills || []).forEach(skill => { addSkillEntry(skill.name, skill.buyLevel); });
// Ensure at least one blank entry remains
if ((data.advantages || []).length === 0) { addEntry('advantage'); }
if ((data.disadvantages || []).length === 0) { addEntry('disadvantage'); }
if ((data.skills || []).length === 0) { addSkillEntry(); }
updateCostsAndTotal();
showMessage(`Fiche "${data.charSheetName || 'Sans Nom'}" chargée depuis le fichier.`);
}
window.loadCharacterData = loadCharacterData;
// --- File I/O Functions (Import/Export) ---
/**
* Télécharge les données du personnage actuel sous forme de fichier JSON.
*/
function exportToJson() {
try {
const data = collectCharacterData();
const jsonString = JSON.stringify(data, null, 2);
// Crée un Blob (Binary Large Object) avec le contenu JSON
const blob = new Blob([jsonString], { type: 'application/json' });
// Crée un lien de téléchargement invisible
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
// Utilise le nom de la fiche pour le nom du fichier
const sheetName = data.charSheetName.replace(/[^a-z0-9]/gi, '_').toLowerCase() || 'gurps_sheet';
a.download = `${sheetName}.json`;
// Simule un clic pour démarrer le téléchargement
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url); // Libère l'URL objet
showMessage(`Fiche de personnage "${data.charSheetName}" exportée en fichier JSON.`);
} catch (error) {
console.error("Erreur lors de l'exportation JSON : ", error);
showMessage("Erreur lors de l'exportation. Impossible de créer le fichier JSON.");
}
}
window.exportToJson = exportToJson;
/**
* Lit le fichier sélectionné par l'utilisateur et charge les données.
*/
function importFromJson(event) {
const file = event.target.files[0];
if (!file) {
return;
}
if (file.type !== "application/json") {
showMessage("Le fichier sélectionné n'est pas un fichier JSON valide (.json).");
return;
}
const reader = new FileReader();
reader.onload = (e) => {
try {
const content = e.target.result;
const data = JSON.parse(content);
loadCharacterData(data);
} catch (error) {
console.error("Erreur de lecture/parsing du fichier JSON : ", error);
showMessage("Erreur de lecture du fichier. Assurez-vous que le fichier est un JSON valide.");
}
};
reader.readAsText(file);
// Réinitialiser l'input file pour permettre le rechargement du même fichier
event.target.value = '';
}
// --- UI & State Management ---
function toggleSecondaryEdit(forceState = null) {
// isEnabled = Vrai si on passe de 'désactivé' à 'activé' (clic sur le bouton)
const isCurrentlyDisabled = dom.hp.disabled;
const newState = forceState !== null ? !forceState : isCurrentlyDisabled;
dom.hp.disabled = !newState;
dom.fp.disabled = !newState;
dom.per.disabled = !newState;
dom.will.disabled = !newState;
dom.hp.classList.toggle('disabled-input', !newState);
dom.fp.classList.toggle('disabled-input', !newState);
dom.per.classList.toggle('disabled-input', !newState);
dom.will.classList.toggle('disabled-input', !newState);
dom.toggleSecondaryEdit.textContent = newState ? "Réinitialiser les caractéristiques secondaires" : "Modifier les caractéristiques secondaires";
if (!newState) {
// If editing is disabled (state is reverted), reset to base values
const stValue = parseInt(dom.st.value) || 10;
const htValue = parseInt(dom.ht.value) || 10;
const iqValue = parseInt(dom.iq.value) || 10;
dom.hp.value = stValue;
dom.fp.value = htValue;
dom.per.value = iqValue;
dom.will.value = iqValue;
}
updateCostsAndTotal();
}
// Event Listeners and Initialization
document.addEventListener('DOMContentLoaded', () => {
// Initialisation avec des entrées vides pour commencer
addEntry('advantage');
addEntry('disadvantage');
addSkillEntry();
updateCostsAndTotal();
// Mettre à jour les coûts en direct pour tous les inputs numériques
attributeInputs.forEach(attr => {
dom[attr].addEventListener('input', updateCostsAndTotal);
});
dom.charPoints.addEventListener('input', updateCostsAndTotal);
// Gérer le bouton pour les caractéristiques secondaires
dom.toggleSecondaryEdit.addEventListener('click', () => toggleSecondaryEdit(null));
// Gérer l'exportation
document.getElementById('exportButton').addEventListener('click', exportToJson);
// Gérer l'importation
document.getElementById('loadFileInput').addEventListener('change', importFromJson);
});
</script>
</body>
</html>