Zones generator update (#1113)

* feat: style - store emblem size mod in style (v1.99.10)

* fix the isOutdated function for versions past 1.99

* fix: showUploadMessage function not called correctly for isUpdated case

* feat: load - improve version detection

* feat: improve version detection and update process

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

* Update versioning.js to fix incorrect message display for stored version

* feat: zones editor - update to work with pack data

* feat: zones editor - update editor

* feat: zones editor - update editor

* chore: update version

* feat: zones - regenerate

* feat: zones - render zones as continuius line

* feat: zones - editot changes

* feat: zones - auto-update

* feat: zones - generation fixes

* feat: zones - generation fixes

* feat: zones - restore layer

* feat: zones - proselytism - check population

---------

Co-authored-by: Azgaar <azgaar.fmg@yandex.com>
This commit is contained in:
Azgaar 2024-09-01 12:48:39 +02:00 committed by GitHub
parent e77202a08a
commit eb29c5ec5d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 1057 additions and 885 deletions

View file

@ -104,8 +104,6 @@ function showUploadErrorMessage(error, URL, random) {
function uploadMap(file, callback) {
uploadMap.timeStart = performance.now();
const OLDEST_SUPPORTED_VERSION = 0.7;
const currentVersion = parseFloat(version);
const fileReader = new FileReader();
fileReader.onloadend = async function (fileLoadedEvent) {
@ -114,14 +112,14 @@ function uploadMap(file, callback) {
const result = fileLoadedEvent.target.result;
const [mapData, mapVersion] = await parseLoadedResult(result);
const isInvalid = !mapData || isNaN(mapVersion) || mapData.length < 26 || !mapData[5];
const isUpdated = mapVersion === currentVersion;
const isAncient = mapVersion < OLDEST_SUPPORTED_VERSION;
const isNewer = mapVersion > currentVersion;
const isOutdated = mapVersion < currentVersion;
const isInvalid = !mapData || !isValidVersion(mapVersion) || mapData.length < 26 || !mapData[5];
const isUpdated = compareVersions(mapVersion, VERSION).isEqual;
const isAncient = compareVersions(mapVersion, "0.7.0").isOlder;
const isNewer = compareVersions(mapVersion, VERSION).isNewer;
const isOutdated = compareVersions(mapVersion, VERSION).isOlder;
if (isInvalid) return showUploadMessage("invalid", mapData, mapVersion);
if (isUpdated) return parseLoadedData(mapData);
if (isUpdated) return showUploadMessage("updated", mapData, mapVersion);
if (isAncient) return showUploadMessage("ancient", mapData, mapVersion);
if (isNewer) return showUploadMessage("newer", mapData, mapVersion);
if (isOutdated) return showUploadMessage("outdated", mapData, mapVersion);
@ -154,8 +152,8 @@ async function parseLoadedResult(result) {
const decoded = isDelimited ? resultAsString : decodeURIComponent(atob(resultAsString));
const mapData = decoded.split("\r\n");
const mapVersion = parseFloat(mapData[0].split("|")[0] || mapData[0]);
return [mapData, mapVersion];
const mapVersionString = mapData[0].split("|")[0] || mapData[0] || "";
return [mapData, mapVersionString];
} catch (error) {
// map file can be compressed with gzip
const uncompressedData = await uncompress(result);
@ -167,35 +165,36 @@ async function parseLoadedResult(result) {
}
function showUploadMessage(type, mapData, mapVersion) {
const archive = link("https://github.com/Azgaar/Fantasy-Map-Generator/wiki/Changelog", "archived version");
let message, title, canBeLoaded;
let message, title;
if (type === "invalid") {
message = `The file does not look like a valid save file.<br>Please check the data format`;
message = "The file does not look like a valid save file.<br>Please check the data format";
title = "Invalid file";
canBeLoaded = false;
} else if (type === "updated") {
parseLoadedData(mapData, mapVersion);
return;
} else if (type === "ancient") {
const archive = link("https://github.com/Azgaar/Fantasy-Map-Generator/wiki/Changelog", "archived version");
message = `The map version you are trying to load (${mapVersion}) is too old and cannot be updated to the current version.<br>Please keep using an ${archive}`;
title = "Ancient file";
canBeLoaded = false;
} else if (type === "newer") {
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";
canBeLoaded = false;
} else if (type === "outdated") {
INFO && console.info(`Loading map. Auto-update from ${mapVersion} to ${version}`);
INFO && console.info(`Loading map. Auto-updating from ${mapVersion} to ${VERSION}`);
parseLoadedData(mapData, mapVersion);
return;
}
alertMessage.innerHTML = message;
const buttons = {
OK: function () {
$(this).dialog("close");
if (canBeLoaded) parseLoadedData(mapData, mapVersion);
$("#alert").dialog({
title,
buttons: {
OK: function () {
$(this).dialog("close");
}
}
};
$("#alert").dialog({title, buttons});
});
}
async function parseLoadedData(data, mapVersion) {
@ -380,6 +379,7 @@ async function parseLoadedData(data, mapVersion) {
pack.rivers = data[32] ? JSON.parse(data[32]) : [];
pack.markers = data[35] ? JSON.parse(data[35]) : [];
pack.routes = data[37] ? JSON.parse(data[37]) : [];
pack.zones = data[38] ? JSON.parse(data[38]) : [];
const cells = pack.cells;
cells.biome = Uint8Array.from(data[16].split(","));
@ -462,9 +462,8 @@ async function parseLoadedData(data, mapVersion) {
{
// dynamically import and run auto-update script
const versionNumber = parseFloat(params[0]);
const {resolveVersionConflicts} = await import("../dynamic/auto-update.js?v=1.99.01");
resolveVersionConflicts(versionNumber);
const {resolveVersionConflicts} = await import("../dynamic/auto-update.js?v=1.100.00");
resolveVersionConflicts(mapVersion);
}
// add custom heightmap color scheme if any
@ -709,7 +708,7 @@ async function parseLoadedData(data, mapVersion) {
ERROR && console.error(error);
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>`;
$("#alert").dialog({

View file

@ -41,7 +41,7 @@ function prepareMapData() {
const date = new Date();
const dateString = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
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 = [
distanceUnitInput.value,
distanceScale,
@ -100,6 +100,7 @@ function prepareMapData() {
const markers = JSON.stringify(pack.markers);
const cellRoutes = JSON.stringify(pack.cells.routes);
const routes = JSON.stringify(pack.routes);
const zones = JSON.stringify(pack.zones);
// store name array only if not the same as default
const defaultNB = Names.getNameBases();
@ -152,7 +153,8 @@ function prepareMapData() {
fonts,
markers,
cellRoutes,
routes
routes,
zones
].join("\r\n");
return mapData;
}