57 lines
2.6 KiB
JavaScript
57 lines
2.6 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { generateMap } from './mapGenerator.js';
|
|
import { createWorldMap } from './worldMap.js';
|
|
import { generatePatch } from './mapPatch.js';
|
|
|
|
function footprintContains(fp, x, y) {
|
|
if (!fp || x < fp.x0 || y < fp.y0 || x >= fp.x1 || y >= fp.y1) return false;
|
|
const row = fp.rowRuns?.[y - fp.y0];
|
|
if (!Array.isArray(row)) return false;
|
|
for (let i = 0; i + 1 < row.length; i += 2) if (x >= row[i] && x < row[i + 1]) return true;
|
|
return false;
|
|
}
|
|
function recordContains(record, x, y) {
|
|
if (record?.generatedFootprint) return footprintContains(record.generatedFootprint, x, y);
|
|
const r = record?.coreRect || record;
|
|
return !!r && x >= r.x0 && y >= r.y0 && x < r.x1 && y < r.y1;
|
|
}
|
|
function generatedAt(world, x, y) {
|
|
return (world.generatedRects || []).some(record => recordContains(record, x, y));
|
|
}
|
|
|
|
const world = createWorldMap(generateMap(24681357, { terrainType: 'auto', onProgress() {} }));
|
|
// This is the exact in-world rectangle produced by the previously failing
|
|
// bottom-right overlap case after validation/clipping. Before the real-frontier
|
|
// portal fix, a minor road wholly inside established geography was mistaken for
|
|
// an expansion seam portal and the whole operation rolled back.
|
|
const rect = { x0: 345, y0: 257, x1: 774, y1: 549 };
|
|
const needed = [];
|
|
for (let y = rect.y0; y < rect.y1; y++) {
|
|
for (let x = rect.x0; x < rect.x1; x++) if (!generatedAt(world, x, y)) needed.push([x, y]);
|
|
}
|
|
const startedAt = Date.now();
|
|
const result = generatePatch(world, rect, {
|
|
patchMode: 'expansion', terrainType: 'auto', seed: 0x4a35b921, variant: 1,
|
|
maxQualityRetries: 0, qualityTerrainAttempts: 1, acceptBestAvailableQuality: true,
|
|
onProgress() {},
|
|
});
|
|
assert.equal(result?.ok, true, result?.reason || result?.code || 'patch failed');
|
|
assert.equal(result?.seamDiagnostics?.hardPass, true, 'seam hard gate failed');
|
|
assert.equal(result?.seamDiagnostics?.roadPortalsBroken || 0, 0, 'false road portal remained');
|
|
let missing = 0;
|
|
for (const [x, y] of needed) if (!generatedAt(world, x, y)) missing++;
|
|
assert.equal(missing, 0, `missing ${missing} previously-ungenerated selected cells`);
|
|
console.log(JSON.stringify({
|
|
ok: true,
|
|
rect,
|
|
selectedCells: (rect.x1 - rect.x0) * (rect.y1 - rect.y0),
|
|
previouslyUngeneratedSelectedCells: needed.length,
|
|
missingPreviouslyUngeneratedCells: missing,
|
|
tileCount: result?.tileCount || 1,
|
|
roadPortalsBefore: result?.seamDiagnostics?.roadPortalsBefore || 0,
|
|
roadPortalsBroken: result?.seamDiagnostics?.roadPortalsBroken || 0,
|
|
seam: result?.seamDiagnostics?.status || null,
|
|
hardPass: result?.seamDiagnostics?.hardPass ?? null,
|
|
ms: Date.now() - startedAt,
|
|
}, null, 2));
|
|
process.exit(0);
|