Skip to content

Export & Import Pipeline

The @world-forge/export-ai-rpg package converts a WorldProject into a set of JSON files that ai-rpg-engine can load directly.

  1. ValidatevalidateProject() runs all 48 structural checks. If any fail, export aborts with error details.
  2. Convert zonesZone[] becomes ZoneDefinition[] with description as TextBlock, exits, neighbors, hazards.
  3. Convert districtsDistrict[] becomes DistrictDefinition[] with safety mapped to surveillance.
  4. Convert entitiesEntityPlacement[] becomes EntityBlueprint[] with role-based defaults, authored stats/resources/AI.
  5. Convert itemsItemPlacement[] becomes ItemDefinition[] with slot, rarity, modifiers, provenance.
  6. Convert dialoguesDialogueDefinition[] passes through to engine’s matching type.
  7. Convert player templatePlayerTemplate becomes ExportedPlayerTemplate with stats, inventory, equipment, spawn.
  8. Convert build catalogBuildCatalogDefinition becomes ExportedBuildCatalog with archetypes, backgrounds, traits, disciplines.
  9. Convert progression treesProgressionTreeDefinition[] maps nodes with requirements and effects.
  10. Build manifest — game ID, title, modules, content pack references.
  11. Build pack metadata — genres, tones, difficulty, narrator tone, authoring mode tag.
  12. Collect warnings — missing player template, build catalog, progression trees, landmarks, factions, hotspots.
  13. Collect assets — asset manifest and zone/entity/item/landmark bindings are attached to the ExportResult for round-trip preservation.
  14. Collect asset packs — asset pack definitions are attached to the ExportResult when present.

The export produces a ContentPack with all authored domains plus manifest and metadata:

type ContentPack = {
entities: EntityBlueprint[];
zones: ZoneDefinition[];
districts: DistrictDefinition[];
dialogues: DialogueDefinition[];
items: ItemDefinition[];
playerTemplate?: ExportedPlayerTemplate;
buildCatalog?: ExportedBuildCatalog;
progressionTrees: ProgressionTreeDefinition[];
};
Terminal window
# Export to directory
npx world-forge-export project.json --out ./my-pack
# Validate only (no output files)
npx world-forge-export project.json --validate-only
import { exportToEngine } from '@world-forge/export-ai-rpg';
const result = exportToEngine(myProject);
if ('ok' in result) {
// Validation failed
console.error(result.errors);
} else {
// Success
const { contentPack, manifest, packMeta, warnings, assets, assetBindings, assetPacks } = result;
}

Role-based defaults are applied when the author hasn’t specified values:

RoleEngine TypeDefault AIDefault Tags
npcnpcpassive
enemyenemyaggressivehostile
merchantnpcpassivemerchant, trader
companionnpcfollowerrecruitable, companion
bossenemyterritorialhostile, boss, elite

Authored values always override defaults. For example, if you set ai.profileId: 'aggressive' on a boss, it uses that instead of the default 'territorial'.

World Forge can import exported JSON back into the editor. The import pipeline reverses the export process with 8 converters:

ConverterInputOutput
importZonesZoneDefinition[]Zone[]
importDistrictsDistrictDefinition[]District[]
importEntitiesEntityBlueprint[]EntityPlacement[]
importItemsItemDefinition[]ItemPlacement[]
importDialoguesDialogueDefinition[]DialogueDefinition[]
importPlayerTemplateExportedPlayerTemplatePlayerTemplate
importBuildCatalogExportedBuildCatalogBuildCatalogDefinition
importProgressionTreesProgressionTreeDefinition[]ProgressionTreeDefinition[]

The importProject() function auto-detects the input format (WorldProject, ExportResult, or ContentPack) and orchestrates all converters.

import { importProject } from '@world-forge/export-ai-rpg';
const result = importProject(jsonString);
if (result.success) {
const { project, format, lossless, fidelityReport } = result;
}
  • WorldProject — lossless round-trip, no conversion needed
  • ExportResult{ contentPack, manifest, packMeta, assets, assetBindings } from exportToEngine()
  • ContentPack — engine content without manifest/metadata wrapper

Every import produces a structured FidelityReport that tracks exactly what happened to each piece of data during conversion. Each entry has:

  • levellossless, approximated, or dropped
  • domain — which system was affected (zones, districts, entities, items, etc.)
  • severityinfo, warning, or error
  • reason — machine-stable key for programmatic use

Common fidelity entries:

Reason KeyLevelDescription
grid-auto-generatedapproximatedZone grid positions auto-generated (engine doesn’t store spatial layout)
surveillance-to-safetyapproximatedDistrict safety reverse-mapped from engine’s surveillance metric
economy-data-lostdroppedDistrict economy profile not stored in engine format
zone-placement-round-robinapproximatedEntities assigned to zones via round-robin (original zones unknown)
role-reverse-mappedapproximatedEntity role inferred from engine tags
textblock-to-stringapproximatedDialogue text normalized from TextBlock arrays to strings
visual-layers-droppeddroppedVisual layers (tiles, props, ambient) not stored in engine format
assets-recoveredlosslessAsset manifest and bindings restored from ExportResult
asset-packs-recoveredlosslessAsset packs restored from ExportResult
assets-droppeddroppedAssets not available in bare ContentPack format
asset-packs-droppeddroppedAsset packs not available in bare ContentPack format
mode-inferredapproximatedAuthoring mode inferred from connection kinds and grid area

The report includes a summary with overall lossless percentage and per-domain breakdowns, displayed in the editor’s Import Summary panel.

The export pipeline stores the project’s authoring mode as a mode:<value> tag in PackMetadata. On import:

  • ExportResult — mode is recovered from the mode: tag in packMeta.tags (lossless)
  • ContentPack / pre-mode projectsinferMode() uses heuristics to recover the likely mode:
    • channel or route connections → ocean
    • warp or docking connections → space
    • trail connections with camp/wild zone tags → wilderness
    • Grid area ≤ 400 → interior
    • Grid area ≥ 4000 → world
    • Fallback → dungeon

Inferred modes generate a mode-inferred fidelity entry at the approximated level.

The dogfood/ directory contains a full export test using the Chapel Threshold fixture — 5 zones, 2 districts, 4 entities, 3 items, 1 dialogue, 1 player template, 1 build catalog, 2 progression trees. Running npx tsx dogfood/chapel-threshold.ts exports the fixture and performs a gap analysis against engine expectations. As of v1.2, the gap analysis reports zero gaps — full engine handshake.