Commit f6b1d081 authored by Matthew Odle's avatar Matthew Odle

sort buildings by priority

parent edaac3c0
......@@ -4,13 +4,18 @@ import { Building } from './building';
import { Stock } from './stock';
export class Village extends React.Component {
sortBuildings = (buildings) => {
buildings.sort((a, b) => a.priority > b.priority)
}
constructor(props) {
super();
this.state = {
buildings: props.buildings.concat(),
buildings: this.sortBuildings(props.buildings.slice()),
elapsed: 0,
villageStore: props.villageStore.concat(),
villagers: props.villagers.concat(),
villageStore: props.villageStore.slice(),
villagers: props.villagers.slice(),
};
}
......@@ -40,7 +45,6 @@ export class Village extends React.Component {
...villagers.slice(villagerIndex + 1),
]
});
}
assignVillagers = (building, amount) => {
......@@ -148,7 +152,6 @@ export class Village extends React.Component {
}
};
getProductionMultiplier = (villagers) => {
let multiplier = 0;
villagers.map(villager =>
......@@ -197,6 +200,7 @@ export class Village extends React.Component {
};
manageProductionBuildings = (buildings) => {
this.sortBuildings(buildings);
// eslint-disable-next-line
buildings.map( building => {
if (this.canProduce(building) || building.materialsInUse) {
......@@ -209,12 +213,7 @@ export class Village extends React.Component {
});
};
componentDidMount = () => {
this.timer = setInterval(() => this.tick(), this.props.knobsAndLevers.interval);
};
componentWillUnmount = () => {
clearInterval(this.timer);
};
tick = () => {
const buildings = this.props.buildings.slice();
this.manageProductionBuildings(buildings);
......@@ -223,9 +222,17 @@ export class Village extends React.Component {
buildings: buildings,
});
};
componentDidMount = () => {
this.timer = setInterval(() => this.tick(), this.props.knobsAndLevers.interval);
};
// prevent memory leak
componentWillUnmount = () => {
clearInterval(this.timer);
};
render = () => {
const buildings = this.props.buildings.slice();
this.sortBuildings(buildings);
const villageStore = this.props.villageStore.slice();
return (
<div className="village">
......
......@@ -42,7 +42,7 @@ buildings.push({type: 'production',
name: 'SMITHY',
label: 'Smithy',
description: 'workers are more efficient with the right tools',
priority: 0,
priority: 3,
materials: ['wood', 'iron'],
goods: ['tool'],
assignedVillagers: [],
......@@ -56,7 +56,7 @@ buildings.push({type: 'extraction',
name: 'FORESTER_HUT',
label: "Forester's Hut",
description: "it's big, it's heavy, it's wood",
priority: 0,
priority: 1,
goods: ['wood'],
assignedVillagers: [],
capacity: knobsAndLevers.defaultCapacity,
......@@ -69,7 +69,7 @@ buildings.push({type: 'extraction',
name: 'MINE',
label: "Mine",
description: "the strength of the earth to forge the tools",
priority: 0,
priority: 2,
goods: ['iron'],
assignedVillagers: [],
capacity: knobsAndLevers.defaultCapacity,
......@@ -82,7 +82,7 @@ buildings.push({type: 'production',
name: 'WOODCUTTER',
label: 'Woodcutter',
description: "it's big, it's heavy, it's wood",
priority: 0,
priority: 4,
materials: ['wood'],
goods: ['firewood'],
assignedVillagers: [],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment