Commit d9fa57c3 authored by Matthew Odle's avatar Matthew Odle

push the villager object to the building assignedVillagers array instead of just the id

parent 222db71c
......@@ -52,7 +52,7 @@ export class Village extends React.Component {
const selectedVillager = allVillagers.find( villager => villager.assignment === 'none' && amount > 0)
selectedVillager.assignment = building.name;
building.assignedVillagers.push(selectedVillager.id);
building.assignedVillagers.push(selectedVillager);
this.updateTheBuildings(building);
this.updateTheVillagers(selectedVillager);
......@@ -63,22 +63,16 @@ export class Village extends React.Component {
}
}
getTheVillager = (villagerId) => {
const allVillagers = this.props.villagers.slice();
return allVillagers.find( villager => villager.id === villagerId);
}
unassignVillagers = (building, amount) => {
if (building.assignedVillagers.length === 0) {
return;
}
const selectedVillagerId = building.assignedVillagers.pop();
const villager = this.getTheVillager(selectedVillagerId);
villager.assignment = 'none';
const removedVillager = building.assignedVillagers.pop();
removedVillager.assignment = 'none';
this.updateTheBuildings(building);
this.updateTheVillagers(villager);
this.updateTheVillagers(removedVillager);
amount -= 1;
if (amount > 0) {
......
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