Compare commits

..

No commits in common. "16db8ee0bec28c50930bcc6a3f6bd280c4cf9c1f" and "80867d6ccf171d7a8044bc3079c327eb6c8f6781" have entirely different histories.

7 changed files with 43 additions and 93 deletions

View File

@ -4,27 +4,6 @@ import type { VillageState } from "./village";
export default { export default {
'townhall': {
name: 'Town Hall',
cost: (level: number) => {
return {
wood: level * 10,
stone: level * 10,
iron: level * 10,
food: 0,
};
},
behavior: {
storage: (_V: VillageState, _self: Building) => {
return {
'wood': 100,
'stone': 100,
'iron': 100,
'food': 100,
}
},
},
},
'woodcutter': { 'woodcutter': {
name: 'Woodcutter', name: 'Woodcutter',
cost: (level: number) => { cost: (level: number) => {
@ -40,13 +19,9 @@ export default {
const prod = getEmptyResources(); const prod = getEmptyResources();
const outputPerMinute = 5 * (self.level * self.level); const outputPerMinute = 5 * (self.level * self.level);
prod.wood = outputPerMinute; prod.wood = outputPerMinute;
const intakePerMinute = Math.ceil(self.level / 5);
prod.food = -intakePerMinute;
return prod; return prod;
}, }
}, }
}, },
'mine': { 'mine': {
name: 'Mine', name: 'Mine',
@ -63,13 +38,9 @@ export default {
const prod = getEmptyResources(); const prod = getEmptyResources();
const outputPerMinute = 5 * (self.level * self.level); const outputPerMinute = 5 * (self.level * self.level);
prod.iron = outputPerMinute; prod.iron = outputPerMinute;
const intakePerMinute = Math.ceil(self.level / 5);
prod.food = -intakePerMinute;
return prod; return prod;
}, }
}, }
}, },
'pit': { 'pit': {
name: 'Pit', name: 'Pit',
@ -86,32 +57,9 @@ export default {
const prod = getEmptyResources(); const prod = getEmptyResources();
const outputPerMinute = 5 * (self.level * self.level); const outputPerMinute = 5 * (self.level * self.level);
prod.stone = outputPerMinute; prod.stone = outputPerMinute;
const intakePerMinute = Math.ceil(self.level / 5);
prod.food = -intakePerMinute;
return prod; return prod;
}, }
}, }
},
'field': {
name: 'Field',
cost: (level: number) => {
return {
wood: level * 10,
stone: level * 10,
iron: level * 10,
food: 0,
};
},
behavior: {
production: (V: VillageState, self: Building) => {
const prod = getEmptyResources();
const outputPerMinute = 5 * (self.level * self.level);
prod.food = outputPerMinute;
return prod;
},
},
}, },
'warehouse': { 'warehouse': {
name: 'Warehouse', name: 'Warehouse',
@ -132,8 +80,8 @@ export default {
'stone': capacity, 'stone': capacity,
'iron': capacity, 'iron': capacity,
'food': 0, 'food': 0,
}; }
}, }
}, },
}, },
'granary': { 'granary': {
@ -155,8 +103,8 @@ export default {
'stone': 0, 'stone': 0,
'iron': 0, 'iron': 0,
'food': capacity, 'food': capacity,
}; }
}, }
}, },
}, },
}; };

View File

@ -1,13 +0,0 @@
import type { Building, BuildingSource } from "./types";
let uid = 0;
export function createBuilding(building: BuildingSource): Building {
return {
...building,
level: 1,
id: uid++,
};
}

View File

@ -6,7 +6,7 @@
function build(type: string) { function build(type: string) {
if (moves.build(type)) { if (moves.createBuilding(type)) {
close(); close();
} }
} }

View File

@ -1,9 +1,11 @@
import buildings from "../buildings"; import buildings from "../buildings";
import { createBuilding } from "../create";
import type { VillageState } from "../village"; import type { VillageState } from "../village";
export default function build(V: VillageState, buildingType: keyof typeof buildings) { let uid = 0;
export default function createBuilding(V: VillageState, buildingType: keyof typeof buildings) {
const building = buildings[buildingType]; const building = buildings[buildingType];
const cost = building.cost(1); const cost = building.cost(1);
@ -21,7 +23,12 @@ export default function build(V: VillageState, buildingType: keyof typeof buildi
V.resources.iron -= cost.iron; V.resources.iron -= cost.iron;
V.resources.food -= cost.food; V.resources.food -= cost.food;
V.buildings.push(createBuilding(building)); const newBuilding = {
...building,
level: 1,
id: uid++,
};
V.buildings.push(newBuilding);
return true; return true;
} }

View File

@ -1,7 +1,7 @@
import { produce } from 'immer'; import { produce } from 'immer';
import village, { type VillageState } from '../village'; import village, { type VillageState } from '../village';
import build from './build'; import createBuilding from './createBuilding';
import upgradeBuilding from './upgradeBuilding'; import upgradeBuilding from './upgradeBuilding';
@ -28,6 +28,6 @@ export function makeMove(move: (...args: any[]) => boolean) {
export default { export default {
build: makeMove(build), createBuilding: makeMove(createBuilding),
upgradeBuilding: makeMove(upgradeBuilding), upgradeBuilding: makeMove(upgradeBuilding),
}; };

View File

@ -11,6 +11,7 @@ export type Production = Cost;
export interface BuildingSource { export interface BuildingSource {
name: string; name: string;
level: number;
cost: (level: number) => Cost; cost: (level: number) => Cost;
behavior: { behavior: {
production?: Function; production?: Function;
@ -21,5 +22,4 @@ export interface BuildingSource {
export interface Building extends BuildingSource { export interface Building extends BuildingSource {
id: number; id: number;
level: number;
} }

View File

@ -1,7 +1,5 @@
import { writable } from "svelte/store"; import { writable } from "svelte/store";
import buildings from "./buildings"; import buildings from "./buildings";
import { createBuilding } from "./create";
import type { Building } from "./types"; import type { Building } from "./types";
@ -16,20 +14,30 @@ export interface VillageState {
}; };
} }
let uid = 0;
const village = writable<VillageState>({ const village = writable<VillageState>({
buildings: [ buildings: [
createBuilding(buildings.townhall), { ...buildings.woodcutter, level: 1, id: uid++ },
createBuilding(buildings.woodcutter), { ...buildings.woodcutter, level: 1, id: uid++ },
createBuilding(buildings.pit), { ...buildings.woodcutter, level: 1, id: uid++ },
createBuilding(buildings.mine), { ...buildings.woodcutter, level: 1, id: uid++ },
createBuilding(buildings.field), { ...buildings.mine, level: 1, id: uid++ },
{ ...buildings.mine, level: 1, id: uid++ },
{ ...buildings.mine, level: 1, id: uid++ },
{ ...buildings.mine, level: 1, id: uid++ },
{ ...buildings.pit, level: 1, id: uid++ },
{ ...buildings.pit, level: 1, id: uid++ },
{ ...buildings.pit, level: 1, id: uid++ },
{ ...buildings.pit, level: 1, id: uid++ },
{ ...buildings.warehouse, level: 1, id: uid++ },
{ ...buildings.granary, level: 1, id: uid++ },
], ],
resources: { resources: {
wood: 60, wood: 100,
stone: 60, stone: 100,
iron: 60, iron: 100,
food: 50, food: 0,
culture: 0, culture: 0,
}, },
}); });