defineIds
Function of @v12-engine/engine
export declare function defineIds<const T extends string>(...names: T[]): {
readonly [K in T]: K;
};Ids the compiler knows. A game's ids are text to the engine (world.spawn('skeleton', ...)), and a slip of the finger in one is found when the game runs, if it is found. Named once with defineIds, they are checked as they are written, completed by the editor, and renamed in one place:
export const UNIT = defineIds('skeleton', 'runner', 'brute') export type TdUnit = IdOftypeof UNIT // 'skeleton' | 'runner' | 'brute'
id: UNIT.skeleton, ... // in the unit's definition world.spawn(UNIT.skeletn, ...) // does not compile const view: GameView = units: looks: skeletn: ... // nor does this
It is a help, not a rule: plain text works wherever an id goes, and what the compiler cannot see is checked when the game's view is fetched in a page (the client's loadGame)