import React, { useState, useRef } from "react"; import htmlToImage from "html-to-image"; import download from "downloadjs"; // OPTCG — Générateur de cartes (Prototype) // - Composant React autonome (export default) // - Utilise un template SVG original pour la carte // - Appelle une API /api/generate-image (mock) pour générer l'illustration IA // - Permet l'édition simple des stats et l'export PNG // - Tailwind classes pour le style (optionnel) export default function CardGenerator() { const [name, setName] = useState("Capitaine Shiro"); const [rarity, setRarity] = useState("Rare"); const [cardType, setCardType] = useState("Character"); const [color, setColor] = useState("red"); const [cost, setCost] = useState(2); const [power, setPower] = useState(5000); const [effect, setEffect] = useState("Quand cette carte attaque, tu peux piocher 1 carte."); const [status, setStatus] = useState("Prêt"); const [artUrl, setArtUrl] = useState(null); const [isGenerating, setIsGenerating] = useState(false); const previewRef = useRef(null); // Simule un appel backend pour générer une image IA async function generateArt() { setIsGenerating(true); setStatus("Génération en cours..."); try { // Ici tu appelleras ton endpoint réel (OpenAI / SDXL / autre) // Ex : const res = await fetch('/api/generate-image', { method: 'POST', body: JSON.stringify({ prompt }) }) // Pour la démo on utilise une image placeholder via picsum await new Promise((r) => setTimeout(r, 1400)); // simule latence const seed = Math.floor(Math.random() * 1000); const url = `https://picsum.photos/seed/op${seed}/800/1000`; setArtUrl(url); setStatus("Image générée (placeholder)"); } catch (err) { console.error(err); setStatus("Erreur lors de la génération"); } finally { setIsGenerating(false); } } async function exportCard() { if (!previewRef.current) return; setStatus("Préparation export..."); try { const dataUrl = await htmlToImage.toPng(previewRef.current, { width: 1024, height: 1280, cacheBust: true }); download(dataUrl, `${name.replace(/\s+/g, '_')}_card.png`); setStatus("Exporté !"); } catch (err) { console.error(err); setStatus("Erreur export"); } } // Prompt builder simple (à envoyer à l'API image réelle) function buildPrompt() { return `${name}, original shonen pirate character, dynamic pose, dramatic lighting, vivid colors, high detail, ${cardType} card art, no copyrighted characters, anime-inspired style`; } return (

Générateur de cartes — Prototype

setName(e.target.value)} className="w-full rounded p-2 bg-slate-800" />
{['red','green','blue','yellow','black','purple'].map((c) => ( ))}
setCost(Number(e.target.value))} className="w-full rounded p-2 bg-slate-800" />
setPower(Number(e.target.value))} className="w-full rounded p-2 bg-slate-800" />