refactor: submap - restore river and biome data

This commit is contained in:
Azgaar 2024-10-20 15:45:47 +02:00
parent 6e38c93841
commit 72be5f8220
4 changed files with 49 additions and 26 deletions

View file

@ -8075,7 +8075,7 @@
<script src="modules/markers-generator.js?v=1.104.0"></script> <script src="modules/markers-generator.js?v=1.104.0"></script>
<script src="modules/zones-generator.js?v=1.104.0"></script> <script src="modules/zones-generator.js?v=1.104.0"></script>
<script src="modules/coa-generator.js?v=1.99.00"></script> <script src="modules/coa-generator.js?v=1.99.00"></script>
<script src="modules/submap.js?v=1.105.13"></script> <script src="modules/resample.js?v=1.105.13"></script>
<script src="libs/alea.min.js?v1.105.0"></script> <script src="libs/alea.min.js?v1.105.0"></script>
<script src="libs/polylabel.min.js?v1.105.0"></script> <script src="libs/polylabel.min.js?v1.105.0"></script>
<script src="libs/lineclip.min.js?v1.105.0"></script> <script src="libs/lineclip.min.js?v1.105.0"></script>

View file

@ -1,6 +1,6 @@
"use strict"; "use strict";
window.Submap = (function () { window.Resample = (function () {
/* /*
generate new map based on an existing one (resampling parentMap) generate new map based on an existing one (resampling parentMap)
parentMap: {grid, pack, notes} from original map parentMap: {grid, pack, notes} from original map
@ -11,7 +11,7 @@ window.Submap = (function () {
inverse: f(Number, Number) -> [Number, Number] inverse: f(Number, Number) -> [Number, Number]
} }
*/ */
function resample(parentMap, options) { function process(parentMap, options) {
const {projection, inverse} = options; const {projection, inverse} = options;
grid = generateGrid(); grid = generateGrid();
@ -33,19 +33,17 @@ window.Submap = (function () {
Features.markupPack(); Features.markupPack();
createDefaultRuler(); createDefaultRuler();
Rivers.generate(); restoreCellData(parentMap, inverse);
Biomes.define(); restoreRivers(parentMap, projection);
rankCells(); rankCells();
restoreSecondaryCellData(parentMap, inverse);
restoreCultures(parentMap, projection); restoreCultures(parentMap, projection);
restoreBurgs(parentMap, projection, options); restoreBurgs(parentMap, projection, options);
restoreStates(parentMap, projection); restoreStates(parentMap, projection);
restoreRoutes(parentMap, projection); restoreRoutes(parentMap, projection);
restoreReligions(parentMap, projection); restoreReligions(parentMap, projection);
restoreProvinces(parentMap); restoreProvinces(parentMap);
restoreRiverDetails(parentMap, inverse); restoreRiverDetails();
restoreFeatureDetails(parentMap, inverse); restoreFeatureDetails(parentMap, inverse);
restoreMarkers(parentMap, projection); restoreMarkers(parentMap, projection);
restoreZones(parentMap, projection, options); restoreZones(parentMap, projection, options);
@ -90,7 +88,9 @@ window.Submap = (function () {
}); });
} }
function restoreSecondaryCellData(parentMap, inverse) { function restoreCellData(parentMap, inverse) {
pack.cells.biome = new Uint8Array(pack.cells.i.length);
pack.cells.fl = new Uint16Array(pack.cells.i.length);
pack.cells.culture = new Uint16Array(pack.cells.i.length); pack.cells.culture = new Uint16Array(pack.cells.i.length);
pack.cells.state = new Uint16Array(pack.cells.i.length); pack.cells.state = new Uint16Array(pack.cells.i.length);
pack.cells.burg = new Uint16Array(pack.cells.i.length); pack.cells.burg = new Uint16Array(pack.cells.i.length);
@ -102,16 +102,42 @@ window.Submap = (function () {
for (const newPackCell of pack.cells.i) { for (const newPackCell of pack.cells.i) {
const [x, y] = inverse(...pack.cells.p[newPackCell]); const [x, y] = inverse(...pack.cells.p[newPackCell]);
if (isWater(pack, newPackCell)) continue;
if (isWater(pack, newPackCell)) {
} else {
const parentPackCell = parentPackLandCellsQuadtree.find(x, y, Infinity)[2]; const parentPackCell = parentPackLandCellsQuadtree.find(x, y, Infinity)[2];
pack.cells.biome[newPackCell] = parentMap.pack.cells.biome[parentPackCell];
pack.cells.fl[newPackCell] = parentMap.pack.cells.fl[parentPackCell];
pack.cells.culture[newPackCell] = parentMap.pack.cells.culture[parentPackCell]; pack.cells.culture[newPackCell] = parentMap.pack.cells.culture[parentPackCell];
pack.cells.state[newPackCell] = parentMap.pack.cells.state[parentPackCell]; pack.cells.state[newPackCell] = parentMap.pack.cells.state[parentPackCell];
pack.cells.religion[newPackCell] = parentMap.pack.cells.religion[parentPackCell]; pack.cells.religion[newPackCell] = parentMap.pack.cells.religion[parentPackCell];
pack.cells.province[newPackCell] = parentMap.pack.cells.province[parentPackCell]; pack.cells.province[newPackCell] = parentMap.pack.cells.province[parentPackCell];
} }
} }
function restoreRivers(parentMap, projection) {
pack.cells.r = new Uint16Array(pack.cells.i.length);
pack.cells.conf = new Uint8Array(pack.cells.i.length);
pack.rivers = parentMap.pack.rivers
.map(river => {
const parentPoints = river.points || river.cells.map(cellId => parentMap.pack.cells.p[cellId]);
const points = parentPoints
.map(([parentX, parentY]) => {
const [x, y] = projection(parentX, parentY);
return isInMap(x, y) ? [rn(x, 2), rn(y, 2)] : null;
})
.filter(Boolean);
if (points.length < 2) return null;
const cells = points.map(point => findCell(...point));
cells.forEach(cellId => {
if (pack.cells.r[cellId]) pack.cells.conf[cellId] = 1;
pack.cells.r[cellId] = river.i;
});
return {...river, cells, points, source: cells.at(0), mouth: cells.at(-2)};
})
.filter(Boolean);
} }
function restoreCultures(parentMap, projection) { function restoreCultures(parentMap, projection) {
@ -276,12 +302,9 @@ window.Submap = (function () {
}); });
} }
// TODO: actually restore rivers function restoreRiverDetails() {
function restoreRiverDetails(parentMap, inverse) {
pack.rivers.forEach(river => { pack.rivers.forEach(river => {
river.basin = Rivers.getBasin(river.i); river.basin = Rivers.getBasin(river.i);
river.name = Rivers.getName(river.mouth);
river.type = Rivers.getType(river);
}); });
} }
@ -319,5 +342,5 @@ window.Submap = (function () {
return x >= 0 && x <= graphWidth && y >= 0 && y <= graphHeight; return x >= 0 && x <= graphWidth && y >= 0 && y <= graphHeight;
} }
return {resample}; return {process};
})(); })();

