/** Public source SDK. Game packages import this entry point, never engine internals. */
import {validateWorld,type WorldDefinition} from '../schema';
import {createWorldDocument,readWorldDocument,type WorldDocument} from '../authoring';
import {compileWorld} from '../compiler';
import {checkpointDigest,checkpointRecord} from '../schema/checkpoints';
export const SDK_VERSION='0.1.0';
export const SDK_API='darkwind-game-sdk.1';
/** Stable source identity. Keep the key when renaming a display label. */
export async function authoredEntityId(namespace:string,key:string){
 if(!namespace||namespace.length>128||!key||key.length>256)throw new Error('Use a bounded namespace and stable entity key');
 return `authored:${await checkpointDigest({namespace,key})}`;
}
export interface GameDefinition {api:typeof SDK_API;world:WorldDefinition}
export interface GameRelease {format:1;sdk:typeof SDK_API;document:WorldDocument;compiler:string;worldHash:string}
export function defineGame(value:GameDefinition):GameDefinition {
 const game=checkpointRecord(value,['api','world']);if(game.api!==SDK_API)throw new Error('Unsupported game SDK API');
 const world=structuredClone(game.world) as WorldDefinition;validateWorld(world);return {api:SDK_API,world};
}
/** A portable release uses existing world migration, semantic validation and hashes. */
export async function buildGame(value:GameDefinition):Promise<GameRelease>{
 const game=defineGame(value),document=await createWorldDocument(game.world),compiled=await compileWorld(document.world);
 return {format:1,sdk:SDK_API,document,compiler:compiled.compiler,worldHash:compiled.worldHash};
}
export async function readGameRelease(value:unknown):Promise<GameRelease>{
 const r=checkpointRecord(value,['format','sdk','document','compiler','worldHash']);if(r.format!==1||r.sdk!==SDK_API)throw new Error('Unsupported game release or SDK API');
 const document=await readWorldDocument(r.document),compiled=await compileWorld(document.world);
 if(r.compiler!==compiled.compiler||r.worldHash!==compiled.worldHash)throw new Error('Game release requires its matching compiler; rebuild explicitly with the selected engine');
 return {format:1,sdk:SDK_API,document,compiler:compiled.compiler,worldHash:compiled.worldHash};
}
export {PlaceBuilder} from '../world';
export {SKY_MOODS} from '../schema/sky';
export {defineComponent} from '../schema/components';
export {defineBehavior,BEHAVIOR_HOOKS} from '../behavior';
export {ActionMap} from '../input';
export {createWorldDocument,readWorldDocument,applyWorldTransaction} from '../authoring';
export {authoringCommandSchema} from '../authoring/observations';
export type {WorldDefinition,Place,SceneObject,Interaction,Material,Vec3} from '../schema';
export type {WorldText} from '../schema/world-text';
export type {WorldDocument,WorldTransaction,WorldCommand} from '../authoring';
export type {BehaviorDefinition,BehaviorContext,BehaviorProgram} from '../behavior';
export type {ActionMapDefinition,BindingProfile} from '../input';

export {initialGameplay,readGameplay,useAbility} from '../schema/gameplay';
export type {ResourceDefinition,AbilityDefinition,GameplayDefinition,GameplayState} from '../schema/gameplay';

export {initialCombat,readCombat,hitTarget,respawnTargets} from '../schema/combat';
export type {CombatTarget,TargetHit,CombatState,CombatantState} from '../schema/combat';

export {initialNavigation,readNavigation,navigationPosition,navigationVisible,stepNavigation} from '../schema/navigation';
export type {NavigationDefinition,NavigationState,NavigationTraveler} from '../schema/navigation';

export {EXTENSION_API,EXTENSION_CAPABILITIES,readExtension,installWorldExtension} from '../schema/extensions';
export type {GameExtension,ExtensionCapability,ExtensionJob} from '../schema/extensions';
export {compileExtension} from '../behavior/extensions';
export type {ValueSchema} from '../schema/components';

export {defineBehaviorJob} from '../behavior';
export type {BehaviorJobDefinition,JobResultEvent} from '../behavior';

export {PLUGIN_API,defineEnginePlugin,installEnginePlugins,pluginPermissions,proposePluginCommand,compilePluginPanel} from '../plugins';
export type {EnginePlugin,PluginCommand,PluginPanel,ObjectCommandCapability} from '../plugins';
export {defineNativeSystem} from '../behavior';
export type {NativeSystemDefinition,NativeSystemContext} from '../behavior';
export type {DefinedComponent,ComponentMigration} from '../schema/components';

export {defineScriptBehavior} from '../behavior/restricted';
export type {ScriptPolicy} from '../behavior/script';
export type {JobResultRecord} from '../behavior';

export {publicComponentCatalog,validPublicComponents} from '../schema/public-components';
export type {PublicComponent,PublicComponentValues} from '../schema/public-components';

export {bakeNavigation} from '../schema/navigation-mesh';
export type {NavigationBake,NavigationMesh} from '../schema/navigation-mesh';

export {readRoomCrossing} from '../schema/room-crossing';
export type {RoomCrossing,RoomCrossingRoute} from '../schema/room-crossing';
/** Add a static, host-validated room doorway to a portable game document. */
export function addRoomCrossing(world:WorldDefinition,place:string,crossing:import('../schema/room-crossing').RoomCrossing){const next=structuredClone(world),target=next.places.find(p=>p.id===place);if(!target)throw new Error('Missing crossing place');next.format=Math.max(next.format,crossing.walkThrough?69:crossing.roomWindow?68:67) as WorldDefinition['format'];target.interactions.push(structuredClone(crossing));validateWorld(next);return next;}

export {bakeWorldNavigation} from '../compiler/navigation';
