feat: Update version and use constant for VERSION in multiple files

This commit is contained in:
Azgaar 2024-08-26 04:40:25 +02:00
parent 5fd55f3f9c
commit 5ec682562b
8 changed files with 31 additions and 32 deletions

View file

@ -14,8 +14,8 @@
# Versioning # Versioning
<!-- Update the version if you want the PR to be merged fast. Currently it's a manual 3-steps process: <!-- Update the VERSION if you want the PR to be merged. Currently it's a manual 3-steps process:
* update version in `versioning.js` using semver principle. Just set the next patch (for fixes) or minor version (for new features) * update VERSION in `versioning.js` using semver principle
* for all changed files update hash (the part after `?`) in place where file is requested (usually it's `index.html`) * for all changed files update hash (the part after `?`) in place where file is requested (usually it's `index.html`)
* if the change can be really interesting for end-users, describe it inside the `showUpdateWindow()` function in `versioning.js` --> * if the change can be really interesting for end-users, describe it inside the `showUpdateWindow()` function in `versioning.js` -->

View file

@ -684,7 +684,7 @@ async function generate(options) {
buttons: { buttons: {
"Clear data": function () { "Clear data": function () {
localStorage.clear(); localStorage.clear();
localStorage.setItem("version", version); localStorage.setItem("version", VERSION);
}, },
Regenerate: function () { Regenerate: function () {
regenerateMap("generation error"); regenerateMap("generation error");

View file

@ -72,7 +72,7 @@ function getGridDataJson() {
function getMapInfo() { function getMapInfo() {
return { return {
version, version: VERSION,
description: "Azgaar's Fantasy Map Generator output: azgaar.github.io/Fantasy-map-generator", description: "Azgaar's Fantasy Map Generator output: azgaar.github.io/Fantasy-map-generator",
exportedAt: new Date().toISOString(), exportedAt: new Date().toISOString(),
mapName: mapName.value, mapName: mapName.value,

View file

@ -113,10 +113,10 @@ function uploadMap(file, callback) {
const [mapData, mapVersion] = await parseLoadedResult(result); const [mapData, mapVersion] = await parseLoadedResult(result);
const isInvalid = !mapData || !isValidVersion(mapVersion) || mapData.length < 26 || !mapData[5]; const isInvalid = !mapData || !isValidVersion(mapVersion) || mapData.length < 26 || !mapData[5];
const isUpdated = compareVersions(mapVersion, version).isEqual; const isUpdated = compareVersions(mapVersion, VERSION).isEqual;
const isAncient = compareVersions(mapVersion, "0.7.0").isOlder; const isAncient = compareVersions(mapVersion, "0.7.0").isOlder;
const isNewer = compareVersions(mapVersion, version).isNewer; const isNewer = compareVersions(mapVersion, VERSION).isNewer;
const isOutdated = compareVersions(mapVersion, version).isOlder; const isOutdated = compareVersions(mapVersion, VERSION).isOlder;
if (isInvalid) return showUploadMessage("invalid", mapData, mapVersion); if (isInvalid) return showUploadMessage("invalid", mapData, mapVersion);
if (isUpdated) return showUploadMessage("updated", mapData, mapVersion); if (isUpdated) return showUploadMessage("updated", mapData, mapVersion);
@ -181,7 +181,7 @@ function showUploadMessage(type, mapData, mapVersion) {
message = `The map version you are trying to load (${mapVersion}) is newer than the current version.<br>Please load the file in the appropriate version`; message = `The map version you are trying to load (${mapVersion}) is newer than the current version.<br>Please load the file in the appropriate version`;
title = "Newer file"; title = "Newer file";
} else if (type === "outdated") { } else if (type === "outdated") {
INFO && console.info(`Loading map. Auto-updating from ${mapVersion} to ${version}`); INFO && console.info(`Loading map. Auto-updating from ${mapVersion} to ${VERSION}`);
parseLoadedData(mapData, mapVersion); parseLoadedData(mapData, mapVersion);
return; return;
} }
@ -707,7 +707,7 @@ async function parseLoadedData(data, mapVersion) {
ERROR && console.error(error); ERROR && console.error(error);
clearMainTip(); clearMainTip();
alertMessage.innerHTML = /* html */ `An error is occured on map loading. Select a different file to load, <br>generate a new random map or cancel the loading.<br>Map version: ${mapVersion}. Generator version: ${version}. alertMessage.innerHTML = /* html */ `An error is occured on map loading. Select a different file to load, <br>generate a new random map or cancel the loading.<br>Map version: ${mapVersion}. Generator version: ${VERSION}.
<p id="errorBox">${parseError(error)}</p>`; <p id="errorBox">${parseError(error)}</p>`;
$("#alert").dialog({ $("#alert").dialog({

View file

@ -41,7 +41,7 @@ function prepareMapData() {
const date = new Date(); const date = new Date();
const dateString = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate(); const dateString = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
const license = "File can be loaded in azgaar.github.io/Fantasy-Map-Generator"; const license = "File can be loaded in azgaar.github.io/Fantasy-Map-Generator";
const params = [version, license, dateString, seed, graphWidth, graphHeight, mapId].join("|"); const params = [VERSION, license, dateString, seed, graphWidth, graphHeight, mapId].join("|");
const settings = [ const settings = [
distanceUnitInput.value, distanceUnitInput.value,
distanceScale, distanceScale,

View file

@ -64,7 +64,7 @@ async function getStylePreset(desiredPreset) {
async function fetchSystemPreset(preset) { async function fetchSystemPreset(preset) {
try { try {
const res = await fetch(`./styles/${preset}.json?v=${version}`); const res = await fetch(`./styles/${preset}.json?v=${VERSION}`);
return await res.json(); return await res.json();
} catch (err) { } catch (err) {
throw new Error("Cannot fetch style preset", preset); throw new Error("Cannot fetch style preset", preset);

View file

@ -159,18 +159,6 @@ window.UISubmap = (function () {
return canvas; return canvas;
} }
// currently unused alternative to PNG version
async function loadPreviewSVG($container, w, h) {
$container.innerHTML = /*html*/ `
<svg id="submapPreviewSVG" viewBox="0 0 ${graphWidth} ${graphHeight}">
<rect width="100%" height="100%" fill="${byId("styleOceanFill").value}" />
<rect fill="url(#oceanic)" width="100%" height="100%" />
<use href="#map"></use>
</svg>
`;
return byId("submapPreviewSVG");
}
// Resample the whole map to different cell resolution or shape // Resample the whole map to different cell resolution or shape
const resampleCurrentMap = debounce(function () { const resampleCurrentMap = debounce(function () {
WARN && console.warn("Resampling current map"); WARN && console.warn("Resampling current map");

View file

@ -1,15 +1,26 @@
"use strict"; "use strict";
/**
// version and caching control * Version Control Guidelines
const version = "1.100.00"; // generator version, update each time * --------------------------
* We use Semantic Versioning: major.minor.patch. Refer to https://semver.org
* Our .map file format is considered the public API.
*
* 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 or features not affecting .map file format
*
* Example: 1.102.0 -> Major version 1, Minor version 102, Patch version 0
*/
const VERSION = "1.100.00";
{ {
document.title += " v" + version; document.title += " v" + VERSION;
const loadingScreenVersion = document.getElementById("versionText"); const loadingScreenVersion = document.getElementById("versionText");
if (loadingScreenVersion) loadingScreenVersion.innerText = `v${version}`; if (loadingScreenVersion) loadingScreenVersion.innerText = `v${VERSION}`;
const storedVersion = localStorage.getItem("version"); const storedVersion = localStorage.getItem("version");
if (compareVersions(storedVersion, version).isOlder) setTimeout(showUpdateWindow, 6000); if (compareVersions(storedVersion, VERSION).isOlder) setTimeout(showUpdateWindow, 6000);
function showUpdateWindow() { function showUpdateWindow() {
const changelog = "https://github.com/Azgaar/Fantasy-Map-Generator/wiki/Changelog"; const changelog = "https://github.com/Azgaar/Fantasy-Map-Generator/wiki/Changelog";
@ -17,7 +28,7 @@ const version = "1.100.00"; // generator version, update each time
const discord = "https://discordapp.com/invite/X7E84HU"; const discord = "https://discordapp.com/invite/X7E84HU";
const patreon = "https://www.patreon.com/azgaar"; const patreon = "https://www.patreon.com/azgaar";
alertMessage.innerHTML = /* html */ `The Fantasy Map Generator is updated up to version <strong>${version}</strong>. This version is compatible with <a href="${changelog}" target="_blank">previous versions</a>, loaded save files will be auto-updated. alertMessage.innerHTML = /* html */ `The Fantasy Map Generator is updated up to version <strong>${VERSION}</strong>. This version is compatible with <a href="${changelog}" target="_blank">previous versions</a>, loaded save files will be auto-updated.
${storedVersion ? "<span>Reload the page to fetch fresh code.</span>" : ""} ${storedVersion ? "<span>Reload the page to fetch fresh code.</span>" : ""}
<ul> <ul>
@ -49,7 +60,7 @@ const version = "1.100.00"; // generator version, update each time
clearCache(); clearCache();
localStorage.clear(); localStorage.clear();
} }
localStorage.setItem("version", version); localStorage.setItem("version", VERSION);
} }
}; };
@ -57,7 +68,7 @@ const version = "1.100.00"; // generator version, update each time
buttons.Reload = () => { buttons.Reload = () => {
clearCache(); clearCache();
localStorage.clear(); localStorage.clear();
localStorage.setItem("version", version); localStorage.setItem("version", VERSION);
location.reload(); location.reload();
}; };
} }