bourgade/src/update.ts

30 lines
616 B
TypeScript
Raw Normal View History

import { produce } from 'immer';
import village, { type VillageState } from "./village";
let lastFrame: number;
export default function update(timestamp: number) {
if (!lastFrame) {
lastFrame = timestamp;
return;
}
const delta = timestamp - lastFrame;
village.update(state => {
return produce(state, (V: VillageState) => {
V.buildings.forEach(b => {
if (b.behavior.production) {
b.behavior.production(V, b, delta);
}
});
return V;
});
});
lastFrame = timestamp;
}