refactor: submap - continue

This commit is contained in:
Azgaar 2024-10-16 00:13:33 +02:00
parent 58ccd238f6
commit fb7d232aae
6 changed files with 241 additions and 356 deletions

View file

@ -5769,7 +5769,7 @@
<div id="submapTool" style="display: none" class="dialog">
<p style="font-weight: bold">
This operation is destructive and irreversible. It will create a completely new map based on the current one.
Don't forget to save the current project as a .map file first!
Don't forget to save the .map file to your machine first!
</p>
<p>Settings to be changed: population rate, map pixel size</p>
@ -5780,20 +5780,14 @@
<p>Data to be regenerated: zones, routes, rivers</p>
<p>Burgs may be remapped incorrectly, manual change is required</p>
<p>Keep data for:</p>
<div data-tip="Lock all markers copied from the original map">
<input id="submapLockMarkers" class="checkbox" type="checkbox" checked />
<label for="submapLockMarkers" class="checkbox-label">Markers</label>
</div>
<div data-tip="Lock all burgs copied from the original map">
<input id="submapLockBurgs" class="checkbox" type="checkbox" checked />
<label for="submapLockBurgs" class="checkbox-label">Burgs</label>
</div>
<p>Experimental features:</p>
<div data-tip="Rivers on the parent map will errode land (helps to get similar river network)">
<input id="submapDepressRivers" class="checkbox" type="checkbox" />
<label for="submapDepressRivers" class="checkbox-label">Errode riverbeds</label>
<div data-tip="Smooth heightmap to get more natural terrain">
<input id="submapSmoothHeightmap" class="checkbox" type="checkbox" checked />
<label for="submapSmoothHeightmap" class="checkbox-label">Smooth heightmap</label>
</div>
<div data-tip="Rivers will erode land (helps to get more similar river network)">
<input id="submapDepressRivers" class="checkbox" type="checkbox" checked />
<label for="submapDepressRivers" class="checkbox-label">Erode riverbeds</label>
</div>
<div data-tip="Rescale styles (burg labels, emblem size) to match the new scale">
<input id="submapRescaleStyles" class="checkbox" type="checkbox" checked />
@ -5803,10 +5797,6 @@
<input id="submapPromoteTowns" class="checkbox" type="checkbox" />
<label for="submapPromoteTowns" class="checkbox-label">Promote towns to largetowns</label>
</div>
<div data-tip="Add lakes in depressions (can be very slow on big landmasses)">
<input id="submapAddLakeInDepression" class="checkbox" type="checkbox" />
<label for="submapAddLakeInDepression" class="checkbox-label">Add lakes in depressions (slow)</label>
</div>
</div>
<div id="transformTool" style="display: none" class="dialog">

View file

