Commit 47a85885 authored by Matthew Odle's avatar Matthew Odle

add a villagerStatus property for unassigned villagers

parent b178c167
......@@ -7,7 +7,7 @@ export class Status extends React.Component {
render(props) {
const statuses = this.props.statuses;
return <div className="statusContainer">
<h3>Status</h3>
<h3>Villager Status</h3>
<div className="statuses">
<div className="infos">
{ Array.from(Object.keys(statuses)).map( status =>
......
......@@ -6,42 +6,12 @@ import { Buildings } from './buildings';
export class VillageManagement extends React.Component {
increasePriority = (building) => {
const buildings = this.props.buildings.slice();
const buildingsWithLowerPriority = buildings.filter( otherBuilding => otherBuilding.priority < building.priority );
if (buildingsWithLowerPriority.length > 0) {
const currentPriority = building.priority;
const buildingToSwapWith = buildingsWithLowerPriority.reduce((a, b) => a.priority > b.priority ? a : b)
building.priority = buildingToSwapWith.priority;
this.props.updateTheBuildings(building);
buildingToSwapWith.priority = currentPriority;
this.props.updateTheBuildings(buildingToSwapWith);
}
}
decreasePriority = (building) => {
const buildings = this.props.buildings.slice();
const buildingsWithHigherPriority = buildings.filter( otherBuilding => otherBuilding.priority > building.priority );
if (buildingsWithHigherPriority.length > 0) {
const currentPriority = building.priority;
const buildingToSwapWith = buildingsWithHigherPriority.reduce((a, b) => a.priority < b.priority ? a : b)
building.priority = buildingToSwapWith.priority;
this.props.updateTheBuildings(building);
buildingToSwapWith.priority = currentPriority;
this.props.updateTheBuildings(buildingToSwapWith);
}
}
getUnassignedVillagers = () => {
return this.props.villagers.slice().filter( villager => villager.assignment === 'IDLE')
return this.props.villagers.slice().filter( villager => villager.assignment === 'IDLE');
}
assignVillagers = (building, amount) => {
if (building.capacity - building.assignedVillagers.length <= 0 || this.getUnassignedVillagers().length === 0) {
if (building.capacity - building.assignedVillagers.length <= 0 || this.props.villagerStatus.unassigned === 0) {
return;
}
......@@ -78,12 +48,13 @@ export class VillageManagement extends React.Component {
}
manageVillagerAssignments = (building, amount, operation) => {
if (operation === 'assign' && this.getUnassignedVillagers().length > 0) {
if (operation === 'assign' && this.props.villagerStatus.unassigned > 0) {
this.assignVillagers(building, amount);
}
if (operation === 'unassign') {
this.unassignVillagers(building, amount);
}
this.props.villagerStatus.unassigned = this.getUnassignedVillagers().length;
};
render = () => {
......
......@@ -22,7 +22,7 @@ export class Village extends React.Component {
villageStore: props.villageStore.slice(),
villagers: props.villagers.slice(),
log: [],
villagerStatus: {naked: 0, toolless: 0, starving: 0, freezing: 0},
villagerStatus: {naked: 0, toolless: 0, starving: 0, freezing: 0, unassigned: props.knobsAndLevers.startingVillagers},
};
}
......@@ -332,7 +332,11 @@ export class Village extends React.Component {
}
captureGameStatusInfo = () => {
let villagerStatus = {naked: 0, toolless: 0, starving: 0, freezing: 0};
const villagerStatus = this.state.villagerStatus;
villagerStatus.toolless = 0;
villagerStatus.naked = 0;
villagerStatus.starving = 0;
villagerStatus.freezing = 0;
const warningValue = this.props.knobsAndLevers.villagerWarningValue;
const villagers = this.state.villagers.slice();
villagers.map(villager => {
......
......@@ -38,6 +38,10 @@ button {
height: 150px;
overflow: hidden;
}
.score {
width: 35px;
padding: 5px 0;
}
.buildingContainer {
float: left;
......@@ -53,9 +57,6 @@ button {
.buildingLabel {
font: bold 1em Georgia, serif;
}
.priority {
float: right;
}
.management {
position: relative;
......@@ -131,12 +132,6 @@ button {
clear: both;
}
.score {
width: 35px;
padding: 5px 0;
}
@media (min-width: 768px) {
* {
font-size: 16px;
......
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