burg remapping

This commit is contained in:
Mészáros Gergely 2021-08-13 20:37:56 +02:00
parent 36248e36b5
commit 6f97864962
3 changed files with 26 additions and 15 deletions

View file

@ -1313,7 +1313,7 @@
<button id="configureWorld" data-tip="Click to open world configurator to setup map position on Globe and World climate" onclick="editWorld()">Configure World</button>
<button id="openSubmapOptions" data-tip="Click to generate new (sub)map from the current viewport" onclick="openSubmapOptions()">Submap</button>
<button id="optionsReset" data-tip="Click to restore default options (page will be reloaded)" onclick="restoreDefaultOptions()">Reset to defaults</button>
<button id="optionsReset" data-tip="Click to restore default options (page will be reloaded)" onclick="restoreDefaultOptions()">Reset</button>
</div>
@ -3507,7 +3507,7 @@
<p style="font-style: italic; color: red">Original map will be destroyed! Don't forget to save your work!</p>
<div id="submapStage"></div>
<div id="submapProgress"></div>
<button id="start" data-tip="Start submap resampling" class="options glow" onclick="generateSubmap()">Ok</button>
<button id="start" data-tip="Start submap resampling" class="options glow" onclick="generateSubmap()">Generate</button>
</div>
<div id="alert" style="display: none" class="dialog">

View file

@ -50,7 +50,7 @@ window.Submap = (function () {
grid.cells.h[id] = gridCells.h[cid];
grid.cells.temp[id] = gridCells.temp[cid];
grid.cells.prec[id] = gridCells.prec[cid];
id%50 || progress(id * 100.0 / grid.points.length)
id%50 || progress(id * 100.0 / grid.points.length);
})
// TODO: add smooth/noise function for h, temp, prec n times
@ -112,32 +112,42 @@ window.Submap = (function () {
// Cultures.expand();
// TODO: update culture centers
// transfer states and burgs. filter states without land
const validStates = new Set(pack.cells.state)
console.log(validStates);
pack.states = baseState.pack.states;
console.log(pack.states)
pack.validStates = pack.states.filter(s => validStates.has(s.i))
// transfer states and burgs. mark states without land as removed.
const validStates = new Set(pack.cells.state);
pack.states = baseState.pack.states
pack.states.forEach(s => {
if (!validStates.has(s.i)) s.removed=true;
});
// BurgsAndStates.generate();
// Religions.generate();
// BurgsAndStates.defineStateForms();
BurgsAndStates.generateProvinces();
// BurgsAndStates.defineBurgFeatures();
// update burg list
//const validBurgs = new Set(pack.cells.burgs);
// remove non-existent burgs
pack.burgs = baseState.pack.burgs
// .filter(b => validBurgs.has(b.i))
const [[xmin, ymin], [xmax, ymax]] = getViewBoxExtent();
const inMap = (x,y) => x>xmin && x<xmax && y>ymin && y<ymax;
// remap burgs to the best new cell
pack.burgs.forEach((b, i) => {
[b.x, b.y] = projection(b.x, b.y);
[b.x,b.y] = projection(b.x, b.y);
if (!inMap(b.x,b.y)) {
// out-of-map (removed) burgs' cell will be undefined
console.log('burg is out of map:', b)
b.removed=true;
b.cell = undefined;
return;
}
b.cell = findCell(b.x, b.y);
pack.cells.burg[b.cell] = i;
// TODO: move port burgs to coast b.x, b.y,
});
BurgsAndStates.generateProvinces();
drawStates();
drawBorders();
BurgsAndStates.drawStateLabels();
@ -155,5 +165,6 @@ window.Submap = (function () {
INFO && console.groupEnd("Generated Map " + seed);
}
// export
return { resample }
})();

View file

@ -27,8 +27,8 @@ const generateSubmap = debounce(function (x, y, w, h) {
progress: p => progressUI.innerHTML = p,
}
const [[x0, y0], [x1, y1]] = getViewBoxExtent();
const projection = (x, y) => {
const [[x0, y0], [x1, y1]] = getViewBoxExtent();
return [x * (x1-x0) / graphWidth + x0, y * (y1-y0) / graphHeight + y0]
}