Commit 88fb60ff authored by Matthew Odle's avatar Matthew Odle

building swapping now appropriately swaps

previously, the values would not have actually swapped, but rather would have incremented/decremented, but appeared to swap correctly because the priorities were in an unbroken sequence
parent dc087a93
......@@ -104,11 +104,12 @@ export class Village extends React.Component {
const buildingsWithLowerPriority = buildings.filter( otherBuilding => otherBuilding.priority < building.priority );
if (buildingsWithLowerPriority.length > 0) {
building.priority = building.priority -= 1;
const currentPriority = building.priority;
const buildingToSwapWith = buildingsWithLowerPriority.reduce((a, b) => a.priority > b.priority ? a : b)
building.priority = buildingToSwapWith.priority;
this.updateTheBuildings(building);
const buildingToSwapWith = buildingsWithLowerPriority.reduce((a, b) => a.priority > b.priority ? a : b)
buildingToSwapWith.priority += 1;
buildingToSwapWith.priority = currentPriority;
this.updateTheBuildings(buildingToSwapWith);
}
}
......@@ -118,11 +119,12 @@ export class Village extends React.Component {
const buildingsWithHigherPriority = buildings.filter( otherBuilding => otherBuilding.priority > building.priority );
if (buildingsWithHigherPriority.length > 0) {
building.priority += 1;
const currentPriority = building.priority;
const buildingToSwapWith = buildingsWithHigherPriority.reduce((a, b) => a.priority < b.priority ? a : b)
building.priority = buildingToSwapWith.priority;
this.updateTheBuildings(building);
const buildingToSwapWith = buildingsWithHigherPriority.reduce((a, b) => a.priority < b.priority ? a : b)
buildingToSwapWith.priority -= 1;
buildingToSwapWith.priority = currentPriority;
this.updateTheBuildings(buildingToSwapWith);
}
}
......
......@@ -45,7 +45,7 @@ buildings.push({type: 'production',
name: 'SMITHY',
label: 'Smithy',
description: 'workers are more efficient with the right tools',
priority: 2,
priority: 8,
materials: ['wood', 'iron'],
goods: ['tool'],
assignedVillagers: [],
......@@ -59,7 +59,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: 2,
goods: ['wood'],
assignedVillagers: [],
capacity: knobsAndLevers.defaultCapacity,
......@@ -72,7 +72,7 @@ buildings.push({type: 'extraction',
name: 'MINE',
label: "Mine",
description: "the strength of the earth to forge the tools",
priority: 1,
priority: 4,
goods: ['iron'],
assignedVillagers: [],
capacity: knobsAndLevers.defaultCapacity,
......@@ -85,7 +85,7 @@ buildings.push({type: 'production',
name: 'WOODCUTTER',
label: 'Woodcutter',
description: "it's big, it's heavy, it's wood",
priority: 3,
priority: 0,
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