mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-16 17:31:24 +01:00
fix: version detection on load
This commit is contained in:
parent
0b8d3c63fc
commit
dd35947ecd
2 changed files with 37 additions and 17 deletions
|
|
@ -1,4 +1,5 @@
|
|||
"use strict";
|
||||
|
||||
// Functions to load and parse .map/.gz files
|
||||
async function quickLoad() {
|
||||
const blob = await ldb.get("lastMap");
|
||||
|
|
@ -109,19 +110,23 @@ function uploadMap(file, callback) {
|
|||
fileReader.onloadend = async function (fileLoadedEvent) {
|
||||
if (callback) callback();
|
||||
byId("coas").innerHTML = ""; // remove auto-generated emblems
|
||||
|
||||
const result = fileLoadedEvent.target.result;
|
||||
const [mapData, mapVersion] = await parseLoadedResult(result);
|
||||
|
||||
const isInvalid = !mapData || !isValidVersion(mapVersion) || mapData.length < 26 || !mapData[5];
|
||||
const isUpdated = compareVersions(mapVersion, VERSION).isEqual;
|
||||
const isAncient = compareVersions(mapVersion, "0.70.0").isOlder;
|
||||
const isNewer = compareVersions(mapVersion, VERSION).isNewer;
|
||||
const isOutdated = compareVersions(mapVersion, VERSION).isOlder;
|
||||
|
||||
if (isInvalid) return showUploadMessage("invalid", mapData, mapVersion);
|
||||
|
||||
const isUpdated = compareVersions(mapVersion, VERSION).isEqual;
|
||||
if (isUpdated) return showUploadMessage("updated", mapData, mapVersion);
|
||||
|
||||
const isAncient = compareVersions(mapVersion, "0.70.0").isOlder;
|
||||
if (isAncient) return showUploadMessage("ancient", mapData, mapVersion);
|
||||
|
||||
const isNewer = compareVersions(mapVersion, VERSION).isNewer;
|
||||
if (isNewer) return showUploadMessage("newer", mapData, mapVersion);
|
||||
|
||||
const isOutdated = compareVersions(mapVersion, VERSION).isOlder;
|
||||
if (isOutdated) return showUploadMessage("outdated", mapData, mapVersion);
|
||||
};
|
||||
|
||||
|
|
@ -151,19 +156,16 @@ async function parseLoadedResult(result) {
|
|||
const isDelimited = resultAsString.substring(0, 10).includes("|");
|
||||
const decoded = isDelimited ? resultAsString : decodeURIComponent(atob(resultAsString));
|
||||
|
||||
const mapData = decoded.split("\r\n");
|
||||
const mapVersionString = mapData[0].split("|")[0] || mapData[0] || "";
|
||||
const [major, minor, patch = 0] = mapVersionString.split(".").map(parseFloat);
|
||||
const mapVersion = `${major}.${minor}.${patch}`;
|
||||
const mapData = decoded.split("\r\n"); // split by CRLF
|
||||
const mapVersion = parseMapVersion(mapData[0].split("|")[0] || mapData[0] || "");
|
||||
|
||||
return [mapData, mapVersion];
|
||||
return {mapData, mapVersion};
|
||||
} catch (error) {
|
||||
// map file can be compressed with gzip
|
||||
const uncompressedData = await uncompress(result);
|
||||
const uncompressedData = await uncompress(result); // file can be gzip compressed
|
||||
if (uncompressedData) return parseLoadedResult(uncompressedData);
|
||||
|
||||
ERROR && console.error(error);
|
||||
return [null, null];
|
||||
return {mapData: null, mapVersion: null};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,12 +7,13 @@
|
|||
*
|
||||
* Update the version MANUALLY on each merge to main:
|
||||
* 1. MAJOR version: Incompatible changes that break existing maps
|
||||
* 2. MINOR version: Backwards-compatible changes requiring old .map files to be updated
|
||||
* 3. PATCH version: Backwards-compatible bug fixes not affecting .map file format
|
||||
* 2. MINOR version: Additions or changes that are backward-compatible but may require old .map files to be updated
|
||||
* 3. PATCH version: Backward-compatible bug fixes and small features that do not affect the .map file format
|
||||
*
|
||||
* Example: 1.102.0 -> Major version 1, Minor version 102, Patch version 0
|
||||
* Example: 1.102.2 -> Major version 1, Minor version 102, Patch version 2
|
||||
*/
|
||||
const VERSION = "1.103.02";
|
||||
const VERSION = "1.103.3";
|
||||
if (parseMapVersion(VERSION) !== VERSION) alert("versioning.js: Invalid format or parsing function");
|
||||
|
||||
{
|
||||
document.title += " v" + VERSION;
|
||||
|
|
@ -80,6 +81,23 @@ const VERSION = "1.103.02";
|
|||
}
|
||||
}
|
||||
|
||||
function parseMapVersion(version) {
|
||||
let [major, minor, patch] = version.split(".");
|
||||
|
||||
if (patch === undefined) {
|
||||
// e.g. 1.732
|
||||
minor = minor.slice(0, 2);
|
||||
patch = minor.slice(2);
|
||||
}
|
||||
|
||||
// e.g. 0.7b
|
||||
major = parseInt(major) || 0;
|
||||
minor = parseInt(minor) || 0;
|
||||
patch = parseInt(patch) || 0;
|
||||
|
||||
return `${major}.${minor}.${patch}`;
|
||||
}
|
||||
|
||||
function isValidVersion(versionString) {
|
||||
if (!versionString) return false;
|
||||
const [major, minor, patch] = versionString.split(".");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue