-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
97 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,35 @@ | ||
const random = require('./random'); | ||
const backgrounds = require('./data/backgrounds.json'); | ||
const Random = require('./random'); | ||
const Sources = require('./sources'); | ||
const Backgrounds = require('./data/backgrounds.json'); | ||
|
||
module.exports = { | ||
names: function (sources = 'ALL') { | ||
return Sources.flatData(Backgrounds, sources).map(b => b.name); | ||
}, | ||
byName: function (name) { | ||
return [].concat.apply([], Object.keys(backgrounds).map(r => backgrounds[r])).filter(r => r.name === name)[0]; | ||
return [].concat.apply([], Object.keys(Backgrounds).map(r => Backgrounds[r])).filter(r => r.name === name)[0]; | ||
}, | ||
reason: function (background) { | ||
return random.element(background.reasons); | ||
return Random.element(background.reasons); | ||
}, | ||
trait: function (background) { | ||
return random.element(background.traits || []); | ||
return Random.element(background.traits || []); | ||
}, | ||
ideal: function (background, alignment) { | ||
const ideals = background.ideals.filter(i => i.alignments.length === 0 || i.alignments.includes(alignment.abbreviation)); | ||
console.log(ideals); | ||
return random.element(ideals); | ||
return Random.element(ideals); | ||
}, | ||
bond: function (background) { | ||
return random.element(background.bonds || []); | ||
return Random.element(background.bonds || []); | ||
}, | ||
flaw: function (background) { | ||
return random.element(background.flaws || []); | ||
return Random.element(background.flaws || []); | ||
}, | ||
other: function (background) { | ||
if (!background.other) return []; | ||
return Object.keys(background.other).map(o => ({ name: o, value: random.element(background.other[o]) })); | ||
return Object.keys(background.other).map(o => ({ name: o, value: Random.element(background.other[o]) })); | ||
}, | ||
random: function (sources = 'ALL') { | ||
return random.sourcedElement(backgrounds, sources); | ||
return Random.sourcedElement(Backgrounds, sources); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,22 @@ | ||
const random = require('./random'); | ||
const classes = require('./data/classes.json'); | ||
const Random = require('./random'); | ||
const Sources = require('./sources'); | ||
const Classes = require('./data/classes.json'); | ||
|
||
module.exports = { | ||
names: function (sources = 'ALL') { | ||
return Sources.flatData(Classes, sources).map(c => c.name); | ||
}, | ||
byName: function (name) { | ||
return [].concat.apply([], Object.keys(classes).map(r => classes[r])).filter(r => r.name === name)[0]; | ||
return [].concat.apply([], Object.keys(Classes).map(r => Classes[r])).filter(r => r.name === name)[0]; | ||
}, | ||
random: function (sources = 'ALL') { | ||
return random.sourcedElement(classes, sources); | ||
return Random.sourcedElement(Classes, sources); | ||
}, | ||
reason: function (cClass) { | ||
return random.element(cClass.reasons); | ||
return Random.element(cClass.reasons); | ||
}, | ||
other: function (cClass) { | ||
if (!cClass.other) return []; | ||
return Object.keys(cClass.other).map(o => ({ name: o, value: random.element(cClass.other[o]) })); | ||
return Object.keys(cClass.other).map(o => ({ name: o, value: Random.element(cClass.other[o]) })); | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,42 @@ | ||
const Generator = require('./generator'); | ||
const Formatter = require('./formatter'); | ||
|
||
const Race = require('./generator/race'); | ||
const Background = require('./generator/background'); | ||
const Class = require('./generator/class'); | ||
|
||
function generateCharacter(e) { | ||
const character = Generator(); | ||
const config = { | ||
race: selectedValue('race'), | ||
class: selectedValue('class'), | ||
background: selectedValue('background'), | ||
} | ||
const character = Generator(config); | ||
document.getElementById('character').innerHTML = Formatter(character); | ||
if (e) { e.preventDefault(); } | ||
return false; | ||
} | ||
|
||
function fillDropdown(id, source) { | ||
const select = document.getElementById(id); | ||
source.forEach(c => { | ||
const o = document.createElement('option'); | ||
o.text = o.value = c; | ||
select.add(o); | ||
}); | ||
} | ||
|
||
function selectedValue(id) { | ||
const select = document.getElementById(id); | ||
return select.options[select.selectedIndex].value; | ||
} | ||
|
||
function populateDropdowns() { | ||
fillDropdown('race', Race.names()); | ||
fillDropdown('class', Class.names()); | ||
fillDropdown('background', Background.names()); | ||
} | ||
|
||
document.getElementById('generate').addEventListener('click', generateCharacter); | ||
generateCharacter(); | ||
generateCharacter(); | ||
populateDropdowns(); |