hoi4-agent-tools 4.20.0 → 4.20.2

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.
Files changed (57) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/hoi4_agent_tools/core/engine-operation.js +27 -0
  3. package/dist/hoi4_agent_tools/core/transactions.js +127 -5
  4. package/dist/hoi4_agent_tools/core/workspace.js +118 -67
  5. package/dist/hoi4_agent_tools/event/algorithms.js +14 -2
  6. package/dist/hoi4_agent_tools/gui/layout.js +10 -6
  7. package/dist/hoi4_agent_tools/gui/renderer.js +74 -34
  8. package/dist/hoi4_agent_tools/gui/source-graph.js +12 -0
  9. package/dist/hoi4_agent_tools/gui/studio.js +5 -0
  10. package/dist/hoi4_agent_tools/version.js +1 -1
  11. package/engine/bin/darwin-arm64/hoi4-engine +0 -0
  12. package/engine/bin/linux-arm64/hoi4-engine +0 -0
  13. package/engine/bin/linux-x64/hoi4-engine +0 -0
  14. package/engine/bin/manifest.json +8 -8
  15. package/engine/bin/win32-x64/hoi4-engine.exe +0 -0
  16. package/npm-shrinkwrap.json +2 -2
  17. package/package.json +1 -1
  18. package/schemas/configuration.schema.json +1 -1
  19. package/schemas/continuous-focus-palette.schema.json +1 -1
  20. package/schemas/custom-weighted-pool.schema.json +1 -1
  21. package/schemas/decision-inspect-input.schema.json +1 -1
  22. package/schemas/error-log-input.schema.json +1 -1
  23. package/schemas/event-feature-manifest.schema.json +1 -1
  24. package/schemas/focus-plan.schema.json +1 -1
  25. package/schemas/focus-planning-sidecar.schema.json +1 -1
  26. package/schemas/geography-model.schema.json +1 -1
  27. package/schemas/gui-animation-source.schema.json +1 -1
  28. package/schemas/gui-helper.schema.json +1 -1
  29. package/schemas/gui-scenario.schema.json +1 -1
  30. package/schemas/helper-expansion-request.schema.json +1 -1
  31. package/schemas/helper-expansion-summary.schema.json +1 -1
  32. package/schemas/impact-inspect-input.schema.json +1 -1
  33. package/schemas/map-operation.schema.json +1 -1
  34. package/schemas/mechanic-test-input.schema.json +1 -1
  35. package/schemas/mod-index-input.schema.json +1 -1
  36. package/schemas/operation-result.schema.json +1 -1
  37. package/schemas/package-check-input.schema.json +1 -1
  38. package/schemas/package-manifest.schema.json +1 -1
  39. package/schemas/probability-analysis-result.schema.json +1 -1
  40. package/schemas/probability-compare-input.schema.json +1 -1
  41. package/schemas/probability-evaluate-input.schema.json +1 -1
  42. package/schemas/probability-inspect-input.schema.json +1 -1
  43. package/schemas/probability-render-input.schema.json +1 -1
  44. package/schemas/probability-scenario-set.schema.json +1 -1
  45. package/schemas/probability-sequence-input.schema.json +1 -1
  46. package/schemas/probability-simulate-input.schema.json +1 -1
  47. package/schemas/probability-sweep-input.schema.json +1 -1
  48. package/schemas/reference-context-input.schema.json +1 -1
  49. package/schemas/reference-read-input.schema.json +1 -1
  50. package/schemas/reference-search-input.schema.json +1 -1
  51. package/schemas/reference-sheets.schema.json +1 -1
  52. package/schemas/scenario-suite.schema.json +1 -1
  53. package/schemas/scenario-test-input.schema.json +1 -1
  54. package/schemas/script-validate-input.schema.json +1 -1
  55. package/schemas/shared-scenario.schema.json +1 -1
  56. package/schemas/source-lookup-input.schema.json +1 -1
  57. package/server.json +2 -2
