Commit 784d59c6 authored by Matthew Odle's avatar Matthew Odle

correct linting errors; add default rates and tooltip

parent b5af0eb7
web: react-scripts start
api: nodemon server.js
'use strict'
// first we import our dependencies…
var express = require('express');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var Leaderboard = require('./model/leaderboard-schema');
var env = require('node-env-file');
env(__dirname + '/.env');
var app = express();
var router = express.Router();
var port = process.env.API_PORT || 3001;
mongoose.connect(process.env.DATABASE_URL, {'useMongoClient': true, });
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// To prevent errors from Cross Origin Resource Sharing,
// set headers to allow CORS with middleware:
app.use(function(req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Credentials', 'true');
res.setHeader('Access-Control-Allow-Methods', 'GET,HEAD,OPTIONS,POST,PUT,DELETE');
res.setHeader('Access-Control-Allow-Headers', 'Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers');
// remove cacheing to get most recent entries
res.setHeader('Cache-Control', 'no-cache');
next();
});
// set root route
router.get('/', function(req, res) {
res.json({ message: 'API Initialized!'});
});
router.route('/leaderboard')
.get(function(req, res) {
Leaderboard.find(function(err, entries) {
if (err) {
res.send(err);
}
res.json(entries)
});
})
.post(function(req, res) {
var leaderboard = new Leaderboard();
leaderboard.name = req.body.name;
leaderboard.score = req.body.score;
leaderboard.save(function(err) {
if (err) {
res.send(err);
}
res.json({ message: 'Leaderboard successfully added!' });
});
});
app.use('/api', router);
app.listen(port, function() {
console.log('api running on port ' + port);
});
const defaultMessages = {
allDead: 'dead... all dead.',
};
export default defaultMessages;
import KNOBS_AND_LEVERS from './knobs-and-levers';
let theBuildings = []
export default theBuildings = [
let theBuildings = [
{type: 'production',
id: 100,
priority: 100,
......@@ -97,3 +96,5 @@ export default theBuildings = [
producing: false
}
]
export default theBuildings;
......@@ -20,7 +20,8 @@ const knobsAndLevers = {
warmthReplenishThreshold: 10,
warmthPerFirewood: 80,
baseEnergyDegradeRate: 100,
baseEnergyDegradeRate: 1,
// baseEnergyDegradeRate: 100,
assignmentEnergyMultiplier: 2,
energyReplenishThreshold: 10,
energyPerFood: 80,
......@@ -29,14 +30,14 @@ const knobsAndLevers = {
defaultCapacity: 20,
defaultProductionRate: 1,
defaultToolStores: 0,
defaultFirewoodStores: 0,
defaultFoodStores: 0,
defaultClothingStores: 0,
// defaultToolStores: 25,
// defaultFirewoodStores: 50,
// defaultFoodStores: 50,
// defaultClothingStores: 25,
// defaultToolStores: 0,
// defaultFirewoodStores: 0,
// defaultFoodStores: 0,
// defaultClothingStores: 0,
defaultToolStores: 25,
defaultFirewoodStores: 50,
defaultFoodStores: 50,
defaultClothingStores: 25,
defaultHideStores: 0,
defaultIronStores: 0,
......
import KNOBS_AND_LEVERS from './knobs-and-levers';
const villageStore = {
wood: {count: KNOBS_AND_LEVERS.defaultWoodStores, source: 'FORESTER_HUT', classNames: {goodThingHappened: false, badThingHappened: false}},
tool: {count: KNOBS_AND_LEVERS.defaultToolStores, source: 'SMITHY', classNames: {goodThingHappened: false, badThingHappened: false}},
iron: {count: KNOBS_AND_LEVERS.defaultIronStores, source: 'MINE', classNames: {goodThingHappened: false, badThingHappened: false}},
firewood: {count: KNOBS_AND_LEVERS.defaultFirewoodStores, source: 'WOODCUTTER_HUT', classNames: {goodThingHappened: false, badThingHappened: false}},
food: {count: KNOBS_AND_LEVERS.defaultFoodStores, source: 'GATHERER_HUT, HUNTER_LODGE', classNames: {goodThingHappened: false, badThingHappened: false}},
hide: {count: KNOBS_AND_LEVERS.defaultHideStores, source: 'HUNTER_LODGE', classNames: {goodThingHappened: false, badThingHappened: false}},
clothing: {count: KNOBS_AND_LEVERS.defaultClothingStores, source: 'TAILOR', classNames: {goodThingHappened: false, badThingHappened: false}},
wood: {count: KNOBS_AND_LEVERS.defaultWoodStores, source: 'FORESTER_HUT', rate: 0, classNames: {goodThingHappened: false, badThingHappened: false}},
tool: {count: KNOBS_AND_LEVERS.defaultToolStores, source: 'SMITHY', rate: 0, classNames: {goodThingHappened: false, badThingHappened: false}},
iron: {count: KNOBS_AND_LEVERS.defaultIronStores, source: 'MINE', rate: 0, classNames: {goodThingHappened: false, badThingHappened: false}},
firewood: {count: KNOBS_AND_LEVERS.defaultFirewoodStores, source: 'WOODCUTTER_HUT', rate: 0, classNames: {goodThingHappened: false, badThingHappened: false}},
food: {count: KNOBS_AND_LEVERS.defaultFoodStores, source: 'GATHERER_HUT, HUNTER_LODGE', rate: 0, classNames: {goodThingHappened: false, badThingHappened: false}},
hide: {count: KNOBS_AND_LEVERS.defaultHideStores, source: 'HUNTER_LODGE', rate: 0, classNames: {goodThingHappened: false, badThingHappened: false}},
clothing: {count: KNOBS_AND_LEVERS.defaultClothingStores, source: 'TAILOR', rate: 0, classNames: {goodThingHappened: false, badThingHappened: false}},
};
export default villageStore;
......@@ -42,7 +42,7 @@ export class LeaderboardForm extends React.Component {
style={ style.leaderboardFormName }
value={ this.state.name }
onChange={ this.onChange }
maxlength="15" />
maxLength="15" />
<div style={style.buttons}>
<button style={ style.leaderboardFormButton } onClick={this.handleSubmit} value="Post" >Submit</button>
<button style={ style.leaderboardFormButton } onClick={() => this.props.hideModal()} >Cancel</button>
......
......@@ -7,11 +7,13 @@ export class StoreRow extends React.Component {
const name = this.props.storeItemName;
const storeItemProps = this.props.storeItemProps;
const count = storeItemProps.count;
const rate = storeItemProps.rate;
const rateString = rate + '/s';
const storeClassNames = storeItemProps.classNames;
storeClassNames.badThing = storeItemProps.count <= 0 ? true : false;
const storeClassName = classNames('storeRow', storeClassNames);
return <div className={storeClassName}>
return <div title={rateString} className={storeClassName}>
<div className="storeName">{name}</div>
<div className="storeCount">{count}</div>
<div className="clear"></div>
......
/* eslint react/prop-types: 0 */
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import style from './style';
export class SubmitScoreDialog extends React.Component {
......
......@@ -7,7 +7,7 @@ import { Buildings } from './buildings';
export class VillageManagement extends React.Component {
getUnassignedVillagers = () => {
return this.props.villagers.slice().filter( villager => villager.assignment === 'IDLE');
return this.props.villagers.slice().filter( villager => villager.assignment === 'IDLE' && villager.assignment !== 'DEAD' );
}
assignVillagers = (building, amount) => {
......
......@@ -11,6 +11,7 @@ import { LeaderboardForm } from './leaderboard-form';
import THE_BUILDINGS from './defaults/generate-buildings';
import THE_VILLAGERS from './defaults/generate-villagers';
import KNOBS_AND_LEVERS from './defaults/knobs-and-levers';
import DEFAULT_MESSAGES from './defaults/default-messages';
import VILLAGE_STORE from './defaults/village-store';
import VILLAGER_STATUS from './defaults/villager-status';
import LEADERBOARD_URL from './defaults/leaderboard-url';
......@@ -226,11 +227,11 @@ export class Village extends React.Component {
getTool = (villager) => {
const villageStore = this.state.villageStore;
if (villageStore['tool'].count > 0) {
if (villageStore.tool.count > 0) {
villager.toolDurability = 100;
villager.hasTool = true;
villageStore['tool'].count -= 1;
villageStore['tool'].classNames.badThingHappened = true;
villageStore.tool.count -= 1;
villageStore.tool.classNames.badThingHappened = true;
this.updateLog('tool -1');
}
}
......@@ -243,9 +244,9 @@ export class Village extends React.Component {
getWarm = (villager) => {
const villageStore = this.state.villageStore;
if (villageStore['firewood'].count > 0) {
if (villageStore.firewood.count > 0) {
villager.warmth += KNOBS_AND_LEVERS.warmthPerFirewood;
villageStore['firewood'].count -= 1;
villageStore.firewood.count -= 1;
this.updateLog('firewood -1');
}
}
......@@ -269,11 +270,11 @@ export class Village extends React.Component {
getClothing = (villager) => {
const villageStore = this.state.villageStore;
if (villageStore['clothing'].count > 0) {
if (villageStore.clothing.count > 0) {
villager.clothingDurability = 100;
villager.clothed = true;
villageStore['clothing'].count -= 1;
villageStore['clothing'].classNames.badThingHappened = true
villageStore.clothing.count -= 1;
villageStore.clothing.classNames.badThingHappened = true
this.updateLog('clothing -1');
}
}
......@@ -286,10 +287,10 @@ export class Village extends React.Component {
getFood = (villager) => {
const villageStore = this.state.villageStore;
if (villageStore['food'].count > 0) {
if (villageStore.food.count > 0) {
villager.energy += KNOBS_AND_LEVERS.energyPerFood;
villageStore['food'].count -= 1;
villageStore['food'].classNames.badThingHappened = true
villageStore.food.count -= 1;
villageStore.food.classNames.badThingHappened = true
this.updateLog('food -1');
}
}
......@@ -388,7 +389,7 @@ export class Village extends React.Component {
const villagers = this.state.villagers.slice();
let everyoneIsDead = true;
villagers.map( villager => villager.assignment === 'DEAD' && everyoneIsDead ? everyoneIsDead = true : everyoneIsDead = false);
everyoneIsDead ? this.updateLog("dead... all dead.") : null;
everyoneIsDead ? this.updateLog(DEFAULT_MESSAGES.allDead) : null;
this.setState({
gameOver: everyoneIsDead,
});
......@@ -404,9 +405,13 @@ export class Village extends React.Component {
}
resetStoreClassNames = () => {
Array.from(Object.keys(this.state.villageStore)).map( key => {
this.state.villageStore[key].classNames.goodThingHappened = false;
this.state.villageStore[key].classNames.badThingHappened = false;
const stores = this.state.villageStore;
Array.from(Object.keys(stores)).map( key => {
stores[key].classNames.goodThingHappened = false;
stores[key].classNames.badThingHappened = false;
});
this.setState({
villageStore: stores,
});
}
......
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