Organize app script sections
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user