Commit 5e3e1c6b authored by Matthew Odle's avatar Matthew Odle

add priority adjustment and sorting

parent f6b1d081
......@@ -30,3 +30,4 @@ update:
* Tools now affect production rate
* Tools now degrade and break
* Added pretty colors to indicate production status
* Added sorting and priority adjustment; it's somewhat fragile: if there is no building with a priority 1 higher, the building will not move; this means if building a has priority 5 and building b has priority 10, nothing will happen when the up/down buttons are pushed. If there is any break in the sequence of priorities in the buildings array, reassignment of priority will not work. A better approach would be to find the next highest value.
import React from 'react';
import { Materials } from './materials';
import { Goods } from './goods';
import { Materials } from './materials';
import { Priority } from './priority';
import { AssignedVillagers } from './assigned-villagers';
export class Building extends React.Component {
......@@ -13,6 +14,7 @@ export class Building extends React.Component {
<div className='tooltip'>{building.label}
<span className='tooltiptext'>{building.description}</span>
</div>
{ building.priority != undefined ? <Priority building={building} increasePriority={this.props.increasePriority} decreasePriority={this.props.decreasePriority} /> : null }
{ building.goods ? <Goods building={building} /> : null }
{ building.materials ? <Materials building={building} /> : null }
<div>Active: {building.producing ? "Yes" : "No" }</div>
......
import React from 'react';
export class Priority extends React.Component {
render() {
var building = this.props.building;
return (
<div className='materials'>
<button type="button" id="increasePriority" onClick={() => this.props.increasePriority(building)}>^</button>
<button type="button" id="decreasePriority" onClick={() => this.props.decreasePriority(building)}>v</button>
</div>
);
}
}
......@@ -19,6 +19,10 @@ export class Village extends React.Component {
};
}
//----- push button functions -----//
getUnassignedVillagers = () => {
return this.props.villagers.slice().filter( villager => villager.assignment === 'none')
}
......@@ -93,6 +97,37 @@ export class Village extends React.Component {
}
};
increasePriority = (building) => {
console.log('increase. beep boop beep.')
if (building.priority === 0) {
return;
}
const buildings = this.state.buildings.slice();
const buildingToSwapWith = buildings.find( otherBuilding => otherBuilding.priority === building.priority - 1 );
if (buildingToSwapWith) {
building.priority = building.priority -= 1;
this.updateTheBuildings(building);
buildingToSwapWith.priority += 1;
this.updateTheBuildings(buildingToSwapWith);
}
}
decreasePriority = (building) => {
const buildings = this.state.buildings.slice();
const buildingToSwapWith = buildings.find( otherBuilding => otherBuilding.priority === building.priority + 1 );
if (buildingToSwapWith) {
building.priority += 1;
this.updateTheBuildings(building);
buildingToSwapWith.priority -= 1;
this.updateTheBuildings(buildingToSwapWith);
}
}
//----- cycle management functions -----//
canProduce = (building) => {
const theItems = this.state.villageStore.slice();
let flag = true;
......@@ -213,7 +248,6 @@ export class Village extends React.Component {
});
};
tick = () => {
const buildings = this.props.buildings.slice();
this.manageProductionBuildings(buildings);
......@@ -246,7 +280,13 @@ export class Village extends React.Component {
<h3>Buildings</h3>
<div className="buildings">
{ buildings.map( building =>
<Building key={building.id} building={building} manageVillagers={this.manageVillagers} />
<Building
key={building.id}
building={building}
manageVillagers={this.manageVillagers}
increasePriority={this.increasePriority}
decreasePriority={this.decreasePriority}
/>
)}
</div>
</div>
......
......@@ -42,7 +42,7 @@ buildings.push({type: 'production',
name: 'SMITHY',
label: 'Smithy',
description: 'workers are more efficient with the right tools',
priority: 3,
priority: 2,
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: 1,
priority: 0,
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: 2,
priority: 1,
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: 4,
priority: 3,
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