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

move index.js defaults to a defaults dir

parent e2671f0b
......@@ -4,7 +4,12 @@ import { Building } from './building';
export class Buildings extends React.Component {
sortBuildings = (buildings) => {
buildings.sort((a, b) => a.priority > b.priority);
}
render(props) {
this.sortBuildings(this.props.buildings);
return <div className="buildingContainer">
<div className="buildings">
<h3>Buildings</h3>
......
import KNOBS_AND_LEVERS from './knobs-and-levers';
let theBuildings = []
export default theBuildings = [
{type: 'production',
id: 100,
priority: 100,
name: 'SMITHY',
label: 'Smithy',
description: 'workers are more efficient with the right tools',
materials: ['wood', 'iron'],
goods: ['tool'],
assignedVillagers: [],
capacity: KNOBS_AND_LEVERS.defaultCapacity,
progress: 0,
baseProductionRate: KNOBS_AND_LEVERS.defaultProductionRate,
producing: false
},
{type: 'extraction',
id: 10,
priority: 10,
name: 'FORESTER_HUT',
label: "Forester's Hut",
description: "it's big, it's heavy, it's wood",
goods: ['wood'],
assignedVillagers: [],
capacity: KNOBS_AND_LEVERS.defaultCapacity,
progress: 0,
baseProductionRate: KNOBS_AND_LEVERS.defaultProductionRate,
producing: false
},
{type: 'extraction',
id: 20,
priority: 20,
name: 'GATHERER_HUT',
label: "Gatherer's Hut",
description: "nuts, berries, and tubers are packed with nutrients",
goods: ['food', 'food'],
assignedVillagers: [],
capacity: KNOBS_AND_LEVERS.defaultCapacity,
progress: 0,
baseProductionRate: KNOBS_AND_LEVERS.defaultProductionRate,
producing: false
},
{type: 'extraction',
id: 30,
priority: 30,
name: 'HUNTER_LODGE',
label: "Hunter's Lodge",
description: "take advantage of nature's bounty",
goods: ['food', 'hide'],
assignedVillagers: [],
capacity: KNOBS_AND_LEVERS.defaultCapacity,
progress: 0,
baseProductionRate: KNOBS_AND_LEVERS.defaultProductionRate,
producing: false
},
{type: 'extraction',
id: 40,
priority: 40,
name: 'MINE',
label: "Mine",
description: "the strength of the earth to forge the tools",
goods: ['iron'],
assignedVillagers: [],
capacity: KNOBS_AND_LEVERS.defaultCapacity,
progress: 0,
baseProductionRate: KNOBS_AND_LEVERS.defaultProductionRate,
producing: false
},
{type: 'production',
id: 110,
priority: 110,
name: 'WOODCUTTER',
label: 'Woodcutter',
description: "it's big, it's heavy, it's wood",
materials: ['wood'],
goods: ['firewood','firewood','firewood'],
assignedVillagers: [],
capacity: KNOBS_AND_LEVERS.defaultCapacity,
progress: 0,
baseProductionRate: KNOBS_AND_LEVERS.defaultProductionRate,
producing: false
},
{type: 'production',
id: 120,
priority: 120,
name: 'TAILOR',
label: 'Tailor',
description: "clothing to keep warm",
materials: ['hide'],
goods: ['clothing'],
assignedVillagers: [],
capacity: KNOBS_AND_LEVERS.defaultCapacity,
progress: 0,
baseProductionRate: KNOBS_AND_LEVERS.defaultProductionRate,
producing: false
}
]
import KNOBS_AND_LEVERS from './knobs-and-levers';
let villagers = []
const addVillager = () => {
let nextId = villagers.length > 0 ? Math.max(...villagers.map(v => v.id)) + 1 : 0;
const villager = {
id: nextId,
hasTool: KNOBS_AND_LEVERS.villagerHasTool,
toolDurability: KNOBS_AND_LEVERS.toolDurability,
assignment: "IDLE",
warmth: 100,
energy: 100,
clothed: KNOBS_AND_LEVERS.villagerClothed,
clothingDurability: 100,
// clothed: nextId % 2 === 0 ? knobsAndLevers.villagerClothed : false,
// clothingDurability: nextId % 2 === 0 ? 100 : 0,
};
villagers.push(villager);
if (villagers.length < KNOBS_AND_LEVERS['startingVillagers']) {
addVillager();
}
}
addVillager();
export default villagers;
const instructions = [
"Generate resources to keep your villagers alive.",
"Food prevents starvation.",
"Firewood prevents freezing.",
"Clothing staves off freezing longer.",
"Tools significantly increase production rate.",
"If a villager is freezing or starving for too long, the villager dies.",
]
export default instructions;
const knobsAndLevers = {
interval: 1000,
score: 0,
maxLogArraySize: 100,
startingVillagers: 10,
villagerDeathValue: -50,
villagerWarningValue: 0,
villagerHasTool: true,
toolMultiplier: 4,
toolDurability: 100,
toolDegradeRate: 1,
villagerClothed: true,
clothingDegradeRate: 1,
clothingWarmthDecayReduction: 2,
baseWarmthDecayRate: 3,
warmthReplenishThreshold: 10,
warmthPerFirewood: 80,
baseEnergyDegradeRate: 1,
assignmentEnergyMultiplier: 2,
energyReplenishThreshold: 10,
energyPerFood: 80,
productionComplete: 100,
defaultCapacity: 20,
defaultProductionRate: 1,
defaultToolStores: 25,
defaultFirewoodStores: 50,
defaultFoodStores: 50,
defaultClothingStores: 25,
defaultHideStores: 0,
defaultIronStores: 0,
defaultWoodStores: 0,
}
module.exports = knobsAndLevers;
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}},
};
export default villageStore;
import KNOBS_AND_LEVERS from './knobs-and-levers';
const villagerStatus = {
naked: {count: 0, classNames: {badThingHappened: false}},
toolless: {count: 0, classNames: {badThingHappened: false}},
starving: {count: 0, classNames: {badThingHappened: false}},
freezing: {count: 0, classNames: {badThingHappened: false}},
unassigned: {count: KNOBS_AND_LEVERS.startingVillagers, classNames: {badThingHappened: false}},
dead: {count: 0, classNames: {badThingHappened: false}},
}
export default villagerStatus;
import React from 'react';
import INSTRUCTIONS from './defaults/instructions';
export class Rules extends React.Component {
render(props) {
return <div className="rules">
{ this.props.rules.map(rule => <div key={Math.random(Date.now())}>{rule}</div> ) }
{ INSTRUCTIONS.map(rule => <div key={Math.random(Date.now())}>{rule}</div> ) }
</div>
}
}
This diff is collapsed.
......@@ -6,217 +6,13 @@ import './index.css';
import { Village } from './components/village';
import { Rules } from './components/rules';
const knobsAndLevers = {
interval: 1000,
score: 0,
maxLogArraySize: 100,
startingVillagers: 10,
villagerDeathValue: -50,
villagerWarningValue: 0,
villagerHasTool: true,
toolMultiplier: 4,
toolDurability: 100,
toolDegradeRate: 1,
villagerClothed: true,
clothingDegradeRate: 1,
clothingWarmthDecayReduction: 2,
baseWarmthDecayRate: 3,
warmthReplenishThreshold: 10,
warmthPerFirewood: 80,
baseEnergyDegradeRate: 1,
assignmentEnergyMultiplier: 2,
energyReplenishThreshold: 10,
energyPerFood: 80,
productionComplete: 100,
defaultCapacity: 50,
defaultProductionRate: 1,
defaultToolStores: 25,
defaultFirewoodStores: 50,
defaultFoodStores: 50,
defaultClothingStores: 25,
defaultHideStores: 0,
defaultIronStores: 0,
defaultWoodStores: 0,
}
const startingLog = [
"Generate resources to keep your villagers alive.",
"Food prevents starvation.",
"Firewood prevents freezing.",
"Clothing staves off freezing longer.",
"Tools significantly increase production rate.",
"If a villager is freezing or starving for too long, the villager dies.",
]
const villageStore = {
wood: {count: knobsAndLevers.defaultWoodStores, source: 'FORESTER_HUT', classNames: {goodThingHappened: false, badThingHappened: false}},
tool: {count: knobsAndLevers.defaultToolStores, source: 'SMITHY', classNames: {goodThingHappened: false, badThingHappened: false}},
iron: {count: knobsAndLevers.defaultIronStores, source: 'MINE', classNames: {goodThingHappened: false, badThingHappened: false}},
firewood: {count: knobsAndLevers.defaultFirewoodStores, source: 'WOODCUTTER_HUT', classNames: {goodThingHappened: false, badThingHappened: false}},
food: {count: knobsAndLevers.defaultFoodStores, source: 'GATHERER_HUT, HUNTER_LODGE', classNames: {goodThingHappened: false, badThingHappened: false}},
hide: {count: knobsAndLevers.defaultHideStores, source: 'HUNTER_LODGE', classNames: {goodThingHappened: false, badThingHappened: false}},
clothing: {count: knobsAndLevers.defaultClothingStores, source: 'TAILOR', classNames: {goodThingHappened: false, badThingHappened: false}},
};
const villagerStatus = {
naked: {count: 0, classNames: {badThingHappened: false}},
toolless: {count: 0, classNames: {badThingHappened: false}},
starving: {count: 0, classNames: {badThingHappened: false}},
freezing: {count: 0, classNames: {badThingHappened: false}},
unassigned: {count: knobsAndLevers.startingVillagers, classNames: {badThingHappened: false}},
dead: {count: 0, classNames: {badThingHappened: false}},
}
const addVillager = () => {
let nextId = villagers.length > 0 ? Math.max(...villagers.map(v => v.id)) + 1 : 0;
const villager = {
id: nextId,
hasTool: knobsAndLevers.villagerHasTool,
toolDurability: knobsAndLevers.toolDurability,
assignment: "IDLE",
warmth: 100,
energy: 100,
clothed: knobsAndLevers.villagerClothed,
clothingDurability: 100,
// clothed: nextId % 2 === 0 ? knobsAndLevers.villagerClothed : false,
// clothingDurability: nextId % 2 === 0 ? 100 : 0,
};
villagers.push(villager);
if (villagers.length < knobsAndLevers['startingVillagers']) {
addVillager();
}
}
const restart = () => {
init();
}
let villagers = []
let buildings = []
const init = () => {
villagers = []
buildings = []
addVillager();
generateBuildings();
}
const generateBuildings = () => {
buildings.push({type: 'production',
id: 100,
priority: 100,
name: 'SMITHY',
label: 'Smithy',
description: 'workers are more efficient with the right tools',
materials: ['wood', 'iron'],
goods: ['tool'],
assignedVillagers: [],
capacity: knobsAndLevers.defaultCapacity,
progress: 0,
baseProductionRate: knobsAndLevers.defaultProductionRate,
producing: false
});
buildings.push({type: 'extraction',
id: 10,
priority: 10,
name: 'FORESTER_HUT',
label: "Forester's Hut",
description: "it's big, it's heavy, it's wood",
goods: ['wood'],
assignedVillagers: [],
capacity: knobsAndLevers.defaultCapacity,
progress: 0,
baseProductionRate: knobsAndLevers.defaultProductionRate,
producing: false
});
buildings.push({type: 'extraction',
id: 20,
priority: 20,
name: 'GATHERER_HUT',
label: "Gatherer's Hut",
description: "nuts, berries, and tubers are packed with nutrients",
goods: ['food', 'food'],
assignedVillagers: [],
capacity: knobsAndLevers.defaultCapacity,
progress: 0,
baseProductionRate: knobsAndLevers.defaultProductionRate,
producing: false
});
buildings.push({type: 'extraction',
id: 30,
priority: 30,
name: 'HUNTER_LODGE',
label: "Hunter's Lodge",
description: "take advantage of nature's bounty",
goods: ['food', 'hide'],
assignedVillagers: [],
capacity: knobsAndLevers.defaultCapacity,
progress: 0,
baseProductionRate: knobsAndLevers.defaultProductionRate,
producing: false
});
buildings.push({type: 'extraction',
id: 40,
priority: 40,
name: 'MINE',
label: "Mine",
description: "the strength of the earth to forge the tools",
goods: ['iron'],
assignedVillagers: [],
capacity: knobsAndLevers.defaultCapacity,
progress: 0,
baseProductionRate: knobsAndLevers.defaultProductionRate,
producing: false
});
buildings.push({type: 'production',
id: 110,
priority: 110,
name: 'WOODCUTTER',
label: 'Woodcutter',
description: "it's big, it's heavy, it's wood",
materials: ['wood'],
goods: ['firewood','firewood','firewood'],
assignedVillagers: [],
capacity: knobsAndLevers.defaultCapacity,
progress: 0,
baseProductionRate: knobsAndLevers.defaultProductionRate,
producing: false
});
buildings.push({type: 'production',
id: 120,
priority: 120,
name: 'TAILOR',
label: 'Tailor',
description: "clothing to keep warm",
materials: ['hide'],
goods: ['clothing'],
assignedVillagers: [],
capacity: knobsAndLevers.defaultCapacity,
progress: 0,
baseProductionRate: knobsAndLevers.defaultProductionRate,
producing: false
});
const Game = () => {
return <div className="game">
<Village buildings={buildings} villageStore={villageStore}
villagers={villagers} knobsAndLevers={knobsAndLevers}
start={Date.now()} restart={restart} villagerStatus={villagerStatus}
/>
<Rules rules={startingLog} />
</div>
}
ReactDOM.render(<Game />,
document.getElementById('root')
);
const Game = () => {
return <div className="game">
<Village start={Date.now()} />
<Rules />
</div>
}
init();
ReactDOM.render(<Game />,
document.getElementById('root')
);
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