Commit 98562dcf authored by Matthew Odle's avatar Matthew Odle

convert building goods array to an object

parent 784d59c6
......@@ -8,7 +8,7 @@ let theBuildings = [
label: 'Smithy',
description: 'workers are more efficient with the right tools',
materials: ['wood', 'iron'],
goods: ['tool'],
goods: {'tool': 1},
assignedVillagers: [],
capacity: KNOBS_AND_LEVERS.defaultCapacity,
progress: 0,
......@@ -21,7 +21,7 @@ let theBuildings = [
name: 'FORESTER_HUT',
label: "Forester's Hut",
description: "it's big, it's heavy, it's wood",
goods: ['wood'],
goods: {'wood': 1},
assignedVillagers: [],
capacity: KNOBS_AND_LEVERS.defaultCapacity,
progress: 0,
......@@ -34,7 +34,7 @@ let theBuildings = [
name: 'GATHERER_HUT',
label: "Gatherer's Hut",
description: "nuts, berries, and tubers are packed with nutrients",
goods: ['food', 'food'],
goods: {'food': 2},
assignedVillagers: [],
capacity: KNOBS_AND_LEVERS.defaultCapacity,
progress: 0,
......@@ -47,7 +47,7 @@ let theBuildings = [
name: 'HUNTER_LODGE',
label: "Hunter's Lodge",
description: "take advantage of nature's bounty",
goods: ['food', 'hide'],
goods: {'food': 1, 'hide': 1},
assignedVillagers: [],
capacity: KNOBS_AND_LEVERS.defaultCapacity,
progress: 0,
......@@ -60,7 +60,7 @@ let theBuildings = [
name: 'MINE',
label: "Mine",
description: "the strength of the earth to forge the tools",
goods: ['iron'],
goods: {'iron': 1},
assignedVillagers: [],
capacity: KNOBS_AND_LEVERS.defaultCapacity,
progress: 0,
......@@ -74,7 +74,7 @@ let theBuildings = [
label: 'Woodcutter',
description: "it's big, it's heavy, it's wood",
materials: ['wood'],
goods: ['firewood','firewood','firewood'],
goods: {'firewood': 3},
assignedVillagers: [],
capacity: KNOBS_AND_LEVERS.defaultCapacity,
progress: 0,
......@@ -88,7 +88,7 @@ let theBuildings = [
label: 'Tailor',
description: "clothing to keep warm",
materials: ['hide'],
goods: ['clothing'],
goods: {'clothing': 1},
assignedVillagers: [],
capacity: KNOBS_AND_LEVERS.defaultCapacity,
progress: 0,
......
......@@ -4,8 +4,7 @@ export class Goods extends React.Component {
render() {
var building = this.props.building;
var goods = {};
building.goods.map( good => Array.from(Object.keys(goods)).includes(good) ? goods[good] += 1 : goods[good] = 1);
var goods = this.props.building.goods;
return (
<div className='goods'>
<span>makes: </span>
......
......@@ -135,21 +135,15 @@ export class Village extends React.Component {
this.updateLog(building.materials.map(material => material + " -1 " ))
};
addProduct = (buildingName, goods) => {
addProduct = (goods) => {
const villageStore = this.state.villageStore;
goods.map(
Array.from(Object.keys(goods)).map(
theGood => {
villageStore[theGood].count += 1;
villageStore[theGood].count += goods[theGood];
villageStore[theGood].classNames.goodThingHappened = true;
}
);
// holy crap this is confusing; basically, count the elements in the goods array and stuff them in an object
// then loop through the keys of the object and print the amounts produced
// this is to enable production of more than one good per tick without printing duplicate good names
// all of this will get rewritten when good stores get moved to the buildings
let goodsMapping = {}
goods.map( good => Array.from(Object.keys(goodsMapping)).includes(good) ? goodsMapping[good] += 1 : goodsMapping[good] = 1);
this.updateLog(Array.from(Object.keys(goodsMapping)).map(good => good + " +" + goodsMapping[good] + " "))
this.updateLog(Array.from(Object.keys(goods)).map(good => good + " +" + goods[good] + " "))
this.updateTheVillageStore(villageStore);
};
......@@ -160,7 +154,7 @@ export class Village extends React.Component {
building.progress = 0;
building.materialsInUse = false;
}
this.addProduct(building.label, building.goods);
this.addProduct(building.goods);
};
startNextProductionCycle = (building) => {
......
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