2024-10-25 19:03:32 +02:00
|
|
|
import buildings from "./data/buildings";
|
2024-10-24 11:32:31 +02:00
|
|
|
import { Hex } from "./hexgrid";
|
2024-11-07 17:15:41 +01:00
|
|
|
import type { BuildingSource, BuildingType } from "./types";
|
2024-10-23 10:14:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-10-25 19:03:32 +02:00
|
|
|
export function createBuilding(buildingType: string): BuildingType {
|
2024-10-24 16:24:39 +02:00
|
|
|
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-11-05 12:42:39 +01:00
|
|
|
state: {
|
|
|
|
upgrade: {
|
|
|
|
isUpgrading: false,
|
|
|
|
remainingTime: 0,
|
|
|
|
}
|
|
|
|
},
|
2024-10-23 10:14:19 +02:00
|
|
|
};
|
|
|
|
}
|