/* Module capture photo - Preview live, compte a rebours, declenchement */ let previewActif = false; let previewInterval = null; const EMOJI_CAR = { 3: '🤪', 2: '😱', 1: '🔥' }; // --- Preview live --- function lancerPreview() { if (previewActif) return; previewActif = true; previewInterval = setInterval(() => { if (previewActif) wsEnvoyer({ type: 'preview' }); }, 100); } function arreterPreview() { previewActif = false; if (previewInterval) { clearInterval(previewInterval); previewInterval = null; } } wsOnMessage('preview', (msg) => { if (!previewActif) return; const img = document.getElementById('img-preview'); if (img) img.src = msg.image; }); // --- Capture --- async function lancerCapture() { photosSession = []; lancerPreview(); majCompteurAccueil(); const nbPhotos = getNombrePhotos(); const compteurEl = document.getElementById('capture-compteur'); for (let i = 0; i < nbPhotos; i++) { if (nbPhotos > 1) { compteurEl.textContent = `Photo ${i + 1} / ${nbPhotos}`; } await compteARebours(); afficherFlash(); arreterPreview(); const resultat = await apiPost('/api/capturer'); if (resultat.erreur) { // Limite atteinte ou erreur allerA('accueil'); return; } if (resultat.nom) { photosSession.push(resultat.nom); } if (i < nbPhotos - 1) { lancerPreview(); await pause(500); } } await traiterCapture(); } function getNombrePhotos() { if (modeActuel === 'simple') return 1; if (modeActuel === 'multi') return config.multi_shot?.nombre_photos || 3; return 1; } async function compteARebours() { const conteneur = document.getElementById('compte-a-rebours'); const chiffre = document.getElementById('chiffre-car'); const duree = config.camera?.compte_a_rebours || 3; const anim = config.camera?.animation_compte_a_rebours || 'classique'; conteneur.classList.remove('cache'); for (let i = duree; i > 0; i--) { // Contenu selon le type d'animation if (anim === 'emoji') { chiffre.textContent = EMOJI_CAR[i] || i; } else { chiffre.textContent = i; } // Appliquer l'animation chiffre.className = 'anim-chiffre anim-' + anim; chiffre.style.animation = 'none'; chiffre.offsetHeight; chiffre.className = 'anim-chiffre anim-' + anim; await pause(1000); } conteneur.classList.add('cache'); } function afficherFlash() { const flash = document.getElementById('flash-blanc'); flash.classList.remove('cache'); flash.style.animation = 'none'; flash.offsetHeight; flash.style.animation = 'flash 0.3s ease-out forwards'; setTimeout(() => flash.classList.add('cache'), 400); } async function traiterCapture() { if (photosSession.length === 0) { allerA('accueil'); return; } if (modeActuel === 'multi') { const mode = config.multi_shot?.mode || 'strip'; let resultat; if (mode === 'strip') { resultat = await apiPost('/api/strip', { photos: photosSession }); } else { resultat = await apiPost('/api/collage', { photos: photosSession }); } if (resultat.nom) { photoFinale = resultat.nom; afficherPreviewPhoto('/data/exports/' + resultat.nom); } } else { photoFinale = photosSession[0]; afficherPreviewPhoto('/data/photos/' + photosSession[0]); } allerA('preview'); } function afficherPreviewPhoto(chemin) { document.getElementById('photo-resultat').src = chemin; document.getElementById('photo-partage').src = chemin; if (modeActuel === 'simple' && config.fonctionnalites?.filtres) { chargerFiltres(); } if (config.fonctionnalites?.overlays) { chargerOverlays(); } } // --- Compteur accueil --- async function majCompteurAccueil() { const etat = await apiGet('/api/compteur'); const el = document.getElementById('compteur-accueil'); if (etat.actif) { el.classList.remove('cache'); document.getElementById('compteur-restant').textContent = etat.restantes; document.getElementById('compteur-limite').textContent = etat.limite; } else { el.classList.add('cache'); } } function pause(ms) { return new Promise(resolve => setTimeout(resolve, ms)); }