2024-10-24 16:24:39 +02:00
|
|
|
import buildings from "./buildings";
|
2024-10-24 11:32:31 +02:00
|
|
|
import { Hex } from "./hexgrid";
|
2024-10-23 10:14:19 +02:00
|
|
|
import type { Building, BuildingSource } from "./types";
|
|
|
|
|
|
|
|
|
|
|
|
let uid = 0;
|
|
|
|
|
|
|
|
|
2024-10-24 16:24:39 +02:00
|
|
|
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);
|
|
|
|
|
2024-10-23 10:14:19 +02:00
|
|
|
return {
|
2024-10-24 16:24:39 +02:00
|
|
|
...source,
|
2024-10-23 10:14:19 +02:00
|
|
|
id: uid++,
|
2024-10-24 11:32:31 +02:00
|
|
|
level: 1,
|
|
|
|
tile: new Hex(0, 0),
|
2024-10-23 10:14:19 +02:00
|
|
|
};
|
|
|
|
}
|