View file

@ -20,7 +20,7 @@ function openSubmapTool() {
if (modules.openSubmapTool) return; if (modules.openSubmapTool) return;
modules.openSubmapTool = true; modules.openSubmapTool = true;
async function generateSubmap() { function generateSubmap() {
INFO && console.group("generateSubmap"); INFO && console.group("generateSubmap");
const [[x0, y0]] = getViewBoxExtent(); const [[x0, y0]] = getViewBoxExtent();
@ -46,7 +46,7 @@ function openSubmapTool() {
resetZoom(0); resetZoom(0);
undraw(); undraw();
await Submap.resample(parentMap, options); Resample.process(parentMap, options);
rescaleBurgStyles(scale); rescaleBurgStyles(scale);
drawLayers(); drawLayers();

View file

@ -120,7 +120,7 @@ async function openTransformTool() {
handleInput(); handleInput();
} }
async function transformMap() { function transformMap() {
INFO && console.group("transformMap"); INFO && console.group("transformMap");
const cellsNumber = +byId("transformPointsInput").value; const cellsNumber = +byId("transformPointsInput").value;
@ -132,7 +132,7 @@ async function openTransformTool() {
resetZoom(0); resetZoom(0);
undraw(); undraw();
await Submap.resample(parentMap, options); Resample.process(parentMap, options);
drawLayers(); drawLayers();
INFO && console.groupEnd("transformMap"); INFO && console.groupEnd("transformMap");