bourgade/src/create.ts

30 lines
683 B
TypeScript
Raw Normal View History

import buildings from "./buildings";
import { Hex } from "./hexgrid";
import type { Building, BuildingSource } from "./types";
let uid = 0;
export function getBuildingSource(buildingType: string): BuildingSource {
const source: BuildingSource | undefined = buildings.find(b => b.type === buildingType);
if (source === undefined) {
throw new Error(`Unknown building type: "${buildingType}"`);
}
return source
}
export function createBuilding(buildingType: string): Building {
const source: BuildingSource = getBuildingSource(buildingType);
return {
...source,
id: uid++,
level: 1,
tile: new Hex(0, 0),
};
}