1098 lines
65 KiB
PHP
1098 lines
65 KiB
PHP
{{-- PLOXION decouverte (🔓) — le MODE JEU de la forge, en JEU INCRÉMENTAL (Kittens/Cookie Clicker).
|
||
Le joueur démarre avec une forge quasi VIDE (2 bions de tier 0) et REDÉCOUVRE
|
||
progressivement tout l'arbre de recettes, façon crafting Minecraft :
|
||
bion = item · composition = recette (une SOURCE + une VUE de même type).
|
||
Boucle incrémentale :
|
||
- ressource de base = koin (le résidu qui s'accumule) ;
|
||
- production passive : chaque tick (1 s) ajoute prod koin (somme 0.2·(tier+1) des bions débloqués) ;
|
||
- récolte manuelle : gros bouton, +max(1,prod) par clic ;
|
||
- plafond de stockage cap = 25 + 25·(bions débloqués au-delà des 2 de départ) → pousse à dépenser ;
|
||
- crafter une recette coûte 10·1.6^k koin (k = crafts déjà faits) et débloque un nouveau bion
|
||
(récompense → augmente prod et cap) → révèle de nouvelles recettes ;
|
||
- progrès hors-ligne : au chargement, gain = prod·min(absence, 1 h), borné par cap.
|
||
FOG OF WAR : on ne révèle JAMAIS l'ampleur du non-débloqué (aucun total, aucune barre de complétion).
|
||
Données : GET /px/synth-catalog.json (bions tiers 0..4, compositions).
|
||
Progression PAR JOUEUR persistée (jOSBoxion ns=decouverte key=progression +
|
||
fallback localStorage xb:decouverte).
|
||
PORTS BUS (jOSPorts) : ÉMET decouverte.craft (bion redécouvert -> minecraft.give),
|
||
decouverte.fundamental (palier son/wifi/xion -> minecraft.dimension),
|
||
decouverte.expedition (bloc/cubion forgé -> minecraft.place) ; ÉCOUTE
|
||
ploxion.decouverte.harvest (<- minecraft.command via jOSWire) : chaque commande
|
||
jouée dans le monde 3D = activité -> récolte de koin (boucle jouer<->forger).
|
||
100% client-side, ES5 STRICT (var/function), DÉTERMINISTE (zéro-LLM). --}}
|
||
<style>
|
||
.dec{display:flex;flex-direction:column;height:100%;box-sizing:border-box;position:relative;overflow:auto;
|
||
background:var(--xr-bg,#0a0f18);color:var(--xr-fg,var(--xr-text,#e8e9f2));font:14px/1.45 system-ui,-apple-system,sans-serif}
|
||
.dec *{box-sizing:border-box}
|
||
.dec__head{position:sticky;top:0;z-index:3;padding:12px 14px 11px;
|
||
background:linear-gradient(180deg,rgba(16,22,36,.98),rgba(12,17,28,.94));border-bottom:1px solid rgba(150,150,180,.16)}
|
||
.dec__titrow{display:flex;align-items:center;gap:8px}
|
||
.dec__title{font-weight:800;font-size:1.06rem;margin-right:auto;display:flex;align-items:center;gap:6px}
|
||
.dec__reset{cursor:pointer;background:rgba(127,127,160,.14);color:inherit;border:1px solid rgba(150,150,180,.28);
|
||
border-radius:7px;padding:5px 9px;font-size:.72rem}
|
||
.dec__reset:hover{background:rgba(127,127,160,.24)}
|
||
.dec__sub{font-size:.72rem;opacity:.58;margin-top:3px}
|
||
.dec__koinrow{display:flex;align-items:center;gap:12px;margin-top:10px;flex-wrap:wrap}
|
||
.dec__koin{display:flex;align-items:baseline;gap:6px;font-variant-numeric:tabular-nums;
|
||
background:rgba(30,38,58,.55);border:1px solid rgba(150,150,180,.2);border-radius:9px;padding:7px 12px}
|
||
.dec__klabel{font-size:.7rem;text-transform:uppercase;letter-spacing:.06em;opacity:.6;font-weight:800}
|
||
.dec__kval{font-size:1.3rem;font-weight:800;color:var(--xr-accent,#7a7cff)}
|
||
.dec__ksep{opacity:.45}
|
||
.dec__kcap{font-size:.95rem;opacity:.72;font-weight:700}
|
||
.dec__kprod{font-size:.72rem;opacity:.62;margin-left:4px;font-weight:700}
|
||
.dec__harvestwrap{position:relative;margin-left:auto}
|
||
.dec__harvest{cursor:pointer;border:none;border-radius:9px;padding:11px 18px;font-weight:800;font-size:.92rem;
|
||
background:var(--xr-accent,#7a7cff);color:#0b0d1a;border-top:2px solid rgba(255,255,255,.32);border-bottom:2px solid rgba(0,0,0,.32)}
|
||
.dec__harvest:active{transform:translateY(1px)}
|
||
.dec__float{position:absolute;left:50%;top:-4px;transform:translateX(-50%);pointer-events:none;z-index:6;
|
||
font-weight:800;color:#bff0d0;font-size:.9rem;font-variant-numeric:tabular-nums;animation:dec-float .9s ease-out forwards}
|
||
@keyframes dec-float{0%{opacity:1;transform:translateX(-50%) translateY(0)}100%{opacity:0;transform:translateX(-50%) translateY(-26px)}}
|
||
.dec__prog{margin-top:9px}
|
||
.dec__progtxt{font-size:.72rem;opacity:.82;margin-top:5px;font-variant-numeric:tabular-nums}
|
||
.dec__win{margin-top:9px;padding:9px 11px;border-radius:9px;text-align:center;font-weight:800;
|
||
background:rgba(60,180,110,.18);border:1px solid rgba(80,200,130,.5);color:#bff0d0}
|
||
.dec__won{padding:13px 12px;font-size:1.02rem;letter-spacing:.03em;color:#eef;
|
||
background:linear-gradient(135deg,rgba(122,124,255,.3),rgba(60,180,110,.22));border-color:rgba(122,124,255,.7);
|
||
text-shadow:0 0 12px rgba(122,124,255,.6);animation:dec-won 2.4s ease-in-out infinite}
|
||
@keyframes dec-won{0%,100%{box-shadow:0 0 0 1px rgba(122,124,255,.3) inset,0 0 18px rgba(122,124,255,.2)}
|
||
50%{box-shadow:0 0 0 1px rgba(122,124,255,.5) inset,0 0 30px rgba(122,124,255,.42)}}
|
||
.dec__voie{padding-top:8px;border-top:1px dashed rgba(122,124,255,.35)}
|
||
.dec__voie .dec__h{color:var(--xr-accent,#7a7cff);opacity:.92}
|
||
.dec__body{padding:13px 14px 26px;display:flex;flex-direction:column;gap:17px}
|
||
.dec__sect{display:flex;flex-direction:column;gap:9px}
|
||
.dec__h{font-size:.7rem;text-transform:uppercase;letter-spacing:.06em;opacity:.72;font-weight:800;display:flex;align-items:center;gap:8px}
|
||
.dec__count{font-variant-numeric:tabular-nums;opacity:.82;font-weight:600}
|
||
.dec__inv{display:grid;grid-template-columns:repeat(auto-fill,minmax(94px,1fr));gap:8px}
|
||
.dec__slot{position:relative;display:flex;flex-direction:column;align-items:center;gap:3px;padding:10px 6px;
|
||
border:2px solid;border-color:#34425c #0a0f18 #0a0f18 #34425c;border-radius:4px;background:rgba(30,38,58,.55)}
|
||
.dec__pill{position:absolute;top:5px;right:5px;width:8px;height:8px;border-radius:50%;box-shadow:0 0 0 1px rgba(0,0,0,.35)}
|
||
.dec__pill--series{background:#7a7cff}
|
||
.dec__pill--coord{background:#ffb454}
|
||
.dec__sicon{font-size:1.4rem;line-height:1}
|
||
.dec__slabel{font-size:.66rem;text-align:center;font-weight:600;line-height:1.2}
|
||
.dec__stier{font-size:.55rem;opacity:.6;text-transform:uppercase;letter-spacing:.04em;font-variant-numeric:tabular-nums}
|
||
.dec__recipes{display:grid;grid-template-columns:repeat(auto-fill,minmax(148px,1fr));gap:8px}
|
||
.dec__rec{display:flex;flex-direction:column;gap:7px;padding:10px;border-radius:9px;min-height:66px;justify-content:center;
|
||
border:1px solid rgba(150,150,180,.18);background:rgba(127,127,160,.07)}
|
||
.dec__rec--go{border-color:rgba(122,124,255,.55);background:rgba(122,124,255,.12);box-shadow:0 0 0 1px rgba(122,124,255,.14) inset}
|
||
.dec__rec--done{border-color:rgba(80,200,130,.4);background:rgba(60,180,110,.12)}
|
||
.dec__rec--xerb{border-color:rgba(160,120,255,.5);background:linear-gradient(160deg,rgba(80,60,160,.22),rgba(30,20,60,.28));
|
||
box-shadow:0 0 0 1px rgba(160,120,255,.18) inset,0 0 16px rgba(140,110,255,.16)}
|
||
.dec__xlock{font-size:.68rem;opacity:.82;color:#cbb8ff;margin-top:2px;line-height:1.3}
|
||
.dec__rlabel{font-size:.79rem;font-weight:700;line-height:1.25}
|
||
.dec__rok{color:#7fe0a6;font-weight:800;margin-right:4px}
|
||
.dec__craft{cursor:pointer;border:none;border-radius:7px;padding:8px 10px;font-weight:800;font-size:.78rem;
|
||
background:var(--xr-accent,#7a7cff);color:#0b0d1a;border-top:2px solid rgba(255,255,255,.32);border-bottom:2px solid rgba(0,0,0,.32);
|
||
font-variant-numeric:tabular-nums}
|
||
.dec__craft:active{transform:translateY(1px)}
|
||
.dec__craft--off,.dec__craft[disabled]{opacity:.42;cursor:not-allowed;filter:grayscale(.5)}
|
||
.dec__craft--off:active,.dec__craft[disabled]:active{transform:none}
|
||
.dec__msg{opacity:.62;font-size:.85rem;padding:22px 14px;text-align:center}
|
||
.dec__toast{position:absolute;left:50%;bottom:16px;z-index:6;max-width:82%;text-align:center;
|
||
transform:translateX(-50%) translateY(8px);background:var(--xr-surface,#1a2233);color:#eef;border:1px solid rgba(122,124,255,.5);
|
||
border-radius:9px;padding:9px 14px;font-size:.8rem;font-weight:600;opacity:0;pointer-events:none;transition:opacity .2s,transform .2s}
|
||
.dec__toast.on{opacity:1;transform:translateX(-50%) translateY(0)}
|
||
/* --- badge du rôle dans l'en-tête du jeu --- */
|
||
.dec__badge{display:inline-flex;align-items:center;gap:4px;font-size:.72rem;font-weight:700;
|
||
background:rgba(122,124,255,.16);border:1px solid rgba(122,124,255,.4);border-radius:20px;padding:3px 9px;color:#cbb8ff}
|
||
.dec__badgename{opacity:.9}
|
||
.dec__badge--creatif{background:rgba(60,180,110,.18);border-color:rgba(80,200,130,.5);color:#bff0d0}
|
||
/* --- écran de création du personnage (.dec__cr*) --- */
|
||
.dec__cr{overflow:auto}
|
||
.dec__crhead{padding:22px 16px 12px;text-align:center}
|
||
.dec__crtitle{font-weight:800;font-size:1.5rem;letter-spacing:.02em}
|
||
.dec__crsubtitle{font-size:.8rem;opacity:.6;margin:6px auto 0;max-width:480px;line-height:1.4}
|
||
.dec__crbody{flex:1;padding:6px 14px 20px;display:flex;flex-direction:column;gap:22px}
|
||
.dec__crsect{display:flex;flex-direction:column;gap:10px}
|
||
.dec__crpacks{display:grid;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));gap:10px}
|
||
.dec__crpack{cursor:pointer;text-align:left;display:flex;flex-direction:column;gap:5px;padding:14px 13px;
|
||
border:1px solid rgba(150,150,180,.22);border-radius:11px;background:rgba(30,38,58,.5);color:inherit;font:inherit}
|
||
.dec__crpack:hover{border-color:rgba(122,124,255,.5)}
|
||
.dec__crpack.is-sel{border-color:var(--xr-accent,#7a7cff);background:rgba(122,124,255,.16);
|
||
box-shadow:0 0 0 1px rgba(122,124,255,.3) inset}
|
||
/* --- choix du mode (créatif / survival), en tête de l'écran de création --- */
|
||
.dec__crmodes{display:grid;grid-template-columns:repeat(auto-fit,minmax(160px,1fr));gap:10px}
|
||
.dec__crmode{cursor:pointer;text-align:left;display:flex;flex-direction:column;gap:5px;padding:15px 14px;
|
||
border:1px solid rgba(150,150,180,.22);border-radius:12px;background:rgba(30,38,58,.5);color:inherit;font:inherit}
|
||
.dec__crmode:hover{border-color:rgba(122,124,255,.5)}
|
||
.dec__crmode.is-sel{border-color:var(--xr-accent,#7a7cff);background:rgba(122,124,255,.16);box-shadow:0 0 0 1px rgba(122,124,255,.3) inset}
|
||
.dec__crmode--creatif.is-sel{border-color:rgba(80,200,130,.7);background:rgba(60,180,110,.16);box-shadow:0 0 0 1px rgba(80,200,130,.4) inset}
|
||
.dec__crmodename{font-weight:800;font-size:1rem;display:flex;align-items:center;gap:7px}
|
||
.dec__crmodedesc{font-size:.75rem;opacity:.66;line-height:1.35}
|
||
.dec__crroles{display:grid;grid-template-columns:repeat(auto-fill,minmax(132px,1fr));gap:9px}
|
||
.dec__crrole{cursor:pointer;text-align:left;display:flex;flex-direction:column;gap:4px;padding:11px 11px;
|
||
border:1px solid rgba(150,150,180,.2);border-radius:10px;background:rgba(127,127,160,.07);color:inherit;font:inherit}
|
||
.dec__crrole:hover{border-color:rgba(122,124,255,.45)}
|
||
.dec__crrole.is-sel{border-color:var(--xr-accent,#7a7cff);background:rgba(122,124,255,.15);
|
||
box-shadow:0 0 0 1px rgba(122,124,255,.3) inset}
|
||
.dec__crrole--heart{grid-column:1/-1;padding:15px 14px;
|
||
background:linear-gradient(150deg,rgba(122,124,255,.16),rgba(60,180,110,.12));border-color:rgba(122,124,255,.5)}
|
||
.dec__crrole--heart .dec__cricon{font-size:2rem}
|
||
.dec__cricon{font-size:1.6rem;line-height:1}
|
||
.dec__crname{font-weight:800;font-size:.92rem;display:flex;align-items:center;gap:7px;flex-wrap:wrap}
|
||
.dec__crheart{font-size:.58rem;text-transform:uppercase;letter-spacing:.06em;font-weight:800;
|
||
background:rgba(122,124,255,.3);color:#e7e3ff;border-radius:20px;padding:2px 8px}
|
||
.dec__crdesc{font-size:.74rem;opacity:.66;line-height:1.35}
|
||
.dec__crmeta{font-size:.68rem;opacity:.55;font-variant-numeric:tabular-nums;font-weight:700;margin-top:2px}
|
||
.dec__crmore{font-size:.72rem;opacity:.5;font-style:italic;padding:2px}
|
||
.dec__crfoot{position:sticky;bottom:0;padding:13px 14px;
|
||
background:linear-gradient(0deg,rgba(10,15,24,.98),rgba(10,15,24,.7));border-top:1px solid rgba(150,150,180,.16)}
|
||
.dec__crgo{width:100%;cursor:pointer;border:none;border-radius:10px;padding:13px;font-weight:800;font-size:1rem;
|
||
background:var(--xr-accent,#7a7cff);color:#0b0d1a;border-top:2px solid rgba(255,255,255,.32);border-bottom:2px solid rgba(0,0,0,.32)}
|
||
.dec__crgo:active{transform:translateY(1px)}
|
||
.dec__crgo[disabled]{opacity:.4;cursor:not-allowed;filter:grayscale(.5)}
|
||
</style>
|
||
<script>
|
||
(function () {
|
||
var ID = 'decouverte';
|
||
var NS = 'decouverte', KEY = 'progression', LSKEY = 'xb:decouverte';
|
||
var START = ['paste', 'chart'];
|
||
// ENDGAME — la « Voie du xerboxion » (fog of war : masquée tant que la base n'est pas complète).
|
||
// 3 bions fondamentaux (hors catalogue synth) : chacun multiplie la production globale (escalade).
|
||
var FUND = [
|
||
{ id: 'son', label: 'Bion son', icon: '🔊', cost: 4000, mult: 2 },
|
||
{ id: 'wifi', label: 'Bion wifi', icon: '📶', cost: 16000, mult: 2 },
|
||
{ id: 'xion', label: 'Bion xion', icon: '⚡', cost: 64000, mult: 2 }
|
||
];
|
||
// le sommet : ne se révèle QUE si les 3 fondamentaux sont forgés ; le forger = VICTOIRE.
|
||
var XERB = { id: 'xerboxion', label: 'Bion xerboxion', icon: '🌌', cost: 300000, needs: ['son', 'wifi', 'xion'] };
|
||
var CAP_ENDGAME = 400000; // palier de stockage débloqué à l'éveil (rend les gros coûts atteignables)
|
||
|
||
// --- EXPEDITIONS : forger les VRAIS cubions (blocs) du xerboxion, un a la fois ---
|
||
// Additif au-dessus de FUND : meme gate baseComplete(). On lit world.blocs (payload synth-catalog).
|
||
// Courbe propre qui n'interfere PAS avec craftCost/FUND. Jeu infini : le monde grandit tout seul.
|
||
var EXP_BASE = 500, EXP_GROWTH = 1.35; // cout = round(EXP_BASE * EXP_GROWTH^forged.length)
|
||
var EXP_PROD = 0.03; // +3% prod permanent par bloc forge (compounde)
|
||
var EXP_RANKS = [ // rangs par SEUIL ABSOLU (jamais X/22) -> cap invisible, fog preserve
|
||
{ n: 1, l: 'Eclaireur', i: '🧭' }, { n: 3, l: 'Pisteur', i: '🐾' },
|
||
{ n: 8, l: 'Cartographe', i: '🗺' }, { n: 16, l: 'Traqueur', i: '🎯' },
|
||
{ n: 30, l: 'Explorateur du xerboxion', i: '🌌' } // n:30 > 22 -> n'arrive QUE si le monde grandit
|
||
];
|
||
|
||
// PACKS — la SAVEUR de départ (RS-7 : tout reste atteignable, juste des éléments de départ différents).
|
||
// Seuls les ids présents dans le catalogue sont réellement ajoutés (voir packUnlocked).
|
||
var PACKS = [
|
||
{ id: 'chill', label: 'chill', icon: '🌿', unlocked: ['paste', 'chart'], koin: 0, desc: 'départ doux, tu poses les bases' },
|
||
{ id: 'chill-tekk', label: 'chill-tekk', icon: '🎛', unlocked: ['paste', 'chart', 'bus', 'stat'], koin: 30, desc: 't\'as déjà le vibe' },
|
||
{ id: 'xerboxion', label: 'xerboxion', icon: '🌌', unlocked: ['paste', 'chart', 'bus', 'stat', 'weather', 'table', 'net'], koin: 120, desc: 'plongée directe dans le grand bain' }
|
||
];
|
||
// ROLES — flavor + petit biais (JAMAIS restrictif). Le chasseur = le cœur du jeu (mis en avant).
|
||
// Rôle flavor ou inconnu → multiplicateurs à 1. Extensible : ajouter une entrée suffit.
|
||
var ROLES = [
|
||
{ id: 'chasseur', label: 'chasseur', icon: '🏹', heart: true, harvestMult: 1.5, prodMult: 1, offlineMult: 1, startBonus: 0, desc: 'la chasse — chaque récolte manuelle rapporte ×1.5' },
|
||
{ id: 'scientifique', label: 'scientifique', icon: '🔬', harvestMult: 1, prodMult: 1, offlineMult: 1, startBonus: 1, desc: 'la méthode — tu démarres avec +1 bion' },
|
||
{ id: 'ingenieur', label: 'ingénieur', icon: '🔧', harvestMult: 1, prodMult: 1.25, offlineMult: 1, startBonus: 0, desc: 'l\'automatisation — production passive ×1.25' },
|
||
{ id: 'chilleur', label: 'chilleur', icon: '🌿', harvestMult: 1, prodMult: 1, offlineMult: 1.5, startBonus: 0, desc: 'l\'idle — bonus hors-ligne ×1.5' },
|
||
{ id: 'gamer', label: 'gamer', icon: '🎮', harvestMult: 1, prodMult: 1, offlineMult: 1, startBonus: 0, desc: 'juste pour le fun' },
|
||
{ id: 'reveur', label: 'rêveur', icon: '💭', harvestMult: 1, prodMult: 1, offlineMult: 1, startBonus: 0, desc: 'la tête dans les idées' },
|
||
{ id: 'shaman', label: 'shaman', icon: '🔮', harvestMult: 1, prodMult: 1, offlineMult: 1, startBonus: 0, desc: 'à l\'écoute de l\'invisible' },
|
||
{ id: 'astronaute', label: 'astronaute', icon: '🚀', harvestMult: 1, prodMult: 1, offlineMult: 1, startBonus: 0, desc: 'cap sur les étoiles' },
|
||
{ id: 'medecin', label: 'médecin', icon: '🩺', harvestMult: 1, prodMult: 1, offlineMult: 1, startBonus: 0, desc: 'prendre soin du vivant' },
|
||
{ id: 'biologiste', label: 'biologiste', icon: '🧬', harvestMult: 1, prodMult: 1, offlineMult: 1, startBonus: 0, desc: 'l\'étude du vivant' }
|
||
];
|
||
|
||
function esc(s) {
|
||
return String(s == null ? '' : s).replace(/[&<>"']/g, function (c) {
|
||
return { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c];
|
||
});
|
||
}
|
||
function has(arr, x) { return arr && arr.indexOf(x) >= 0; }
|
||
|
||
// Format chill : K/M/B au-dessus de 1000, une décimale sous 100 (sans .0 inutile).
|
||
function fmt(n) {
|
||
if (n == null || !isFinite(n)) n = 0;
|
||
var a = Math.abs(n);
|
||
if (a >= 1e9) return (n / 1e9).toFixed(1) + 'B';
|
||
if (a >= 1e6) return (n / 1e6).toFixed(1) + 'M';
|
||
if (a >= 1e3) return (n / 1e3).toFixed(1) + 'K';
|
||
if (a >= 100) return String(Math.round(n));
|
||
var r = Math.round(n * 10) / 10;
|
||
return (r === Math.floor(r)) ? String(r) : r.toFixed(1);
|
||
}
|
||
|
||
function mount(container, ctx) {
|
||
var alive = true;
|
||
var BIONS = [], COMPS = [], byBion = {}, byComp = {}, WORLD = null;
|
||
var unlocked = START.slice(), discovered = [], koin = 0;
|
||
var fund = [], won = false; // ENDGAME : fondamentaux forgés + victoire xerboxion
|
||
var forged = [], worldMark = null; // EXPEDITIONS : blocs (cubions) forges + repere du monde vu
|
||
var toastEl = null, toastTimer = 0;
|
||
var tickTimer = 0, tickN = 0;
|
||
var created = false, pack = '', role = '', mode = 'survival'; // profil du joueur (posé par l'écran de création) ; mode = 'survival' | 'creatif'
|
||
var crPack = '', crRole = '', crMode = 'survival'; // sélection en cours dans l'écran de création
|
||
var root, body, progtxtEl, winEl, koinEl, capEl, prodEl, harvestBtn, harvestWrap;
|
||
|
||
// Construit (ou reconstruit) le DOM du JEU et recapture les références.
|
||
// Séparé de l'écran de création : on bascule de l'un à l'autre en remplaçant container.innerHTML
|
||
// (le listener délégué est posé sur `container`, il survit au remplacement).
|
||
function buildGameDOM() {
|
||
container.innerHTML =
|
||
'<div class="dec">'
|
||
+ ' <div class="dec__head">'
|
||
+ ' <div class="dec__titrow">'
|
||
+ ' <span class="dec__title">🔓 Découverte</span>'
|
||
+ ' <span class="dec__badge" data-badge style="display:none"></span>'
|
||
+ ' <span class="dec__badge dec__badge--creatif" data-badgemode style="display:none">✨ créatif</span>'
|
||
+ ' <button class="dec__reset" data-reset type="button">↺ recommencer</button>'
|
||
+ ' </div>'
|
||
+ ' <div class="dec__sub">redécouvre l\'arbre que RS-7 a déjà découvert</div>'
|
||
+ ' <div class="dec__koinrow">'
|
||
+ ' <div class="dec__koin">'
|
||
+ ' <span class="dec__klabel">koin</span>'
|
||
+ ' <span class="dec__kval" data-koin>0</span>'
|
||
+ ' <span class="dec__ksep">/</span>'
|
||
+ ' <span class="dec__kcap" data-cap>25</span>'
|
||
+ ' <span class="dec__kprod">+<span data-prod>0</span>/s</span>'
|
||
+ ' </div>'
|
||
+ ' <div class="dec__harvestwrap" data-hwrap>'
|
||
+ ' <button class="dec__harvest" data-harvest type="button">⛏ récolter</button>'
|
||
+ ' </div>'
|
||
+ ' </div>'
|
||
+ ' <div class="dec__prog">'
|
||
+ ' <div class="dec__progtxt" data-progtxt>chargement…</div>'
|
||
+ ' </div>'
|
||
+ ' <div class="dec__win" data-win style="display:none">🏆 tu as redécouvert la forge</div>'
|
||
+ ' </div>'
|
||
+ ' <div class="dec__body" data-body><div class="dec__msg">chargement du catalogue…</div></div>'
|
||
+ '</div>';
|
||
root = container.querySelector('.dec');
|
||
body = container.querySelector('[data-body]');
|
||
progtxtEl = container.querySelector('[data-progtxt]');
|
||
winEl = container.querySelector('[data-win]');
|
||
koinEl = container.querySelector('[data-koin]');
|
||
capEl = container.querySelector('[data-cap]');
|
||
prodEl = container.querySelector('[data-prod]');
|
||
harvestBtn = container.querySelector('[data-harvest]');
|
||
harvestWrap = container.querySelector('[data-hwrap]');
|
||
toastEl = null; // toast recréé à la demande dans le nouveau root
|
||
}
|
||
buildGameDOM();
|
||
|
||
/* ---------------- toast ---------------- */
|
||
function showToast(msg) {
|
||
if (!alive) return;
|
||
if (!toastEl) {
|
||
toastEl = document.createElement('div');
|
||
toastEl.className = 'dec__toast';
|
||
root.appendChild(toastEl);
|
||
}
|
||
toastEl.textContent = msg;
|
||
toastEl.className = 'dec__toast on';
|
||
if (toastTimer) clearTimeout(toastTimer);
|
||
toastTimer = setTimeout(function () { if (toastEl) toastEl.className = 'dec__toast'; }, 2400);
|
||
}
|
||
|
||
/* ---------------- économie incrémentale ---------------- */
|
||
// prod (koin/s) = somme des contributions des bions débloqués : 0.2·(tier+1).
|
||
function bionProd(b) { return b ? 0.2 * (b.tier + 1) : 0; }
|
||
// base complète = TOUS les bions du catalogue débloqués → éveil de la forge (ouvre la Voie).
|
||
function baseComplete() { return !!(BIONS.length && unlocked.length === BIONS.length); }
|
||
// MODE CRÉATIF (Minecraft creative) : tout débloqué d'un coup, économie NEUTRALISÉE
|
||
// (koin non requis, affiché « ∞ » ; crafts/forges gratuits & décoratifs). Fog of war OFF (voir plus bas).
|
||
function creative() { return mode === 'creatif'; }
|
||
function canAfford(cost) { return creative() || koin >= cost; }
|
||
// multiplicateur de production : produit des mult des fondamentaux forgés (escalade Paperclips).
|
||
function fundMult() {
|
||
var m = 1, i, f;
|
||
for (i = 0; i < FUND.length; i++) { f = FUND[i]; if (has(fund, f.id)) m *= f.mult; }
|
||
return m;
|
||
}
|
||
// multiplicateur du rôle (rôle flavor ou inconnu → 1 ; jamais restrictif).
|
||
function roleById(id) {
|
||
var i;
|
||
for (i = 0; i < ROLES.length; i++) if (ROLES[i].id === id) return ROLES[i];
|
||
return null;
|
||
}
|
||
function roleMult(kind) {
|
||
var r = roleById(role);
|
||
if (!r) return 1;
|
||
if (kind === 'harvest') return r.harvestMult || 1;
|
||
if (kind === 'prod') return r.prodMult || 1;
|
||
if (kind === 'offline') return r.offlineMult || 1;
|
||
return 1;
|
||
}
|
||
function prod() {
|
||
var p = 0, i, b;
|
||
for (i = 0; i < unlocked.length; i++) { b = byBion[unlocked[i]]; if (b) p += bionProd(b); }
|
||
return p * fundMult() * roleMult('prod') * expoMult(); // base × fondamentaux × rôle × expéditions (+3%/bloc)
|
||
}
|
||
// cap : 25 + 25 par bion débloqué au-delà des 2 de départ ; à l'éveil, palier endgame.
|
||
function capForUnlocked(list) {
|
||
var c = 25 + 25 * Math.max(0, list.length - START.length);
|
||
if (BIONS.length && list.length === BIONS.length) c = Math.max(c, CAP_ENDGAME);
|
||
return c;
|
||
}
|
||
function cap() { return capForUnlocked(unlocked) + expoCapBonus(); }
|
||
// coût du prochain craft : le k-ième craft coûte 10·1.6^k (k = crafts déjà faits).
|
||
function craftCost() { return Math.round(10 * Math.pow(1.6, discovered.length)); }
|
||
function allDone() { return !!(BIONS.length && COMPS.length && unlocked.length === BIONS.length && discovered.length === COMPS.length); }
|
||
|
||
// --- EXPEDITIONS : economie cablee dans l'existant (world.blocs = les vrais cubions) ---
|
||
function worldBlocs() { return (WORLD && WORLD.blocs instanceof Array) ? WORLD.blocs : []; }
|
||
function prettyCubion(id) { return String(id).replace(/^cubion-/, ''); }
|
||
function expoCost() { return Math.round(EXP_BASE * Math.pow(EXP_GROWTH, forged.length)); }
|
||
function expoMult() { return 1 + EXP_PROD * forged.length; }
|
||
// le cap doit RESTER DEVANT le cout sinon la chasse se bloque -> somme geometrique x2 (toujours en avance)
|
||
function expoCapBonus() {
|
||
var n = forged.length;
|
||
return n ? Math.round(2 * EXP_BASE * (Math.pow(EXP_GROWTH, n) - 1) / (EXP_GROWTH - 1)) : 0;
|
||
}
|
||
function expoRank() { var r = null, i; for (i = 0; i < EXP_RANKS.length; i++) if (forged.length >= EXP_RANKS[i].n) r = EXP_RANKS[i]; return r; }
|
||
// prochaine cible = 1er bloc non forge dans l'ordre canonique (filesystem) ; null = front atteint
|
||
function nextExpo() { var b = worldBlocs(), i; for (i = 0; i < b.length; i++) if (b[i] && b[i].id && !has(forged, b[i].id)) return b[i]; return null; }
|
||
function expoCraftable() { var t = nextExpo(); return baseComplete() && !!t && canAfford(expoCost()); }
|
||
// repere du monde (pour sentir qu'il grandit sans jamais reveler d'ampleur)
|
||
function curMark() { return { blocs: worldBlocs().length, ploxions: (WORLD && +WORLD.ploxions) || 0 }; }
|
||
function checkGrowth() {
|
||
var cur = curMark();
|
||
if (baseComplete() && worldMark && cur.blocs > worldMark.blocs) {
|
||
showToast('🌱 le xerboxion a grandi — de nouveaux blocs sont apparus a explorer');
|
||
}
|
||
worldMark = cur; saveState();
|
||
}
|
||
|
||
/* ---------------- persistance ---------------- */
|
||
function boxed() { return window.jOSBoxion && jOSBoxion.authed && jOSBoxion.authed(); }
|
||
|
||
function validate(st) {
|
||
if (!st || typeof st !== 'object') return null;
|
||
if (!(st.unlocked instanceof Array) || !(st.discovered instanceof Array)) return null;
|
||
var u = [], d = [], i;
|
||
for (i = 0; i < st.unlocked.length; i++) if (byBion[st.unlocked[i]] && !has(u, st.unlocked[i])) u.push(st.unlocked[i]);
|
||
for (i = 0; i < START.length; i++) if (!has(u, START[i])) u.push(START[i]);
|
||
for (i = 0; i < st.discovered.length; i++) {
|
||
var c = byComp[st.discovered[i]];
|
||
if (c && has(u, c.source) && has(u, c.view) && !has(d, c.id)) d.push(c.id);
|
||
}
|
||
// fondamentaux : on ne garde que des ids connus de FUND, dédupliqués.
|
||
var fu = [], j;
|
||
if (st.fund instanceof Array) {
|
||
for (i = 0; i < st.fund.length; i++) {
|
||
var fid = st.fund[i], known = false;
|
||
for (j = 0; j < FUND.length; j++) if (FUND[j].id === fid) known = true;
|
||
if (known && !has(fu, fid)) fu.push(fid);
|
||
}
|
||
}
|
||
var wo = st.won === true;
|
||
// EXPEDITIONS : blocs forges (ids du monde, dedupliques) + repere du monde vu.
|
||
var fg = [];
|
||
if (st.forged instanceof Array) {
|
||
for (i = 0; i < st.forged.length; i++) {
|
||
var gid = st.forged[i];
|
||
if (typeof gid === 'string' && gid && !has(fg, gid)) fg.push(gid);
|
||
}
|
||
}
|
||
var wm = null;
|
||
if (st.worldMark && typeof st.worldMark === 'object') {
|
||
var wmb = (typeof st.worldMark.blocs === 'number' && isFinite(st.worldMark.blocs)) ? st.worldMark.blocs : 0;
|
||
var wmp = (typeof st.worldMark.ploxions === 'number' && isFinite(st.worldMark.ploxions)) ? st.worldMark.ploxions : 0;
|
||
wm = { blocs: wmb, ploxions: wmp };
|
||
}
|
||
var capv = 25 + 25 * Math.max(0, u.length - START.length);
|
||
if (BIONS.length && u.length === BIONS.length) capv = Math.max(capv, CAP_ENDGAME);
|
||
// le bonus de cap des expeditions (somme geometrique x2) doit compter dans le clamp, sinon perte de koin au load.
|
||
capv += fg.length ? Math.round(2 * EXP_BASE * (Math.pow(EXP_GROWTH, fg.length) - 1) / (EXP_GROWTH - 1)) : 0;
|
||
var k = (typeof st.koin === 'number' && isFinite(st.koin)) ? st.koin : 0;
|
||
if (k < 0) k = 0; if (k > capv) k = capv;
|
||
var t = (typeof st.t === 'number' && isFinite(st.t)) ? st.t : 0;
|
||
// profil du joueur : pack + rôle bornés aux ids connus ; rôle inconnu → flavor (mult 1 via roleMult).
|
||
var cr = st.created === true;
|
||
var pk = '';
|
||
for (i = 0; i < PACKS.length; i++) if (PACKS[i].id === st.pack) pk = st.pack;
|
||
var ro = '';
|
||
for (i = 0; i < ROLES.length; i++) if (ROLES[i].id === st.role) ro = st.role;
|
||
// mode : borné à 'creatif' | 'survival' (défaut survival). Vieilles saves sans mode → survival.
|
||
var md = (st.mode === 'creatif') ? 'creatif' : 'survival';
|
||
return { unlocked: u, discovered: d, koin: k, t: t, fund: fu, won: wo, created: cr, pack: pk, role: ro, forged: fg, worldMark: wm, mode: md };
|
||
}
|
||
|
||
function saveState() {
|
||
var st = { unlocked: unlocked.slice(), discovered: discovered.slice(), koin: koin, t: Date.now(), fund: fund.slice(), won: won, created: created, pack: pack, role: role, forged: forged.slice(), worldMark: worldMark, mode: mode };
|
||
try { localStorage.setItem(LSKEY, JSON.stringify(st)); } catch (e) {}
|
||
try { if (boxed() && jOSBoxion.saveSoon) jOSBoxion.saveSoon(NS, KEY, st, 'Découverte'); } catch (e) {}
|
||
}
|
||
|
||
function loadLocal() {
|
||
try { return validate(JSON.parse(localStorage.getItem(LSKEY) || 'null')); } catch (e) { return null; }
|
||
}
|
||
|
||
/* ---------------- règles du jeu ---------------- */
|
||
function isCraftable(c) { return has(unlocked, c.source) && has(unlocked, c.view) && !has(discovered, c.id); }
|
||
function isDiscovered(c) { return has(discovered, c.id); }
|
||
|
||
// récompense : le bion verrouillé de plus BAS tier
|
||
// (à tier égal : source avant view, sinon ordre du catalogue).
|
||
function nextRewardFrom(list) {
|
||
var cand = [], i;
|
||
for (i = 0; i < BIONS.length; i++) {
|
||
var b = BIONS[i];
|
||
if (!has(list, b.id)) cand.push({ b: b, idx: i });
|
||
}
|
||
if (!cand.length) return null;
|
||
cand.sort(function (a, bb) {
|
||
if (a.b.tier !== bb.b.tier) return a.b.tier - bb.b.tier;
|
||
var ka = a.b.kind === 'source' ? 0 : 1, kb = bb.b.kind === 'source' ? 0 : 1;
|
||
if (ka !== kb) return ka - kb;
|
||
return a.idx - bb.idx;
|
||
});
|
||
return cand[0].b;
|
||
}
|
||
function nextReward() { return nextRewardFrom(unlocked); }
|
||
|
||
function craft(id) {
|
||
var c = byComp[id];
|
||
if (!c || !isCraftable(c)) return;
|
||
var cost = craftCost();
|
||
if (!creative() && koin < cost) return; // pas assez de koin : on ne crafte pas (créatif = gratuit)
|
||
if (!creative()) koin -= cost;
|
||
discovered.push(id);
|
||
var reward = nextReward();
|
||
if (reward) { unlocked.push(reward.id); showToast('nouveau bion débloqué : ' + reward.label); }
|
||
saveState();
|
||
// OUT craft → minecraft.give : le bion redécouvert (l'item) part sur le bus avec sa recette.
|
||
try { if (window.jOSPorts) jOSPorts.emit(ID, 'craft', { id: id, source: c.source, view: c.view, bion: reward ? reward.id : null, label: reward ? reward.label : null }); } catch (e) {}
|
||
renderBody();
|
||
updateProgress();
|
||
updateKoinUI();
|
||
if (allDone()) showToast('🔓 forge de base redécouverte — la Voie du xerboxion s\'ouvre');
|
||
}
|
||
|
||
/* ---------------- ENDGAME : Voie du xerboxion ---------------- */
|
||
function fundById(id) {
|
||
var i;
|
||
for (i = 0; i < FUND.length; i++) if (FUND[i].id === id) return FUND[i];
|
||
return null;
|
||
}
|
||
// un fondamental est craftable si la base est complète, pas déjà forgé, et assez de koin.
|
||
function fundCraftable(f) { return baseComplete() && !!f && !has(fund, f.id) && canAfford(f.cost); }
|
||
function craftFund(id) {
|
||
var f = fundById(id);
|
||
if (!f || !baseComplete() || has(fund, f.id) || (!creative() && koin < f.cost)) return;
|
||
if (!creative()) koin -= f.cost;
|
||
fund.push(f.id); // multiplie prod() via fundMult()
|
||
saveState();
|
||
// OUT fundamental → minecraft.dimension : le palier forgé (son/wifi/xion) ouvre une dimension.
|
||
try { if (window.jOSPorts) jOSPorts.emit(ID, 'fundamental', { id: f.id, label: f.label }); } catch (e) {}
|
||
showToast('bion fondamental forgé : ' + f.label);
|
||
renderBody();
|
||
updateProgress();
|
||
updateKoinUI();
|
||
}
|
||
// EXPEDITION : forger le prochain bloc reel du xerboxion (revele t + monte prod + monte cap).
|
||
function expedition() {
|
||
var t = nextExpo(), cost = expoCost();
|
||
if (!baseComplete() || !t || (!creative() && koin < cost)) return;
|
||
if (!creative()) koin -= cost;
|
||
forged.push(t.id);
|
||
saveState();
|
||
// OUT expedition → minecraft.place : le bloc (cubion) forgé se matérialise dans le monde 3D.
|
||
try { if (window.jOSPorts) jOSPorts.emit(ID, 'expedition', { id: t.id, label: prettyCubion(t.id), n: forged.length }); } catch (e) {}
|
||
showToast('🧊 bloc forge : ' + prettyCubion(t.id) + ' — un morceau reel du xerboxion');
|
||
renderBody();
|
||
updateProgress();
|
||
updateKoinUI();
|
||
}
|
||
// le xerboxion ne se révèle QUE si les 3 fondamentaux sont forgés (fog of war).
|
||
function xerbReady() {
|
||
var i;
|
||
for (i = 0; i < XERB.needs.length; i++) if (!has(fund, XERB.needs[i])) return false;
|
||
return true;
|
||
}
|
||
function xerbCraftable() { return false; } // achievement xerboxion RÉSERVÉ au créateur — jamais craftable par le joueur (jeu infini)
|
||
function craftXerb() {
|
||
// Jeu infini : le joueur ne peut pas « finir » le xerboxion (pour l'instant, seul RS-7 l'a).
|
||
showToast('🌌 le xerboxion : seul le créateur l\'a découvert · pour l\'instant · on le découvre ensemble');
|
||
}
|
||
|
||
function harvest() {
|
||
var gain = Math.max(1, prod()) * roleMult('harvest'); // biais du rôle chasseur (×1.5)
|
||
koin = Math.min(cap(), koin + gain);
|
||
updateKoinUI();
|
||
floatGain(gain);
|
||
}
|
||
|
||
function floatGain(n) {
|
||
if (!alive || !harvestWrap) return;
|
||
var f = document.createElement('span');
|
||
f.className = 'dec__float';
|
||
f.textContent = '+' + fmt(n);
|
||
harvestWrap.appendChild(f);
|
||
setTimeout(function () { if (f && f.parentNode) f.parentNode.removeChild(f); }, 900);
|
||
}
|
||
|
||
function resetGame() {
|
||
// ↺ recommencer = repartir de l'écran de création (created=false), profil remis à zéro.
|
||
stopTick();
|
||
unlocked = START.slice();
|
||
discovered = [];
|
||
koin = 0;
|
||
fund = [];
|
||
won = false;
|
||
forged = [];
|
||
worldMark = null;
|
||
created = false;
|
||
pack = '';
|
||
role = '';
|
||
mode = 'survival';
|
||
saveState();
|
||
showCreation();
|
||
showToast('nouvelle partie — choisis ton départ');
|
||
}
|
||
|
||
/* ---------------- tick : production passive ---------------- */
|
||
function tick() {
|
||
if (!alive) return;
|
||
koin = Math.min(cap(), koin + prod());
|
||
updateKoinUI();
|
||
tickN++;
|
||
if (tickN % 10 === 0) saveState(); // sauvegarde douce toutes les ~10 s
|
||
}
|
||
function startTick() {
|
||
if (tickTimer) return;
|
||
tickTimer = setInterval(tick, 1000);
|
||
}
|
||
function stopTick() { if (tickTimer) { clearInterval(tickTimer); tickTimer = 0; } }
|
||
|
||
/* ---------------- rendu ---------------- */
|
||
// Mise à jour LÉGÈRE chaque seconde : juste le compteur + l'état des boutons crafter.
|
||
// (Pas de re-render complet au tick — celui-ci n'a lieu qu'à un craft/déblocage.)
|
||
function updateKoinUI() {
|
||
if (koinEl) koinEl.textContent = creative() ? '∞' : fmt(koin);
|
||
if (capEl) capEl.textContent = creative() ? '∞' : fmt(cap());
|
||
if (prodEl) prodEl.textContent = fmt(prod());
|
||
if (!body) return;
|
||
var cost = craftCost(), can = canAfford(cost);
|
||
var btns = body.querySelectorAll('[data-craft]'), i, cls;
|
||
for (i = 0; i < btns.length; i++) {
|
||
btns[i].disabled = !can;
|
||
cls = can ? 'dec__craft' : 'dec__craft dec__craft--off';
|
||
if (btns[i].className !== cls) btns[i].className = cls;
|
||
}
|
||
// boutons de la Voie du xerboxion + Expeditions : chacun porte son propre data-cost.
|
||
var fb = body.querySelectorAll('[data-fund],[data-xerb],[data-expo]'), can2, cls2;
|
||
for (i = 0; i < fb.length; i++) {
|
||
can2 = canAfford(parseFloat(fb[i].getAttribute('data-cost')) || 0);
|
||
fb[i].disabled = !can2;
|
||
cls2 = can2 ? 'dec__craft' : 'dec__craft dec__craft--off';
|
||
if (fb[i].className !== cls2) fb[i].className = cls2;
|
||
}
|
||
}
|
||
|
||
function updateProgress() {
|
||
// MODE CRÉATIF : fog of war OFF — tout est débloqué, on PEUT montrer les totaux (plus de mystère).
|
||
if (creative()) {
|
||
progtxtEl.textContent = '✨ mode créatif — tout est débloqué · '
|
||
+ BIONS.length + (BIONS.length === 1 ? ' bion' : ' bions')
|
||
+ ' · ' + COMPS.length + (COMPS.length === 1 ? ' recette' : ' recettes')
|
||
+ (worldBlocs().length ? ' · ' + worldBlocs().length + ' blocs' : '');
|
||
winEl.textContent = '✨ mode créatif — la forge complète comme un OS · le xerboxion reste l\'horizon du créateur';
|
||
winEl.className = 'dec__win dec__won';
|
||
winEl.style.display = '';
|
||
return;
|
||
}
|
||
// FOG OF WAR : pas de total ni de barre — on ne trahit JAMAIS l'ampleur de ce qui reste
|
||
// à trouver (RS-7 : « on sait juste pas le potentiel du truc »). Juste ce qu'on a déjà.
|
||
progtxtEl.textContent = discovered.length + (discovered.length === 1 ? ' recette découverte' : ' recettes découvertes')
|
||
+ ' · ' + unlocked.length + (unlocked.length === 1 ? ' bion' : ' bions');
|
||
// Jeu INFINI : JAMAIS de « victoire », pas de 100%. Frontière atteinte = les 3 fondamentaux forgés
|
||
// = tu es au stade du créateur (tu as tout testé → tu peux contribuer). L'horizon reste ouvert.
|
||
if (fund.length >= FUND.length) {
|
||
winEl.textContent = '🌌 tu es au stade du créateur — tu as tout traversé. Le xerboxion se découvre ENSEMBLE · jeu infini';
|
||
winEl.className = 'dec__win dec__won';
|
||
winEl.style.display = '';
|
||
} else if (allDone()) {
|
||
winEl.textContent = '🔓 forge de base redécouverte — la Voie du xerboxion s\'ouvre';
|
||
winEl.className = 'dec__win';
|
||
winEl.style.display = '';
|
||
} else {
|
||
winEl.className = 'dec__win';
|
||
winEl.style.display = 'none';
|
||
}
|
||
}
|
||
|
||
function bionSlot(b) {
|
||
var icon = b.kind === 'source' ? '⬇' : '📊';
|
||
return '<div class="dec__slot" title="' + esc(b.label) + '">'
|
||
+ '<span class="dec__pill dec__pill--' + esc(b.type) + '"></span>'
|
||
+ '<span class="dec__sicon">' + icon + '</span>'
|
||
+ '<span class="dec__slabel">' + esc(b.label) + '</span>'
|
||
+ '<span class="dec__stier">tier ' + esc(String(b.tier)) + ' · +' + fmt(bionProd(b)) + '/s</span>'
|
||
+ '</div>';
|
||
}
|
||
|
||
function recipeCard(c) {
|
||
var src = byBion[c.source] || { label: c.source }, vw = byBion[c.view] || { label: c.view };
|
||
if (isDiscovered(c)) {
|
||
return '<div class="dec__rec dec__rec--done"><div class="dec__rlabel">'
|
||
+ '<span class="dec__rok">✓</span>' + esc(src.label) + ' → ' + esc(vw.label) + '</div></div>';
|
||
}
|
||
if (isCraftable(c)) {
|
||
var cost = craftCost(), off = !canAfford(cost);
|
||
return '<div class="dec__rec dec__rec--go">'
|
||
+ '<div class="dec__rlabel">' + esc(src.label) + ' + ' + esc(vw.label) + '</div>'
|
||
+ '<button class="dec__craft' + (off ? ' dec__craft--off' : '') + '" data-craft="' + esc(c.id) + '"'
|
||
+ ' data-cost="' + cost + '" type="button"' + (off ? ' disabled' : '') + '>'
|
||
+ '⚒ crafter (' + fmt(cost) + ' koin)</button>'
|
||
+ '</div>';
|
||
}
|
||
return ''; // verrouillé = INVISIBLE : on ne doit même pas savoir que ça existe (RS-7)
|
||
}
|
||
|
||
/* ---------------- rendu de la Voie du xerboxion (endgame) ---------------- */
|
||
function fundCard(f) {
|
||
if (has(fund, f.id)) {
|
||
return '<div class="dec__rec dec__rec--done"><div class="dec__rlabel">'
|
||
+ '<span class="dec__rok">✓</span>' + f.icon + ' ' + esc(f.label) + '</div></div>';
|
||
}
|
||
var off = !canAfford(f.cost);
|
||
return '<div class="dec__rec dec__rec--go">'
|
||
+ '<div class="dec__rlabel">' + f.icon + ' ' + esc(f.label) + '</div>'
|
||
+ '<button class="dec__craft' + (off ? ' dec__craft--off' : '') + '" data-fund="' + esc(f.id) + '"'
|
||
+ ' data-cost="' + f.cost + '" type="button"' + (off ? ' disabled' : '') + '>'
|
||
+ '⚒ forger (' + fmt(f.cost) + ' koin)</button>'
|
||
+ '</div>';
|
||
}
|
||
function xerbCard() {
|
||
if (!xerbReady()) return ''; // fog of war : invisible tant que les 3 fondamentaux ne sont pas forgés
|
||
// Jeu INFINI : pas de victoire, pas de 100%. L'achievement XERBOXION est RÉSERVÉ au créateur
|
||
// (RS-7) — inatteignable par le joueur pour l'instant. Il reste l'horizon qu'on découvre ensemble.
|
||
return '<div class="dec__rec dec__rec--xerb">'
|
||
+ '<div class="dec__rlabel">' + XERB.icon + ' ' + esc(XERB.label) + '</div>'
|
||
+ '<div class="dec__xlock">🔒 seul le créateur l\'a découvert · pour l\'instant · on le découvre ensemble</div>'
|
||
+ '</div>';
|
||
}
|
||
function renderVoie() {
|
||
var i, html = '';
|
||
for (i = 0; i < FUND.length; i++) html += fundCard(FUND[i]);
|
||
html += xerbCard();
|
||
return '<div class="dec__sect dec__voie">'
|
||
+ ' <div class="dec__h">🌌 Voie du xerboxion</div>'
|
||
+ ' <div class="dec__recipes">' + html + '</div>'
|
||
+ '</div>';
|
||
}
|
||
|
||
/* ---------------- rendu des Expeditions (forger les vrais cubions, un a la fois) ---------------- */
|
||
// bloc deja forge = face visible (nom + glacon). Aucune grille de total : fog of war strict.
|
||
function expoSlot(id) {
|
||
return '<div class="dec__rec dec__rec--done"><div class="dec__rlabel">'
|
||
+ '<span class="dec__rok">🧊</span>' + esc(prettyCubion(id)) + '</div></div>';
|
||
}
|
||
function renderExpeditions() {
|
||
if (!baseComplete()) return '';
|
||
var i, forgedHtml = '';
|
||
for (i = 0; i < forged.length; i++) forgedHtml += expoSlot(forged[i]);
|
||
// UNE cible a la fois : silhouette (jamais le nom avant paiement) + teaser local (ne trahit aucun total).
|
||
var t = nextExpo(), targetHtml;
|
||
if (t) {
|
||
var cost = expoCost(), off = !canAfford(cost);
|
||
var teaser = (t.membres && +t.membres > 0) ? ('≈' + (+t.membres) + ' ploxions a l\'interieur') : 'signal inconnu';
|
||
targetHtml = '<div class="dec__rec dec__rec--go">'
|
||
+ '<div class="dec__rlabel">??? · bloc inconnu</div>'
|
||
+ '<div class="dec__xlock">' + esc(teaser) + '</div>'
|
||
+ '<button class="dec__craft' + (off ? ' dec__craft--off' : '') + '" data-expo="1"'
|
||
+ ' data-cost="' + cost + '" type="button"' + (off ? ' disabled' : '') + '>'
|
||
+ '⛏ forger (' + fmt(cost) + ' koin)</button>'
|
||
+ '</div>';
|
||
} else {
|
||
targetHtml = '<div class="dec__rec"><div class="dec__xlock">🌌 front atteint — reviens quand le xerboxion aura grandi</div></div>';
|
||
}
|
||
var rank = expoRank();
|
||
var sub = forged.length
|
||
? ('production ×' + fmt(expoMult()) + (rank ? ' · ' + rank.i + ' ' + esc(rank.l) : ''))
|
||
: 'forge les vrais blocs du xerboxion, un a la fois';
|
||
return '<div class="dec__sect dec__voie">'
|
||
+ ' <div class="dec__h">🧊 Expeditions <span class="dec__count">' + forged.length + '</span></div>'
|
||
+ ' <div class="dec__progtxt" style="margin-top:0">' + sub + '</div>'
|
||
+ ' <div class="dec__recipes">' + targetHtml + forgedHtml + '</div>'
|
||
+ '</div>';
|
||
}
|
||
|
||
function renderBody() {
|
||
var i, invHtml = '', unlockedBions = [];
|
||
for (i = 0; i < BIONS.length; i++) if (has(unlocked, BIONS[i].id)) unlockedBions.push(BIONS[i]);
|
||
for (i = 0; i < unlockedBions.length; i++) invHtml += bionSlot(unlockedBions[i]);
|
||
|
||
// recettes VISIBLES seulement : craftables (à découvrir) puis découvertes. Les verrouillées
|
||
// ne sont PAS listées — on ne sait pas qu'elles existent (mystère du potentiel).
|
||
var go = [], done = [];
|
||
for (i = 0; i < COMPS.length; i++) {
|
||
var c = COMPS[i];
|
||
if (isDiscovered(c)) done.push(c);
|
||
else if (isCraftable(c)) go.push(c);
|
||
}
|
||
var ordered = go.concat(done), recHtml = '';
|
||
for (i = 0; i < ordered.length; i++) recHtml += recipeCard(ordered[i]);
|
||
if (!recHtml) recHtml = '<div class="dec__msg">crafte pour découvrir de nouvelles recettes…</div>';
|
||
|
||
// FOG OF WAR : la Voie n'apparaît JAMAIS tant que la base n'est pas complète.
|
||
var voieHtml = baseComplete() ? renderVoie() : '';
|
||
// EXPEDITIONS : rendu SOUS la Voie, meme gate (renderExpeditions re-teste baseComplete()).
|
||
var expoHtml = renderExpeditions();
|
||
|
||
body.innerHTML =
|
||
'<div class="dec__sect">'
|
||
+ ' <div class="dec__h">Inventaire <span class="dec__count">' + unlockedBions.length + '</span></div>'
|
||
+ ' <div class="dec__inv">' + invHtml + '</div>'
|
||
+ '</div>'
|
||
+ '<div class="dec__sect">'
|
||
+ ' <div class="dec__h">Recettes <span class="dec__count">' + discovered.length + '</span></div>'
|
||
+ ' <div class="dec__recipes">' + recHtml + '</div>'
|
||
+ '</div>'
|
||
+ voieHtml
|
||
+ expoHtml;
|
||
}
|
||
|
||
/* ---------------- écran de création du personnage ---------------- */
|
||
// liste de départ d'un pack : START + ids du pack QUI EXISTENT dans le catalogue (jamais d'id fantôme).
|
||
function packUnlocked(pk) {
|
||
var out = START.slice(), i, id;
|
||
if (pk && pk.unlocked instanceof Array) {
|
||
for (i = 0; i < pk.unlocked.length; i++) {
|
||
id = pk.unlocked[i];
|
||
if (byBion[id] && !has(out, id)) out.push(id);
|
||
}
|
||
}
|
||
return out;
|
||
}
|
||
function startCount(pk) { return packUnlocked(pk).length; }
|
||
function packById(id) {
|
||
var i;
|
||
for (i = 0; i < PACKS.length; i++) if (PACKS[i].id === id) return PACKS[i];
|
||
return null;
|
||
}
|
||
|
||
function showCreation() {
|
||
stopTick();
|
||
crPack = '';
|
||
crRole = '';
|
||
crMode = 'survival';
|
||
var i, pk, r, cls, packHtml = '', roleHtml = '', modeHtml = '';
|
||
// choix du mode (comme Minecraft) : ✨ créatif (tout débloqué) vs 🎮 survival (le voyage incrémental).
|
||
modeHtml =
|
||
'<button class="dec__crmode" data-base="dec__crmode" data-crmode="survival" type="button">'
|
||
+ ' <span class="dec__crmodename">🎮 survival</span>'
|
||
+ ' <span class="dec__crmodedesc">le voyage incrémental — tu grind, tu débloques, tu découvres l\'arbre (fog of war)</span>'
|
||
+ '</button>'
|
||
+ '<button class="dec__crmode dec__crmode--creatif" data-base="dec__crmode dec__crmode--creatif" data-crmode="creatif" type="button">'
|
||
+ ' <span class="dec__crmodename">✨ créatif</span>'
|
||
+ ' <span class="dec__crmodedesc">tout débloqué, direct la forge complète (comme Minecraft creative) — rien à unlock</span>'
|
||
+ '</button>';
|
||
for (i = 0; i < PACKS.length; i++) {
|
||
pk = PACKS[i];
|
||
packHtml += '<button class="dec__crpack" data-base="dec__crpack" data-crpack="' + esc(pk.id) + '" type="button">'
|
||
+ '<span class="dec__cricon">' + esc(pk.icon) + '</span>'
|
||
+ '<span class="dec__crname">' + esc(pk.label) + '</span>'
|
||
+ '<span class="dec__crdesc">' + esc(pk.desc) + '</span>'
|
||
+ '<span class="dec__crmeta">' + startCount(pk) + ' bions · ' + fmt(pk.koin) + ' koin</span>'
|
||
+ '</button>';
|
||
}
|
||
for (i = 0; i < ROLES.length; i++) {
|
||
r = ROLES[i];
|
||
cls = 'dec__crrole' + (r.heart ? ' dec__crrole--heart' : '');
|
||
roleHtml += '<button class="' + cls + '" data-base="' + cls + '" data-crrole="' + esc(r.id) + '" type="button">'
|
||
+ '<span class="dec__cricon">' + esc(r.icon) + '</span>'
|
||
+ '<span class="dec__crname">' + esc(r.label)
|
||
+ (r.heart ? ' <span class="dec__crheart">le cœur du jeu</span>' : '') + '</span>'
|
||
+ '<span class="dec__crdesc">' + esc(r.desc) + '</span>'
|
||
+ '</button>';
|
||
}
|
||
container.innerHTML =
|
||
'<div class="dec dec__cr">'
|
||
+ ' <div class="dec__crhead">'
|
||
+ ' <div class="dec__crtitle">qui es-tu ?</div>'
|
||
+ ' <div class="dec__crsubtitle">choisis ton départ et ton rôle — tout reste atteignable, c\'est juste ta saveur du début</div>'
|
||
+ ' </div>'
|
||
+ ' <div class="dec__crbody">'
|
||
+ ' <div class="dec__crsect">'
|
||
+ ' <div class="dec__h">comment tu joues</div>'
|
||
+ ' <div class="dec__crmodes">' + modeHtml + '</div>'
|
||
+ ' </div>'
|
||
+ ' <div class="dec__crsect" data-packsect>'
|
||
+ ' <div class="dec__h">① ton départ</div>'
|
||
+ ' <div class="dec__crpacks">' + packHtml + '</div>'
|
||
+ ' </div>'
|
||
+ ' <div class="dec__crsect">'
|
||
+ ' <div class="dec__h">② ton rôle</div>'
|
||
+ ' <div class="dec__crroles">' + roleHtml + '</div>'
|
||
+ ' <div class="dec__crmore">… et bien d\'autres rôles (extensible)</div>'
|
||
+ ' </div>'
|
||
+ ' </div>'
|
||
+ ' <div class="dec__crfoot">'
|
||
+ ' <button class="dec__crgo" data-crgo type="button" disabled>⚔ commencer</button>'
|
||
+ ' </div>'
|
||
+ '</div>';
|
||
root = container.querySelector('.dec');
|
||
toastEl = null;
|
||
applyModeUI(); // marque le mode par défaut (survival) + affiche/masque le choix de pack + libellé du bouton
|
||
}
|
||
|
||
// reflète le mode sélectionné dans l'écran de création : en créatif, le choix de pack est inutile
|
||
// (tout est débloqué) → on le masque et on ne garde que le rôle (flavor). Le bouton change de libellé.
|
||
function applyModeUI() {
|
||
markSel('[data-crmode]', 'data-crmode', crMode);
|
||
var ps = container.querySelector('[data-packsect]');
|
||
if (ps) ps.style.display = (crMode === 'creatif') ? 'none' : '';
|
||
var g = container.querySelector('[data-crgo]');
|
||
if (g) g.textContent = (crMode === 'creatif') ? '✨ entrer en créatif' : '⚔ commencer';
|
||
refreshGo();
|
||
}
|
||
function selectMode(id) {
|
||
if (id !== 'survival' && id !== 'creatif') return;
|
||
crMode = id;
|
||
applyModeUI();
|
||
}
|
||
|
||
function markSel(sel, attr, id) {
|
||
var els = container.querySelectorAll(sel), i, el;
|
||
for (i = 0; i < els.length; i++) {
|
||
el = els[i];
|
||
el.className = (el.getAttribute('data-base') || '') + (el.getAttribute(attr) === id ? ' is-sel' : '');
|
||
}
|
||
}
|
||
function refreshGo() {
|
||
var g = container.querySelector('[data-crgo]');
|
||
if (!g) return;
|
||
// créatif : seul le rôle (flavor) est requis, pas de pack. survival : pack + rôle.
|
||
g.disabled = (crMode === 'creatif') ? !crRole : !(crPack && crRole);
|
||
}
|
||
function selectPack(id) {
|
||
if (!packById(id)) return;
|
||
crPack = id;
|
||
markSel('[data-crpack]', 'data-crpack', id);
|
||
refreshGo();
|
||
}
|
||
function selectRole(id) {
|
||
if (!roleById(id)) return;
|
||
crRole = id;
|
||
markSel('[data-crrole]', 'data-crrole', id);
|
||
refreshGo();
|
||
}
|
||
|
||
function commitCreation() {
|
||
var r, j, nb, k;
|
||
// MODE CRÉATIF : le rôle suffit (flavor). Tout est débloqué d'un coup, direct la forge complète.
|
||
if (crMode === 'creatif') {
|
||
r = roleById(crRole);
|
||
if (!r) return;
|
||
var uAll = [], dAll = [], fgAll = [], fundAll = [], wb = worldBlocs();
|
||
for (k = 0; k < BIONS.length; k++) uAll.push(BIONS[k].id); // tous les bions
|
||
for (k = 0; k < COMPS.length; k++) dAll.push(COMPS[k].id); // toutes les compositions
|
||
for (k = 0; k < FUND.length; k++) fundAll.push(FUND[k].id); // son + wifi + xion
|
||
for (k = 0; k < wb.length; k++) if (wb[k] && wb[k].id) fgAll.push(wb[k].id); // tous les blocs connus
|
||
var stC = {
|
||
unlocked: uAll, discovered: dAll, koin: 1e9, t: 0,
|
||
fund: fundAll, won: false, created: true, mode: 'creatif', pack: '', role: r.id,
|
||
forged: fgAll, worldMark: null
|
||
};
|
||
buildGameDOM();
|
||
startGame(stC);
|
||
saveState();
|
||
showToast('✨ mode créatif — tout est débloqué, à toi la forge');
|
||
return;
|
||
}
|
||
// SURVIVAL : le voyage incrémental (inchangé) — pack + rôle.
|
||
if (!crPack || !crRole) return;
|
||
var pk = packById(crPack);
|
||
r = roleById(crRole);
|
||
if (!pk || !r) return;
|
||
var u = packUnlocked(pk);
|
||
// scientifique : +startBonus bion(s) de départ = le prochain de plus BAS tier non débloqué.
|
||
for (j = 0; j < (r.startBonus || 0); j++) {
|
||
nb = nextRewardFrom(u);
|
||
if (nb && !has(u, nb.id)) u.push(nb.id);
|
||
}
|
||
var startKoin = Math.min(pk.koin || 0, capForUnlocked(u));
|
||
var st = {
|
||
unlocked: u, discovered: [], koin: startKoin, t: 0,
|
||
fund: [], won: false, created: true, mode: 'survival', pack: pk.id, role: r.id,
|
||
forged: [], worldMark: null
|
||
};
|
||
buildGameDOM();
|
||
startGame(st);
|
||
saveState();
|
||
showToast('bienvenue, ' + r.label + ' ' + r.icon);
|
||
}
|
||
|
||
function updateRoleBadge() {
|
||
var mb = container.querySelector('[data-badgemode]');
|
||
if (mb) mb.style.display = creative() ? '' : 'none'; // badge « ✨ créatif » à côté du rôle
|
||
var el = container.querySelector('[data-badge]');
|
||
if (!el) return;
|
||
var r = roleById(role);
|
||
if (r) {
|
||
el.innerHTML = esc(r.icon) + ' <span class="dec__badgename">' + esc(r.label) + '</span>';
|
||
el.style.display = '';
|
||
} else {
|
||
el.innerHTML = '';
|
||
el.style.display = 'none';
|
||
}
|
||
}
|
||
|
||
/* ---------------- listeners ---------------- */
|
||
function onClick(e) {
|
||
var t = e.target;
|
||
var mob = t.closest ? t.closest('[data-crmode]') : null;
|
||
if (mob) { selectMode(mob.getAttribute('data-crmode')); return; }
|
||
var pkb = t.closest ? t.closest('[data-crpack]') : null;
|
||
if (pkb) { selectPack(pkb.getAttribute('data-crpack')); return; }
|
||
var rob = t.closest ? t.closest('[data-crrole]') : null;
|
||
if (rob) { selectRole(rob.getAttribute('data-crrole')); return; }
|
||
var gob = t.closest ? t.closest('[data-crgo]') : null;
|
||
if (gob) { commitCreation(); return; }
|
||
var hb = t.closest ? t.closest('[data-harvest]') : null;
|
||
if (hb) { harvest(); return; }
|
||
var cb = t.closest ? t.closest('[data-craft]') : null;
|
||
if (cb) { craft(cb.getAttribute('data-craft')); return; }
|
||
var fb = t.closest ? t.closest('[data-fund]') : null;
|
||
if (fb) { craftFund(fb.getAttribute('data-fund')); return; }
|
||
var eb = t.closest ? t.closest('[data-expo]') : null;
|
||
if (eb) { expedition(); return; }
|
||
var xb = t.closest ? t.closest('[data-xerb]') : null;
|
||
if (xb) { craftXerb(); return; }
|
||
var rb = t.closest ? t.closest('[data-reset]') : null;
|
||
if (rb) {
|
||
if (window.confirm('Recommencer la découverte depuis le début ? La progression sera perdue.')) resetGame();
|
||
return;
|
||
}
|
||
}
|
||
container.addEventListener('click', onClick);
|
||
|
||
/* ---------------- IN harvest (bus) ---------------- */
|
||
// minecraft.command → ploxion.decouverte.harvest (fil jOSWire) : chaque commande jouée
|
||
// dans le monde 3D (poser/miner) compte comme activité → même récolte que le bouton ⛏
|
||
// (koin + flottant visible). Throttlé (≥400 ms) pour qu'une rafale de setblock (gros
|
||
// build) ne spamme pas l'économie. Payload opaque : sa simple occurrence = l'activité.
|
||
var lastBusHarvest = 0, offHarvest = null;
|
||
try {
|
||
if (window.jOSPorts && jOSPorts.on) {
|
||
offHarvest = jOSPorts.on('ploxion.' + ID + '.harvest', function (payload) {
|
||
if (!alive || !created) return; // jeu pas commencé (écran de création) → rien
|
||
if (payload == null) return; // payload invalide : ignoré proprement
|
||
var now = Date.now();
|
||
if (now - lastBusHarvest < 400) return;
|
||
lastBusHarvest = now;
|
||
harvest();
|
||
});
|
||
}
|
||
} catch (e) {}
|
||
|
||
/* ---------------- boot ---------------- */
|
||
function startGame(st) {
|
||
var v = st || { unlocked: START.slice(), discovered: [], koin: 0, t: 0 };
|
||
unlocked = v.unlocked;
|
||
discovered = v.discovered;
|
||
fund = (v.fund instanceof Array) ? v.fund : [];
|
||
won = v.won === true;
|
||
forged = (v.forged instanceof Array) ? v.forged : []; // EXPEDITIONS : blocs deja forges
|
||
worldMark = (v.worldMark && typeof v.worldMark === 'object') ? v.worldMark : null;
|
||
created = true;
|
||
mode = (v.mode === 'creatif') ? 'creatif' : 'survival'; // défaut survival (vieilles saves incluses)
|
||
if (v.pack) pack = v.pack;
|
||
if (v.role) role = v.role;
|
||
koin = (typeof v.koin === 'number' && isFinite(v.koin)) ? v.koin : 0;
|
||
// progrès hors-ligne (idle) : gain = prod · min(absence, 1 h) · biais du rôle, borné par cap.
|
||
// Date.now() est OK ici : c'est du client-side navigateur, PAS un script workflow.
|
||
if (v.t) {
|
||
var elapsed = (Date.now() - v.t) / 1000;
|
||
if (elapsed > 0) {
|
||
var before = koin;
|
||
koin = Math.min(cap(), koin + prod() * Math.min(elapsed, 3600) * roleMult('offline'));
|
||
var got = koin - before;
|
||
if (got > 0) showToast('+' + fmt(got) + ' koin pendant ton absence');
|
||
}
|
||
}
|
||
renderBody();
|
||
updateProgress();
|
||
updateKoinUI();
|
||
updateRoleBadge();
|
||
startTick();
|
||
checkGrowth(); // EXPEDITIONS : diffe le monde vu -> toast si le xerboxion a grandi, puis reancre worldMark
|
||
}
|
||
// au tout premier lancement (aucun état OU pas de state.created) → écran de création AVANT le jeu.
|
||
function apply(st) {
|
||
if (!st || st.created !== true) { showCreation(); return; }
|
||
buildGameDOM();
|
||
startGame(st);
|
||
}
|
||
|
||
function boot(cat) {
|
||
if (!alive) return;
|
||
BIONS = (cat && cat.bions instanceof Array) ? cat.bions : [];
|
||
COMPS = (cat && cat.compositions instanceof Array) ? cat.compositions : [];
|
||
WORLD = (cat && cat.world && typeof cat.world === 'object') ? cat.world : null; // le monde vivant (blocs/ploxions)
|
||
byBion = {}; byComp = {};
|
||
var i;
|
||
for (i = 0; i < BIONS.length; i++) byBion[BIONS[i].id] = BIONS[i];
|
||
for (i = 0; i < COMPS.length; i++) byComp[COMPS[i].id] = COMPS[i];
|
||
|
||
var local = loadLocal();
|
||
if (boxed() && jOSBoxion.load) {
|
||
jOSBoxion.load(NS, KEY).then(function (it) {
|
||
if (!alive) return;
|
||
var st = (it && it.data) ? validate(it.data) : null;
|
||
apply(st || local);
|
||
}).catch(function () { if (alive) apply(local); });
|
||
} else {
|
||
apply(local);
|
||
}
|
||
try { if (window.jOSPorts) jOSPorts.emit(ID, 'ready', { bions: BIONS.length, compositions: COMPS.length }); } catch (e) {}
|
||
}
|
||
|
||
function fail(msg) {
|
||
if (!alive) return;
|
||
progtxtEl.textContent = 'catalogue indisponible';
|
||
body.innerHTML = '<div class="dec__msg">' + esc(msg || 'impossible de charger le catalogue de la forge.')
|
||
+ '<br>vérifie ta connexion puis rouvre le ploxion.</div>';
|
||
}
|
||
|
||
try {
|
||
fetch('/px/synth-catalog.json', { credentials: 'same-origin' }).then(function (r) {
|
||
if (!r.ok) throw new Error('http ' + r.status);
|
||
return r.json();
|
||
}).then(function (cat) {
|
||
if (!cat || !(cat.bions instanceof Array) || !(cat.compositions instanceof Array)) { fail('catalogue vide ou invalide.'); return; }
|
||
boot(cat);
|
||
}).catch(function () { fail(); });
|
||
} catch (e) { fail(); }
|
||
|
||
return {
|
||
unmount: function () {
|
||
if (tickTimer) { clearInterval(tickTimer); tickTimer = 0; }
|
||
if (toastTimer) clearTimeout(toastTimer);
|
||
try { saveState(); } catch (e) {} // dernière sauvegarde avec state.t frais
|
||
alive = false;
|
||
try { if (offHarvest) offHarvest(); } catch (e) {} // droit au silence : désabonne le port harvest
|
||
try { container.removeEventListener('click', onClick); } catch (e) {}
|
||
container.innerHTML = '';
|
||
}
|
||
};
|
||
}
|
||
|
||
// ===== XUI (contrat v0) : describe() PUR, marche NON MONTÉ — lit la sauvegarde
|
||
// localStorage (LSKEY), jamais le DOM. Ne lève jamais. =====
|
||
function describe(){
|
||
try {
|
||
var st = null;
|
||
try { st = JSON.parse(localStorage.getItem(LSKEY) || 'null'); } catch (e0) {}
|
||
var unlocked = (st && st.unlocked instanceof Array) ? st.unlocked.length : START.length;
|
||
var crafts = (st && st.discovered instanceof Array) ? st.discovered.length : 0;
|
||
var koin = (st && typeof st.koin === 'number' && isFinite(st.koin)) ? Math.round(st.koin) : 0;
|
||
var forged = (st && st.forged instanceof Array) ? st.forged.length : 0;
|
||
var items = [
|
||
{ p:1, kind:'stat', label: (st && st.won) ? '🏆 découverte (gagné)' : '🔓 découverte',
|
||
value: unlocked + ' bions · ' + crafts + ' crafts' },
|
||
{ p:2, kind:'stat', label:'koin', value: (st && st.mode === 'creatif') ? '∞ (créatif)' : koin },
|
||
{ p:3, kind:'stat', label:'expéditions forgées', value: forged },
|
||
{ p:4, kind:'text', label: st ? 'partie en cours — mode ' + ((st.mode === 'creatif') ? 'créatif' : 'survival') : 'aucune partie — départ avec 2 bions' }
|
||
];
|
||
return { v:1, id:ID, title:'Découverte', icon:'🔓', items:items };
|
||
} catch (e) {
|
||
return { v:1, id:ID, title:'Découverte', icon:'🔓', items:[{ p:1, kind:'text', label:'Découverte' }] };
|
||
}
|
||
}
|
||
|
||
window.jOSApps = window.jOSApps || {};
|
||
window.jOSApps[ID] = { manifest: { id: ID, name: 'Découverte', icon: '🔓' }, mount: mount, describe: describe };
|
||
})();
|
||
</script>
|