|
|
|
@ -40,23 +40,47 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleAction(type) {
|
|
|
|
|
async function handleAction(type) {
|
|
|
|
|
if (selectedCards.length !== 2) {
|
|
|
|
|
alert("Tu dois sélectionner 2 créatures.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const name1 = selectedCards[0].dataset.name;
|
|
|
|
|
const name2 = selectedCards[1].dataset.name;
|
|
|
|
|
const id1 = selectedCards[0].dataset.id;
|
|
|
|
|
const id2 = selectedCards[1].dataset.id;
|
|
|
|
|
|
|
|
|
|
if (type === 'reproduction') {
|
|
|
|
|
window.location.href = `/fusion/${encodeURIComponent(name1)}/${encodeURIComponent(name2)}`;
|
|
|
|
|
return;
|
|
|
|
|
} else if (type === 'combat') {
|
|
|
|
|
console.log(`Combat : ${name1} contre ${name2}`);
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`/emoji/fusion/${encodeURIComponent(id1)}/${encodeURIComponent(id2)}`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
'Accept': 'application/json'
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
throw new Error("Erreur serveur : " + response.status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
|
|
|
|
|
alert(`Succès : ${data.message} (ID : ${data.childId})`);
|
|
|
|
|
|
|
|
|
|
// Tu peux aussi mettre à jour le DOM ici avec le nouvel enfant
|
|
|
|
|
// ex: ajouter une carte, etc.
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Erreur lors de la reproduction :", error);
|
|
|
|
|
alert("Une erreur est survenue lors de la reproduction.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return; // on quitte ici
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (type === 'combat') {
|
|
|
|
|
console.log(`Combat : ${id1} contre ${id2}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Réinitialiser après l'action (seulement si pas redirigé)
|
|
|
|
|
// Réinitialiser si pas redirection
|
|
|
|
|
selectedCards.forEach(card => card.classList.remove('selected'));
|
|
|
|
|
selectedCards = [];
|
|
|
|
|
updateSelectionDisplay();
|
|
|
|
|