// ============ research.js — unlock tree ============ import { UNLOCKS, RESEARCH_TRACKS } from '../core/config.js'; export function isUnlocked(state, key) { if (state.sandbox) return true; return state.research.unlocked.includes(key); } export function canBuy(state, u) { if (isUnlocked(state, u.key)) return { ok: false, why: 'owned' }; if (state.research.rp >= u.rp) return { ok: true }; return { ok: false, why: 'rp' }; } export function buyUnlock(state, key) { const u = UNLOCKS.find(u => u.key === key); if (!u) return false; const chk = canBuy(state, u); if (!chk.ok) return false; state.research.rp -= u.rp; state.research.spentTotal += u.rp; state.research.unlocked.push(key); state.toasts.push({ kind: 'good', title: 'Research complete!', text: `${u.label} is now available to build.` }); return true; } export function unlocksByTrack() { const out = {}; for (const t of Object.keys(RESEARCH_TRACKS)) out[t] = []; for (const u of UNLOCKS) (out[u.track] || (out[u.track] = [])).push(u); return out; }