From acc2d112f3b2fcd966d74cca3daa6f6ab3f1b224 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 14 Nov 2025 02:33:16 +0000 Subject: [PATCH] feat: add default map setting feature Add ability to set a specific map as the default that opens on load: - Add 'Open default map' option to onload behavior dropdown - Implement saveAsDefaultMap() to store map as default in IndexedDB - Implement clearDefaultMap() to remove default map setting - Modify checkLoadParameters() to load default map when configured - Add UI buttons in Save dialog for setting/clearing default map - Update version to 1.108.12 and hash in index.html Users can now: 1. Open any map they want as default 2. Go to Options > Onload behavior > Select "Open default map" 3. Save > Click "Set as default" button 4. The map will now open automatically every time This sets the foundation for the planned time-based worldbuilding and lore database features by ensuring users always start with their primary world map. --- index.html | 14 ++++++++++++-- main.js | 16 ++++++++++++++++ modules/io/save.js | 26 ++++++++++++++++++++++++++ versioning.js | 2 +- 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 3c0ba0f3..9175879e 100644 --- a/index.html +++ b/index.html @@ -1830,6 +1830,7 @@ @@ -6087,6 +6088,15 @@ browser +
+ Default map + + +

Maps are saved in .map format, that can be loaded back via the Load in menu. There is no way to restore the progress if file is lost. Please keep old save files on your machine or cloud storage as backups. @@ -8118,7 +8128,7 @@ - + @@ -8163,7 +8173,7 @@ - + diff --git a/main.js b/main.js index 848ff3c5..4f4bdb63 100644 --- a/main.js +++ b/main.js @@ -291,6 +291,22 @@ async function checkLoadParameters() { return; } + // check if there is a default map saved to indexedDB + if (byId("onloadBehavior").value === "default") { + try { + const blob = await ldb.get("defaultMap"); + if (blob) { + WARN && console.warn("Loading default map"); + uploadMap(blob); + return; + } else { + WARN && console.warn("No default map set, generating random map"); + } + } catch (error) { + ERROR && console.error(error); + } + } + // check if there is a map saved to indexedDB if (byId("onloadBehavior").value === "lastSaved") { try { diff --git a/modules/io/save.js b/modules/io/save.js index 304fef59..7a9236c7 100644 --- a/modules/io/save.js +++ b/modules/io/save.js @@ -167,6 +167,32 @@ async function saveToStorage(mapData, showTip = false) { showTip && tip("Map is saved to the browser storage", false, "success"); } +// save current map as the default map +async function saveAsDefaultMap() { + if (customization) return tip("Map cannot be saved in EDIT mode, please complete the edit and retry", false, "error"); + + try { + const mapData = prepareMapData(); + const blob = new Blob([mapData], {type: "text/plain"}); + await ldb.set("defaultMap", blob); + tip("Map is set as default and will open on load", true, "success", 5000); + } catch (error) { + ERROR && console.error(error); + tip("Failed to set default map", true, "error", 3000); + } +} + +// clear the default map setting +async function clearDefaultMap() { + try { + await ldb.set("defaultMap", null); + tip("Default map cleared", false, "success", 2000); + } catch (error) { + ERROR && console.error(error); + tip("Failed to clear default map", false, "error", 2000); + } +} + // download map file function saveToMachine(mapData, filename) { const blob = new Blob([mapData], {type: "text/plain"}); diff --git a/versioning.js b/versioning.js index a785e90e..1094599c 100644 --- a/versioning.js +++ b/versioning.js @@ -13,7 +13,7 @@ * Example: 1.102.2 -> Major version 1, Minor version 102, Patch version 2 */ -const VERSION = "1.108.11"; +const VERSION = "1.108.12"; if (parseMapVersion(VERSION) !== VERSION) alert("versioning.js: Invalid format or parsing function"); {