From 503eabd9d4d51b2abce3cbd14eb4690c334a8ece 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 17:16:54 +0300
Subject: [PATCH 1/3] Api-Like map save option (#730)
* Added Save Option for Api-like json export.
Will be updated and set to a scheme
* Save Option for Api-like added
* Moved UI of json export to export dialog.
Moved json export to another file named export-json.js
* Added Seperated json export selections
- all JSON : exports all json data.
- minimal JSON : exports json data without cells data.
- cells JSON : exports json data only with pack.cells data.
* More Stable Cell Export...
---
.gitignore | 4 +-
index.html | 9 +-
modules/export-json.js | 362 +++++++++++++++++++++++++++++++++++++++++
modules/save.js | 2 +
4 files changed, 375 insertions(+), 2 deletions(-)
create mode 100644 modules/export-json.js
diff --git a/.gitignore b/.gitignore
index eb169d8d..8cd42a0d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
.bat
-.vscode
\ No newline at end of file
+.vscode
+.idea
+.idea/Fantasy-Map-Generator.iml
diff --git a/index.html b/index.html
index ebb2b775..871503bf 100644
--- a/index.html
+++ b/index.html
@@ -978,7 +978,7 @@
-
+
|
@@ -3607,6 +3607,12 @@
GeoJSON format is used in GIS tools such as QGIS. Check out wiki-page for guidance.
Generator uses pop-up window to download files. Please ensure your browser does not block popups.
It's also possible to export map to Foundry VTT, see the module.
+ Export To Json
+
+
+
+
+
@@ -4400,6 +4406,7 @@
+
diff --git a/modules/export-json.js b/modules/export-json.js
new file mode 100644
index 00000000..174a303a
--- /dev/null
+++ b/modules/export-json.js
@@ -0,0 +1,362 @@
+
+/**
+ * Downloads created data of getMapDataAPIJson()
+ * Download all data generated
+ *
+ * @see getMapDataAPIJson
+ */
+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() + "All.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);
+}
+
+/**
+ * Downloads created data of getMinimalMapJSONData()
+ * Downloads data without cells
+ *
+ * @see getMinimalMapJSONData
+ */
+function downloadMapDataMinimalAPIJson() {
+ 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 = getMinimalMapJSONData();
+ const blob = new Blob([mapData], {type: "application/json"});
+ const URL = window.URL.createObjectURL(blob);
+ const link = document.createElement("a");
+ link.download = getFileName() + "MinimalDataAPI.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);
+}
+
+
+/**
+ * Downloads created data of getCellJSONData()
+ *
+ * @see getCellJSONData
+ */
+function downloadCellsDataJSON() {
+ 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 = getCellJSONData();
+ const blob = new Blob([mapData], {type: "application/json"});
+ const URL = window.URL.createObjectURL(blob);
+ const link = document.createElement("a");
+ link.download = getFileName() + "CellsData.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);
+}
+
+
+
+
+
+
+
+
+/**
+ * Gets current loaded map data as a JSON string.
+ * The file contains data looks like:
+ * - info
+ * - settings (because population and other things are related to this)
+ * - coords
+ * - notes
+ * - pack
+ *
+ * @returns {string} JSONString of loaded and constructed data object
+ */
+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 CellConverted = {
+ "i" : Array.from(pack.cells.i),
+ "v" : pack.cells.v,
+ "c" : pack.cells.c,
+ "p" : pack.cells.p,
+ "g" : Array.from(pack.cells.g),
+ "h" : Array.from(pack.cells.h),
+ "area" : Array.from(pack.cells.area),
+ "f" : Array.from(pack.cells.f),
+ "t" : Array.from(pack.cells.t),
+ "haven" : Array.from(pack.cells.haven),
+ "harbor" : Array.from(pack.cells.harbor),
+ "fl" : Array.from(pack.cells.fl),
+ "r" : Array.from(pack.cells.r),
+ "conf" : Array.from(pack.cells.conf),
+ "biome" : Array.from(pack.cells.biome),
+ "s" : Array.from(pack.cells.s),
+ "pop" : Array.from(pack.cells.pop),
+ "culture" : Array.from(pack.cells.culture),
+ "burg" : Array.from(pack.cells.burg),
+ "road" : Array.from(pack.cells.road),
+ "crossroad" : Array.from(pack.cells.crossroad),
+ "state" : Array.from(pack.cells.state),
+ "religion" : Array.from(pack.cells.religion),
+ "province" : Array.from(pack.cells.province)
+ };
+ const cellObjArr = [];
+ {
+ CellConverted.i.forEach(value => {
+ const cellobj = {
+ "i" : value,
+ "v" : CellConverted.v[value],
+ "c" : CellConverted.c[value],
+ "p" : CellConverted.p[value],
+ "g" : CellConverted.g[value],
+ "h" : CellConverted.h[value],
+ "area" : CellConverted.area[value],
+ "f" : CellConverted.f[value],
+ "t" : CellConverted.t[value],
+ "haven" : CellConverted.haven[value],
+ "harbor" : CellConverted.harbor[value],
+ "fl" : CellConverted.fl[value],
+ "r" : CellConverted.r[value],
+ "conf" : CellConverted.conf[value],
+ "biome" : CellConverted.biome[value],
+ "s" : CellConverted.s[value],
+ "pop" : CellConverted.pop[value],
+ "culture" : CellConverted.culture[value],
+ "burg" : CellConverted.burg[value],
+ "road" : CellConverted.road[value],
+ "crossroad" : CellConverted.crossroad[value],
+ "state" : CellConverted.state[value],
+ "religion" : CellConverted.religion[value],
+ "province" : CellConverted.province[value]
+ }
+ cellObjArr.push(cellobj)
+ })
+ };
+ const packs = {
+ "cells": cellObjArr,
+ "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);
+}
+
+
+/**
+* For exporting as JSON without pack.cells
+* This can become handy if user don't want a huge data.
+* For assigning data to cells user must download cells data with downloadCellsData().
+*
+* @returns {string} JSONString data of the created object
+*/
+function getMinimalMapJSONData(){
+
+ TIME && console.time("createMapDataMinimalJson");
+
+ 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 = {
+ "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("createMapDataMinimalJson");
+ return JSON.stringify(ExportData);
+}
+/**
+ * Gets data that created with info and pack.cell
+ * This function is created for primarly pack.cell data is too big.
+ * for speeding up the proccess the main data and cell data is seperated as two files.
+ *
+ * exported data look like:
+ * - info
+ * - cells
+ *
+ * @see pack
+ * @see getMinimalMapJSONData
+ * @returns {string} The JSONString of pack.cell
+ */
+function getCellJSONData() {
+ TIME && console.time("createMapDataMinimalJson");
+
+ 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 CellConverted = {
+ "i" : Array.from(pack.cells.i),
+ "v" : pack.cells.v,
+ "c" : pack.cells.c,
+ "p" : pack.cells.p,
+ "g" : Array.from(pack.cells.g),
+ "h" : Array.from(pack.cells.h),
+ "area" : Array.from(pack.cells.area),
+ "f" : Array.from(pack.cells.f),
+ "t" : Array.from(pack.cells.t),
+ "haven" : Array.from(pack.cells.haven),
+ "harbor" : Array.from(pack.cells.harbor),
+ "fl" : Array.from(pack.cells.fl),
+ "r" : Array.from(pack.cells.r),
+ "conf" : Array.from(pack.cells.conf),
+ "biome" : Array.from(pack.cells.biome),
+ "s" : Array.from(pack.cells.s),
+ "pop" : Array.from(pack.cells.pop),
+ "culture" : Array.from(pack.cells.culture),
+ "burg" : Array.from(pack.cells.burg),
+ "road" : Array.from(pack.cells.road),
+ "crossroad" : Array.from(pack.cells.crossroad),
+ "state" : Array.from(pack.cells.state),
+ "religion" : Array.from(pack.cells.religion),
+ "province" : Array.from(pack.cells.province)
+ };
+ const cellObjArr = [];
+ {
+ CellConverted.i.forEach(value => {
+ const cellobj = {
+ "i" : value,
+ "v" : CellConverted.v[value],
+ "c" : CellConverted.c[value],
+ "p" : CellConverted.p[value],
+ "g" : CellConverted.g[value],
+ "h" : CellConverted.h[value],
+ "area" : CellConverted.area[value],
+ "f" : CellConverted.f[value],
+ "t" : CellConverted.t[value],
+ "haven" : CellConverted.haven[value],
+ "harbor" : CellConverted.harbor[value],
+ "fl" : CellConverted.fl[value],
+ "r" : CellConverted.r[value],
+ "conf" : CellConverted.conf[value],
+ "biome" : CellConverted.biome[value],
+ "s" : CellConverted.s[value],
+ "pop" : CellConverted.pop[value],
+ "culture" : CellConverted.culture[value],
+ "burg" : CellConverted.burg[value],
+ "road" : CellConverted.road[value],
+ "crossroad" : CellConverted.crossroad[value],
+ "state" : CellConverted.state[value],
+ "religion" : CellConverted.religion[value],
+ "province" : CellConverted.province[value]
+ }
+ cellObjArr.push(cellobj)
+ })
+ };
+ const cells = cellObjArr;
+
+ const ExportData = {info, cells}
+
+ TIME && console.timeEnd("createMapDataMinimalJson");
+ return JSON.stringify(ExportData);
+}
+
+
diff --git a/modules/save.js b/modules/save.js
index 04f3e665..52e1d30e 100644
--- a/modules/save.js
+++ b/modules/save.js
@@ -120,6 +120,7 @@ function getMapData() {
return mapData;
}
+
// 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");
@@ -136,6 +137,7 @@ function dowloadMap() {
window.URL.revokeObjectURL(URL);
}
+
async function saveToDropbox() {
if (customization) return tip("Map cannot be saved when edit mode is active, please exit the mode and retry", false, "error");
closeDialogs("#alert");
From 3fe225e293627bddc99945d1ce9e31cbf6c4fada Mon Sep 17 00:00:00 2001
From: Azgaar
Date: Wed, 26 Jan 2022 18:13:32 +0300
Subject: [PATCH 2/3] export json cleanup
---
index.html | 12 +-
modules/export-json.js | 508 ++++++++++++++---------------------------
2 files changed, 173 insertions(+), 347 deletions(-)
diff --git a/index.html b/index.html
index 871503bf..c07a88e3 100644
--- a/index.html
+++ b/index.html
@@ -978,7 +978,7 @@
-
+
|
@@ -3607,12 +3607,14 @@
GeoJSON format is used in GIS tools such as QGIS. Check out wiki-page for guidance.
Generator uses pop-up window to download files. Please ensure your browser does not block popups.
It's also possible to export map to Foundry VTT, see the module.
- Export To Json
+
+ Export To JSON
-
-
-
+
+
+
+ Export in JSON format can be used as an API replacement.
diff --git a/modules/export-json.js b/modules/export-json.js
index 174a303a..b4c62916 100644
--- a/modules/export-json.js
+++ b/modules/export-json.js
@@ -1,362 +1,186 @@
+function exportToJson(type) {
+ if (customization) return tip("Map cannot be saved when edit mode is active, please exit the mode and retry", false, "error");
+ closeDialogs("#alert");
-/**
- * Downloads created data of getMapDataAPIJson()
- * Download all data generated
- *
- * @see getMapDataAPIJson
- */
-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 typeMap = {
+ Full: getFullDataJson,
+ Minimal: getMinimalDataJson,
+ Cells: getCellsDataJson
+ };
- 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() + "All.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);
+ const mapData = typeMap[type]();
+ const blob = new Blob([mapData], {type: "application/json"});
+ const URL = window.URL.createObjectURL(blob);
+ const link = document.createElement("a");
+ link.download = getFileName(type) + ".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);
}
-/**
- * Downloads created data of getMinimalMapJSONData()
- * Downloads data without cells
- *
- * @see getMinimalMapJSONData
- */
-function downloadMapDataMinimalAPIJson() {
- if (customization) return tip("Map cannot be saved when edit mode is active, please exit the mode and retry", false, "error");
- closeDialogs("#alert");
+function getMapInfo() {
+ const info = {
+ version,
+ description: "Azgaar's Fantasy Map Generator output: azgaar.github.io/Fantasy-map-generator",
+ exportedAt: new Date().toISOString(),
+ mapName: mapName.value,
+ seed,
+ mapId
+ };
- const mapData = getMinimalMapJSONData();
- const blob = new Blob([mapData], {type: "application/json"});
- const URL = window.URL.createObjectURL(blob);
- const link = document.createElement("a");
- link.download = getFileName() + "MinimalDataAPI.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);
+ return info;
}
+function getSettings() {
+ 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
+ };
-/**
- * Downloads created data of getCellJSONData()
- *
- * @see getCellJSONData
- */
-function downloadCellsDataJSON() {
- 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 = getCellJSONData();
- const blob = new Blob([mapData], {type: "application/json"});
- const URL = window.URL.createObjectURL(blob);
- const link = document.createElement("a");
- link.download = getFileName() + "CellsData.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);
+ return settings;
}
+function getCellsData() {
+ const cellConverted = {
+ i: Array.from(pack.cells.i),
+ v: pack.cells.v,
+ c: pack.cells.c,
+ p: pack.cells.p,
+ g: Array.from(pack.cells.g),
+ h: Array.from(pack.cells.h),
+ area: Array.from(pack.cells.area),
+ f: Array.from(pack.cells.f),
+ t: Array.from(pack.cells.t),
+ haven: Array.from(pack.cells.haven),
+ harbor: Array.from(pack.cells.harbor),
+ fl: Array.from(pack.cells.fl),
+ r: Array.from(pack.cells.r),
+ conf: Array.from(pack.cells.conf),
+ biome: Array.from(pack.cells.biome),
+ s: Array.from(pack.cells.s),
+ pop: Array.from(pack.cells.pop),
+ culture: Array.from(pack.cells.culture),
+ burg: Array.from(pack.cells.burg),
+ road: Array.from(pack.cells.road),
+ crossroad: Array.from(pack.cells.crossroad),
+ state: Array.from(pack.cells.state),
+ religion: Array.from(pack.cells.religion),
+ province: Array.from(pack.cells.province)
+ };
+ const cellObjArr = [];
+ {
+ cellConverted.i.forEach(value => {
+ const cellobj = {
+ i: value,
+ v: cellConverted.v[value],
+ c: cellConverted.c[value],
+ p: cellConverted.p[value],
+ g: cellConverted.g[value],
+ h: cellConverted.h[value],
+ area: cellConverted.area[value],
+ f: cellConverted.f[value],
+ t: cellConverted.t[value],
+ haven: cellConverted.haven[value],
+ harbor: cellConverted.harbor[value],
+ fl: cellConverted.fl[value],
+ r: cellConverted.r[value],
+ conf: cellConverted.conf[value],
+ biome: cellConverted.biome[value],
+ s: cellConverted.s[value],
+ pop: cellConverted.pop[value],
+ culture: cellConverted.culture[value],
+ burg: cellConverted.burg[value],
+ road: cellConverted.road[value],
+ crossroad: cellConverted.crossroad[value],
+ state: cellConverted.state[value],
+ religion: cellConverted.religion[value],
+ province: cellConverted.province[value]
+ };
+ cellObjArr.push(cellobj);
+ });
+ }
+ const cellsData = {
+ cells: cellObjArr,
+ features: pack.features,
+ cultures: pack.cultures,
+ burgs: pack.burgs,
+ states: pack.states,
+ provinces: pack.provinces,
+ religions: pack.religions,
+ rivers: pack.rivers,
+ markers: pack.markers
+ };
-
-
-
-
-/**
- * Gets current loaded map data as a JSON string.
- * The file contains data looks like:
- * - info
- * - settings (because population and other things are related to this)
- * - coords
- * - notes
- * - pack
- *
- * @returns {string} JSONString of loaded and constructed data object
- */
-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 CellConverted = {
- "i" : Array.from(pack.cells.i),
- "v" : pack.cells.v,
- "c" : pack.cells.c,
- "p" : pack.cells.p,
- "g" : Array.from(pack.cells.g),
- "h" : Array.from(pack.cells.h),
- "area" : Array.from(pack.cells.area),
- "f" : Array.from(pack.cells.f),
- "t" : Array.from(pack.cells.t),
- "haven" : Array.from(pack.cells.haven),
- "harbor" : Array.from(pack.cells.harbor),
- "fl" : Array.from(pack.cells.fl),
- "r" : Array.from(pack.cells.r),
- "conf" : Array.from(pack.cells.conf),
- "biome" : Array.from(pack.cells.biome),
- "s" : Array.from(pack.cells.s),
- "pop" : Array.from(pack.cells.pop),
- "culture" : Array.from(pack.cells.culture),
- "burg" : Array.from(pack.cells.burg),
- "road" : Array.from(pack.cells.road),
- "crossroad" : Array.from(pack.cells.crossroad),
- "state" : Array.from(pack.cells.state),
- "religion" : Array.from(pack.cells.religion),
- "province" : Array.from(pack.cells.province)
- };
- const cellObjArr = [];
- {
- CellConverted.i.forEach(value => {
- const cellobj = {
- "i" : value,
- "v" : CellConverted.v[value],
- "c" : CellConverted.c[value],
- "p" : CellConverted.p[value],
- "g" : CellConverted.g[value],
- "h" : CellConverted.h[value],
- "area" : CellConverted.area[value],
- "f" : CellConverted.f[value],
- "t" : CellConverted.t[value],
- "haven" : CellConverted.haven[value],
- "harbor" : CellConverted.harbor[value],
- "fl" : CellConverted.fl[value],
- "r" : CellConverted.r[value],
- "conf" : CellConverted.conf[value],
- "biome" : CellConverted.biome[value],
- "s" : CellConverted.s[value],
- "pop" : CellConverted.pop[value],
- "culture" : CellConverted.culture[value],
- "burg" : CellConverted.burg[value],
- "road" : CellConverted.road[value],
- "crossroad" : CellConverted.crossroad[value],
- "state" : CellConverted.state[value],
- "religion" : CellConverted.religion[value],
- "province" : CellConverted.province[value]
- }
- cellObjArr.push(cellobj)
- })
- };
- const packs = {
- "cells": cellObjArr,
- "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);
+ return cellsData;
}
+function getFullDataJson() {
+ TIME && console.time("getFullDataJson");
-/**
-* For exporting as JSON without pack.cells
-* This can become handy if user don't want a huge data.
-* For assigning data to cells user must download cells data with downloadCellsData().
-*
-* @returns {string} JSONString data of the created object
-*/
-function getMinimalMapJSONData(){
+ const info = getMapInfo();
+ const settings = getSettings();
+ const cells = getCellsData();
+ const exportData = {info, settings, coords: mapCoordinates, cells, biomes: biomesData, notes, nameBases};
- TIME && console.time("createMapDataMinimalJson");
-
- 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 = {
- "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("createMapDataMinimalJson");
- return JSON.stringify(ExportData);
-}
-/**
- * Gets data that created with info and pack.cell
- * This function is created for primarly pack.cell data is too big.
- * for speeding up the proccess the main data and cell data is seperated as two files.
- *
- * exported data look like:
- * - info
- * - cells
- *
- * @see pack
- * @see getMinimalMapJSONData
- * @returns {string} The JSONString of pack.cell
- */
-function getCellJSONData() {
- TIME && console.time("createMapDataMinimalJson");
-
- 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 CellConverted = {
- "i" : Array.from(pack.cells.i),
- "v" : pack.cells.v,
- "c" : pack.cells.c,
- "p" : pack.cells.p,
- "g" : Array.from(pack.cells.g),
- "h" : Array.from(pack.cells.h),
- "area" : Array.from(pack.cells.area),
- "f" : Array.from(pack.cells.f),
- "t" : Array.from(pack.cells.t),
- "haven" : Array.from(pack.cells.haven),
- "harbor" : Array.from(pack.cells.harbor),
- "fl" : Array.from(pack.cells.fl),
- "r" : Array.from(pack.cells.r),
- "conf" : Array.from(pack.cells.conf),
- "biome" : Array.from(pack.cells.biome),
- "s" : Array.from(pack.cells.s),
- "pop" : Array.from(pack.cells.pop),
- "culture" : Array.from(pack.cells.culture),
- "burg" : Array.from(pack.cells.burg),
- "road" : Array.from(pack.cells.road),
- "crossroad" : Array.from(pack.cells.crossroad),
- "state" : Array.from(pack.cells.state),
- "religion" : Array.from(pack.cells.religion),
- "province" : Array.from(pack.cells.province)
- };
- const cellObjArr = [];
- {
- CellConverted.i.forEach(value => {
- const cellobj = {
- "i" : value,
- "v" : CellConverted.v[value],
- "c" : CellConverted.c[value],
- "p" : CellConverted.p[value],
- "g" : CellConverted.g[value],
- "h" : CellConverted.h[value],
- "area" : CellConverted.area[value],
- "f" : CellConverted.f[value],
- "t" : CellConverted.t[value],
- "haven" : CellConverted.haven[value],
- "harbor" : CellConverted.harbor[value],
- "fl" : CellConverted.fl[value],
- "r" : CellConverted.r[value],
- "conf" : CellConverted.conf[value],
- "biome" : CellConverted.biome[value],
- "s" : CellConverted.s[value],
- "pop" : CellConverted.pop[value],
- "culture" : CellConverted.culture[value],
- "burg" : CellConverted.burg[value],
- "road" : CellConverted.road[value],
- "crossroad" : CellConverted.crossroad[value],
- "state" : CellConverted.state[value],
- "religion" : CellConverted.religion[value],
- "province" : CellConverted.province[value]
- }
- cellObjArr.push(cellobj)
- })
- };
- const cells = cellObjArr;
-
- const ExportData = {info, cells}
-
- TIME && console.timeEnd("createMapDataMinimalJson");
- return JSON.stringify(ExportData);
+ TIME && console.timeEnd("getFullDataJson");
+ return JSON.stringify(exportData);
}
+// data excluding cells
+function getMinimalDataJson() {
+ TIME && console.time("getMinimalDataJson");
+ const info = getMapInfo();
+ const settings = getSettings();
+ const packData = {
+ 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 exportData = {info, settings, coords: mapCoordinates, pack: packData, biomes: biomesData, notes, nameBases};
+
+ TIME && console.timeEnd("getMinimalDataJson");
+ return JSON.stringify(exportData);
+}
+
+function getCellsDataJson() {
+ TIME && console.time("getCellsDataJson");
+
+ const info = getMapInfo();
+ const cells = getCellsData();
+ const exportData = {info, cells};
+
+ TIME && console.timeEnd("getCellsDataJson");
+ return JSON.stringify(exportData);
+}
From 2608a27a34f38d482494c35345b2d53f195c1234 Mon Sep 17 00:00:00 2001
From: Azgaar
Date: Wed, 26 Jan 2022 18:17:07 +0300
Subject: [PATCH 3/3] export json - Foundry should go below
---
index.html | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/index.html b/index.html
index c07a88e3..b8bcb074 100644
--- a/index.html
+++ b/index.html
@@ -3606,15 +3606,18 @@
GeoJSON format is used in GIS tools such as QGIS. Check out wiki-page for guidance.
Generator uses pop-up window to download files. Please ensure your browser does not block popups.
- It's also possible to export map to Foundry VTT, see the module.
Export To JSON
-
+
Export in JSON format can be used as an API replacement.
+
+
+
It's also possible to export map to Foundry VTT, see the module.
+