This commit is contained in:
33333-33333 2026-05-28 23:51:55 +09:00
commit 112e6bf86b
11 changed files with 1586 additions and 1253 deletions

View file

@ -30,6 +30,8 @@ const NEGATIVE_ONE_FIELDS = new Set([
"prefectureRegionId",
"regionId",
"municipalityId",
"naturalCompartmentId",
"watershedId",
]);
function isCellField(value) {
@ -133,9 +135,50 @@ function transformSegments(segments, camera, originX, originY) {
.filter(segmentIntersectsViewport);
}
function transformTransportDebug(debug, camera, originX, originY) {
function copySourceMapViewportField(source, camera, originX, originY, viewWidth, viewHeight) {
if (!ArrayBuffer.isView(source) || typeof source.length !== "number" || source.length !== SIZE) return source;
const out = new source.constructor(viewWidth * viewHeight);
const cx = Math.round(camera.x || 0);
const cy = Math.round(camera.y || 0);
for (let y = 0; y < viewHeight; y++) {
for (let x = 0; x < viewWidth; x++) {
const sx = cx + x - originX;
const sy = cy + y - originY;
if (sx >= 0 && sy >= 0 && sx < MAP_W && sy < MAP_H) out[y * viewWidth + x] = source[sy * MAP_W + sx];
}
}
return out;
}
function transformTransportDebug(debug, camera, originX, originY, viewport = null) {
if (!debug?.layers) return debug;
const layers = { ...debug.layers };
for (const [key, value] of Object.entries(layers)) {
if (ArrayBuffer.isView(value) && value.length === SIZE) layers[key] = copySourceMapViewportField(value, camera, originX, originY, MAP_W, MAP_H);
}
// The original transport-debug potential layers are fixed-map arrays. Once the
// viewport pans into patched world cells, synthesize equivalent viewport-sized
// debug fields from the current world-backed fields so the color overlay moves
// with the terrain instead of staying tied to the initial source map.
if (viewport) {
const n = MAP_W * MAP_H;
const make = (fn) => {
const out = new Float32Array(n);
for (let i = 0; i < n; i++) out[i] = fn(i);
return out;
};
const sea = viewport.sea || new Uint8Array(n);
const slope = viewport.slope || new Float32Array(n);
const plain = viewport.plain || new Float32Array(n);
const pop = viewport.populationDensity || viewport.settlementScore || new Float32Array(n);
const road = viewport.roadInfluence || new Float32Array(n);
const rail = viewport.railInfluence2 || viewport.stationInfluence || new Float32Array(n);
layers.expresswayPotential = make((i) => sea[i] ? 0 : Math.max(0, Math.min(1, road[i] * 0.72 + pop[i] * 0.42 + plain[i] * 0.22 - slope[i] * 0.52)));
layers.nationalRoadPotential = make((i) => sea[i] ? 0 : Math.max(0, Math.min(1, road[i] * 0.58 + pop[i] * 0.55 + plain[i] * 0.18 - slope[i] * 0.38)));
layers.railPotential = make((i) => sea[i] ? 0 : Math.max(0, Math.min(1, rail[i] * 0.72 + pop[i] * 0.38 + plain[i] * 0.26 - slope[i] * 0.72)));
layers.slopeSeaPenalty = make((i) => sea[i] ? 1 : Math.max(0, Math.min(1, slope[i] * 1.35)));
}
if (Array.isArray(layers.components)) {
layers.components = layers.components.map((component) => ({
...component,
@ -191,7 +234,7 @@ export function getViewportMap(world, camera, viewWidth = MAP_W, viewHeight = MA
lowlandAdminSeeds: transformPointArray(sourceMap.adminDebug.lowlandAdminSeeds || [], normalizedCamera, originX, originY),
};
}
if (sourceMap.transportDebug) viewport.transportDebug = transformTransportDebug(sourceMap.transportDebug, normalizedCamera, originX, originY);
if (sourceMap.transportDebug) viewport.transportDebug = transformTransportDebug(sourceMap.transportDebug, normalizedCamera, originX, originY, viewport);
if (sourceMap.neighborPrefectureDetails) {
viewport.neighborPrefectureDetails = {
...sourceMap.neighborPrefectureDetails,