mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-22 20:11:24 +01:00
Save Option for Api-like added
This commit is contained in:
parent
8f3aaeaaaa
commit
a1ef32ddad
1 changed files with 51 additions and 84 deletions
135
modules/save.js
135
modules/save.js
|
|
@ -120,23 +120,30 @@ function getMapData() {
|
||||||
return mapData;
|
return mapData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Prepare data for API-JSON
|
||||||
function getMapDataAPIJson() {
|
function getMapDataAPIJson() {
|
||||||
|
|
||||||
TIME && console.time("createMapDataJson");
|
TIME && console.time("createMapDataJson");
|
||||||
|
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
const dateString = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
|
const dateString = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
|
||||||
const license = "Api-Like Output File Gathered From: azgaar.github.io/Fantasy-Map-Generator";
|
const info = {
|
||||||
const params = {version, license, dateString, seed, graphWidth, graphHeight, mapId};
|
"version": version,
|
||||||
const SettingsOut = {
|
"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,
|
"distanceUnit" : distanceUnitInput.value,
|
||||||
"distanceScale": distanceScaleInput.value,
|
"distanceScale": distanceScaleInput.value,
|
||||||
"areaUnit" : areaUnit.value,
|
"areaUnit" : areaUnit.value,
|
||||||
"heightUnit" : heightUnit.value,
|
"heightUnit" : heightUnit.value,
|
||||||
"heightExponent" : heightExponentInput.value,
|
"heightExponent" : heightExponentInput.value,
|
||||||
"temperatureScale" : temperatureScale.value,
|
"temperatureScale" : temperatureScale.value,
|
||||||
"barSizeInput" : barSizeInput.value,
|
"barSize" : barSizeInput.value,
|
||||||
"barLabel" : barLabel.value,
|
"barLabel" : barLabel.value,
|
||||||
"barBackOpacity" : barBackOpacity.value,
|
"barBackOpacity" : barBackOpacity.value,
|
||||||
"barBackColor" : barBackColor.value,
|
"barBackColor" : barBackColor.value,
|
||||||
|
|
@ -144,11 +151,11 @@ function getMapDataAPIJson() {
|
||||||
"barPosY" : barPosY.value,
|
"barPosY" : barPosY.value,
|
||||||
"populationRate" : populationRate,
|
"populationRate" : populationRate,
|
||||||
"urbanization" : urbanization,
|
"urbanization" : urbanization,
|
||||||
"mapSizeOutput" : mapSizeOutput.value,
|
"mapSize" : mapSizeOutput.value,
|
||||||
"latitudeOutput" : latitudeOutput.value,
|
"latitudeO" : latitudeOutput.value,
|
||||||
"temperatureEquatorOutput" : temperatureEquatorOutput.value,
|
"temperatureEquator" : temperatureEquatorOutput.value,
|
||||||
"temperaturePoleOutput" : temperaturePoleOutput.value,
|
"temperaturePole" : temperaturePoleOutput.value,
|
||||||
"precOutput" : precOutput.value,
|
"prec" : precOutput.value,
|
||||||
"options" : options,
|
"options" : options,
|
||||||
"mapName" : mapName.value,
|
"mapName" : mapName.value,
|
||||||
"hideLabels" : hideLabels.checked,
|
"hideLabels" : hideLabels.checked,
|
||||||
|
|
@ -157,84 +164,43 @@ function getMapDataAPIJson() {
|
||||||
"urbanDensity" : urbanDensity
|
"urbanDensity" : urbanDensity
|
||||||
};
|
};
|
||||||
const coords = mapCoordinates;
|
const coords = mapCoordinates;
|
||||||
let BiomeObjArr = [];
|
const packs = {
|
||||||
{
|
"cells":{
|
||||||
for (let i = 0; i < biomesData.name.length; i++)
|
"h": pack.cells.h,
|
||||||
{
|
"f": pack.cells.f,
|
||||||
const biome = {
|
"t": pack.cells.t,
|
||||||
"name": biomesData.name[i],
|
"s": pack.cells.s,
|
||||||
"biomeColor": biomesData.color[i],
|
"biome": pack.cells.biome,
|
||||||
"habitability": biomesData.habitability[i]
|
"burg": pack.cells.burg,
|
||||||
};
|
"culture": pack.cells.culture,
|
||||||
BiomeObjArr.push(biome);
|
"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 biomes = BiomeObjArr;
|
|
||||||
const notesData = notes;
|
|
||||||
const fonts = getUsedFonts(svg.node());
|
|
||||||
|
|
||||||
const {spacing, cellsX, cellsY, boundary, points, features} = grid;
|
const ExportData = {info,settings,coords,packs,biomes,notes,nameBases}
|
||||||
const gridGeneral = {spacing, cellsX, cellsY, boundary, points, features};
|
|
||||||
const packFeatures = pack.features;
|
|
||||||
const cultures = pack.cultures;
|
|
||||||
const states = pack.states;
|
|
||||||
const burgs = pack.burgs;
|
|
||||||
const religions = pack.religions;
|
|
||||||
const provinces = pack.provinces;
|
|
||||||
const rivers = pack.rivers;
|
|
||||||
const markers = pack.markers;
|
|
||||||
|
|
||||||
// store name array only if not the same as default
|
|
||||||
const defaultNB = Names.getNameBases();
|
|
||||||
const namesData = nameBases
|
|
||||||
.map((b, i) => {
|
|
||||||
const names = defaultNB[i] && defaultNB[i].b === b.b ? "" : b.b;
|
|
||||||
return {"name":b.name,"min":b.min,"max":b.max,"d":b.d,"m":b.m,"names":names}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
// round population to save space
|
|
||||||
const pop = Array.from(pack.cells.pop).map(p => rn(p, 4));
|
|
||||||
|
|
||||||
|
|
||||||
const ExportData =JSON.stringify({
|
|
||||||
"params" : params,
|
|
||||||
"settings" : SettingOut,
|
|
||||||
"coords" : coords,
|
|
||||||
"biomes" : biomes,
|
|
||||||
"notesData" : notesData,
|
|
||||||
"gridGeneral" : gridGeneral,
|
|
||||||
"gridCellsH" : grid.cells.h,
|
|
||||||
"gridCellsPrec" : grid.cells.prec,
|
|
||||||
"gridCellsF" : grid.cells.f,
|
|
||||||
"gridCellsT" : grid.cells.t,
|
|
||||||
"gridCellsTemp" : grid.cells.temp,
|
|
||||||
"packFeatures" : packFeatures,
|
|
||||||
"cultures" : cultures,
|
|
||||||
"states" : states,
|
|
||||||
"burgs" : burgs,
|
|
||||||
"packCellsBiome" : pack.cells.biome,
|
|
||||||
"packCellsBurg" : pack.cells.burg,
|
|
||||||
"packCellsConf" : pack.cells.conf,
|
|
||||||
"packCellsCulture" : pack.cells.culture,
|
|
||||||
"packCellsFl" : pack.cells.fl,
|
|
||||||
"pop" : pop,
|
|
||||||
"packCellsR" : pack.cells.r,
|
|
||||||
"packCellsRoad" : pack.cells.road,
|
|
||||||
"packCellsState" : pack.cells.state,
|
|
||||||
"packCellsReligion" : pack.cells.religion,
|
|
||||||
"packCellsCrossroad" : pack.cells.crossroad,
|
|
||||||
"provinces": provinces,
|
|
||||||
"religions" : religions,
|
|
||||||
"namesData" : namesData,
|
|
||||||
"rivers" : rivers,
|
|
||||||
"rulers" : rulers,
|
|
||||||
"fonts" : fonts,
|
|
||||||
"markers" : markers
|
|
||||||
})
|
|
||||||
|
|
||||||
TIME && console.timeEnd("createMapDataJson");
|
TIME && console.timeEnd("createMapDataJson");
|
||||||
return ExportData;
|
return JSON.stringify(ExportData);
|
||||||
}
|
}
|
||||||
// Download .map file
|
// Download .map file
|
||||||
function dowloadMap() {
|
function dowloadMap() {
|
||||||
|
|
@ -266,6 +232,7 @@ function downloadMapDataAPIJson() {
|
||||||
tip(`${link.download} is saved. Open "Downloads" screen (CTRL + J) to check`, true, "success", 7000);
|
tip(`${link.download} is saved. Open "Downloads" screen (CTRL + J) to check`, true, "success", 7000);
|
||||||
window.URL.revokeObjectURL(URL);
|
window.URL.revokeObjectURL(URL);
|
||||||
}
|
}
|
||||||
|
|
||||||
function exportGridCellsData(exportName){
|
function exportGridCellsData(exportName){
|
||||||
if(customization) return tip("Map cannot be saved when edit mode is active, please exit and retry",false,"error");
|
if(customization) return tip("Map cannot be saved when edit mode is active, please exit and retry",false,"error");
|
||||||
closeDialogs("#alert");
|
closeDialogs("#alert");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue