From 7fc73c1f893aae90bf0385140b05c98433b69bbb Mon Sep 17 00:00:00 2001 From: Justin Oros Date: Mon, 21 Sep 2026 21:06:07 -0700 Subject: [PATCH] Add Clear inventory button --- app.js | 13 +++++++++++++ index.html | 1 + 2 files changed, 14 insertions(+) diff --git a/app.js b/app.js index 932aa9e..a43da12 100644 --- a/app.js +++ b/app.js @@ -2,6 +2,7 @@ const DISCLAIMER_KEY = "sotf-inventory-disclaimer-v1"; const SAVES_PATH = "%USERPROFILE%\\AppData\\LocalLow\\Endnight\\SonsOfTheForest\\Saves"; const INVENTORY_FILE = "PlayerInventorySaveData.json"; + const KEEP_ON_CLEAR = new Set([351, 379, 380, 402, 412, 413, 483, 486, 552, 589]); const $ = (id) => document.getElementById(id); const els = { @@ -20,6 +21,7 @@ emptyState: $("emptyState"), changeSummary: $("changeSummary"), resetBtn: $("resetBtn"), + clearBtn: $("clearBtn"), saveBtn: $("saveBtn"), disclaimer: $("disclaimer"), disclaimerOk: $("disclaimerOk"), @@ -157,11 +159,16 @@ return [...state.items.values()].filter((i) => i.count !== i.original); } + function clearableItems() { + return [...state.items.values()].filter((i) => !i.equipped && !KEEP_ON_CLEAR.has(i.id)); + } + function updateSummary() { const n = changedItems().length; els.changeSummary.textContent = n === 0 ? "No changes" : `${n} item${n === 1 ? "" : "s"} changed`; els.changeSummary.classList.toggle("has-changes", n > 0); els.resetBtn.disabled = n === 0; + els.clearBtn.disabled = !clearableItems().some((i) => i.count > 0); els.saveBtn.disabled = !state.source || n === 0; els.saveBtn.title = state.source ? "" : "Load a save first"; } @@ -442,6 +449,12 @@ render(); }); + els.clearBtn.addEventListener("click", () => { + for (const item of clearableItems()) item.count = 0; + render(); + toast("Inventory cleared. Equipped items and starting tools were kept. Use Undo changes to restore."); + }); + els.saveBtn.addEventListener("click", () => { if (!state.source) return; els.saveFileName.textContent = state.source.fileName; diff --git a/index.html b/index.html index c8bde9c..11cacd2 100644 --- a/index.html +++ b/index.html @@ -68,6 +68,7 @@