diff --git a/index.html b/index.html index 6ce84cb4..b073ac30 100644 --- a/index.html +++ b/index.html @@ -5825,18 +5825,12 @@
Export To JSON
- - - + + -
@@ -7929,7 +7923,7 @@ - + @@ -7977,7 +7971,6 @@ - diff --git a/modules/io/export-json.js b/modules/dynamic/export-json.js similarity index 87% rename from modules/io/export-json.js rename to modules/dynamic/export-json.js index 28d87a09..d9e6d42e 100644 --- a/modules/io/export-json.js +++ b/modules/dynamic/export-json.js @@ -1,12 +1,13 @@ -function exportToJson(type) { - if (customization) return tip("Map cannot be saved when edit mode is active, please exit the mode and retry", false, "error"); +export function exportToJson(type) { + if (customization) + return tip("Data cannot be exported when edit mode is active, please exit the mode and retry", false, "error"); closeDialogs("#alert"); const typeMap = { Full: getFullDataJson, Minimal: getMinimalDataJson, PackCells: getPackCellsDataJson, - GridCells: getGridCellsDataJson, + GridCells: getGridCellsDataJson }; const mapData = typeMap[type](); @@ -20,6 +21,62 @@ function exportToJson(type) { window.URL.revokeObjectURL(URL); } +function getFullDataJson() { + TIME && console.time("getFullDataJson"); + + const info = getMapInfo(); + const settings = getSettings(); + const cells = getPackCellsData(); + const vertices = getPackVerticesData(); + const exportData = {info, settings, coords: mapCoordinates, cells, vertices, biomes: biomesData, notes, nameBases}; + + TIME && console.timeEnd("getFullDataJson"); + return JSON.stringify(exportData); +} + +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 getPackCellsDataJson() { + TIME && console.time("getCellsDataJson"); + + const info = getMapInfo(); + const cells = getPackCellsData(); + const exportData = {info, cells}; + + TIME && console.timeEnd("getCellsDataJson"); + return JSON.stringify(exportData); +} + +function getGridCellsDataJson() { + TIME && console.time("getGridCellsDataJson"); + + const info = getMapInfo(); + const gridCells = getGridCellsData(); + const exportData = {info, gridCells}; + + TIME && console.log("getGridCellsDataJson"); + return JSON.stringify(exportData); +} + function getMapInfo() { const info = { version, @@ -92,6 +149,7 @@ function getPackCellsData() { religion: Array.from(pack.cells.religion), province: Array.from(pack.cells.province) }; + const cellObjArr = []; { cellConverted.i.forEach(value => { @@ -140,70 +198,28 @@ function getPackCellsData() { return cellsData; } -//data only containing graphical appearance -function getGridCellsData(){ +function getGridCellsData() { const gridData = { + cellsDesired: grid.cellsDesired, spacing: grid.spacing, cellsY: grid.cellsY, cellsX: grid.cellsX, points: grid.points, boundary: grid.boundary - } - return gridData -} - -function getFullDataJson() { - TIME && console.time("getFullDataJson"); - - const info = getMapInfo(); - const settings = getSettings(); - const cells = getPackCellsData(); - const exportData = {info, settings, coords: mapCoordinates, cells, biomes: biomesData, notes, nameBases}; - - 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); + return gridData; } -function getPackCellsDataJson() { - TIME && console.time("getCellsDataJson"); - - const info = getMapInfo(); - const cells = getPackCellsData(); - const exportData = {info, cells}; - - TIME && console.timeEnd("getCellsDataJson"); - return JSON.stringify(exportData); +function getPackVerticesData() { + const {vertices} = pack; + const verticesNumber = vertices.p.length; + const verticesArray = new Array(verticesNumber); + for (let i = 0; i < verticesNumber; i++) { + verticesArray[i] = { + p: vertices.p[i], + v: vertices.v[i], + c: vertices.c[i] + }; + } + return verticesArray; } - -function getGridCellsDataJson() { - TIME && console.time("getGridCellsDataJson"); - - const info = getMapInfo(); - const gridCells = getGridCellsData() - const exportData = {info,gridCells}; - - TIME && console.log("getGridCellsDataJson"); - return JSON.stringify(exportData); -} \ No newline at end of file diff --git a/modules/ui/options.js b/modules/ui/options.js index 5e65a655..28b6aafc 100644 --- a/modules/ui/options.js +++ b/modules/ui/options.js @@ -717,6 +717,11 @@ function showExportPane() { }); } +async function exportToJson(type) { + const {exportToJson} = await import("../dynamic/export-json.js"); + exportToJson(type); +} + async function showLoadPane() { $("#loadMapData").dialog({ title: "Load map", diff --git a/versioning.js b/versioning.js index 1fb0e83e..24ba6288 100644 --- a/versioning.js +++ b/versioning.js @@ -1,7 +1,7 @@ "use strict"; // version and caching control -const version = "1.85.01"; // generator version, update each time +const version = "1.85.02"; // generator version, update each time { document.title += " v" + version;