/** * In-memory form of a BLK document. * * Every value keeps its BLK type, so a document read from the game can be written back * without the game reading a different type than it expects (an int stays an int even * when its value is 5, a real stays a real even when its value is 5.0). * * A block keeps its parameters and its sub-blocks as two ordered lists, because that is * what the binary format stores: the relative order of a parameter and a sub-block is not * recorded. Names may repeat; a repeated parameter is how BLK expresses a list. */ export type BlkValue = | { readonly type: 'string'; readonly value: string } | { readonly type: 'int'; readonly value: number } | { readonly type: 'real'; readonly value: number } | { readonly type: 'point2'; readonly value: readonly [number, number] } | { readonly type: 'point3'; readonly value: readonly [number, number, number] } | { readonly type: 'point4'; readonly value: readonly [number, number, number, number] } | { readonly type: 'ipoint2'; readonly value: readonly [number, number] } | { readonly type: 'ipoint3'; readonly value: readonly [number, number, number] } | { readonly type: 'ipoint4'; readonly value: readonly [number, number, number, number] } | { readonly type: 'bool'; readonly value: boolean } | { readonly type: 'color'; readonly value: number } | { readonly type: 'matrix'; readonly value: readonly number[] } | { readonly type: 'int64'; readonly value: bigint }; export type BlkValueType = BlkValue['type']; export interface BlkParam { name: string; value: BlkValue; } export interface BlkBlock { /** Empty for the root block. */ name: string; params: BlkParam[]; blocks: BlkBlock[]; } export function emptyBlock(name = ''): BlkBlock { return { name, params: [], blocks: [] }; }