Files
WT-Offline/packages/blk/src/model.ts
T
N0VAN0M4LY c3914ec0d6 feat(patcher): build a loopback client copy with TypeScript
Add the shared BLK, VROMFS, executable patch, and build packages. Preserve
typed fields and shared name tables when reading BLK data. Rewrite the
service endpoints in place so the original environment names remain
available to the client, then build the client copy.
2026-11-24 00:35:13 +08:00

45 lines
1.8 KiB
TypeScript

/**
* 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: [] };
}