From 7b475ee0bd7cf30ced8ac5da3f30495ddb7bab55 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: Wed, 26 Jan 2022 00:22:43 +0300
Subject: [PATCH] Moved UI of json export to export dialog. Moved json export
to another file named export-json.js
---
index.html | 6 ++-
modules/export-json.js | 99 ++++++++++++++++++++++++++++++++++++
modules/save.js | 111 -----------------------------------------
3 files changed, 104 insertions(+), 112 deletions(-)
create mode 100644 modules/export-json.js
diff --git a/index.html b/index.html
index dd03ab7c..3e76fadd 100644
--- a/index.html
+++ b/index.html
@@ -3607,13 +3607,16 @@
Generator uses pop-up window to download files. Please ensure your browser does not block popups.
Save map to
-
@@ -4401,6 +4404,7 @@
+
diff --git a/modules/export-json.js b/modules/export-json.js
new file mode 100644
index 00000000..4822defe
--- /dev/null
+++ b/modules/export-json.js
@@ -0,0 +1,99 @@
+function downloadMapDataAPIJson() {
+ if (customization) return tip("Map cannot be saved when edit mode is active, please exit the mode and retry", false, "error");
+ closeDialogs("#alert");
+
+ const mapData = getMapDataAPIJson();
+ const blob = new Blob([mapData], {type: "application/json"});
+ const URL = window.URL.createObjectURL(blob);
+ const link = document.createElement("a");
+ link.download = getFileName() + ".json";
+ link.href = URL;
+ link.click();
+ tip(`${link.download} is saved. Open "Downloads" screen (CTRL + J) to check`, true, "success", 7000);
+ window.URL.revokeObjectURL(URL);
+}
+
+
+//Prepare data for API-JSON
+function getMapDataAPIJson() {
+
+ TIME && console.time("createMapDataJson");
+
+ const date = new Date();
+ const dateString = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
+ const info = {
+ "version": version,
+ "description": "Api-Like Output File Gathered From: azgaar.github.io/Fantasy-map-generator",
+ "creation-date":dateString,
+ "seed" : seed,
+ "mapId":mapId,
+ "mapName" : mapName.value
+ }
+
+ const settings = {
+ "distanceUnit" : distanceUnitInput.value,
+ "distanceScale": distanceScaleInput.value,
+ "areaUnit" : areaUnit.value,
+ "heightUnit" : heightUnit.value,
+ "heightExponent" : heightExponentInput.value,
+ "temperatureScale" : temperatureScale.value,
+ "barSize" : barSizeInput.value,
+ "barLabel" : barLabel.value,
+ "barBackOpacity" : barBackOpacity.value,
+ "barBackColor" : barBackColor.value,
+ "barPosX" : barPosX.value,
+ "barPosY" : barPosY.value,
+ "populationRate" : populationRate,
+ "urbanization" : urbanization,
+ "mapSize" : mapSizeOutput.value,
+ "latitudeO" : latitudeOutput.value,
+ "temperatureEquator" : temperatureEquatorOutput.value,
+ "temperaturePole" : temperaturePoleOutput.value,
+ "prec" : precOutput.value,
+ "options" : options,
+ "mapName" : mapName.value,
+ "hideLabels" : hideLabels.checked,
+ "stylePreset" : stylePreset.value,
+ "rescaleLabels" : rescaleLabels.checked,
+ "urbanDensity" : urbanDensity
+ };
+ const coords = mapCoordinates;
+ const packs = {
+ "cells":{
+ "h": pack.cells.h,
+ "f": pack.cells.f,
+ "t": pack.cells.t,
+ "s": pack.cells.s,
+ "biome": pack.cells.biome,
+ "burg": pack.cells.burg,
+ "culture": pack.cells.culture,
+ "state": pack.cells.state,
+ "province" : pack.cells.province,
+ "religion" : pack.cells.religion,
+ "area": pack.cells.area,
+ "pop" : pack.cells.pop,
+ "r" : pack.cells.r,
+ "fl" : pack.cells.fl,
+ "conf" : pack.cells.conf,
+ "harbor":pack.cells.harbor,
+ "haven" : pack.cells.haven,
+ "road":pack.cells.road,
+ "crossroad":pack.cells.crossroad
+ },
+ "features":pack.features,
+ "cultures":pack.cultures,
+ "burgs":pack.burgs,
+ "states":pack.states,
+ "provinces":pack.provinces,
+ "religions":pack.religions,
+ "rivers":pack.rivers,
+ "markers":pack.markers,
+ }
+ const biomes = biomesData;
+
+ const ExportData = {info,settings,coords,packs,biomes,notes,nameBases}
+
+ TIME && console.timeEnd("createMapDataJson");
+ return JSON.stringify(ExportData);
+}
+
diff --git a/modules/save.js b/modules/save.js
index 7abf7829..52e1d30e 100644
--- a/modules/save.js
+++ b/modules/save.js
@@ -120,88 +120,7 @@ function getMapData() {
return mapData;
}
-//Prepare data for API-JSON
-function getMapDataAPIJson() {
- TIME && console.time("createMapDataJson");
-
- const date = new Date();
- const dateString = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
- const info = {
- "version": version,
- "description": "Api-Like Output File Gathered From: azgaar.github.io/Fantasy-map-generator",
- "creation-date":dateString,
- "seed" : seed,
- "mapId":mapId,
- "mapName" : mapName.value
- }
-
- const settings = {
- "distanceUnit" : distanceUnitInput.value,
- "distanceScale": distanceScaleInput.value,
- "areaUnit" : areaUnit.value,
- "heightUnit" : heightUnit.value,
- "heightExponent" : heightExponentInput.value,
- "temperatureScale" : temperatureScale.value,
- "barSize" : barSizeInput.value,
- "barLabel" : barLabel.value,
- "barBackOpacity" : barBackOpacity.value,
- "barBackColor" : barBackColor.value,
- "barPosX" : barPosX.value,
- "barPosY" : barPosY.value,
- "populationRate" : populationRate,
- "urbanization" : urbanization,
- "mapSize" : mapSizeOutput.value,
- "latitudeO" : latitudeOutput.value,
- "temperatureEquator" : temperatureEquatorOutput.value,
- "temperaturePole" : temperaturePoleOutput.value,
- "prec" : precOutput.value,
- "options" : options,
- "mapName" : mapName.value,
- "hideLabels" : hideLabels.checked,
- "stylePreset" : stylePreset.value,
- "rescaleLabels" : rescaleLabels.checked,
- "urbanDensity" : urbanDensity
- };
- const coords = mapCoordinates;
- const packs = {
- "cells":{
- "h": pack.cells.h,
- "f": pack.cells.f,
- "t": pack.cells.t,
- "s": pack.cells.s,
- "biome": pack.cells.biome,
- "burg": pack.cells.burg,
- "culture": pack.cells.culture,
- "state": pack.cells.state,
- "province" : pack.cells.province,
- "religion" : pack.cells.religion,
- "area": pack.cells.area,
- "pop" : pack.cells.pop,
- "r" : pack.cells.r,
- "fl" : pack.cells.fl,
- "conf" : pack.cells.conf,
- "harbor":pack.cells.harbor,
- "haven" : pack.cells.haven,
- "road":pack.cells.road,
- "crossroad":pack.cells.crossroad
- },
- "features":pack.features,
- "cultures":pack.cultures,
- "burgs":pack.burgs,
- "states":pack.states,
- "provinces":pack.provinces,
- "religions":pack.religions,
- "rivers":pack.rivers,
- "markers":pack.markers,
- }
- const biomes = biomesData;
-
- const ExportData = {info,settings,coords,packs,biomes,notes,nameBases}
-
- TIME && console.timeEnd("createMapDataJson");
- return JSON.stringify(ExportData);
-}
// Download .map file
function dowloadMap() {
if (customization) return tip("Map cannot be saved when edit mode is active, please exit the mode and retry", false, "error");
@@ -218,36 +137,6 @@ function dowloadMap() {
window.URL.revokeObjectURL(URL);
}
-function downloadMapDataAPIJson() {
- if (customization) return tip("Map cannot be saved when edit mode is active, please exit the mode and retry", false, "error");
- closeDialogs("#alert");
-
- const mapData = getMapDataAPIJson();
- const blob = new Blob([mapData], {type: "application/json"});
- const URL = window.URL.createObjectURL(blob);
- const link = document.createElement("a");
- link.download = getFileName() + ".json";
- link.href = URL;
- link.click();
- tip(`${link.download} is saved. Open "Downloads" screen (CTRL + J) to check`, true, "success", 7000);
- window.URL.revokeObjectURL(URL);
-}
-
-function exportGridCellsData(exportName){
- if(customization) return tip("Map cannot be saved when edit mode is active, please exit and retry",false,"error");
- closeDialogs("#alert");
-
- const toWrite = JSON.stringify(grid.cells);
- const blob = new Blob([toWrite],{type: "application/json"});
- const URL = window.URL.createObjectURL(blob);
- const link = document.createElement("a");
- link.download = exportName + ".json";
- link.href = URL;
- link.click();
- window.URL.revokeObjectURL(URL);
- return "Item Must Be Downloading"
-}
-
async function saveToDropbox() {
if (customization) return tip("Map cannot be saved when edit mode is active, please exit the mode and retry", false, "error");