@@ -36,6 +36,32 @@ function outlineDefinitionId(key) {
36
36
  function bitmapDefinitionId(key, layer = 'face') {
37
37
  return `gui-font-bitmap-${layer === 'face' ? '' : 'border-'}${sha256Bytes(key).slice(0, 20)}`;
38
38
  }
39
+ /**
40
+ * The textures of one SVG. Each texture's bytes are written once, as a unit-square symbol in
41
+ * `<defs>`, and every draw is a `<use>` that stretches it over its rectangle. Writing the bytes
42
+ * at every use made one nine-slice texture shared by many elements fill the artifact ceiling.
43
+ */
44
+ class TextureDefinitions {
45
+ ids = new Map();
46
+ id(dataUri) {
47
+ let id = this.ids.get(dataUri);
48
+ if (id === undefined) {
49
+ id = `gui-texture-${sha256Bytes(dataUri).slice(0, 20)}`;
50
+ this.ids.set(dataUri, id);
51
+ }
52
+ return id;
53
+ }
54
+ /** The texture stretched over `rect`, like `<image preserveAspectRatio="none">`. */
55
+ use(dataUri, rect, attributes = '') {
56
+ return `<use${attributes} href="#${this.id(dataUri)}" ${rectAttributes(rect)}/>`;
57
+ }
58
+ definitions() {
59
+ return [...this.ids.entries()]
60
+ .sort(([, left], [, right]) => compareCodeUnits(left, right))
61
+ .map(([dataUri, id]) => `<symbol id="${id}" viewBox="0 0 1 1" preserveAspectRatio="none"><image width="1" height="1" href="${dataUri}" preserveAspectRatio="none"/></symbol>`)
62
+ .join('');
63
+ }
64
+ }
39
65
  function sceneGlyphDefinitions(scene) {
40
66
  const outlines = new Map();
41
67
  const bitmaps = new Map();
@@ -92,7 +118,7 @@ function actualGlyphMarkup(glyphLine, originX, baseline, horizontalScale, bitmap
92
118
  .join('');
93
119
  return '';
94
120
  }
95
- function renderText(element, toolText) {
121
+ function renderText(element, toolText, textures) {
96
122
  const text = element.text;
97
123
  if (text === undefined || text.lines.length === 0)
98
124
  return '';
@@ -127,7 +153,7 @@ function renderText(element, toolText) {
127
153
  height: icon.height,
128
154
  };
129
155
  if (icon.sprite?.supported === true && icon.sprite.dataUri !== undefined)
130
- return `<image data-inline-icon="${escapeXml(icon.token)}" ${rectAttributes(iconRect)} href="${icon.sprite.dataUri}" preserveAspectRatio="xMidYMid meet"/>`;
156
+ return textures.use(icon.sprite.dataUri, containedRect(iconRect, icon.sprite.width, icon.sprite.height), ` data-inline-icon="${escapeXml(icon.token)}"`);
131
157
  return `<g data-inline-icon-missing="${escapeXml(icon.token)}"><rect ${rectAttributes(iconRect)} fill="#331f3f" stroke="#ff42d0" stroke-width="1"/><path d="M ${finite(iconRect.x)} ${finite(iconRect.y)} L ${finite(iconRect.x + iconRect.width)} ${finite(iconRect.y + iconRect.height)} M ${finite(iconRect.x + iconRect.width)} ${finite(iconRect.y)} L ${finite(iconRect.x)} ${finite(iconRect.y + iconRect.height)}" stroke="#ff42d0"/></g>`;
132
158
  })
133
159
  .join('');
@@ -209,12 +235,24 @@ function renderText(element, toolText) {
209
235
  const clip = text.fixedSize ? ` clip-path="url(#${textClipId})"` : '';
210
236
  return `${clipDefinition}<g data-source-id="${escapeXml(element.sourceId)}" fill="#f5f2e8" stroke="#12151a" stroke-width="0.6" paint-order="stroke"${clip}>${lines.join('')}</g>`;
211
237
  }
212
- function renderSpriteImage(sprite, rect) {
238
+ /** `rect` shrunk to the texture's aspect ratio and centred, like `xMidYMid meet`. */
239
+ function containedRect(rect, width, height) {
240
+ if (!(width > 0) || !(height > 0) || rect.width <= 0 || rect.height <= 0)
241
+ return rect;
242
+ const scale = Math.min(rect.width / width, rect.height / height);
243
+ return {
244
+ x: rect.x + (rect.width - width * scale) / 2,
245
+ y: rect.y + (rect.height - height * scale) / 2,
246
+ width: width * scale,
247
+ height: height * scale,
248
+ };
249
+ }
250
+ function renderSpriteImage(sprite, rect, textures) {
213
251
  if (!sprite.supported || sprite.dataUri === undefined)
214
252
  return '';
215
- return `<image ${rectAttributes(rect)} href="${sprite.dataUri}" preserveAspectRatio="none"/>`;
253
+ return textures.use(sprite.dataUri, rect);
216
254
  }
217
- function renderSpriteSlice(sprite, source, destination) {
255
+ function renderSpriteSlice(sprite, source, destination, textures) {
218
256
  if (!sprite.supported ||
219
257
  sprite.dataUri === undefined ||
220
258
  source.width <= 0 ||
@@ -222,9 +260,9 @@ function renderSpriteSlice(sprite, source, destination) {
222
260
  destination.width <= 0 ||
223
261
  destination.height <= 0)
224
262
  return '';
225
- return `<svg ${rectAttributes(destination)} viewBox="${finite(source.x)} ${finite(source.y)} ${finite(source.width)} ${finite(source.height)}" preserveAspectRatio="none" overflow="hidden"><image x="0" y="0" width="${finite(sprite.width)}" height="${finite(sprite.height)}" href="${sprite.dataUri}" preserveAspectRatio="none"/></svg>`;
263
+ return `<svg ${rectAttributes(destination)} viewBox="${finite(source.x)} ${finite(source.y)} ${finite(source.width)} ${finite(source.height)}" preserveAspectRatio="none" overflow="hidden">${textures.use(sprite.dataUri, { x: 0, y: 0, width: sprite.width, height: sprite.height })}</svg>`;
226
264
  }
227
- function renderTiledSpriteSlice(element, sprite, source, destination) {
265
+ function renderTiledSpriteSlice(element, sprite, source, destination, textures) {
228
266
  if (!sprite.supported ||
229
267
  sprite.dataUri === undefined ||
230
268
  source.width <= 0 ||
@@ -235,9 +273,9 @@ function renderTiledSpriteSlice(element, sprite, source, destination) {
235
273
  const tileWidth = Math.max(1, source.width * element.scale);
236
274
  const tileHeight = Math.max(1, source.height * element.scale);
237
275
  const id = `gui-tile-${sha256Bytes(`${element.id}:${source.x}:${source.y}:${source.width}:${source.height}`).slice(0, 20)}`;
238
- return `<defs><pattern id="${id}" patternUnits="userSpaceOnUse" x="${finite(destination.x)}" y="${finite(destination.y)}" width="${finite(tileWidth)}" height="${finite(tileHeight)}"><svg width="${finite(tileWidth)}" height="${finite(tileHeight)}" viewBox="${finite(source.x)} ${finite(source.y)} ${finite(source.width)} ${finite(source.height)}" preserveAspectRatio="none" overflow="hidden"><image x="0" y="0" width="${finite(sprite.width)}" height="${finite(sprite.height)}" href="${sprite.dataUri}" preserveAspectRatio="none"/></svg></pattern></defs><rect ${rectAttributes(destination)} fill="url(#${id})"/>`;
276
+ return `<defs><pattern id="${id}" patternUnits="userSpaceOnUse" x="${finite(destination.x)}" y="${finite(destination.y)}" width="${finite(tileWidth)}" height="${finite(tileHeight)}"><svg width="${finite(tileWidth)}" height="${finite(tileHeight)}" viewBox="${finite(source.x)} ${finite(source.y)} ${finite(source.width)} ${finite(source.height)}" preserveAspectRatio="none" overflow="hidden">${textures.use(sprite.dataUri, { x: 0, y: 0, width: sprite.width, height: sprite.height })}</svg></pattern></defs><rect ${rectAttributes(destination)} fill="url(#${id})"/>`;
239
277
  }
240
- function renderCorneredTile(element) {
278
+ function renderCorneredTile(element, textures) {
241
279
  const sprite = element.sprite;
242
280
  const rect = element.unclippedRect;
243
281
  const border = element.spriteBorderSize;
@@ -246,7 +284,7 @@ function renderCorneredTile(element) {
246
284
  border === undefined ||
247
285
  border.width < 0 ||
248
286
  border.height < 0)
249
- return sprite === undefined ? '' : renderSpriteImage(sprite, rect);
287
+ return sprite === undefined ? '' : renderSpriteImage(sprite, rect, textures);
250
288
  const sourceBorderX = Math.min(border.width, sprite.width / 2);
251
289
  const sourceBorderY = Math.min(border.height, sprite.height / 2);
252
290
  const destinationBorderX = Math.min(sourceBorderX * element.scale, rect.width / 2);
@@ -291,13 +329,13 @@ function renderCorneredTile(element) {
291
329
  height: destinationHeights[row] ?? 0,
292
330
  };
293
331
  parts.push(row === 1 && column === 1 && element.spriteTilingCenter === true
294
- ? renderTiledSpriteSlice(element, sprite, source, destination)
295
- : renderSpriteSlice(sprite, source, destination));
332
+ ? renderTiledSpriteSlice(element, sprite, source, destination, textures)
333
+ : renderSpriteSlice(sprite, source, destination, textures));
296
334
  }
297
335
  }
298
336
  return parts.join('');
299
337
  }
300
- function renderProgressbar(element) {
338
+ function renderProgressbar(element, textures) {
301
339
  const rect = element.unclippedRect;
302
340
  const sprite = element.sprite;
303
341
  const secondary = element.secondarySprite;
@@ -332,7 +370,7 @@ function renderProgressbar(element) {
332
370
  width: (region.width / rect.width) * texture.width,
333
371
  height: (region.height / rect.height) * texture.height,
334
372
  };
335
- return renderSpriteSlice(texture, source, region);
373
+ return renderSpriteSlice(texture, source, region, textures);
336
374
  };
337
375
  const content = `${layer(secondary, remainder, element.progressColours?.second)}${layer(sprite, filled, element.progressColours?.first)}`;
338
376
  const filtering = element.progressShader?.textureFiltering;
@@ -342,39 +380,39 @@ function renderProgressbar(element) {
342
380
  const mode = filtering[shrinking ? 'minification' : 'magnification'];
343
381
  return `<g image-rendering="${mode === 'nearest' ? 'optimizeSpeed' : 'optimizeQuality'}">${content}</g>`;
344
382
  }
345
- function renderMaskedShield(element) {
383
+ function renderMaskedShield(element, textures) {
346
384
  const rect = element.unclippedRect;
347
385
  const sprite = element.sprite;
348
386
  const mask = element.secondarySprite;
349
387
  if (sprite?.supported !== true || sprite.dataUri === undefined)
350
388
  return '';
351
389
  if (mask?.supported !== true || mask.dataUri === undefined)
352
- return renderSpriteImage(sprite, rect);
390
+ return renderSpriteImage(sprite, rect, textures);
353
391
  const id = `gui-mask-${sha256Bytes(element.id).slice(0, 20)}`;
354
- return `<defs><mask id="${id}" maskUnits="userSpaceOnUse" ${rectAttributes(rect)}><image ${rectAttributes(rect)} href="${mask.dataUri}" preserveAspectRatio="none"/></mask></defs><image ${rectAttributes(rect)} href="${sprite.dataUri}" preserveAspectRatio="none" mask="url(#${id})"/>`;
392
+ return `<defs><mask id="${id}" maskUnits="userSpaceOnUse" ${rectAttributes(rect)}>${textures.use(mask.dataUri, rect)}</mask></defs>${textures.use(sprite.dataUri, rect, ` mask="url(#${id})"`)}`;
355
393
  }
356
- function renderElementSprite(element) {
394
+ function renderElementSprite(element, textures) {
357
395
  if (element.sprite?.supported !== true || element.sprite.dataUri === undefined)
358
396
  return '';
359
397
  if (element.spriteRenderMode === 'cornered-tile')
360
- return renderCorneredTile(element);
398
+ return renderCorneredTile(element, textures);
361
399
  if (element.spriteRenderMode === 'progressbar')
362
- return renderProgressbar(element);
400
+ return renderProgressbar(element, textures);
363
401
  if (element.spriteRenderMode === 'masked-shield')
364
- return renderMaskedShield(element);
365
- return renderSpriteImage(element.sprite, element.unclippedRect);
402
+ return renderMaskedShield(element, textures);
403
+ return renderSpriteImage(element.sprite, element.unclippedRect, textures);
366
404
  }
367
- function renderBaseElement(element, clipId, toolText) {
405
+ function renderBaseElement(element, clipId, toolText, textures) {
368
406
  if (!element.visible)
369
407
  return '';
370
408
  const rect = element.unclippedRect;
371
409
  const clip = clipId === undefined ? '' : ` clip-path="url(#${clipId})"`;
372
410
  const content = [];
373
411
  if (element.spriteRenderMode === 'progressbar' && element.progressColours !== undefined) {
374
- content.push(renderProgressbar(element));
412
+ content.push(renderProgressbar(element, textures));
375
413
  }
376
414
  else if (element.sprite?.supported === true && element.sprite.dataUri !== undefined) {
377
- const sprite = renderElementSprite(element);
415
+ const sprite = renderElementSprite(element, textures);
378
416
  if (element.spriteShader === undefined)
379
417
  content.push(sprite);
380
418
  else {
@@ -393,7 +431,7 @@ function renderBaseElement(element, clipId, toolText) {
393
431
  if (element.progressRatio !== undefined && element.spriteRenderMode !== 'progressbar') {
394
432
  content.push(`<rect x="${finite(rect.x)}" y="${finite(rect.y)}" width="${finite(rect.width * element.progressRatio)}" height="${finite(rect.height)}" fill="#5ecf8d" fill-opacity="0.65"/>`);
395
433
  }
396
- content.push(renderText(element, toolText));
434
+ content.push(renderText(element, toolText, textures));
397
435
  return `<g id="${escapeXml(element.id)}" data-source="${escapeXml(element.sourcePath)}" data-source-id="${escapeXml(element.sourceId)}"${clip}>${content.join('')}</g>`;
398
436
  }
399
437
  function renderOverlay(element, variant, toolText) {
@@ -423,12 +461,12 @@ function renderOverlay(element, variant, toolText) {
423
461
  }
424
462
  return '';
425
463
  }
426
- function renderTooltipPreview(scene, toolText) {
464
+ function renderTooltipPreview(scene, toolText, textures) {
427
465
  const tooltip = scene.tooltipPreview;
428
466
  if (tooltip === undefined)
429
467
  return '';
430
- return (renderBaseElement(tooltip.element, undefined, toolText) +
431
- renderBaseElement(tooltip.textElement, undefined, toolText));
468
+ return (renderBaseElement(tooltip.element, undefined, toolText, textures) +
469
+ renderBaseElement(tooltip.textElement, undefined, toolText, textures));
432
470
  }
433
471
  function viewFor(scene, variant) {
434
472
  if (variant !== 'cropped' || scene.bounds.width <= 0 || scene.bounds.height <= 0) {
@@ -466,17 +504,18 @@ export function sceneToSvg(scene, variant) {
466
504
  const view = viewFor(scene, variant);
467
505
  assertRenderDimensions(view.width, view.height, `GUI ${variant} SVG`);
468
506
  const toolText = new DeterministicSvgTextRenderer();
507
+ const textures = new TextureDefinitions();
469
508
  const clipDefinitions = scene.elements.flatMap((element, index) => element.clipRect === undefined
470
509
  ? []
471
510
  : [`<clipPath id="clip-${index}"><rect ${rectAttributes(element.clipRect)}/></clipPath>`]);
472
511
  const body = scene.elements
473
- .map((element, index) => renderBaseElement(element, element.clipRect === undefined ? undefined : `clip-${index}`, toolText))
474
- .join('') + renderTooltipPreview(scene, toolText);
512
+ .map((element, index) => renderBaseElement(element, element.clipRect === undefined ? undefined : `clip-${index}`, toolText, textures))
513
+ .join('') + renderTooltipPreview(scene, toolText, textures);
475
514
  const overlays = scene.elements
476
515
  .map((element) => renderOverlay(element, variant, toolText))
477
516
  .join('');
478
517
  const fidelity = escapeXml(canonicalJson(scene.fidelity));
479
- return `<svg xmlns="http://www.w3.org/2000/svg" width="${view.width}" height="${view.height}" viewBox="${finite(view.viewBox.x)} ${finite(view.viewBox.y)} ${finite(view.viewBox.width)} ${finite(view.viewBox.height)}"><metadata data-renderer="hoi4-agent-tools" data-mode="offline">${fidelity}</metadata><defs>${clipDefinitions.join('')}${sceneGlyphDefinitions(scene)}${toolText.definitions()}</defs>${backdrop(scene, view.viewBox)}${body}${overlays}</svg>`;
518
+ return `<svg xmlns="http://www.w3.org/2000/svg" width="${view.width}" height="${view.height}" viewBox="${finite(view.viewBox.x)} ${finite(view.viewBox.y)} ${finite(view.viewBox.width)} ${finite(view.viewBox.height)}"><metadata data-renderer="hoi4-agent-tools" data-mode="offline">${fidelity}</metadata><defs>${clipDefinitions.join('')}${textures.definitions()}${sceneGlyphDefinitions(scene)}${toolText.definitions()}</defs>${backdrop(scene, view.viewBox)}${body}${overlays}</svg>`;
480
519
  }
481
520
  async function cooperativeParts(values, render, signal) {
482
521
  const output = [];
@@ -494,13 +533,14 @@ async function sceneToSvgCooperative(scene, variant, signal) {
494
533
  const view = viewFor(scene, variant);
495
534
  assertRenderDimensions(view.width, view.height, `GUI ${variant} SVG`);
496
535
  const toolText = new DeterministicSvgTextRenderer();
536
+ const textures = new TextureDefinitions();
497
537
  const clipDefinitions = await cooperativeParts(scene.elements, (element, index) => element.clipRect === undefined
498
538
  ? ''
499
539
  : `<clipPath id="clip-${index}"><rect ${rectAttributes(element.clipRect)}/></clipPath>`, signal);
500
- const body = (await cooperativeParts(scene.elements, (element, index) => renderBaseElement(element, element.clipRect === undefined ? undefined : `clip-${index}`, toolText), signal)) + renderTooltipPreview(scene, toolText);
540
+ const body = (await cooperativeParts(scene.elements, (element, index) => renderBaseElement(element, element.clipRect === undefined ? undefined : `clip-${index}`, toolText, textures), signal)) + renderTooltipPreview(scene, toolText, textures);
501
541
  const overlays = await cooperativeParts(scene.elements, (element) => renderOverlay(element, variant, toolText), signal);
502
542
  const fidelity = escapeXml(canonicalJson(scene.fidelity));
503
- return `<svg xmlns="http://www.w3.org/2000/svg" width="${view.width}" height="${view.height}" viewBox="${finite(view.viewBox.x)} ${finite(view.viewBox.y)} ${finite(view.viewBox.width)} ${finite(view.viewBox.height)}"><metadata data-renderer="hoi4-agent-tools" data-mode="offline">${fidelity}</metadata><defs>${clipDefinitions}${sceneGlyphDefinitions(scene)}${toolText.definitions()}</defs>${backdrop(scene, view.viewBox)}${body}${overlays}</svg>`;
543
+ return `<svg xmlns="http://www.w3.org/2000/svg" width="${view.width}" height="${view.height}" viewBox="${finite(view.viewBox.x)} ${finite(view.viewBox.y)} ${finite(view.viewBox.width)} ${finite(view.viewBox.height)}"><metadata data-renderer="hoi4-agent-tools" data-mode="offline">${fidelity}</metadata><defs>${clipDefinitions}${textures.definitions()}${sceneGlyphDefinitions(scene)}${toolText.definitions()}</defs>${backdrop(scene, view.viewBox)}${body}${overlays}</svg>`;
504
544
  }
505
545
  export function hierarchyToSvg(scene) {
506
546
  const rows = scene.elements.toSorted((left, right) => left.depth - right.depth || left.zIndex - right.zIndex || compareCodeUnits(left.id, right.id));
@@ -54,6 +54,7 @@ const modelledElementAttributes = new Set([
54
54
  'text',
55
55
  'font',
56
56
  'fontSize',
57
+ 'text_color_code',
57
58
  'maxWidth',
58
59
  'maxHeight',
59
60
  'fixedsize',
@@ -1317,6 +1318,13 @@ function referenceLabel(edge) {
1317
1318
  return String(value);
1318
1319
  return value === undefined ? edge.to : JSON.stringify(value);
1319
1320
  }
1321
+ /** `localisation/replace/**` or `localisation/<language>/replace/**`. */
1322
+ function inLocalisationReplaceFolder(relativePath) {
1323
+ const segments = relativePath.replaceAll('\\', '/').toLowerCase().split('/');
1324
+ return (segments[0] === 'localisation' &&
1325
+ ((segments[1] === 'replace' && segments.length > 2) ||
1326
+ (segments[2] === 'replace' && segments.length > 3)));
1327
+ }
1320
1328
  export function buildGuiSourceGraph(files, providedIndex, additionalLocalisationKeys = [], limits = {}) {
1321
1329
  const sharedIndex = providedIndex ?? new SymbolIndex();
1322
1330
  const activeFiles = files.filter(({ shadowedBy }) => shadowedBy === undefined);
@@ -1456,7 +1464,11 @@ export function buildGuiSourceGraph(files, providedIndex, additionalLocalisation
1456
1464
  throw new ServiceError('GUI_LOCALISATION_BUDGET_INVALID', 'Localisation candidate limit must be a positive safe integer');
1457
1465
  let candidateCount = 0;
1458
1466
  const localisationCandidates = new Map();
1467
+ // The first candidate of a key is the one the game shows: higher load order first, and within
1468
+ // one root a file in a `replace` folder before the root's other files.
1459
1469
  for (const { file, fileNodeId } of localisationFiles.sort((left, right) => right.file.loadOrder - left.file.loadOrder ||
1470
+ Number(inLocalisationReplaceFolder(right.file.relativePath)) -
1471
+ Number(inLocalisationReplaceFolder(left.file.relativePath)) ||
1460
1472
  compareCodeUnits(left.file.displayPath, right.file.displayPath))) {
1461
1473
  const document = parseLocalisation(file.bytes, file.displayPath);
1462
1474
  if (providedIndex === undefined &&
@@ -211,6 +211,11 @@ function guiLocalisationPatterns(workspace, languages = ['l_english']) {
211
211
  ...under(roots.localisation, [
212
212
  '*.{yml,yaml}',
213
213
  ...languageDirectories.flatMap((directory) => [
214
+ // The game reads `localisation/replace/` over every other definition. Only the files
215
+ // of the preview's languages count: a mod with replace files in many languages would
216
+ // otherwise fill the candidate ceiling with text the preview never shows.
217
+ `replace/**/*_l_${directory}.yml`,
218
+ `replace/**/*_l_${directory}.yaml`,
214
219
  `${directory}/**/*.yml`,
215
220
  `${directory}/**/*.yaml`,
216
221
  ]),
@@ -1,6 +1,6 @@
1
1
  import { LATEST_PROTOCOL_VERSION } from '@modelcontextprotocol/sdk/types.js';
2
2
  export const PACKAGE_NAME = 'hoi4-agent-tools';
3
- export const PACKAGE_VERSION = '4.20.0';
3
+ export const PACKAGE_VERSION = '4.20.2';
4
4
  export const MCP_PROTOCOL_VERSION = LATEST_PROTOCOL_VERSION;
5
5
  export const CONFIG_VERSION = 1;
6
6
  export const TRANSACTION_VERSION = 2;
Binary file
Binary file
Binary file
@@ -4,23 +4,23 @@
4
4
  "binaries": {
5
5
  "darwin-arm64": {
6
6
  "file": "darwin-arm64/hoi4-engine",
7
- "sha256": "0e7f759e5ab76d7161b8a3819cd1a534ffd0f65a6701de89e20258c2b8ee8cc5",
8
- "size": 5227664
7
+ "sha256": "7a515361a74ea68802b1b730535b7eb9ca00634912e2c6e76f846d8cdac50532",
8
+ "size": 5332720
9
9
  },
10
10
  "linux-arm64": {
11
11
  "file": "linux-arm64/hoi4-engine",
12
- "sha256": "b5d669f7da8aeab27276a7d65e7df055897b90ffca4183bbd9a2c8702beb63ea",
13
- "size": 5589920
12
+ "sha256": "61310845bb5dbcc4eae49c88159da62c263e2c3c44d1c8a555afc7215fac1400",
13
+ "size": 5635832
14
14
  },
15
15
  "linux-x64": {
16
16
  "file": "linux-x64/hoi4-engine",
17
- "sha256": "9d65f6855921ab4d5ed894a7cf1f7cda61f25f021b10d81185163c32eacc8919",
18
- "size": 6111040
17
+ "sha256": "66c15c1bed9da19a85ca842ca19c70b6eb1fc995ac71543893e8548b229ba796",
18
+ "size": 6208144
19
19
  },
20
20
  "win32-x64": {
21
21
  "file": "win32-x64/hoi4-engine.exe",
22
- "sha256": "1885b0a9ee0d1d611e326a44f1f73303697185dd4236b5060f306c957c2bbb13",
23
- "size": 5028864
22
+ "sha256": "fa4be35babe58ec16ee1c34ef373124f23218c4b0b9c34b3f9279d05241d2976",
23
+ "size": 5149184
24
24
  }
25
25
  }
26
26
  }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "hoi4-agent-tools",
3
- "version": "4.20.0",
3
+ "version": "4.20.2",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "hoi4-agent-tools",
9
- "version": "4.20.0",
9
+ "version": "4.20.2",
10
10
  "license": "Apache-2.0",
11
11
  "dependencies": {
12
12
  "@fontsource-variable/roboto": "5.3.0",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hoi4-agent-tools",
3
3
  "mcpName": "io.github.klimPaskov/hoi4-agent-tools",
4
- "version": "4.20.0",
4
+ "version": "4.20.2",
5
5
  "description": "Build HOI4 mods: focus trees, events, decisions, worlds, GUI previews, docs and AI balance.",
6
6
  "type": "module",
7
7
  "license": "Apache-2.0",
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.0/schemas/configuration.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.2/schemas/configuration.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.0/schemas/continuous-focus-palette.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.2/schemas/continuous-focus-palette.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.0/schemas/custom-weighted-pool.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.2/schemas/custom-weighted-pool.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.0/schemas/decision-inspect-input.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.2/schemas/decision-inspect-input.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.0/schemas/error-log-input.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.2/schemas/error-log-input.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.0/schemas/event-feature-manifest.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.2/schemas/event-feature-manifest.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.0/schemas/focus-plan.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.2/schemas/focus-plan.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.0/schemas/focus-planning-sidecar.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.2/schemas/focus-planning-sidecar.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.0/schemas/geography-model.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.2/schemas/geography-model.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.0/schemas/gui-animation-source.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.2/schemas/gui-animation-source.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.0/schemas/gui-helper.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.2/schemas/gui-helper.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.0/schemas/gui-scenario.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.2/schemas/gui-scenario.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.0/schemas/helper-expansion-request.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.2/schemas/helper-expansion-request.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.0/schemas/helper-expansion-summary.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.2/schemas/helper-expansion-summary.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.0/schemas/impact-inspect-input.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.2/schemas/impact-inspect-input.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.0/schemas/map-operation.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.2/schemas/map-operation.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "oneOf": [
5
5
  {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.0/schemas/mechanic-test-input.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.2/schemas/mechanic-test-input.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.0/schemas/mod-index-input.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.2/schemas/mod-index-input.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.0/schemas/operation-result.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.2/schemas/operation-result.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.0/schemas/package-check-input.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.2/schemas/package-check-input.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.0/schemas/package-manifest.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.2/schemas/package-manifest.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.0/schemas/probability-analysis-result.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.2/schemas/probability-analysis-result.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.0/schemas/probability-compare-input.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.2/schemas/probability-compare-input.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.0/schemas/probability-evaluate-input.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.2/schemas/probability-evaluate-input.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.0/schemas/probability-inspect-input.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.2/schemas/probability-inspect-input.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.0/schemas/probability-render-input.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.2/schemas/probability-render-input.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.0/schemas/probability-scenario-set.schema.json",
2
+ "$id": "https://github.com/klimPaskov/hoi4-agent-tools/blob/v4.20.2/schemas/probability-scenario-set.schema.json",
3
3
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
4
  "type": "object",
5
5
  "properties": {