hoi4-agent-tools 4.21.0 → 4.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/README.md +3 -1
- package/dist/bin/setup.js +1 -0
- package/dist/bin/stdio.js +1 -0
- package/dist/hoi4_agent_tools/common-write/documented-lists.js +62 -0
- package/dist/hoi4_agent_tools/common-write/limits.js +35 -0
- package/dist/hoi4_agent_tools/common-write/paths.js +17 -0
- package/dist/hoi4_agent_tools/common-write/write-job-operations.js +42 -0
- package/dist/hoi4_agent_tools/common-write/write-operations.js +360 -0
- package/dist/hoi4_agent_tools/common-write/write-plan.js +34 -0
- package/dist/hoi4_agent_tools/core/bounded-source.js +1 -1
- package/dist/hoi4_agent_tools/core/domain-tools.js +8 -0
- package/dist/hoi4_agent_tools/core/engine-client.js +3 -1
- package/dist/hoi4_agent_tools/core/image-diff.js +1 -1
- package/dist/hoi4_agent_tools/core/job-controls.js +12 -2
- package/dist/hoi4_agent_tools/core/job-executor.js +8 -7
- package/dist/hoi4_agent_tools/core/job-operation-registration.js +4 -0
- package/dist/hoi4_agent_tools/core/job-store.js +97 -5
- package/dist/hoi4_agent_tools/core/job-worker-host.js +2 -2
- package/dist/hoi4_agent_tools/core/lazy-native.js +26 -0
- package/dist/hoi4_agent_tools/core/operation-result.js +118 -33
- package/dist/hoi4_agent_tools/core/operation-tasks.js +1 -1
- package/dist/hoi4_agent_tools/core/svg-text.js +1 -1
- package/dist/hoi4_agent_tools/core/workspace.js +11 -1
- package/dist/hoi4_agent_tools/country/job-operations.js +42 -0
- package/dist/hoi4_agent_tools/country/write-operations.js +646 -0
- package/dist/hoi4_agent_tools/country/write-plan.js +28 -0
- package/dist/hoi4_agent_tools/event/render.js +1 -1
- package/dist/hoi4_agent_tools/focus/continuous-render.js +1 -1
- package/dist/hoi4_agent_tools/focus/game-view-output.js +1 -1
- package/dist/hoi4_agent_tools/focus/limits.js +3 -0
- package/dist/hoi4_agent_tools/focus/quality/schematic.js +1 -1
- package/dist/hoi4_agent_tools/focus/render.js +3 -3
- package/dist/hoi4_agent_tools/gui/assets.js +2 -2
- package/dist/hoi4_agent_tools/gui/limits.js +2 -0
- package/dist/hoi4_agent_tools/gui/renderer.js +1 -1
- package/dist/hoi4_agent_tools/gui/studio.js +2 -4
- package/dist/hoi4_agent_tools/map/engine-validation.js +1 -1
- package/dist/hoi4_agent_tools/map/geography/preview.js +1 -1
- package/dist/hoi4_agent_tools/map/landmass-source.js +42 -0
- package/dist/hoi4_agent_tools/map/landmass.js +190 -0
- package/dist/hoi4_agent_tools/map/operations.js +20 -6
- package/dist/hoi4_agent_tools/map/reference-import.js +1 -1
- package/dist/hoi4_agent_tools/map/reference-labels.js +1 -1
- package/dist/hoi4_agent_tools/map/reference-preparation.js +1 -1
- package/dist/hoi4_agent_tools/map/reference-world.js +1 -1
- package/dist/hoi4_agent_tools/map/references.js +6 -3
- package/dist/hoi4_agent_tools/map/render.js +1 -1
- package/dist/hoi4_agent_tools/map/service.js +88 -8
- package/dist/hoi4_agent_tools/map/world-preview.js +1 -1
- package/dist/hoi4_agent_tools/mcp/server/argument-errors.js +2 -0
- package/dist/hoi4_agent_tools/mcp/server/create-modern-operations.js +1 -1
- package/dist/hoi4_agent_tools/mcp/server/create.js +4 -0
- package/dist/hoi4_agent_tools/mcp/server/task-tool-catalog.js +4 -0
- package/dist/hoi4_agent_tools/mcp/tools/common-write.js +21 -0
- package/dist/hoi4_agent_tools/mcp/tools/country-write.js +21 -0
- package/dist/hoi4_agent_tools/mcp/tools/focus.js +3 -2
- package/dist/hoi4_agent_tools/mcp/tools/map.js +1 -1
- package/dist/hoi4_agent_tools/mcp/transports/http.js +2 -0
- package/dist/hoi4_agent_tools/probability/render.js +1 -1
- package/dist/hoi4_agent_tools/reference/known-mistakes.js +65 -0
- package/dist/hoi4_agent_tools/reference/known-mistakes.json +19 -0
- package/dist/hoi4_agent_tools/reference/operations.js +15 -2
- package/dist/hoi4_agent_tools/runtime.js +79 -1
- package/dist/hoi4_agent_tools/schemas/character-write.js +5 -1
- package/dist/hoi4_agent_tools/schemas/common-write.js +74 -0
- package/dist/hoi4_agent_tools/schemas/country-write.js +206 -0
- package/dist/hoi4_agent_tools/schemas/decision-write.js +5 -1
- package/dist/hoi4_agent_tools/schemas/doctrine-write.js +5 -1
- package/dist/hoi4_agent_tools/schemas/event-write.js +5 -1
- package/dist/hoi4_agent_tools/schemas/focus-requests.js +1 -1
- package/dist/hoi4_agent_tools/schemas/gui-requests.js +2 -1
- package/dist/hoi4_agent_tools/schemas/idea-write.js +5 -1
- package/dist/hoi4_agent_tools/schemas/landmass.js +129 -0
- package/dist/hoi4_agent_tools/schemas/localisation-write.js +10 -1
- package/dist/hoi4_agent_tools/schemas/map-requests.js +1 -1
- package/dist/hoi4_agent_tools/schemas/map.js +2 -0
- package/dist/hoi4_agent_tools/schemas/tech-write.js +5 -1
- package/dist/hoi4_agent_tools/technology/render.js +1 -1
- package/dist/hoi4_agent_tools/version.js +1 -1
- package/docs/focus.md +1 -1
- package/docs/jobs.md +2 -2
- package/docs/reference.md +10 -9
- package/docs/setup.md +13 -1
- package/docs/tools.md +16 -2
- package/engine/bin/darwin-arm64/hoi4-engine +0 -0
- package/engine/bin/darwin-x64/hoi4-engine +0 -0
- package/engine/bin/linux-arm64/hoi4-engine +0 -0
- package/engine/bin/linux-x64/hoi4-engine +0 -0
- package/engine/bin/manifest.json +13 -8
- package/engine/bin/win32-x64/hoi4-engine.exe +0 -0
- package/npm-shrinkwrap.json +43 -19
- package/package.json +1 -1
- package/schemas/configuration.schema.json +1 -1
- package/schemas/continuous-focus-palette.schema.json +1 -1
- package/schemas/custom-weighted-pool.schema.json +1 -1
- package/schemas/decision-inspect-input.schema.json +1 -1
- package/schemas/error-log-input.schema.json +1 -1
- package/schemas/event-feature-manifest.schema.json +1 -1
- package/schemas/focus-plan.schema.json +1 -1
- package/schemas/focus-planning-sidecar.schema.json +1 -1
- package/schemas/geography-model.schema.json +1 -1
- package/schemas/gui-animation-source.schema.json +1 -1
- package/schemas/gui-helper.schema.json +1 -1
- package/schemas/gui-scenario.schema.json +1 -1
- package/schemas/helper-expansion-request.schema.json +1 -1
- package/schemas/helper-expansion-summary.schema.json +1 -1
- package/schemas/impact-inspect-input.schema.json +1 -1
- package/schemas/map-operation.schema.json +354 -1
- package/schemas/mechanic-test-input.schema.json +1 -1
- package/schemas/mod-index-input.schema.json +1 -1
- package/schemas/operation-result.schema.json +1 -1
- package/schemas/package-check-input.schema.json +1 -1
- package/schemas/package-manifest.schema.json +1 -1
- package/schemas/probability-analysis-result.schema.json +1 -1
- package/schemas/probability-compare-input.schema.json +1 -1
- package/schemas/probability-evaluate-input.schema.json +1 -1
- package/schemas/probability-inspect-input.schema.json +1 -1
- package/schemas/probability-render-input.schema.json +1 -1
- package/schemas/probability-scenario-set.schema.json +1 -1
- package/schemas/probability-sequence-input.schema.json +1 -1
- package/schemas/probability-simulate-input.schema.json +1 -1
- package/schemas/probability-sweep-input.schema.json +1 -1
- package/schemas/reference-context-input.schema.json +1 -1
- package/schemas/reference-read-input.schema.json +1 -1
- package/schemas/reference-search-input.schema.json +1 -1
- package/schemas/reference-sheets.schema.json +1 -1
- package/schemas/scenario-suite.schema.json +1 -1
- package/schemas/scenario-test-input.schema.json +1 -1
- package/schemas/script-validate-input.schema.json +1 -1
- package/schemas/shared-scenario.schema.json +1 -1
- package/schemas/source-lookup-input.schema.json +1 -1
- package/server.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import sharp from '
|
|
1
|
+
import sharp from '../core/lazy-native.js';
|
|
2
2
|
import { canonicalJson, compareCodeUnits, sha256Bytes } from '../core/canonical.js';
|
|
3
3
|
import { RenderBudget, RENDER_MAX_PIXELS } from '../core/render-budget.js';
|
|
4
4
|
import { DeterministicSvgTextRenderer } from '../core/svg-text.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import sharp from '
|
|
1
|
+
import sharp from '../core/lazy-native.js';
|
|
2
2
|
import { boundedSourceHashEvidence, } from '../core/artifacts.js';
|
|
3
3
|
import { canonicalJson, sha256Bytes } from '../core/canonical.js';
|
|
4
4
|
import { assertRenderDimensions, RenderBudget, RENDER_MAX_PIXELS } from '../core/render-budget.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import sharp from '
|
|
1
|
+
import sharp from '../core/lazy-native.js';
|
|
2
2
|
import { ArtifactStore, boundedSourceHashEvidence, } from '../core/artifacts.js';
|
|
3
3
|
import { canonicalJson, sha256Bytes } from '../core/canonical.js';
|
|
4
4
|
import { PACKAGE_VERSION } from '../version.js';
|
|
@@ -6,3 +6,6 @@ export const FOCUS_LAYOUT_WORK_MAX = 8_000_000;
|
|
|
6
6
|
export const FOCUS_LINT_WORK_MAX = 2_000_000;
|
|
7
7
|
export const FOCUS_DIAGNOSTIC_MAX = 2_000;
|
|
8
8
|
export const FOCUS_CYCLE_SAMPLE_MAX = 128;
|
|
9
|
+
/** The output scale a focus render accepts. Kept here so request schemas need not load the renderer. */
|
|
10
|
+
export const FOCUS_RENDER_MIN_OUTPUT_SCALE = 0.25;
|
|
11
|
+
export const FOCUS_RENDER_MAX_OUTPUT_SCALE = 1;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import sharp from '
|
|
1
|
+
import sharp from '../../core/lazy-native.js';
|
|
2
2
|
import { compareCodeUnits } from '../../core/canonical.js';
|
|
3
3
|
import { RENDER_MAX_PIXELS } from '../../core/render-budget.js';
|
|
4
4
|
import { DeterministicSvgTextRenderer } from '../../core/svg-text.js';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import sharp from '
|
|
1
|
+
import sharp from '../core/lazy-native.js';
|
|
2
|
+
import { FOCUS_RENDER_MAX_OUTPUT_SCALE, FOCUS_RENDER_MIN_OUTPUT_SCALE } from './limits.js';
|
|
2
3
|
import { boundedSourceHashEvidence, } from '../core/artifacts.js';
|
|
3
4
|
import { compareCodeUnits, canonicalJson, sha256Bytes } from '../core/canonical.js';
|
|
4
5
|
import { assertRenderDimensions, RenderBudget, RENDER_MAX_DECODED_PIXELS, RENDER_MAX_ENCODED_IMAGE_BYTES, RENDER_MAX_PIXELS, } from '../core/render-budget.js';
|
|
@@ -10,8 +11,7 @@ import { FOCUS_HORIZONTAL_GRID_PIXELS, FOCUS_NODE_HEIGHT_PIXELS, FOCUS_NODE_WIDT
|
|
|
10
11
|
import { createFocusPlanningSidecar, serializeFocusPlanningSidecar } from './planning.js';
|
|
11
12
|
import { FOCUS_GRAPH_MAX_EDGES, FOCUS_GRAPH_MAX_NODES } from './lint.js';
|
|
12
13
|
import { layoutNodeMap, } from './model.js';
|
|
13
|
-
export
|
|
14
|
-
export const FOCUS_RENDER_MAX_OUTPUT_SCALE = 1;
|
|
14
|
+
export { FOCUS_RENDER_MAX_OUTPUT_SCALE, FOCUS_RENDER_MIN_OUTPUT_SCALE };
|
|
15
15
|
export async function admitFocusIconDataUris(options, budget, renderedDataUris) {
|
|
16
16
|
const declaredDataUris = [
|
|
17
17
|
...Object.values(options.iconDataUris ?? {}),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import {
|
|
3
|
-
import sharp from '
|
|
2
|
+
import { createFont } from '../core/lazy-native.js';
|
|
3
|
+
import sharp from '../core/lazy-native.js';
|
|
4
4
|
import { compareCodeUnits, hashCanonical } from '../core/canonical.js';
|
|
5
5
|
import { RenderBudget, RENDER_MAX_DECODED_PIXELS } from '../core/render-budget.js';
|
|
6
6
|
import { ServiceError } from '../core/result.js';
|
|
@@ -24,3 +24,5 @@ export const GUI_BMFONT_MAX_PAGES = 256;
|
|
|
24
24
|
export const GUI_BMFONT_MAX_CHARACTERS = 32_768;
|
|
25
25
|
export const GUI_BMFONT_MAX_KERNING_PAIRS = 32_768;
|
|
26
26
|
export const GUI_BINARY_FONT_MAX_BYTES = 8_388_608;
|
|
27
|
+
export const GUI_TEXT_PACKAGE_MAX_FILES = 32;
|
|
28
|
+
export const GUI_TEXT_PACKAGE_MAX_BYTES = 16_777_216;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import sharp from '
|
|
1
|
+
import sharp from '../core/lazy-native.js';
|
|
2
2
|
import { compareCodeUnits, canonicalJson, sha256Bytes } from '../core/canonical.js';
|
|
3
3
|
import { comparePngImages } from '../core/image-diff.js';
|
|
4
4
|
import { assertRenderDimensions, RenderBudget, RENDER_MAX_PIXELS } from '../core/render-budget.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import sharp from '
|
|
1
|
+
import sharp from '../core/lazy-native.js';
|
|
2
2
|
import { readFile } from 'node:fs/promises';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { ArtifactStore, boundedSourceHashEvidence, publicArtifactLink, } from '../core/artifacts.js';
|
|
@@ -21,7 +21,7 @@ import { GuiAssetCatalog, parseBmFont } from './assets.js';
|
|
|
21
21
|
import { scenarioNeedsCountryHistory } from './native-state.js';
|
|
22
22
|
import { projectGuiGraphForArtifact } from './inspection-artifact.js';
|
|
23
23
|
import { buildGuiScene } from './layout.js';
|
|
24
|
-
import { GUI_VALIDATION_MAX_DIAGNOSTICS } from './limits.js';
|
|
24
|
+
import { GUI_TEXT_PACKAGE_MAX_BYTES, GUI_TEXT_PACKAGE_MAX_FILES, GUI_VALIDATION_MAX_DIAGNOSTICS, } from './limits.js';
|
|
25
25
|
import { compareGuiImages, galleryDimensions, renderGallerySvg, renderGuiScene, } from './renderer.js';
|
|
26
26
|
import { generatedCountryTags, generateGuiPreviewScenarios, resolveScenarioScriptedLocalisation, } from './scenario-generator.js';
|
|
27
27
|
import { parseGeneratedScenarioOptions, parsePreviewScenario } from './scenario.js';
|
|
@@ -39,8 +39,6 @@ const staticGuiDefinitionPatterns = [
|
|
|
39
39
|
'fonts/**/*.{gfx,txt}',
|
|
40
40
|
'hoi4_agent/animation_sources/**/*.json',
|
|
41
41
|
];
|
|
42
|
-
export const GUI_TEXT_PACKAGE_MAX_FILES = 32;
|
|
43
|
-
export const GUI_TEXT_PACKAGE_MAX_BYTES = 16_777_216;
|
|
44
42
|
const GUI_TRANSACTION_PHASE_DIAGNOSTIC_BUDGET = Math.floor(TRANSACTION_MAX_DIAGNOSTICS / 3);
|
|
45
43
|
function hardDiagnostic(diagnostic) {
|
|
46
44
|
return diagnostic.severity === 'error' || diagnostic.severity === 'blocker';
|
|
@@ -226,5 +226,5 @@ export function engineMapOperationSync(op, request, schema, fromPayload) {
|
|
|
226
226
|
const length = typeof announced === 'number' && Number.isSafeInteger(announced) ? announced : 0;
|
|
227
227
|
if (length < 0 || answer.length < newline + 1 + length)
|
|
228
228
|
throw unavailable(`hoi4-engine ${op} answered a short payload`, 'invalid_output');
|
|
229
|
-
return fromPayload(answer.subarray(newline + 1, newline + 1 + length));
|
|
229
|
+
return fromPayload(answer.subarray(newline + 1, newline + 1 + length), parsed.data);
|
|
230
230
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { sha256Bytes } from '../core/canonical.js';
|
|
2
|
+
import { ServiceError } from '../core/result.js';
|
|
3
|
+
import { prepareSource, readBoundedFile, verifySource } from '../core/scanner.js';
|
|
4
|
+
/** Largest `add_landmass` mask image (a full-size 24-bit bitmap of the largest map fits). */
|
|
5
|
+
export const LANDMASS_MASK_MAX_BYTES = 256 * 1024 * 1024;
|
|
6
|
+
/**
|
|
7
|
+
* Read an `add_landmass` mask image from the workspace's own mod root, through the same
|
|
8
|
+
* canonical-path and stale-source checks as every other workspace source.
|
|
9
|
+
*/
|
|
10
|
+
export async function readLandmassMask(resolver, workspaceId, requestedPath, principal, signal) {
|
|
11
|
+
const relativePath = requestedPath.replaceAll('\\', '/');
|
|
12
|
+
if (!/\.(?:png|tga|dds|bmp)$/iu.test(relativePath) || relativePath.includes(':'))
|
|
13
|
+
throw new ServiceError('MAP_LANDMASS_MASK_PATH_INVALID', 'maskImage.path must name a workspace-relative .png, .tga, .dds or .bmp file');
|
|
14
|
+
const resolved = await resolver.resolvePath(workspaceId, relativePath, 'read', ['mod'], principal);
|
|
15
|
+
const source = await prepareSource(resolved.root, relativePath, signal);
|
|
16
|
+
try {
|
|
17
|
+
if (!source.metadata.isFile())
|
|
18
|
+
throw new ServiceError('SOURCE_NOT_REGULAR_FILE', 'The mask image must be a regular file');
|
|
19
|
+
if (source.metadata.size < 1 || source.metadata.size > LANDMASS_MASK_MAX_BYTES)
|
|
20
|
+
throw new ServiceError('MAP_LANDMASS_MASK_TOO_LARGE', `The mask image must hold between 1 byte and ${LANDMASS_MASK_MAX_BYTES} bytes`, { limit: LANDMASS_MASK_MAX_BYTES });
|
|
21
|
+
const bytes = await readBoundedFile(source.handle, LANDMASS_MASK_MAX_BYTES, signal);
|
|
22
|
+
await verifySource(resolved.root, source);
|
|
23
|
+
const sha256 = sha256Bytes(bytes);
|
|
24
|
+
const displayPath = `mod:${relativePath}`;
|
|
25
|
+
return {
|
|
26
|
+
prepared: { displayPath, sha256, bytes },
|
|
27
|
+
evidence: {
|
|
28
|
+
absolutePath: source.canonicalPath,
|
|
29
|
+
displayPath,
|
|
30
|
+
relativePath,
|
|
31
|
+
rootKind: resolved.root.kind,
|
|
32
|
+
loadOrder: resolved.root.loadOrder,
|
|
33
|
+
size: source.metadata.size,
|
|
34
|
+
modifiedMs: source.metadata.mtimeMs,
|
|
35
|
+
sha256,
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
await source.handle.close();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { z } from 'zod/v4';
|
|
2
|
+
import { ServiceError } from '../core/result.js';
|
|
3
|
+
import { engineMapOperationSync, mapValidateRequest } from './engine-validation.js';
|
|
4
|
+
import { nodeLocation } from '../core/source/index.js';
|
|
5
|
+
import { collectMapScriptReferences, mapReferenceScriptFile } from './references.js';
|
|
6
|
+
/**
|
|
7
|
+
* `add_landmass` (packet T4) on the engine: `map.add_landmass` plans an island with relief in
|
|
8
|
+
* open sea (provinces, heightmap, terrain, rivers, trees, normal and colour maps, states, its own
|
|
9
|
+
* strategic region, weather, positions and supply) from the scanned map files and returns every
|
|
10
|
+
* changed file. The map rewrite then validates the whole map against its baseline and writes the
|
|
11
|
+
* plan as one transaction, as for every map operation. Nothing falls back to TypeScript.
|
|
12
|
+
*/
|
|
13
|
+
export const MAP_ADD_LANDMASS_OP = 'map.add_landmass';
|
|
14
|
+
const answerSchema = z
|
|
15
|
+
.object({
|
|
16
|
+
files: z.array(z
|
|
17
|
+
.object({
|
|
18
|
+
relativePath: z.string().min(1),
|
|
19
|
+
beforeSha256: z.string().nullable(),
|
|
20
|
+
length: z.number().int().min(0),
|
|
21
|
+
mediaType: z.string().min(1),
|
|
22
|
+
})
|
|
23
|
+
.strict()),
|
|
24
|
+
summary: z.record(z.string(), z.unknown()),
|
|
25
|
+
warnings: z.array(z.looseObject({ code: z.string(), message: z.string() })),
|
|
26
|
+
changedBounds: z
|
|
27
|
+
.object({
|
|
28
|
+
minX: z.number().int(),
|
|
29
|
+
minY: z.number().int(),
|
|
30
|
+
maxX: z.number().int(),
|
|
31
|
+
maxY: z.number().int(),
|
|
32
|
+
count: z.number().int().min(0),
|
|
33
|
+
})
|
|
34
|
+
.strict(),
|
|
35
|
+
})
|
|
36
|
+
.strict();
|
|
37
|
+
/** Typed arrays as plain arrays, so the resolved geography reads the same in the engine. */
|
|
38
|
+
function plainGeography(geography) {
|
|
39
|
+
return JSON.parse(JSON.stringify(geography, (_key, value) => ArrayBuffer.isView(value) && !(value instanceof DataView)
|
|
40
|
+
? Array.from(value)
|
|
41
|
+
: value instanceof Map
|
|
42
|
+
? undefined
|
|
43
|
+
: value));
|
|
44
|
+
}
|
|
45
|
+
/** The English names an island writes: its states, their capitals' victory points and its region. */
|
|
46
|
+
export function landmassLocalisation(operation, summary) {
|
|
47
|
+
const file = operation.localisation?.file ??
|
|
48
|
+
`localisation/english/map_landmass_${operation.id.replace(/[^A-Za-z0-9_]/gu, '_').toLowerCase()}_l_english.yml`;
|
|
49
|
+
const region = Number(summary.strategicRegion);
|
|
50
|
+
const regionName = operation.region.name ?? 'Island';
|
|
51
|
+
const states = summary.stateCapitals ?? [];
|
|
52
|
+
const entries = [];
|
|
53
|
+
states.forEach(({ state, capital, victoryPoints }, index) => {
|
|
54
|
+
const name = operation.states.names?.[index] ??
|
|
55
|
+
(states.length === 1 ? regionName : `${regionName} ${index + 1}`);
|
|
56
|
+
entries.push({ key: `STATE_${state}`, value: name, file });
|
|
57
|
+
if (victoryPoints)
|
|
58
|
+
entries.push({ key: `VICTORY_POINTS_${capital}`, value: name, file });
|
|
59
|
+
});
|
|
60
|
+
if (Number.isInteger(region))
|
|
61
|
+
entries.push({ key: `STRATEGICREGION_${region}`, value: regionName, file });
|
|
62
|
+
return entries;
|
|
63
|
+
}
|
|
64
|
+
export function planAddLandmass(index, operation, geography, mask) {
|
|
65
|
+
if (geography === undefined)
|
|
66
|
+
throw new ServiceError('MAP_GEOGRAPHY_NOT_PREPARED', 'Geography models must be prepared by the authorized workspace service');
|
|
67
|
+
if (!geography.valid)
|
|
68
|
+
throw new ServiceError('MAP_GEOGRAPHY_INVALID', 'The island geography has errors; fix them (see the MAP_GEOGRAPHY_* diagnostics) before adding it', { modelHash: geography.geography.hash });
|
|
69
|
+
if ((operation.maskImage === undefined) !== (mask === undefined))
|
|
70
|
+
throw new ServiceError('MAP_LANDMASS_MASK_NOT_PREPARED', 'The mask image was not prepared');
|
|
71
|
+
const request = mapValidateRequest(index);
|
|
72
|
+
// The localisation file is the adapter's (it writes the names); the engine plans the map only.
|
|
73
|
+
const { geography: _inline, geographyPath: _path, maskImage, localisation: _localisation, ...rest } = operation;
|
|
74
|
+
const body = {
|
|
75
|
+
files: request.body.files,
|
|
76
|
+
sourceRoots: request.body.sourceRoots,
|
|
77
|
+
operation: {
|
|
78
|
+
...rest,
|
|
79
|
+
geography: plainGeography(geography.geography),
|
|
80
|
+
...(maskImage === undefined || mask === undefined
|
|
81
|
+
? {}
|
|
82
|
+
: {
|
|
83
|
+
maskImage: {
|
|
84
|
+
displayPath: mask.displayPath,
|
|
85
|
+
sha256: mask.sha256,
|
|
86
|
+
size: mask.bytes.length,
|
|
87
|
+
x: maskImage.x,
|
|
88
|
+
y: maskImage.y,
|
|
89
|
+
},
|
|
90
|
+
}),
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
const payload = mask === undefined ? request.payload : Buffer.concat([request.payload, mask.bytes]);
|
|
94
|
+
const plan = engineMapOperationSync(MAP_ADD_LANDMASS_OP, { body, payload }, answerSchema, (bytes, answer) => {
|
|
95
|
+
const changes = [];
|
|
96
|
+
let at = 0;
|
|
97
|
+
for (const file of answer.files) {
|
|
98
|
+
if (at + file.length > bytes.length)
|
|
99
|
+
throw new ServiceError('ENGINE_UNAVAILABLE', 'hoi4-engine map.add_landmass answered a short payload', {
|
|
100
|
+
op: MAP_ADD_LANDMASS_OP,
|
|
101
|
+
reason: 'invalid_output',
|
|
102
|
+
});
|
|
103
|
+
changes.push({
|
|
104
|
+
relativePath: file.relativePath,
|
|
105
|
+
content: Buffer.from(bytes.subarray(at, at + file.length)),
|
|
106
|
+
mediaType: file.mediaType,
|
|
107
|
+
});
|
|
108
|
+
at += file.length;
|
|
109
|
+
}
|
|
110
|
+
const diagnostics = answer.warnings.map((warning) => ({
|
|
111
|
+
code: warning.code,
|
|
112
|
+
severity: warning.severity === 'info' ? 'info' : 'warning',
|
|
113
|
+
category: 'map',
|
|
114
|
+
message: warning.message,
|
|
115
|
+
operationId: operation.id,
|
|
116
|
+
...(typeof warning.details === 'object' && warning.details !== null
|
|
117
|
+
? { details: warning.details }
|
|
118
|
+
: {}),
|
|
119
|
+
}));
|
|
120
|
+
diagnostics.push({
|
|
121
|
+
code: 'MAP_LANDMASS_ADDED',
|
|
122
|
+
severity: 'info',
|
|
123
|
+
category: 'map',
|
|
124
|
+
message: `Added an island of ${String(answer.summary.provinces?.land ?? 0)} land province(s) with its own strategic region ${String(answer.summary.strategicRegion)}`,
|
|
125
|
+
operationId: operation.id,
|
|
126
|
+
details: answer.summary,
|
|
127
|
+
});
|
|
128
|
+
return { changes, bounds: answer.changedBounds, diagnostics, summary: answer.summary };
|
|
129
|
+
});
|
|
130
|
+
const absorbed = plan.summary.seaProvincesAbsorbed;
|
|
131
|
+
if (Array.isArray(absorbed) && absorbed.length > 0)
|
|
132
|
+
refuseAbsorbedSeaReferences(index.sourceFiles, absorbed.filter((id) => typeof id === 'number'));
|
|
133
|
+
return plan;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Script files read for references to an absorbed sea province: the map reference folders
|
|
137
|
+
* (`MAP_REFERENCE_SCRIPT_PATTERNS`: events, focuses, decisions, scripted helpers, on-actions,
|
|
138
|
+
* ideas, characters, AI, country and unit history) and every other script under `common/`.
|
|
139
|
+
*/
|
|
140
|
+
export function absorbedSeaScriptFile(relativePath) {
|
|
141
|
+
return (mapReferenceScriptFile(relativePath) ||
|
|
142
|
+
/^common\/.+\.txt$/iu.test(relativePath.replaceAll('\\', '/')));
|
|
143
|
+
}
|
|
144
|
+
/** Whether `text` holds `id` as a whole number token (not part of a longer number, word or decimal). */
|
|
145
|
+
function namesNumber(text, id) {
|
|
146
|
+
const match = new RegExp(`(?<![\\w.])${String(id)}(?![\\w.])`, 'u').exec(text);
|
|
147
|
+
return match === null ? undefined : text.slice(0, match.index).split('\n').length;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Script and unit-history references to the sea provinces an island absorbs
|
|
151
|
+
* (`absorbCoveredSeaProvinces`): fleets based or located there, and every event, focus, decision,
|
|
152
|
+
* scripted helper, on-action, idea, AI strategy, country history or other `common/` script that
|
|
153
|
+
* names the province. A file that does not parse is searched as text instead: it counts as a
|
|
154
|
+
* reference when it holds the province id as a whole number. The engine refuses the map-side
|
|
155
|
+
* references itself; these lie outside the map files.
|
|
156
|
+
*/
|
|
157
|
+
export function absorbedSeaReferences(files, provinces) {
|
|
158
|
+
const wanted = new Set(provinces);
|
|
159
|
+
const { references, unparsable } = collectMapScriptReferences(files, absorbedSeaScriptFile);
|
|
160
|
+
return {
|
|
161
|
+
references: references
|
|
162
|
+
.filter(({ entity, id }) => entity === 'province' && wanted.has(id))
|
|
163
|
+
.map(({ id, file, key, document, node }) => ({
|
|
164
|
+
province: id,
|
|
165
|
+
file: file.displayPath,
|
|
166
|
+
key,
|
|
167
|
+
line: nodeLocation(document, node).start.line,
|
|
168
|
+
})),
|
|
169
|
+
unparsable: unparsable.flatMap(({ file }) => {
|
|
170
|
+
const text = file.bytes.toString('latin1');
|
|
171
|
+
return provinces.flatMap((province) => {
|
|
172
|
+
const line = namesNumber(text, province);
|
|
173
|
+
return line === undefined
|
|
174
|
+
? []
|
|
175
|
+
: [{ province, file: file.displayPath, key: '(unparsable file)', line }];
|
|
176
|
+
});
|
|
177
|
+
}),
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Refuses the island when a script uses an absorbed sea province, or may: a script that does not
|
|
182
|
+
* parse and holds the province id.
|
|
183
|
+
*/
|
|
184
|
+
export function refuseAbsorbedSeaReferences(files, provinces) {
|
|
185
|
+
const { references, unparsable } = absorbedSeaReferences(files, provinces);
|
|
186
|
+
if (references.length > 0)
|
|
187
|
+
throw new ServiceError('MAP_LANDMASS_SEA_REFERENCED', `Sea province(s) ${[...new Set(references.map(({ province }) => province))].join(', ')} that the island would absorb are named by ${String(references.length)} script or unit-history reference(s); remove them or move the island`, { references });
|
|
188
|
+
if (unparsable.length > 0)
|
|
189
|
+
throw new ServiceError('MAP_LANDMASS_SEA_REFERENCED', `${String(unparsable.length)} script file(s) that do not parse hold the id of a sea province the island would absorb, so a reference cannot be ruled out; fix or check them first`, { provinces, unparsable });
|
|
190
|
+
}
|
|
@@ -2,6 +2,7 @@ import path from 'node:path';
|
|
|
2
2
|
import { setImmediate as yieldToEventLoop } from 'node:timers/promises';
|
|
3
3
|
import { lookupMapCoordinate } from './catalog.js';
|
|
4
4
|
import { canonicalJson, compareCodeUnits, deterministicId, sha256Bytes, } from '../core/canonical.js';
|
|
5
|
+
import { publicServiceErrorDetails } from '../core/operation-result.js';
|
|
5
6
|
import { ServiceError } from '../core/result.js';
|
|
6
7
|
import { applyReplacements, assignments, encodeSource, parseLocalisation, parseClausewitz, } from '../core/source/index.js';
|
|
7
8
|
import { rgbKey } from './bmp.js';
|
|
@@ -17,6 +18,7 @@ import { planWorldOutputs, refreshWorldOutputs, WORLD_OUTPUT_MANIFEST, } from '.
|
|
|
17
18
|
import { resolvePartitionMode } from './partition.js';
|
|
18
19
|
import { applyAssignTerritory, applyRepartitionStates, } from './territory-operations.js';
|
|
19
20
|
import { unsupportedGeographyParts } from './relief/index.js';
|
|
21
|
+
import { landmassLocalisation, planAddLandmass, } from './landmass.js';
|
|
20
22
|
import { resolvePaintedRelief } from './relief/painted-relief.js';
|
|
21
23
|
export function* cancellationCheckpoint(signal, iteration = 0, stride = 1) {
|
|
22
24
|
if (iteration % stride !== 0)
|
|
@@ -934,7 +936,10 @@ export function appendLocalisationEntry(document, key, value) {
|
|
|
934
936
|
return encodeSource(`${document.text}${separator}${key}: "${escapedLocalisationValue(value)}"${document.newline}`, 'utf8-bom');
|
|
935
937
|
}
|
|
936
938
|
function applyStateLocalisation(index, changes, operation, key) {
|
|
937
|
-
|
|
939
|
+
applyEnglishLocalisationPolicy(index, changes, operation.id, operation.localisation, key);
|
|
940
|
+
}
|
|
941
|
+
/** One English localisation key by an `existing` or `upsert` policy, as state creation writes it. */
|
|
942
|
+
function applyEnglishLocalisationPolicy(index, changes, operationId, policy, key) {
|
|
938
943
|
if (policy === null || typeof policy !== 'object' || Array.isArray(policy)) {
|
|
939
944
|
throw new ServiceError('MAP_STATE_LOCALISATION_POLICY_REQUIRED', 'State creation requires an explicit existing or upsert localisation policy');
|
|
940
945
|
}
|
|
@@ -978,7 +983,7 @@ function applyStateLocalisation(index, changes, operation, key) {
|
|
|
978
983
|
}
|
|
979
984
|
const replacement = localisationEntryLine(current.document, current.entry, value);
|
|
980
985
|
const text = `${current.document.text.slice(0, current.entry.start)}${replacement}${current.document.text.slice(current.entry.end)}`;
|
|
981
|
-
addChange(changes, current.file.relativePath, encodeSource(text, 'utf8-bom'),
|
|
986
|
+
addChange(changes, current.file.relativePath, encodeSource(text, 'utf8-bom'), operationId, 'text/yaml');
|
|
982
987
|
return;
|
|
983
988
|
}
|
|
984
989
|
if (requestedFile === undefined) {
|
|
@@ -987,12 +992,12 @@ function applyStateLocalisation(index, changes, operation, key) {
|
|
|
987
992
|
const relativePath = safeLocalisationRelativePath(index, requestedFile);
|
|
988
993
|
const target = index.activeFiles.byRelativePath.get(normalizeRelative(relativePath));
|
|
989
994
|
if (target === undefined) {
|
|
990
|
-
addChange(changes, relativePath, encodeSource(`l_english:\n${key}: "${escapedLocalisationValue(value)}"\n`, 'utf8-bom'),
|
|
995
|
+
addChange(changes, relativePath, encodeSource(`l_english:\n${key}: "${escapedLocalisationValue(value)}"\n`, 'utf8-bom'), operationId, 'text/yaml');
|
|
991
996
|
return;
|
|
992
997
|
}
|
|
993
998
|
const document = parseLocalisation(target.bytes, target.displayPath);
|
|
994
999
|
requireSafeLocalisationDocument(document, target.relativePath);
|
|
995
|
-
addChange(changes, target.relativePath, appendLocalisationEntry(document, key, value),
|
|
1000
|
+
addChange(changes, target.relativePath, appendLocalisationEntry(document, key, value), operationId, 'text/yaml');
|
|
996
1001
|
}
|
|
997
1002
|
function splitScalar(total, ratio, policy) {
|
|
998
1003
|
if (policy.method === 'retain-in-source')
|
|
@@ -4228,6 +4233,15 @@ function* planMapOperationSteps(base, operations, signal, context = {}) {
|
|
|
4228
4233
|
if (outputs !== undefined)
|
|
4229
4234
|
worldOutputs.push(outputs);
|
|
4230
4235
|
}
|
|
4236
|
+
else if (operation.kind === 'add_landmass') {
|
|
4237
|
+
const landmass = planAddLandmass(currentIndex(base, changes), operation, context.geographyModels?.get(operation.id), context.landmassMasks?.get(operation.id));
|
|
4238
|
+
for (const change of landmass.changes)
|
|
4239
|
+
addChange(changes, change.relativePath, change.content, operation.id, change.mediaType);
|
|
4240
|
+
for (const entry of landmassLocalisation(operation, landmass.summary))
|
|
4241
|
+
applyEnglishLocalisationPolicy(currentIndex(base, changes), changes, operation.id, { method: 'upsert', language: 'l_english', value: entry.value, file: entry.file }, entry.key);
|
|
4242
|
+
diagnostics.push(...landmass.diagnostics);
|
|
4243
|
+
expectedChangedBounds = mergeBounds(expectedChangedBounds, landmass.bounds);
|
|
4244
|
+
}
|
|
4231
4245
|
else if (operation.kind === 'move_state_provinces')
|
|
4232
4246
|
applyMoveStateProvinces(base, changes, operation);
|
|
4233
4247
|
else if (operation.kind === 'assign_territory') {
|
|
@@ -4295,7 +4309,7 @@ function* planMapOperationSteps(base, operations, signal, context = {}) {
|
|
|
4295
4309
|
operationId: operation.id,
|
|
4296
4310
|
...(Object.keys(serviceError.details).length === 0
|
|
4297
4311
|
? {}
|
|
4298
|
-
: { details: serviceError
|
|
4312
|
+
: { details: publicServiceErrorDetails(serviceError) }),
|
|
4299
4313
|
};
|
|
4300
4314
|
blockers.push(blocker);
|
|
4301
4315
|
diagnostics.push({
|
|
@@ -4345,7 +4359,7 @@ function* planMapOperationSteps(base, operations, signal, context = {}) {
|
|
|
4345
4359
|
operationId: lastOperation.id,
|
|
4346
4360
|
...(Object.keys(serviceError.details).length === 0
|
|
4347
4361
|
? {}
|
|
4348
|
-
: { details: serviceError
|
|
4362
|
+
: { details: publicServiceErrorDetails(serviceError) }),
|
|
4349
4363
|
});
|
|
4350
4364
|
diagnostics.push({
|
|
4351
4365
|
code: serviceError.code,
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Disagreement above the threshold is an error diagnostic, which blocks the write but leaves the
|
|
5
5
|
* preview and its evidence available.
|
|
6
6
|
*/
|
|
7
|
-
import sharp from '
|
|
7
|
+
import sharp from '../core/lazy-native.js';
|
|
8
8
|
import { canonicalJson } from '../core/canonical.js';
|
|
9
9
|
import { PACKAGE_VERSION } from '../version.js';
|
|
10
10
|
import { rasterizeGeographyKind } from './relief/land.js';
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import { readFile } from 'node:fs/promises';
|
|
8
8
|
import { createRequire } from 'node:module';
|
|
9
9
|
import { Worker } from 'node:worker_threads';
|
|
10
|
-
import sharp from '
|
|
10
|
+
import sharp from '../core/lazy-native.js';
|
|
11
11
|
import { z } from 'zod';
|
|
12
12
|
import { compareCodeUnits } from '../core/canonical.js';
|
|
13
13
|
import { ServiceError } from '../core/result.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import sharp from '
|
|
1
|
+
import sharp from '../core/lazy-native.js';
|
|
2
2
|
import { readReferenceImageSource, } from '../core/bounded-source.js';
|
|
3
3
|
import { readWorkspaceJsonSource } from '../core/workspace-json.js';
|
|
4
4
|
import { REFERENCE_SHEETS_SOURCE_MAX_BYTES, referenceSheetsDocumentSchema, } from '../schemas/reference-sheets.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Bounded, offline reference-image interpretation. These are visual heuristics, not OCR. */
|
|
2
|
-
import sharp from '
|
|
2
|
+
import sharp from '../core/lazy-native.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { ServiceError } from '../core/result.js';
|
|
5
5
|
export const REFERENCE_WORLD_PIXEL_LIMIT = 13_238_272;
|
|
@@ -116,12 +116,15 @@ const SINGLE_VALUED_KEYS = new Set([
|
|
|
116
116
|
export function singleValuedReference(reference) {
|
|
117
117
|
return reference.form === 'field' && SINGLE_VALUED_KEYS.has(reference.key);
|
|
118
118
|
}
|
|
119
|
-
/**
|
|
120
|
-
|
|
119
|
+
/**
|
|
120
|
+
* Collect every numbered map reference in the active (unshadowed) script files given. `accept` picks
|
|
121
|
+
* the script files read (by default the folders of `MAP_REFERENCE_SCRIPT_PATTERNS`).
|
|
122
|
+
*/
|
|
123
|
+
export function collectMapScriptReferences(files, accept = mapReferenceScriptFile) {
|
|
121
124
|
const references = [];
|
|
122
125
|
const unparsable = [];
|
|
123
126
|
const active = files
|
|
124
|
-
.filter((file) => file.shadowedBy === undefined &&
|
|
127
|
+
.filter((file) => file.shadowedBy === undefined && accept(file.relativePath))
|
|
125
128
|
.sort((left, right) => left.loadOrder - right.loadOrder || compareCodeUnits(left.displayPath, right.displayPath));
|
|
126
129
|
for (const file of active) {
|
|
127
130
|
const document = parseClausewitz(file.bytes, file.displayPath);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import sharp from '
|
|
1
|
+
import sharp from '../core/lazy-native.js';
|
|
2
2
|
import { compareCodeUnits, canonicalJson, sha256Bytes } from '../core/canonical.js';
|
|
3
3
|
import { assertRenderDimensions, RenderBudget, RENDER_MAX_PIXELS } from '../core/render-budget.js';
|
|
4
4
|
import { ServiceError } from '../core/result.js';
|