From f763c9794c2fbb3863fe0a2b1ca031b8d9743596 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Wed, 17 Jun 2026 22:31:34 +0200 Subject: [PATCH] Organize app script sections --- app.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/app.js b/app.js index 80d5f7b..09a8a7d 100644 --- a/app.js +++ b/app.js @@ -1,3 +1,7 @@ +/* ========================================================================== + Data definitions and shared helpers + ========================================================================== */ + const EFFECTS = [ { id: "critChance", label: "Crit chance", cap: 12, group: "offense" }, { id: "critDamage", label: "Crit damage", cap: 80, group: "offense" }, @@ -55,6 +59,10 @@ const effectById = (id) => EFFECTS.find((effect) => effect.id === id); let state = loadDraft() || createDefaultState(); +/* ========================================================================== + State creation and normalization + ========================================================================== */ + function createDefaultState() { return { profile: "lifesteal", @@ -166,6 +174,10 @@ function clampEffectValue(type, value) { return Math.min(effect.cap, Math.max(1, Number.isFinite(value) ? value : 1)); } +/* ========================================================================== + Rendering + ========================================================================== */ + function render() { renderControls(); renderGear(); @@ -370,6 +382,10 @@ function updateSwapControls() { $("#swapStatus").textContent = "Press Swap again to exchange back."; } +/* ========================================================================== + Replacement comparison and swap helpers + ========================================================================== */ + function calculateTotals() { const totals = { baseDamage: 0, baseHealth: 0, effects: Object.fromEntries(EFFECTS.map((effect) => [effect.id, 0])) }; for (const piece of state.pieces) { @@ -490,6 +506,10 @@ function createNewItemFromPiece(piece, target, targetPieceId = null) { }; } +/* ========================================================================== + Calculations and scoring + ========================================================================== */ + function formatDelta(value, suffix = "") { const sign = value > 0 ? "+" : ""; return `${sign}${fmt(value)}${suffix}`; @@ -669,6 +689,10 @@ function renderSacrifices(pieceScores) { `).join(""); } +/* ========================================================================== + Persistence, save slots, import, and export + ========================================================================== */ + function saveDraft() { localStorage.setItem(DRAFT_KEY, JSON.stringify(state)); } @@ -801,6 +825,10 @@ function importUploadedJson(event) { reader.readAsText(file); } +/* ========================================================================== + Event handling + ========================================================================== */ + function bindEvents() { $("#profileSelect").addEventListener("change", (event) => { state.profile = event.target.value; @@ -921,5 +949,9 @@ function escapeHtml(value) { return String(value).replace(/[&<>"]/g, (char) => ({ "&": "&", "<": "<", ">": ">", '"': """ }[char])); } +/* ========================================================================== + Bootstrap + ========================================================================== */ + bindEvents(); render();