@ -724,10 +724,11 @@ function setSeed(precreatedSeed) {
function addLakesInDeepDepressions() {
TIME && console.time("addLakesInDeepDepressions");
const elevationLimit = +byId("lakeElevationLimitOutput").value;
if (elevationLimit === 80) return;
const {cells, features} = grid;
const {c, h, b} = cells;
const ELEVATION_LIMIT = +byId("lakeElevationLimitOutput").value;
if (ELEVATION_LIMIT === 80) return;
for (const i of cells.i) {
if (b[i] || h[i] < 20) continue;
@ -736,7 +737,7 @@ function addLakesInDeepDepressions() {
if (h[i] > minHeight) continue;
let deep = true;
const threshold = h[i] + ELEVATION_LIMIT;
const threshold = h[i] + elevationLimit;
const queue = [i];
const checked = [];
checked[i] = true;

View file

@ -1,362 +1,269 @@
"use strict";
window.Submap = (function () {
const isWater = (pack, id) => pack.cells.h[id] < 20;
const inMap = (x, y) => x => 0 && x <= graphWidth && y >= 0 && y <= graphHeight;
/*
generate new map based on an existing one (resampling parentMap)
parentMap: {grid, pack, notes} from original map
options = {
smoothHeightmap: Bool; run smooth filter on heights
depressRivers: Bool; lower elevation of riverbed cells
projection: f(Number, Number) -> [Number, Number]
function to calculate new coordinates
inverse: g(Number, Number) -> [Number, Number]
inverse of f
depressRivers: Bool carve out riverbeds
smoothHeightMap: Bool run smooth filter on heights
addLakesInDepressions: call FMG original funtion on heightmap
lockMarkers: Bool Auto lock all copied markers
lockBurgs: Bool Auto lock all copied burgs
}
inverse: f(Number, Number) -> [Number, Number]
}
*/
function resample(parentMap, options) {
const {grid: parentGrid, pack: parentPack} = parentMap;
const {projection, inverse} = options;
grid = generateGrid();
pack = {};
notes = parentMap.notes;
// resample heightmap from old WorldState
const n = grid.points.length;
grid.cells.h = new Uint8Array(n); // heightmap
grid.cells.temp = new Int8Array(n); // temperature
grid.cells.prec = new Uint8Array(n); // precipitation
const reverseGridMap = new Uint32Array(n); // cellmap from new -> oldcell
const forwardGridMap = parentGrid.points.map(_ => []); // old -> [newcelllist]
for (const [gridId, [x, y]] of grid.points.entries()) {
const [parentX, parentY] = inverse(x, y);
const parentPackId = parentPack.cells.q.find(parentX, parentY, Infinity)[2];
const parentGridId = parentPack.cells.g[parentPackId];
grid.cells.h[gridId] = parentGrid.cells.h[parentGridId];
grid.cells.temp[gridId] = parentGrid.cells.temp[parentGridId];
grid.cells.prec[gridId] = parentGrid.cells.prec[parentGridId];
if (options.depressRivers) forwardGridMap[parentGridId].push(gridId);
reverseGridMap[gridId] = parentGridId;
}
// smoothing should not change cell type (land -> water or vice versa)
if (options.smoothHeightMap) {
const gcells = grid.cells;
gcells.h.forEach((h, i) => {
const hs = gcells.c[i].map(c => gcells.h[c]);
hs.push(h);
gcells.h[i] = h >= 20 ? Math.max(d3.mean(hs), 20) : Math.min(d3.mean(hs), 19);
});
}
if (options.depressRivers) {
const rbeds = new Uint16Array(grid.cells.i.length);
// and erode riverbeds
parentMap.pack.rivers.forEach(r =>
r.cells.forEach(oldpc => {
if (oldpc < 0) return; // ignore out-of-map marker (-1)
const oldc = parentMap.pack.cells.g[oldpc];
const targetCells = forwardGridMap[oldc];
if (!targetCells) throw "TargetCell shouldn't be empty";
targetCells.forEach(c => {
if (grid.cells.h[c] < 20) return;
rbeds[c] = 1;
});
})
);
// raise every land cell a bit except riverbeds
grid.cells.h.forEach((h, i) => {
if (rbeds[i] || h < 20) return;
grid.cells.h[i] = Math.min(h + 2, 100);
});
}
resamplePrimaryGridData(parentMap, inverse);
Features.markupGrid();
addLakesInDeepDepressions();
openNearSeaLakes();
OceanLayers();
calculateMapCoordinates();
calculateTemperatures();
generatePrecipitation();
reGraph();
reGraph();
Features.markupPack();
createDefaultRuler();
// Packed Graph
const oldCells = parentMap.pack.cells;
const forwardMap = parentMap.pack.cells.p.map(_ => []); // old -> [newcelllist]
const pn = pack.cells.i.length;
const cells = pack.cells;
cells.culture = new Uint16Array(pn);
cells.state = new Uint16Array(pn);
cells.burg = new Uint16Array(pn);
cells.religion = new Uint16Array(pn);
cells.province = new Uint16Array(pn);
for (const [id, gridCellId] of cells.g.entries()) {
const oldGridId = reverseGridMap[gridCellId];
if (oldGridId === undefined) {
console.error("Can not find old cell id", reverseGridMap, "in", gridCellId);
continue;
}
// find old parent's children
const oldChildren = oldCells.i.filter(oid => oldCells.g[oid] == oldGridId);
let oldid; // matching cell on the original map
if (!oldChildren.length) {
// it *must* be a (deleted) deep ocean cell
if (!parentGrid.cells.h[oldGridId] < 20) {
console.error(`Warning, ${gridCellId} should be water cell, not ${parentGrid.cells.h[oldGridId]}`);
continue;
}
// find replacement: closest water cell
const [ox, oy] = cells.p[id];
const [tx, ty] = inverse(x, y);
oldid = oldCells.q.find(tx, ty, Infinity)[2];
if (!oldid) {
console.warn("Warning, no id found in quad", id, "parent", gridCellId);
continue;
}
} else {
// find closest children (packcell) on the parent map
const distance = x => (x[0] - cells.p[id][0]) ** 2 + (x[1] - cells.p[id][1]) ** 2;
let d = Infinity;
oldChildren.forEach(oid => {
// this should be always true, unless some algo modded the height!
if (isWater(parentMap.pack, oid) !== isWater(pack, id))
console.warn(`cell sank because of addLakesInDepressions: ${oid}`);
const [oldpx, oldpy] = oldCells.p[oid];
const nd = distance(projection(oldpx, oldpy));
if (isNaN(nd)) {
console.error("Distance is not a number!", "Old point:", oldpx, oldpy);
}
if (nd < d) [d, oldid] = [nd, oid];
});
if (oldid === undefined) {
console.warn("Warning, no match for", id, "(parent:", gridCellId, ")");
continue;
}
}
if (isWater(pack, id) !== isWater(parentMap.pack, oldid)) {
WARN && console.warn("Type discrepancy detected:", id, oldid, `${pack.cells.t[id]} != ${oldCells.t[oldid]}`);
}
cells.culture[id] = oldCells.culture[oldid];
cells.state[id] = oldCells.state[oldid];
cells.religion[id] = oldCells.religion[oldid];
cells.province[id] = oldCells.province[oldid];
// reverseMap.set(id, oldid)
forwardMap[oldid].push(id);
}
Rivers.generate();
// biome calculation based on (resampled) grid.cells.temp and prec
// it's safe to recalculate.
Biomes.define();
// recalculate suitability and population
// TODO: normalize according to the base-map
rankCells();
pack.cultures = parentMap.pack.cultures;
// fix culture centers
const validCultures = new Set(pack.cells.culture);
pack.cultures.forEach((c, i) => {
if (!i) return; // ignore wildlands
if (!validCultures.has(i)) {
c.removed = true;
c.center = null;
return;
}
const newCenters = forwardMap[c.center];
c.center = newCenters.length ? newCenters[0] : pack.cells.culture.findIndex(x => x === i);
});
restoreSecondaryCellData(parentMap, inverse);
restoreCultures(parentMap, projection);
restoreBurgs(parentMap, projection, options);
restoreStates(parentMap, projection);
restoreReligions(parentMap, projection);
restoreProvinces(parentMap);
restoreMarkers(parentMap, projection);
restoreZones(parentMap, projection, options);
copyBurgs(parentMap, projection, options);
// transfer states, mark states without land as removed.
const validStates = new Set(pack.cells.state);
pack.states = parentMap.pack.states;
// keep valid states and neighbors only
pack.states.forEach((s, i) => {
if (!s.i || s.removed) return; // ignore removed and neutrals
if (!validStates.has(i)) s.removed = true;
s.neighbors = s.neighbors.filter(n => validStates.has(n));
// find center
s.center = pack.burgs[s.capital].cell
? pack.burgs[s.capital].cell // capital is the best bet
: pack.cells.state.findIndex(x => x === i); // otherwise use the first valid cell
});
BurgsAndStates.getPoles();
// transfer provinces, mark provinces without land as removed.
const validProvinces = new Set(pack.cells.province);
pack.provinces = parentMap.pack.provinces;
// mark uneccesary provinces
pack.provinces.forEach((p, i) => {
if (!p || p.removed) return;
if (!validProvinces.has(i)) {
p.removed = true;
return;
}
const newCenters = forwardMap[p.center];
p.center = newCenters.length ? newCenters[0] : pack.cells.province.findIndex(x => x === i);
});
Provinces.getPoles();
regenerateRoutes();
Routes.generate();
Rivers.specify();
Features.specify();
for (const s of pack.states) {
if (!s.military) continue;
for (const m of s.military) {
[m.x, m.y] = projection(m.x, m.y);
[m.bx, m.by] = projection(m.bx, m.by);
const cc = forwardMap[m.cell];
m.cell = cc && cc.length ? cc[0] : null;
}
s.military = s.military.filter(m => m.cell).map((m, i) => ({...m, i}));
}
for (const m of pack.markers) {
const [x, y] = projection(m.x, m.y);
if (!inMap(x, y)) {
Markers.deleteMarker(m.i);
} else {
m.x = x;
m.y = y;
m.cell = findCell(x, y);
if (options.lockMarkers) m.lock = true;
}
}
if (layerIsOn("toggleMarkers")) drawMarkers();
Zones.generate();
Names.getMapName();
notes = parentMap.notes;
showStatistics();
}
/* find the nearest cell accepted by filter f *and* having at
* least one *neighbor* fulfilling filter g, up to cell-distance `max`
* returns [cellid, neighbor] tuple or undefined if no such cell.
* accepts coordinates (x, y)
*/
const findNearest =
(f, g, max = 3) =>
(px, py) => {
const d2 = c => (px - pack.cells.p[c][0]) ** 2 + (py - pack.cells.p[c][0]) ** 2;
const startCell = findCell(px, py);
const tested = new Set([startCell]); // ignore analyzed cells
const kernel = (cs, level) => {
const [bestf, bestg] = cs.filter(f).reduce(
([cf, cg], c) => {
const neighbors = pack.cells.c[c];
const betterg = neighbors.filter(g).reduce((u, x) => (d2(x) < d2(u) ? x : u));
if (cf === undefined) return [c, betterg];
return betterg && d2(cf) < d2(c) ? [c, betterg] : [cf, cg];
},
[undefined, undefined]
);
if (bestf && bestg) return [bestf, bestg];
function resamplePrimaryGridData(parentMap, inverse) {
grid.cells.h = new Uint8Array(grid.points.length);
grid.cells.temp = new Int8Array(grid.points.length);
grid.cells.prec = new Uint8Array(grid.points.length);
// no suitable pair found, retry with next ring
const targets = new Set(cs.map(c => pack.cells.c[c]).flat());
const ring = Array.from(targets).filter(nc => !tested.has(nc));
if (level >= max || !ring.length) return [undefined, undefined];
ring.forEach(c => tested.add(c));
return kernel(ring, level + 1);
};
const pair = kernel([startCell], 1);
return pair;
};
grid.points.forEach(([x, y], newGridCell) => {
const [parentX, parentY] = inverse(x, y);
const parentPackCell = parentMap.pack.cells.q.find(parentX, parentY, Infinity)[2];
const parentGridCell = parentMap.pack.cells.g[parentPackCell];
function copyBurgs(parentMap, projection, options) {
const cells = pack.cells;
pack.burgs = parentMap.pack.burgs;
grid.cells.h[newGridCell] = parentMap.grid.cells.h[parentGridCell];
grid.cells.temp[newGridCell] = parentMap.grid.cells.temp[parentGridCell];
grid.cells.prec[newGridCell] = parentMap.grid.cells.prec[parentGridCell];
});
// remap burgs to the best new cell
pack.burgs.forEach((b, id) => {
if (id == 0) return; // skip empty city of neturals
[b.x, b.y] = projection(b.x, b.y);
b.population = b.population * options.scale; // adjust for populationRate change
if (options.smoothHeightmap) smoothHeightmap();
if (options.depressRivers) depressRivers(parentMap, inverse);
}
// disable out-of-map (removed) burgs
if (!inMap(b.x, b.y)) {
b.removed = true;
b.cell = null;
return;
}
const cityCell = findCell(b.x, b.y);
let searchFunc;
const isFreeLand = c => cells.t[c] === 1 && !cells.burg[c];
const nearCoast = c => cells.t[c] === -1;
// check if we need to relocate the burg
if (cells.burg[cityCell])
// already occupied
searchFunc = findNearest(isFreeLand, _ => true, 3);
if (isWater(pack, cityCell) || b.port)
// burg is in water or port
searchFunc = findNearest(isFreeLand, nearCoast, 6);
if (searchFunc) {
const [newCell, neighbor] = searchFunc(b.x, b.y);
if (!newCell) {
WARN && console.warn(`Can not relocate Burg: ${b.name} sunk and destroyed. :-(`);
b.cell = null;
b.removed = true;
return;
}
DEBUG && console.info(`Moving ${b.name} from ${cityCell} to ${newCell} near ${neighbor}.`);
[b.x, b.y] = b.port ? getCloseToEdgePoint(newCell, neighbor) : cells.p[newCell];
if (b.port) b.port = cells.f[neighbor]; // copy feature number
b.cell = newCell;
if (b.port && !isWater(pack, neighbor)) console.error("betrayal! negihbor must be water!", b);
} else {
b.cell = cityCell;
}
if (b.i && !b.lock) b.lock = options.lockBurgs;
cells.burg[b.cell] = id;
function smoothHeightmap() {
grid.cells.h.forEach((height, newGridCell) => {
const heights = [height, ...grid.cells.c[newGridCell].map(c => grid.cells.h[c])];
const meanHeight = d3.mean(heights);
grid.cells.h[newGridCell] = isWater(grid, newGridCell) ? Math.min(meanHeight, 19) : Math.max(meanHeight, 20);
});
}
function getCloseToEdgePoint(cell1, cell2) {
const {cells, vertices} = pack;
function depressRivers(parentMap, inverse) {
// lower elevation of cells with rivers by 1
grid.cells.points.forEach(([x, y], newGridCell) => {
const [parentX, parentY] = inverse(x, y);
const parentPackCell = parentMap.pack.cells.q.find(parentX, parentY, Infinity)[2];
const hasRiver = Boolean(parentMap.pack.cells.r[parentPackCell]);
if (hasRiver && grid.cells.h[newGridCell] > 20) grid.cells.h[newGridCell] -= 1;
});
}
const [x0, y0] = cells.p[cell1];
function restoreSecondaryCellData(parentMap, inverse) {
pack.cells.culture = 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.religion = new Uint16Array(pack.cells.i.length);
pack.cells.province = new Uint16Array(pack.cells.i.length);
const commonVertices = cells.v[cell1].filter(vertex => vertices.c[vertex].some(cell => cell === cell2));
const [x1, y1] = vertices.p[commonVertices[0]];
const [x2, y2] = vertices.p[commonVertices[1]];
const xEdge = (x1 + x2) / 2;
const yEdge = (y1 + y2) / 2;
const parentPackCellGroups = groupCellsByType(parentMap.pack);
const parentPackLandCellsQuadtree = d3.quadtree(parentPackCellGroups.land);
const x = rn(x0 + 0.95 * (xEdge - x0), 2);
const y = rn(y0 + 0.95 * (yEdge - y0), 2);
for (const newPackCell of pack.cells.i) {
const [x, y] = inverse(...pack.cells.p[newPackCell]);
return [x, y];
if (isWater(pack, newPackCell)) {
} else {
const parentPackCell = parentPackLandCellsQuadtree.find(x, y, Infinity)[2];
pack.cells.culture[newPackCell] = parentMap.pack.cells.culture[parentPackCell];
pack.cells.state[newPackCell] = parentMap.pack.cells.state[parentPackCell];
pack.cells.religion[newPackCell] = parentMap.pack.cells.religion[parentPackCell];
pack.cells.province[newPackCell] = parentMap.pack.cells.province[parentPackCell];
}
}
}
function restoreCultures(parentMap, projection) {
const validCultures = new Set(pack.cells.culture);
const culturePoles = getPolesOfInaccessibility(pack, cellId => pack.cells.culture[cellId]);
pack.cultures = parentMap.pack.cultures.map(culture => {
if (!culture.i || culture.removed) return culture;
if (!validCultures.has(culture.i)) return {...culture, removed: true, lock: false};
const [xp, yp] = projection(...parentMap.pack.cells.p[culture.center]);
const [x, y] = [rn(xp, 2), rn(yp, 2)];
const centerCoords = isInMap(x, y) ? [x, y] : culturePoles[culture.i];
const center = findCell(...centerCoords);
return {...culture, center};
});
}
function restoreBurgs(parentMap, projection, options) {
const packLandCellsQuadtree = d3.quadtree(groupCellsByType(pack).land);
pack.burgs = parentMap.pack.burgs.map(burg => {
if (!burg.i || burg.removed) return burg;
burg.population *= options.scale; // adjust for populationRate change
const [xp, yp] = projection(burg.x, burg.y);
const [x, y] = [rn(xp, 2), rn(yp, 2)];
if (!isInMap(x, y)) return {...burg, removed: true, lock: false};
const cell = packLandCellsQuadtree.find(x, y, Infinity)?.[2];
if (!cell) {
ERROR && console.error(`Could not find cell for burg ${burg.name} (${burg.i}). Had to remove it`);
return {...burg, removed: true, lock: false};
}
if (pack.cells.burg[cell]) {
WARN && console.warn(`Cell ${cell} already has a burg. Had to remove burg ${burg.name} (${burg.i})`);
return {...burg, removed: true, lock: false};
}
pack.cells.burg[cell] = burg.i;
return {...burg, x, y, cell};
});
}
function restoreStates(parentMap, projection) {
const validStates = new Set(pack.cells.state);
pack.states = parentMap.pack.states.map(state => {
if (!state.i || state.removed) return state;
if (!validStates.has(state.i)) return {...state, removed: true, lock: false};
const military = state.military.map(regiment => {
const cell = findCell(...projection(...parentMap.pack.cells.p[regiment.cell]));
const [xBase, yBase] = projection(regiment.bx, regiment.by);
const [xCurrent, yCurrent] = projection(regiment.x, regiment.y);
return {...regiment, cell, bx: rn(xBase, 2), by: rn(yBase, 2), x: rn(xCurrent, 2), y: rn(yCurrent, 2)};
});
const neighbors = state.neighbors.filter(stateId => validStates.has(stateId));
return {...state, neighbors, military};
});
BurgsAndStates.getPoles();
pack.states.forEach(state => {
if (!state.i || state.removed) return;
const capital = pack.burgs[state.capital];
state.center = !capital?.removed ? capital.cell : findCell(...state.pole);
});
}
function restoreReligions(parentMap, projection) {
const validReligions = new Set(pack.cells.religion);
const religionPoles = getPolesOfInaccessibility(pack, cellId => pack.cells.religion[cellId]);
pack.religions = parentMap.pack.religions.map(religion => {
if (!religion.i || religion.removed) return religion;
if (!validReligions.has(religion.i)) return {...religion, removed: true, lock: false};
const [xp, yp] = projection(...parentMap.pack.cells.p[religion.center]);
const [x, y] = [rn(xp, 2), rn(yp, 2)];
const centerCoords = isInMap(x, y) ? [x, y] : religionPoles[religion.i];
const center = findCell(...centerCoords);
return {...religion, center};
});
}
function restoreProvinces(parentMap) {
const validProvinces = new Set(pack.cells.province);
pack.provinces = parentMap.pack.provinces.map(province => {
if (!province.i || province.removed) return province;
if (!validProvinces.has(province.i)) return {...province, removed: true, lock: false};
return province;
});
Provinces.getPoles();
pack.provinces.forEach(province => {
if (!province.i || province.removed) return;
const capital = pack.burgs[province.burg];
province.center = !capital?.removed ? capital.cell : findCell(...province.pole);
});
}
function restoreMarkers(parentMap, projection) {
pack.markers = parentMap.pack.markers;
pack.markers.forEach(marker => {
const [x, y] = projection(marker.x, marker.y);
if (!isInMap(x, y)) Markers.deleteMarker(marker.i);
const cell = findCell(x, y);
marker.x = rn(x, 2);
marker.y = rn(y, 2);
marker.cell = cell;
});
}
function restoreZones(parentMap, projection, options) {
const getSearchRadius = cellId => Math.sqrt(parentMap.pack.cells.area[cellId] / Math.PI) * options.scale;
pack.zones = parentMap.pack.zones.map(zone => {
const cells = zone.cells
.map(cellId => {
const [x, y] = projection(...parentMap.pack.cells.p[cellId]);
if (!isInMap(x, y)) return null;
return findAll(x, y, getSearchRadius(cellId));
})
.filter(Boolean)
.flat();
return {...zone, cells: unique(cells)};
});
}
function groupCellsByType(graph) {
return graph.cells.p.reduce(
(acc, [x, y], cellId) => {
const group = isWater(graph, cellId) ? "water" : "land";
acc[group].push([x, y, cellId]);
return acc;
},
{land: [], water: []}
);
}
function isWater(graph, cellId) {
return graph.cells.h[cellId] < 20;
}
function isInMap(x, y) {
return x >= 0 && x <= graphWidth && y >= 0 && y <= graphHeight;
}
return {resample};

View file

@ -17,8 +17,8 @@ function openSubmapTool() {
}
});
if (modules.openSubmapMenu) return;
modules.openSubmapMenu = true;
if (modules.openSubmapTool) return;
modules.openSubmapTool = true;
async function generateSubmap() {
INFO && console.group("generateSubmap");
@ -34,18 +34,15 @@ function openSubmapTool() {
byId("mapSizeInput").value = mapSizeOutput.value;
byId("latitudeInput").value = latitudeOutput.value;
distanceScale = distanceScaleInput.value = rn(distanceScaleInput.value / scale, 2);
populationRate = populationRateInput.value = rn(populationRateInput.value / scale, 2);
distanceScale = distanceScaleInput.value = rn(distanceScale / scale, 2);
populationRate = populationRateInput.value = rn(populationRate / scale, 2);
const parentMap = {grid: deepCopy(grid), pack: deepCopy(pack), notes: deepCopy(notes)};
const options = {
lockMarkers: byId("submapLockMarkers").checked,
lockBurgs: byId("submapLockBurgs").checked,
smoothHeightmap: byId("submapSmoothHeightmap").checked,
depressRivers: byId("submapDepressRivers").checked,
addLakesInDepressions: byId("submapAddLakeInDepression").checked,
smoothHeightMap: scale > 2,
inverse: (x, y) => [x / scale + x0, y / scale + y0],
projection: (x, y) => [(x - x0) * scale, (y - y0) * scale],
inverse: (x, y) => [x / scale + x0, y / scale + y0],
scale
};

View file

@ -45,6 +45,7 @@ async function openTransformTool() {
const options = {noWater: true, fullMap: true, noLabels: true, noScaleBar: true, noVignette: true, noIce: true};
const url = await getMapURL("png", options);
const SCALE = 4;
const img = new Image();
img.src = url;
@ -52,9 +53,9 @@ async function openTransformTool() {
const $canvas = byId("transformPreviewCanvas");
$canvas.style.width = width + "px";
$canvas.style.height = height + "px";
$canvas.width = width * 2;
$canvas.height = height * 2;
$canvas.getContext("2d").drawImage(img, 0, 0, width * 2, height * 2);
$canvas.width = width * SCALE;
$canvas.height = height * SCALE;
$canvas.getContext("2d").drawImage(img, 0, 0, width * SCALE, height * SCALE);
};
}
@ -124,16 +125,7 @@ async function openTransformTool() {
const parentMap = {grid: deepCopy(grid), pack: deepCopy(pack), notes: deepCopy(notes)};
const [projection, inverse] = getProjection();
const options = {
lockMarkers: false,
lockBurgs: false,
depressRivers: false,
addLakesInDepressions: false,
smoothHeightMap: false,
scale: 1,
inverse,
projection
};
const options = {depressRivers: false, smoothHeightmap: false, scale: 1, inverse, projection};
const cellsNumber = +byId("transformPointsInput").value;
changeCellsDensity(cellsNumber);

View file

@ -241,10 +241,8 @@ void (function addFindAll() {
};
const tree_filter = function (x, y, radius) {
var t = {x, y, x0: this._x0, y0: this._y0, x3: this._x1, y3: this._y1, quads: [], node: this._root};
if (t.node) {
t.quads.push(new Quad(t.node, t.x0, t.y0, t.x3, t.y3));
}
const t = {x, y, x0: this._x0, y0: this._y0, x3: this._x1, y3: this._y1, quads: [], node: this._root};
if (t.node) t.quads.push(new Quad(t.node, t.x0, t.y0, t.x3, t.y3));
radiusSearchInit(t, radius);
var i = 0;