feat: Update main.js and modules/io/load.js versions to 1.99.00

This commit is contained in:
Azgaar 2024-07-29 12:59:28 +02:00
parent 06c4f78c35
commit 66004de6f4
5 changed files with 98 additions and 28 deletions

View file

@ -8134,7 +8134,7 @@
<script src="modules/ui/general.js?v=1.98.01"></script> <script src="modules/ui/general.js?v=1.98.01"></script>
<script src="modules/ui/options.js?v=1.98.04"></script> <script src="modules/ui/options.js?v=1.98.04"></script>
<script src="main.js?v=1.98.05"></script> <script src="main.js?v=1.99.00"></script>
<script defer src="modules/relief-icons.js"></script> <script defer src="modules/relief-icons.js"></script>
<script defer src="modules/ui/style.js?v=1.96.00"></script> <script defer src="modules/ui/style.js?v=1.96.00"></script>
@ -8176,7 +8176,7 @@
<script defer src="libs/rgbquant.min.js"></script> <script defer src="libs/rgbquant.min.js"></script>
<script defer src="libs/jquery.ui.touch-punch.min.js"></script> <script defer src="libs/jquery.ui.touch-punch.min.js"></script>
<script defer src="modules/io/save.js?v=1.99.00"></script> <script defer src="modules/io/save.js?v=1.99.00"></script>
<script defer src="modules/io/load.js?v=1.98.01"></script> <script defer src="modules/io/load.js?v=1.99.00"></script>
<script defer src="modules/io/cloud.js?v=1.96.00"></script> <script defer src="modules/io/cloud.js?v=1.96.00"></script>
<script defer src="modules/io/export.js?v=1.98.05"></script> <script defer src="modules/io/export.js?v=1.98.05"></script>

63
main.js
View file

