From d25f626b8b612b51f863c5b27a0c8922133755b3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Efruz=20Y=C4=B1ld=C4=B1r=C4=B1r?=
<30903352+yldrefruz@users.noreply.github.com>
Date: Mon, 14 Aug 2023 15:48:14 +0300
Subject: [PATCH] refactor file save type to .gz and update the data in ui.
---
index.html | 32 ++++++++++++++++----------------
main.js | 10 +++++-----
modules/dynamic/auto-update.js | 2 +-
modules/io/load.js | 4 ++--
modules/io/save.js | 20 ++++++++++----------
modules/ui/heightmap-editor.js | 2 +-
modules/ui/hotkeys.js | 2 +-
modules/ui/options.js | 4 ++--
versioning.js | 3 ++-
9 files changed, 40 insertions(+), 39 deletions(-)
diff --git a/index.html b/index.html
index b435fab2..efe1d661 100644
--- a/index.html
+++ b/index.html
@@ -2329,8 +2329,8 @@
-
-
+
+
@@ -5884,10 +5884,10 @@
Save map to
-
- 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 .map files on your machine or cloud storage as
+ Maps are saved in .gz 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 .gz or .map files on your machine or cloud storage as
backups.
This operation is destructive and irreversible. It will create a completely new map based on the current one.
- Don't forget to save the current project as a .map file first!
+ Don't forget to save the current project as a .gz file first!
-
Drop a .map file to open
+
Drop a .gz or .map file to open
-
+
@@ -7963,15 +7963,15 @@
-
-
+
+
-
+
@@ -8001,7 +8001,7 @@
-
+
diff --git a/main.js b/main.js
index 4c40de43..ab36463b 100644
--- a/main.js
+++ b/main.js
@@ -270,7 +270,7 @@ async function checkLoadParameters() {
const url = new URL(window.location.href);
const params = url.searchParams;
- // of there is a valid maplink, try to load .map file from URL
+ // of there is a valid maplink, try to load .gz/.map file from URL
if (params.get("maplink")) {
WARN && console.warn("Load map from URL");
const maplink = params.get("maplink");
@@ -574,9 +574,9 @@ void (function addDragToUpload() {
overlay.style.display = "none";
if (e.dataTransfer.items == null || e.dataTransfer.items.length !== 1) return; // no files or more than one
const file = e.dataTransfer.items[0].getAsFile();
- if (file.name.indexOf(".map") == -1) {
- // not a .map file
- alertMessage.innerHTML = "Please upload a .map file you have previously downloaded";
+ if (!file.name.endsWith(".map") && !file.name.endsWith(".gz")) {
+ // not a .gz/.map file
+ alertMessage.innerHTML = "Please upload a .gz or .map file you have previously downloaded";
$("#alert").dialog({
resizable: false,
title: "Invalid file format",
@@ -596,7 +596,7 @@ void (function addDragToUpload() {
if (closeDialogs) closeDialogs();
uploadMap(file, () => {
overlay.style.display = "none";
- overlay.innerHTML = "Drop a .map file to open";
+ overlay.innerHTML = "Drop a .gz or .map file to open";
});
});
})();
diff --git a/modules/dynamic/auto-update.js b/modules/dynamic/auto-update.js
index 2319219c..e5e53785 100644
--- a/modules/dynamic/auto-update.js
+++ b/modules/dynamic/auto-update.js
@@ -1,6 +1,6 @@
"use strict";
-// update old .map version to the current one
+// update old .gz/.map version to the current one
export function resolveVersionConflicts(version) {
if (version < 1) {
// v1.0 added a new religions layer
diff --git a/modules/io/load.js b/modules/io/load.js
index 4618c93c..d55e8a4a 100644
--- a/modules/io/load.js
+++ b/modules/io/load.js
@@ -1,5 +1,5 @@
"use strict";
-// Functions to load and parse .map files
+// Functions to load and parse .gz/.map files
async function quickLoad() {
const blob = await ldb.get("lastMap");
if (blob) loadMapPrompt(blob);
@@ -170,7 +170,7 @@ function showUploadMessage(type, mapData, mapVersion) {
let message, title, canBeLoaded;
if (type === "invalid") {
- message = `The file does not look like a valid .map file. Please check the data format`;
+ message = `The file does not look like a valid .gz or .map file. Please check the data format`;
title = "Invalid file";
canBeLoaded = false;
} else if (type === "ancient") {
diff --git a/modules/io/save.js b/modules/io/save.js
index 5a47d84f..d5f2a939 100644
--- a/modules/io/save.js
+++ b/modules/io/save.js
@@ -1,5 +1,5 @@
"use strict";
-// functions to save project as .map file
+// functions to save project as .gz file
// prepare map data for saving
function getMapData() {
@@ -126,7 +126,7 @@ async function compressMapData(mapData){
}
-// Download .map file
+// Download .gz file
async function downloadMap() {
if (customization)
return tip("Map cannot be saved when edit mode is active, please exit the mode and retry", false, "error");
@@ -136,7 +136,7 @@ async function downloadMap() {
const blob = new Blob([mapData], {type: "text/plain"});
const URL = window.URL.createObjectURL(blob);
const link = document.createElement("a");
- link.download = getFileName() + ".map";
+ link.download = getFileName() + ".gz";
link.href = URL;
link.click();
tip(`${link.download} is saved. Open "Downloads" screen (CTRL + J) to check`, true, "success", 7000);
@@ -148,13 +148,13 @@ async function saveToDropbox() {
return tip("Map cannot be saved when edit mode is active, please exit the mode and retry", false, "error");
closeDialogs("#alert");
const mapData = await compressMapData(getMapData());
- const filename = getFileName() + ".map";
+ const filename = getFileName() + ".gz";
try {
await Cloud.providers.dropbox.save(filename, mapData);
tip("Map is saved to your Dropbox", true, "success", 8000);
} catch (msg) {
ERROR && console.error(msg);
- tip("Cannot save .map to your Dropbox", true, "error", 8000);
+ tip("Cannot save .gz to your Dropbox", true, "error", 8000);
}
}
@@ -188,19 +188,19 @@ async function quickSave() {
const mapData = await compressMapData(getMapData());
const blob = new Blob([mapData], {type: "text/plain"});
await ldb.set("lastMap", blob); // auto-save map
- tip("Map is saved to browser memory. Please also save as .map file to secure progress", true, "success", 2000);
+ tip("Map is saved to browser memory. Please also save as .gz file to secure progress", true, "success", 2000);
}
const saveReminder = function () {
if (localStorage.getItem("noReminder")) return;
const message = [
- "Please don't forget to save your work as a .map file",
- "Please remember to save work as a .map file",
- "Saving in .map format will ensure your data won't be lost in case of issues",
+ "Please don't forget to save your work as a .gz file",
+ "Please remember to save work as a .gz file",
+ "Saving in .gz format will ensure your data won't be lost in case of issues",
"Safety is number one priority. Please save the map",
"Don't forget to save your map on a regular basis!",
"Just a gentle reminder for you to save the map",
- "Please don't forget to save your progress (saving as .map is the best option)",
+ "Please don't forget to save your progress (saving as .gz is the best option)",
"Don't want to be reminded about need to save? Press CTRL+Q"
];
const interval = 15 * 60 * 1000; // remind every 15 minutes
diff --git a/modules/ui/heightmap-editor.js b/modules/ui/heightmap-editor.js
index 41031786..1bb53ab8 100644
--- a/modules/ui/heightmap-editor.js
+++ b/modules/ui/heightmap-editor.js
@@ -28,7 +28,7 @@ function editHeightmap(options) {
Erase mode also allows you Convert an Image into a heightmap or use Template Editor.
You can keep the data, but you won't be able to change the coastline.
Try risk mode to change the coastline and keep the data. The data will be restored as much as possible, but it can cause unpredictable errors.
-
Please save the map before editing the heightmap!
+
Please save the map before editing the heightmap!
Check out ${link(
"https://github.com/Azgaar/Fantasy-Map-Generator/wiki/Heightmap-customization",
"wiki"
diff --git a/modules/ui/hotkeys.js b/modules/ui/hotkeys.js
index f7443469..5f03cb2d 100644
--- a/modules/ui/hotkeys.js
+++ b/modules/ui/hotkeys.js
@@ -32,7 +32,7 @@ function handleKeyup(event) {
else if (code === "Delete") removeElementOnKey();
else if (code === "KeyO" && document.getElementById("canvas3d")) toggle3dOptions();
else if (ctrl && code === "KeyQ") toggleSaveReminder();
- else if (ctrl && code === "KeyS") dowloadMap();
+ else if (ctrl && code === "KeyS") downloadMap();
else if (ctrl && code === "KeyC") saveToDropbox();
else if (ctrl && code === "KeyZ" && undo?.offsetParent) undo.click();
else if (ctrl && code === "KeyY" && redo?.offsetParent) redo.click();
diff --git a/modules/ui/options.js b/modules/ui/options.js
index ce3b3561..ff2003a1 100644
--- a/modules/ui/options.js
+++ b/modules/ui/options.js
@@ -844,8 +844,8 @@ async function connectToDropbox() {
function loadURL() {
const pattern = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
- const inner = `Provide URL to a .map file:
-
+ const inner = `Provide URL to a .gz or .map file:
+
Please note server should allow CORS for file to be loaded. If CORS is not allowed, save file to Dropbox and provide a direct link`;
alertMessage.innerHTML = inner;
$("#alert").dialog({
diff --git a/versioning.js b/versioning.js
index 5582a17e..7d07e077 100644
--- a/versioning.js
+++ b/versioning.js
@@ -23,11 +23,12 @@ const version = "1.93.00"; // generator version, update each time
const discord = "https://discordapp.com/invite/X7E84HU";
const patreon = "https://www.patreon.com/azgaar";
- alertMessage.innerHTML = /* html */ `The Fantasy Map Generator is updated up to version ${version}. This version is compatible with previous versions, loaded .map files will be auto-updated.
+ alertMessage.innerHTML = /* html */ `The Fantasy Map Generator is updated up to version ${version}. This version is compatible with previous versions, loaded .gz or .map files will be auto-updated.
${storedVersion ? "Reload the page to fetch fresh code." : ""}
Latest changes:
+
Map save file extension is changed to .gz, .map files are still loadable
New label placement algorithm for states
North and South Poles temperature can be set independently