"use strict";
// functions to save the project to a file
async function saveMap(method) {
if (customization) return tip("Map cannot be saved in EDIT mode, please complete the edit and retry", false, "error");
closeDialogs("#alert");
try {
const mapData = prepareMapData();
const filename = getFileName() + ".map";
saveToStorage(mapData, method === "storage"); // any method saves to indexedDB
if (method === "machine") saveToMachine(mapData, filename);
if (method === "dropbox") saveToDropbox(mapData, filename);
} catch (error) {
ERROR && console.error(error);
alertMessage.innerHTML = /* html */ `An error is occured on map saving. If the issue persists, please copy the message below and report it on ${link(
"https://github.com/Azgaar/Fantasy-Map-Generator/issues",
"GitHub"
)}.
${parseError(error)}
`;
$("#alert").dialog({
resizable: false,
title: "Saving error",
width: "28em",
buttons: {
Retry: function () {
$(this).dialog("close");
saveMap(method);
},
Close: function () {
$(this).dialog("close");
}
},
position: {my: "center", at: "center", of: "svg"}
});
}
}
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 settings = [
distanceUnitInput.value,
distanceScale,
areaUnit.value,
heightUnit.value,
heightExponentInput.value,
temperatureScale.value,
"", // previously used for barSize.value
"", // previously used for barLabel.value
"", // previously used for barBackColor.value
"", // previously used for barBackColor.value
"", // previously used for barPosX.value
"", // previously used for barPosY.value
populationRate,
urbanization,
mapSizeOutput.value,
latitudeOutput.value,
"", // previously used for temperatureEquatorOutput.value
"", // previously used for tempNorthOutput.value
precOutput.value,
JSON.stringify(options),
mapName.value,
+hideLabels.checked,
stylePreset.value,
+rescaleLabels.checked,
urbanDensity,
longitudeOutput.value,
growthRate.value
].join("|");
const coords = JSON.stringify(mapCoordinates);
const biomes = [biomesData.color, biomesData.habitability, biomesData.name].join("|");
const notesData = JSON.stringify(notes);
const rulersString = rulers.toString();
const fonts = JSON.stringify(getUsedFonts(svg.node()));
// save svg
// Temporarily inject