@ -311,35 +311,48 @@ async function checkLoadParameters() {
} }
function debugGrids() { function debugGrids() {
debug // debug
.selectAll("circle.grid") // .selectAll("circle.grid")
.data(grid.points) // .data(grid.points)
.enter() // .enter()
.append("circle") // .append("circle")
.attr("data-id", (d, i) => "point-" + i) // .attr("data-id", (d, i) => "point-" + i)
.attr("cx", d => d[0]) // .attr("cx", d => d[0])
.attr("cy", d => d[1]) // .attr("cy", d => d[1])
.attr("r", 0.5) // .attr("r", 0.5)
.attr("fill", "blue"); // .attr("fill", "blue");
let path = ""; let path = "";
grid.cells.i.forEach(i => (path += "M" + getGridPolygon(i))); grid.cells.i.forEach(i => (path += "M" + getGridPolygon(i)));
debug.append("path").attr("fill", "none").attr("stroke", "blue").attr("stroke-width", 0.3).attr("d", path); debug.append("path").attr("fill", "none").attr("stroke", "blue").attr("stroke-width", 0.3).attr("d", path);
debug // debug
.selectAll("circle.boundary") // .selectAll("circle.boundary")
.data(grid.boundary) // .data(grid.boundary)
.enter() // .enter()
.append("circle") // .append("circle")
.attr("cx", d => d[0]) // .attr("cx", d => d[0])
.attr("cy", d => d[1]) // .attr("cy", d => d[1])
.attr("r", 0.3) // .attr("r", 0.3)
.attr("fill", "white"); // .attr("fill", "white");
zoom.translateExtent([ zoom.translateExtent([
[-graphWidth / 2, -graphHeight / 2], [-graphWidth / 2, -graphHeight / 2],
[graphWidth * 1.5, graphHeight * 1.5] [graphWidth * 1.5, graphHeight * 1.5]
]); ]);
const text = debug
.append("g")
.style("font-size", "0.5px")
.attr("text-anchor", "middle")
.attr("dominant-baseline", "central");
for (let x = 0; x < 100; x++) {
for (let y = 0; y < 100; y++) {
const cellId = findGridCell(x, y, grid);
text.append("text").attr("x", x).attr("y", y).text(cellId);
}
}
} }
async function generateMapOnLoad() { async function generateMapOnLoad() {
@ -1068,12 +1081,12 @@ function generatePrecipitation() {
// define wind directions based on cells latitude and prevailing winds there // define wind directions based on cells latitude and prevailing winds there
d3.range(0, cells.i.length, cellsX).forEach(function (cellId, i) { d3.range(0, cells.i.length, cellsX).forEach(function (cellId, i) {
debug // debug
.append("circle") // .append("circle")
.attr("cx", grid.points[cellId][0]) // .attr("cx", grid.points[cellId][0])
.attr("cy", grid.points[cellId][1]) // .attr("cy", grid.points[cellId][1])
.attr("r", 2) // .attr("r", 2)
.attr("fill", "blue"); // .attr("fill", "blue");
const lat = mapCoordinates.latN - (i / cellsY) * mapCoordinates.latT; const lat = mapCoordinates.latN - (i / cellsY) * mapCoordinates.latT;
const latBand = ((Math.abs(lat) - 1) / 5) | 0; const latBand = ((Math.abs(lat) - 1) / 5) | 0;

View file

@ -120,6 +120,8 @@ function showMapTooltip(point, e, i, g) {
const subgroup = path[path.length - 8].id; const subgroup = path[path.length - 8].id;
const land = pack.cells.h[i] >= 20; const land = pack.cells.h[i] >= 20;
// console.log(findGridCell(point[0], point[1], grid));
// specific elements // specific elements
if (group === "armies") return tip(e.target.parentNode.dataset.name + ". Click to edit"); if (group === "armies") return tip(e.target.parentNode.dataset.name + ". Click to edit");

View file

@ -45,6 +45,61 @@ function calculateVoronoi(points, boundary) {
// return cell index on a regular square grid // return cell index on a regular square grid
function findGridCell(x, y, grid) { function findGridCell(x, y, grid) {
if (grid.type === "hexFlat") return findHexCellIndex(x, y, false, grid.spacing, grid.cellsX);
if (grid.type === "hexPointy") return findHexCellIndex(x, y, true, grid.spacing, grid.cellsX);
return findSquareGridCell(x, y, grid);
}
const hexRatio = Math.sqrt(3) / 2;
function findHexCellIndex(x, y, isPointy, spacing, cellsX) {
const spacingX = isPointy ? spacing / hexRatio : spacing * 2;
const spacingY = isPointy ? spacing : spacing / hexRatio / 2;
let col = Math.floor(x / spacingX);
let row = Math.floor((y + spacingY * 1.5) / spacingY);
if (isPointy) {
if (row % 2 === 1 && x < col * spacingX + spacingX / 2) col -= 1;
} else {
if (col % 2 === 1 && y < row * spacingY + spacingY / 2) row -= 1;
}
const suspect = row * cellsX + col;
const candidates = isPointy
? [
suspect,
suspect - cellsX - 1,
suspect - cellsX,
suspect - 1,
suspect + 1,
suspect + cellsX - 1,
suspect + cellsX
]
: [
suspect,
suspect - cellsX,
suspect - cellsX * 2,
suspect - cellsX + 1,
suspect + cellsX,
suspect + cellsX + 1,
suspect + cellsX * 2
];
const closest = candidates.reduce(
(acc, candidate) => {
const point = grid.points[candidate];
if (!point) return acc;
const dist2 = Math.abs(x - point[0]) + Math.abs(y - point[1]);
if (dist2 < acc.dist2) return {dist2, cell: candidate};
return acc;
},
{dist2: Infinity, cell: suspect}
);
return closest.cell;
}
function findSquareGridCell(x, y, grid) {
return ( return (
Math.floor(Math.min(y / grid.spacing, grid.cellsY - 1)) * grid.cellsX + Math.floor(Math.min(y / grid.spacing, grid.cellsY - 1)) * grid.cellsX +
Math.floor(Math.min(x / grid.spacing, grid.cellsX - 1)) Math.floor(Math.min(x / grid.spacing, grid.cellsX - 1))

View file

@ -1,7 +1,7 @@
"use strict"; "use strict";
// version and caching control // version and caching control
const version = "1.98.05"; // generator version, update each time const version = "1.99.00"; // generator version, update each time
{ {
document.title += " v" + version; document.title += " v" + version;