-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtirage.js
233 lines (199 loc) · 9.96 KB
/
tirage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
// Variables globales
resultmail = "";
function tirerCartes() {
const nombreDePersonnes = document.getElementById('nombreDePersonnes').value;
const cartesUniques = document.getElementById('cartesUniques').checked;
const choixFichierJson = document.getElementById('choixFichierJson');
const resultDiv = document.getElementById('result');
const nomsDiv = document.getElementById('noms');
const formTirage = document.getElementById('formTirage');
const rebootBTN = document.getElementById('reboot');
const goMail = document.getElementById('goMail');
const cheminFichierJson = "decks/" + choixFichierJson.value; // Récupère le chemin du fichier sélectionné
// Vérifiez que le nombre de personnes est valide
if (nombreDePersonnes < 1) {
alert("Veuillez entrer un nombre de personnes valide (au moins 1).");
return;
}
// Efface les résultats précédents
resultDiv.innerHTML = '';
// Récupérer les prénoms depuis les champs de saisie
const prenoms = [];
for (let i = 0; i < nombreDePersonnes; i++) {
const input = nomsDiv.children[i];
const nom = input.value.trim();
if (!nom) {
alert(`Veuillez entrer le prénom du participant n°${i + 1}.`);
return;
}
prenoms.push(nom);
}
// Charger les listes de cartes depuis le fichier JSON sélectionné
fetch(cheminFichierJson)
.then(response => response.json())
.then(data => {
const listesDeCartes = data.listesDeCartes;
const univers = data.univers;
resultmail += `Deck : ` + univers[0] +` ; `;
// Cloner les catégories dans des tableaux temporaires
tPerso = [];
tAspect = [];
tObjet = [];
tLieu = [];
tEvent = [];
tChute = [];
// personnages
who = -1;
while (++who < listesDeCartes[0].length) {
tPerso[who] = listesDeCartes[0][who];
};
// aspects
who = -1;
while (++who < listesDeCartes[1].length) {
tAspect[who] = listesDeCartes[1][who];
};
// lieux
who = -1;
while (++who < listesDeCartes[2].length) {
tLieu[who] = listesDeCartes[2][who];
};
// événements
who = -1;
while (++who < listesDeCartes[3].length) {
tEvent[who] = listesDeCartes[3][who];
};
// objets
who = -1;
while (++who < listesDeCartes[4].length) {
tObjet[who] = listesDeCartes[4][who];
};
// chutes
who = -1;
while (++who < listesDeCartes[5].length) {
tChute[who] = listesDeCartes[5][who];
};
// Afficher le deck choisi
const choixUnivers = document.createElement('h3');
choixUnivers.className = "univers";
choixUnivers.innerHTML = '<img class="pictos" src="svg/'+ univers[1] +'.svg" alt="'+ univers[1] +'" title="'+ univers[1] +'" /> Dans l’univers '+ univers[0] +' <img class="pictos" src="svg/'+ univers[1] +'.svg" alt="'+ univers[1] +'" title="'+ univers[1] +'" />';
resultDiv.appendChild(choixUnivers);
// Tirer les cartes pour chaque personne
for (let i = 0; i < nombreDePersonnes; i++) {
switch(cartesUniques) {
case true:
// VERSION CARTES UNIQUES
// Tirage perso
randPerso = Math.floor(Math.random() * tPerso.length);
rPerso = tPerso[randPerso];
tPerso.splice(randPerso, 1)
// Tirage aspect
randAspect = Math.floor(Math.random() * tAspect.length);
rAspect = tAspect[randAspect];
tAspect.splice(randAspect, 1)
// Tirage objet
randObjet = Math.floor(Math.random() * tObjet.length);
rObjet = tObjet[randObjet];
tObjet.splice(randObjet, 1)
// Tirage lieu
randLieu = Math.floor(Math.random() * tLieu.length);
rLieu = tLieu[randLieu];
tLieu.splice(randLieu, 1)
// Tirage événement
randEvent = Math.floor(Math.random() * tEvent.length);
rEvent = tEvent[randEvent];
tEvent.splice(randEvent, 1)
// Tirage chute
randChute = Math.floor(Math.random() * tChute.length);
rChute = tChute[randChute];
tChute.splice(randChute, 1)
break;
case false:
// VERSION CARTES CLONÉES
rPerso = listesDeCartes[0][Math.floor(Math.random() * listesDeCartes[0].length)];
rAspect = listesDeCartes[1][Math.floor(Math.random() * listesDeCartes[1].length)];
rObjet = listesDeCartes[4][Math.floor(Math.random() * listesDeCartes[4].length)];
rLieu = listesDeCartes[2][Math.floor(Math.random() * listesDeCartes[2].length)];
rEvent = listesDeCartes[3][Math.floor(Math.random() * listesDeCartes[3].length)];
rChute = listesDeCartes[5][Math.floor(Math.random() * listesDeCartes[5].length)];
break;
}
// Étape 2 – Afficher les résultats
const participantDiv = document.createElement('div');
participantDiv.className = 'participant-block';
participantDiv.innerHTML = `
<table>
<tr>
<td class="celParticipant celPicto"><img class="pictos" src="svg/participant_01.svg" alt="Participant" title="Le participant"></td>
<td class="celTab celParticipant">${prenoms[i].toLowerCase()}</td>
<td class="celPicto"><img class="pictos" src="svg/personnage.svg" alt="Personnage" title="Le personnage"></td>
<td class="celTab">${rPerso}</td> <!-- Carte Personnage -->
<td class="celPicto"><img class="pictos" src="svg/aspect.svg" alt="Aspect" title="L’aspect"></td>
<td class="celTab">${rAspect}</td> <!-- Carte Aspect -->
</tr>
<tr>
<td class="celPicto"><img class="pictos" src="svg/objet.svg" alt="Objet" title="L’objet"></td>
<td class="celTab">${rObjet}</td> <!-- Carte Objet -->
<td class="celPicto"><img class="pictos" src="svg/lieu.svg" alt="Lieu" title="Le lieu"></td>
<td class="celTab">${rLieu}</td> <!-- Carte Lieu -->
<td class="celPicto"><img class="pictos" src="svg/evenement.svg" alt="Événement" title="L'événement"></td>
<td class="celTab">${rEvent}</td> <!-- Carte Événement -->
</tr>
</table>
<table>
<tr>
<td class="celChute celPicto"><img class="pictos" src="svg/chute.svg" alt="Fin de l’histoire" title="La fin de l’histoire"></td>
<td class="celChute">${rChute}</td> <!-- Carte Fin d'histoire -->
</tr>
</table>
<br/>
<hr/>
<br/>`;
resultDiv.appendChild(participantDiv);
// Étape 3 – Remplir le corps du mail
resultmail += 'Participant : ' + prenoms[i] +` ; `
resultmail += 'Personnage : ' + rPerso +` ; `
resultmail += 'Aspect : ' + rAspect +` ; `
resultmail += 'Objet : ' + rObjet +` ; `
resultmail += 'Lieu : ' + rLieu +` ; `
resultmail += 'Événement : ' + rEvent +` ; `
resultmail += 'Fin d’histoire : ' + rChute +` ; `
resultmail += ' /// ';
}
// Affiche la DIV des résultats
resultDiv.style.display = 'block';
rebootBTN.style.display = 'block';
goMail.style.display = 'block';
formTirage.style.display = 'none';
})
.catch(error => console.error('Erreur lors du chargement du fichier JSON :', error));
}
function reinitialiserPage() {
document.getElementById('nombreDePersonnes').value = 1;
document.getElementById('formTirage').style.display = 'block';
location.reload();
}
const envoyerMail = () => {
const dateDuJour = new Date();
const jour = ('0' + dateDuJour.getDate()).slice(-2);
const mois = ('0' + (dateDuJour.getMonth() + 1)).slice(-2);
const annee = dateDuJour.getFullYear();
const dateFormattee = `${jour}/${mois}/${annee}`;
const destinataire = '[email protected]';
const sujet = `Cartes du ${dateFormattee}`;
const corps = `Tirage du ${dateFormattee} : ${resultmail}`;
const mailtoLink = `mailto:${destinataire}?subject=${encodeURIComponent(sujet)}&body=${encodeURIComponent(corps)}`;
window.location.href = mailtoLink;
}
/*
_____ _______ _____ _____
/ ____|__ __/ ____| | __ \
| | __ | | | | | |__) |
| | |_ | | | | | | _ /
| |__| |_ | |_| |____ _| | \ \ _
\_____(_)|_(_)\_____(_)_| \_(_)
Générateur de Tirages de Cartes à Raconter©™®
Version 0.8b — Janvier 2024
Créé par Vincent Corlaix avec de gros coups de main de ChatGPT 3.5
Github du projet : https://github.com/Nootilus/Cartes_a_Raconter
Fichier : tirage.js
*/