brouillon3
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| brouillon3 [2026/05/12 12:19] – nanaki | brouillon3 [2026/05/12 13:53] (Version actuelle) – nanaki | ||
|---|---|---|---|
| Ligne 675: | Ligne 675: | ||
| - | // ===== ENCODE / DECODE | + | // ===================================== |
| + | // ENCODE / DECODE | ||
| + | // ===================================== | ||
| function encodeBuild(data){ | function encodeBuild(data){ | ||
| - | return JSON.stringify(data); | + | return |
| } | } | ||
| function decodeBuild(code){ | function decodeBuild(code){ | ||
| - | return JSON.parse(code); | + | return JSON.parse(decodeURIComponent(code)); |
| } | } | ||
| - | // ===== EXPORT | + | // ===================================== |
| - | function exportBuild(){ | + | // BUILD DATA |
| + | // ===================================== | ||
| - | let data = { | + | function getBuildData(){ |
| - | race: raceSelect.value, | + | |
| - | stats: {}, | + | |
| - | equip: {}, | + | |
| - | skills: [], | + | |
| - | spells: [] | + | |
| - | }; | + | |
| - | for(let s in costTable){ | + | |
| - | data.stats[s] = +document.getElementById(s).value || 0; | + | race: raceSelect.value, |
| - | } | + | |
| + | equip: {}, | ||
| + | skills: | ||
| + | | ||
| + | | ||
| - | Object.entries(slots).forEach(([k, | + | // stats |
| - | data.equip[k] = s.value; | + | for(let s in costTable){ |
| - | }); | + | data.stats[s] = +document.getElementById(s).value |
| + | } | ||
| - | document.querySelectorAll(" | + | // équipements |
| - | data.skills.push(s.dataset.name); | + | Object.entries(slots).forEach(([k,s])=>{ |
| - | }); | + | data.equip[k] = s.value; |
| + | }); | ||
| - | document.querySelectorAll(" | + | // passifs |
| - | data.spells.push({ | + | |
| - | dex: +s.dataset.dex, | + | data.skills.push(s.dataset.name); |
| - | prot: +s.dataset.prot | + | }); |
| - | }); | + | |
| - | }); | + | |
| - | let code = encodeBuild(data); | + | // sorts |
| + | document.querySelectorAll(" | ||
| + | | ||
| + | dex: +s.dataset.dex, | ||
| + | prot: +s.dataset.prot | ||
| + | }); | ||
| + | }); | ||
| - | // 🔥 important → stringify lisible | + | return data; |
| - | prompt(" | + | |
| } | } | ||
| - | // ===== IMPORT | + | // ===================================== |
| - | function importBuild(codeInput){ | + | // APPLY BUILD |
| + | // ===================================== | ||
| - | let code = codeInput || prompt("Colle le code du build :"); | + | function applyBuild(data){ |
| - | if(!code) return; | + | |
| - | try{ | + | // race |
| + | raceSelect.value = data.race || " | ||
| - | code = code.trim(); | + | // recharge équipements race |
| + | resetSlots(); | ||
| + | fillEquip(); | ||
| - | let data = decodeBuild(code); | + | // stats |
| + | for(let s in costTable){ | ||
| + | document.getElementById(s).value = | ||
| + | data.stats? | ||
| + | } | ||
| - | raceSelect.value = data.race; | + | // équipements |
| + | Object.entries(slots).forEach(([k, | ||
| + | s.value = data.equip?.[k] || ""; | ||
| + | }); | ||
| - | for(let s in costTable){ | + | // passifs |
| - | document.getElementById(s).value = data.stats[s] || 0; | + | document.querySelectorAll(" |
| + | | ||
| + | data.skills? | ||
| + | }); | ||
| + | |||
| + | // sorts | ||
| + | document.querySelectorAll(" | ||
| + | |||
| + | s.checked | ||
| + | sp.dex == +s.dataset.dex && | ||
| + | sp.prot == +s.dataset.prot | ||
| + | ); | ||
| + | |||
| + | }); | ||
| + | |||
| + | displayBase(); | ||
| + | checkLimit(); | ||
| + | autoCalculate(); | ||
| } | } | ||
| - | Object.entries(slots).forEach(([k, | + | // ===================================== |
| - | s.value | + | // EXPORT |
| - | }); | + | // ===================================== |
| - | document.querySelectorAll(" | + | function exportBuild(){ |
| - | s.checked = data.skills.includes(s.dataset.name); | + | |
| - | }); | + | |
| - | document.querySelectorAll(" | + | let data = getBuildData(); |
| - | s.checked = data.spells.some(sp => | + | |
| - | sp.dex == +s.dataset.dex && sp.prot == +s.dataset.prot | + | |
| - | ); | + | |
| - | }); | + | |
| - | displayBase(); | + | let code = encodeBuild(data); |
| - | checkLimit(); | + | |
| - | autoCalculate(); | + | |
| - | }catch(e){ | + | prompt("Copie ton build :", code); |
| - | alert("❌ Code invalide"); | + | |
| - | console.log(e); | + | |
| - | } | + | |
| } | } | ||
| - | // ===== LIEN PARTAGE | + | // ===================================== |
| - | function | + | // IMPORT |
| + | // ===================================== | ||
| + | |||
| + | function | ||
| + | |||
| + | let code = codeInput; | ||
| + | |||
| + | if(!code){ | ||
| + | code = prompt(" | ||
| + | } | ||
| + | |||
| + | if(!code) return; | ||
| + | |||
| + | try{ | ||
| + | |||
| + | code = code.trim(); | ||
| + | |||
| + | let data = decodeBuild(code); | ||
| + | |||
| + | applyBuild(data); | ||
| + | |||
| + | alert(" | ||
| + | |||
| + | }catch(e){ | ||
| - | let data = { | + | console.log(e); |
| - | race: raceSelect.value, | + | |
| - | stats: {}, | + | |
| - | equip: {}, | + | |
| - | skills: [], | + | |
| - | spells: [] | + | |
| - | }; | + | |
| - | for(let s in costTable){ | + | alert("❌ Code invalide" |
| - | data.stats[s] = +document.getElementById(s).value || 0; | + | } |
| } | } | ||
| - | Object.entries(slots).forEach(([k, | + | // ===================================== |
| - | data.equip[k] | + | // LIEN PARTAGE |
| - | }); | + | // ===================================== |
| - | document.querySelectorAll(" | + | function copyLink(){ |
| - | data.skills.push(s.dataset.name); | + | |
| - | }); | + | let data = getBuildData(); |
| + | |||
| + | let code = encodeBuild(data); | ||
| + | |||
| + | let url = | ||
| + | window.location.origin + | ||
| + | window.location.pathname + | ||
| + | "? | ||
| - | document.querySelectorAll(" | + | navigator.clipboard.writeText(url).then(()=>{ |
| - | data.spells.push({ | + | |
| - | dex: +s.dataset.dex, | + | |
| - | prot: +s.dataset.prot | + | |
| - | }); | + | |
| - | }); | + | |
| - | let code = encodeBuild(data); | + | alert("🔗 Lien copié !"); |
| - | // 🔥 ENCODAGE URL OBLIGATOIRE | + | }).catch(()=>{ |
| - | let url = window.location.origin + window.location.pathname + "? | + | |
| - | navigator.clipboard.writeText(url).catch(()=> | + | |
| - | | + | |
| - | }); | + | |
| - | alert(" | + | }); |
| } | } | ||
| - | // ===== AUTO LOAD URL ===== | + | // ===================================== |
| + | // AUTO LOAD URL | ||
| + | // ===================================== | ||
| (function(){ | (function(){ | ||
| - | let params = new URLSearchParams(window.location.search); | + | try{ |
| - | let code = params.get(" | + | |
| - | if(!code) return; | + | let params = |
| + | new URLSearchParams(window.location.search); | ||
| - | try{ | + | let code = params.get(" |
| - | code = decodeURIComponent(code); | + | |
| - | importBuild(code); | + | if(!code) return; |
| - | }catch(e){ | + | |
| - | console.log(" | + | let data = decodeBuild(code); |
| - | } | + | |
| + | applyBuild(data); | ||
| + | |||
| + | console.log(" | ||
| + | |||
| + | | ||
| + | |||
| + | | ||
| + | |||
| + | | ||
| })(); | })(); | ||
brouillon3.1778581144.txt.gz · Dernière modification : 2026/05/12 12:19 de nanaki
