Commit 446e3e03 authored by Matthew Odle's avatar Matthew Odle

convert building materials array to an object

parent 98562dcf
......@@ -7,7 +7,7 @@ let theBuildings = [
name: 'SMITHY',
label: 'Smithy',
description: 'workers are more efficient with the right tools',
materials: ['wood', 'iron'],
materials: {'wood': 1, 'iron': 1},
goods: {'tool': 1},
assignedVillagers: [],
capacity: KNOBS_AND_LEVERS.defaultCapacity,
......@@ -73,7 +73,7 @@ let theBuildings = [
name: 'WOODCUTTER',
label: 'Woodcutter',
description: "it's big, it's heavy, it's wood",
materials: ['wood'],
materials: {'wood': 1},
goods: {'firewood': 3},
assignedVillagers: [],
capacity: KNOBS_AND_LEVERS.defaultCapacity,
......@@ -87,7 +87,7 @@ let theBuildings = [
name: 'TAILOR',
label: 'Tailor',
description: "clothing to keep warm",
materials: ['hide'],
materials: {'hide': 1},
goods: {'clothing': 1},
assignedVillagers: [],
capacity: KNOBS_AND_LEVERS.defaultCapacity,
......
......@@ -34,12 +34,15 @@ const knobsAndLevers = {
// defaultFirewoodStores: 0,
// defaultFoodStores: 0,
// defaultClothingStores: 0,
defaultToolStores: 25,
defaultFirewoodStores: 50,
defaultFoodStores: 50,
defaultClothingStores: 25,
defaultHideStores: 0,
defaultHideStores: 1,
// defaultHideStores: 0,
defaultIronStores: 0,
defaultWoodStores: 0,
}
......
......@@ -3,10 +3,12 @@ import React from 'react';
export class Materials extends React.Component {
render() {
var building = this.props.building;
var materials = this.props.building.materials;
return (
<div className='materials'>
<span>uses: </span>
<span>{building.materials.toString()}</span>
<span>{Array.from(Object.keys(materials)).map(material => material + ":" + materials[material] + " ")}</span>
</div>
);
}
......
......@@ -113,11 +113,11 @@ export class Village extends React.Component {
//----- cycle management functions -----//
canProduce = (building) => {
const theItems = this.state.villageStore;
const villageStore = this.state.villageStore;
let flag = true;
if (building.materials) {
building.materials.map( material =>
theItems[material].count > 0 && flag ? flag = true : flag = false
Array.from(Object.keys(building.materials)).map( material =>
villageStore[material].count >= building.materials[material] && flag ? flag = true : flag = false
)
}
return flag;
......@@ -125,14 +125,14 @@ export class Village extends React.Component {
useMaterials = (building) => {
const villageStore = this.state.villageStore;
building.materials.map(
material => villageStore[material] && villageStore[material].count > 0
? (villageStore[material].count -= 1, villageStore[material].classNames.badThingHappened = true)
Array.from(Object.keys(building.materials)).map(
material => villageStore[material] && villageStore[material].count >= building.materials[material]
? (villageStore[material].count -= building.materials[material], villageStore[material].classNames.badThingHappened = true)
: null
);
this.updateTheVillageStore(villageStore);
building.materialsInUse = true;
this.updateLog(building.materials.map(material => material + " -1 " ))
this.updateLog(Array.from(Object.keys(building.materials)).map(material => material + " -" + building.materials[material] + " "))
};
addProduct = (goods) => {
......
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