diff --git a/public/js/home.js b/public/js/home.js
index 5fcb4c0..e5501ac 100644
--- a/public/js/home.js
+++ b/public/js/home.js
@@ -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();
diff --git a/src/Command/PopulateDBEmojiAvailableCommand.php b/src/Command/PopulateDBEmojiAvailableCommand.php
index 62404d4..0985b4c 100644
--- a/src/Command/PopulateDBEmojiAvailableCommand.php
+++ b/src/Command/PopulateDBEmojiAvailableCommand.php
@@ -38,31 +38,33 @@ class PopulateDBEmojiAvailableCommand extends Command
$this->connection->executeStatement('
CREATE TABLE stock_emoji (
id INT PRIMARY KEY,
- code VARCHAR(255) NOT NULL
+ code VARCHAR(255) NOT NULL,
+ name VARCHAR(255) NOT NULL
)
');
+
// On peuple la table
- $this->connection->executeStatement("INSERT INTO stock_emoji (id, code) VALUES
- (1,'🤖'),
- (2,'😺'),
- (3,'🧠'),
- (4,'👻'),
- (5,'🧟'),
- (6,'🐶'),
- (7,'👽'),
- (8,'🧛'),
- (9,'🎃'),
- (10,'🐸'),
- (11,'⚡'),
- (12,'💀'),
- (13,'🔥'),
- (14,'🧙'),
- (15,'🌪️'),
- (16,'😎'),
- (17,'😁'),
- (18,'🌟'),
- (19,'😈')
+ $this->connection->executeStatement("INSERT INTO stock_emoji (id, code, name) VALUES
+ (1,'🤖','Rodolph'),
+ (2,'😺','Bobette'),
+ (3,'🧠','Diana'),
+ (4,'👻','Ian'),
+ (5,'🧟','Alice'),
+ (6,'🐶','Eric'),
+ (7,'👽','Hannah'),
+ (8,'🧛','Fiona'),
+ (9,'🎃','George'),
+ (10,'🐸','John'),
+ (11,'⚡','Charlie'),
+ (12,'💀','Benoit'),
+ (13,'🔥','Sophie'),
+ (14,'🧙','Bob'),
+ (15,'🌪️','Ethan'),
+ (16,'😎','Luna'),
+ (17,'😁','Maxence'),
+ (18,'🌟','Jasper'),
+ (19,'😈','Nora')
");
$output->writeln('Base de données peuplée.');
diff --git a/src/Entity/StockEmoji.php b/src/Entity/StockEmoji.php
index 1626de0..c5f2e05 100644
--- a/src/Entity/StockEmoji.php
+++ b/src/Entity/StockEmoji.php
@@ -16,6 +16,9 @@ class StockEmoji
#[ORM\Column(length: 255)]
private ?string $code = null;
+ #[ORM\Column(length: 255)]
+ private ?string $name = null;
+
public function getId(): ?int
{
return $this->id;
@@ -32,4 +35,16 @@ class StockEmoji
return $this;
}
+
+ public function getName(): ?string
+ {
+ return $this->name;
+ }
+
+ public function setName(string $name): self
+ {
+ $this->name = $name;
+
+ return $this;
+ }
}
diff --git a/templates/home/index.html.twig b/templates/home/index.html.twig
index 2f191c6..0df96bb 100644
--- a/templates/home/index.html.twig
+++ b/templates/home/index.html.twig
@@ -103,5 +103,5 @@
{% endblock %}
{% block javascripts %}
-
+
{% endblock %}
\ No newline at end of file