mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 01:41:22 +01:00
fix(#781): add vertices data to full json export
This commit is contained in:
parent
d54a6a44b1
commit
1142be65c6
4 changed files with 87 additions and 73 deletions
17
index.html
17
index.html
|
|
@ -5825,18 +5825,12 @@
|
|||
|
||||
<div style="margin: 1em 0 0.3em; font-weight: bold">Export To JSON</div>
|
||||
<div>
|
||||
<button onclick="exportToJson('Full')" data-tip="Download full data as in JSON format">full</button>
|
||||
<button onclick="exportToJson('Minimal')" data-tip="Download minimal data as in JSON format">minimal</button>
|
||||
<button
|
||||
onclick="exportToJson('PackCells')"
|
||||
data-tip="Download map metadata and pack cells data as in JSON format"
|
||||
>
|
||||
<button onclick="exportToJson('Full')" data-tip="Download full data in JSON">full</button>
|
||||
<button onclick="exportToJson('Minimal')" data-tip="Download minimal data in JSON">minimal</button>
|
||||
<button onclick="exportToJson('PackCells')" data-tip="Download map metadata and pack cells data in JSON">
|
||||
pack cells
|
||||
</button>
|
||||
<button
|
||||
onclick="exportToJson('GridCells')"
|
||||
data-tip="Download map metadata and grid cells data as in JSON format"
|
||||
>
|
||||
<button onclick="exportToJson('GridCells')" data-tip="Download map metadata and grid cells data in JSON">
|
||||
grid cells
|
||||
</button>
|
||||
</div>
|
||||
|
|
@ -7929,7 +7923,7 @@
|
|||
<script src="modules/ui/stylePresets.js"></script>
|
||||
|
||||
<script src="modules/ui/general.js?v=02062022"></script>
|
||||
<script src="modules/ui/options.js?v=04062022"></script>
|
||||
<script src="modules/ui/options.js?v=040620222"></script>
|
||||
<script src="main.js?v=020620222"></script>
|
||||
|
||||
<script defer src="modules/relief-icons.js"></script>
|
||||
|
|
@ -7977,7 +7971,6 @@
|
|||
<script defer src="modules/io/load.js?v=01062022"></script>
|
||||
<script defer src="modules/io/cloud.js?v=04062022"></script>
|
||||
<script defer src="modules/io/export.js?v=04062022"></script>
|
||||
<script defer src="modules/io/export-json.js"></script>
|
||||
<script defer src="modules/io/formats.js"></script>
|
||||
|
||||
<!-- Web Components -->
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
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]
|
||||
};
|
||||
}
|
||||
|
||||
function getGridCellsDataJson() {
|
||||
TIME && console.time("getGridCellsDataJson");
|
||||
|
||||
const info = getMapInfo();
|
||||
const gridCells = getGridCellsData()
|
||||
const exportData = {info,gridCells};
|
||||
|
||||
TIME && console.log("getGridCellsDataJson");
|
||||
return JSON.stringify(exportData);
|
||||
return verticesArray;
|
||||
}
|
||||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue