Commit edaac3c0 authored by Matthew Odle's avatar Matthew Odle

tools now do things

* Added more knobsAndLevers values
* Tools now affect production rate
* Tools now degrade and break
* Added pretty colors to indicate production status
parent 081dc821
......@@ -24,3 +24,9 @@ update:
2017-10-31
* Implemented villager object assignment to buildings; used filter and find operations on the Villager array to handle determining how many unassigned, and first unassigned
* Next: have tool affect production rate
2017-11-01
* Added more knobsAndLevers values
* Tools now affect production rate
* Tools now degrade and break
* Added pretty colors to indicate production status
......@@ -9,19 +9,19 @@ export class Building extends React.Component {
render() {
var building = this.props.building;
return (
<div className='building'>
<div className={ building.producing ? "building yes" : "building no" }>
<div className='tooltip'>{building.label}
<span className='tooltiptext'>{building.description}</span>
</div>
<button type="button" id="addAVillager" onClick={() => this.props.manageVillagers(building, 1, 'assign')}>+</button>
<button type="button" id="removeAVillger" onClick={() => this.props.manageVillagers(building, 1, 'unassign')}>-</button>
<button type="button" id="addManyVillagers" onClick={() => this.props.manageVillagers(building, 10, 'assign')}>++</button>
<button type="button" id="removeManyVillagers" onClick={() => this.props.manageVillagers(building, 10, 'unassign')}>--</button>
{ building.goods ? <Goods building={building} /> : null }
{ building.materials ? <Materials building={building} /> : null }
<div>Active: {building.producing ? "Yes" : "No" }</div>
<div>Progress: {building.progress}</div>
{ building.assignedVillagers ? <AssignedVillagers building={building} /> : null }
<button type="button" id="addAVillager" onClick={() => this.props.manageVillagers(building, 1, 'assign')}>+</button>
<button type="button" id="removeAVillger" onClick={() => this.props.manageVillagers(building, 1, 'unassign')}>-</button>
<button type="button" id="addManyVillagers" onClick={() => this.props.manageVillagers(building, 10, 'assign')}>++</button>
<button type="button" id="removeManyVillagers" onClick={() => this.props.manageVillagers(building, 10, 'unassign')}>--</button>
</div>
);
}
......
......@@ -148,24 +148,52 @@ export class Village extends React.Component {
}
};
processProductionCycle = (building) => {
getProductionMultiplier = (villagers) => {
let multiplier = 0;
building.assignedVillagers.map(villager =>
villagers.map(villager =>
multiplier += villager.hasTool
? this.props.knobsAndLevers.toolMultiplier
: 1
);
// if multiplier is 0 or less, we're not producing
if (multiplier <= 0) {
building.producing = false;
return;
}
return multiplier;
}
degradeTools = (villagers) => {
// eslint-disable-next-line
villagers.map(villager => {
// eslint-disable-next-line
villager.hasTool && villager.toolDurability > 0
? villager.toolDurability -= this.props.knobsAndLevers.toolDegradeRate
: null;
// eslint-disable-next-line
villager.hasTool && villager.toolDurability <= 0
? villager.hasTool = false
: null
})
}
manageBuildingMaterials = (building) => {
if (building.materials && !building.materialsInUse) {
this.useMaterials(building);
};
}
updateProductionStatus = (building, multiplier) => {
building.progress += building.baseProductionRate * multiplier;
this.degradeTools(building.assignedVillagers);
building.producing = true;
}
processProductionCycle = (building) => {
const multiplier = this.getProductionMultiplier(building.assignedVillagers);
// if multiplier is 0, we're not producing
if (multiplier === 0) {
building.producing = false;
return;
}
this.manageBuildingMaterials(building);
this.updateProductionStatus(building, multiplier);
};
manageProductionBuildings = (buildings) => {
......
......@@ -40,3 +40,16 @@
button {
margin-left: 10px;
}
.yes {
background-color: aquamarine;
}
.no {
background-color: bisque;
}
.building {
width: 200px;
margin-right: none;
}
\ No newline at end of file
......@@ -10,10 +10,12 @@ const knobsAndLevers = {
villagerHasTool: true,
toolMultiplier: 4,
toolDurability: 100,
toolDegradeRate: 20,
interval: 1000,
productionComplete: 100,
defaultCapacity: 50,
defaultProductionRate: 1,
elapsed: 0,
}
const villageStore = [
{name: 'wood', count: 0, source: 'FORESTER_HUT'},
......
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