mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-12 21:52:42 +00:00
Populate now generates a bunch of rnadom brews
This commit is contained in:
@@ -5,16 +5,20 @@ const DB = require('../server/db.js');
|
||||
const BrewData = require('../server/brew.data.js');
|
||||
//const BrewGen = require('../tests/brew.gen.js');
|
||||
|
||||
const BrewGen = require('../shared/homebrewery/snippets/brew/brew.snippet.js');
|
||||
|
||||
const BREW_COUNT = 50;
|
||||
|
||||
return Promise.resolve()
|
||||
.then(DB.connect)
|
||||
.then(BrewData.removeAll)
|
||||
.then(() => {
|
||||
console.log('Adding random brews...');
|
||||
return BrewGen.populateDB(BrewGen.random(50));
|
||||
return _.reduce(_.times(BREW_COUNT, BrewGen.brewModel), (flow, model)=>{
|
||||
return flow.then(()=>BrewData.create(model))
|
||||
}, Promise.resolve());
|
||||
})
|
||||
.then(() => {
|
||||
console.log('Adding specific brews...');
|
||||
return BrewGen.populateDB(BrewGen.static());
|
||||
console.log(`Added ${BREW_COUNT} brews`);
|
||||
})
|
||||
.then(() => {
|
||||
return DB.close();
|
||||
|
||||
@@ -11,7 +11,6 @@ renderer.paragraph = function(text){
|
||||
if(!matches) return `\n<p>${text}</p>\n`;
|
||||
let matchIndex = 0;
|
||||
const res = _.reduce(text.split(blockReg), (r, text) => {
|
||||
console.log(text);
|
||||
//if(text) r.push(text);
|
||||
if(text) r.push(Markdown(text, {renderer : renderer, sanitize: true}));
|
||||
|
||||
|
||||
@@ -11,25 +11,53 @@ const Snips = _.merge(
|
||||
);
|
||||
|
||||
const BrewSnippets = {
|
||||
brewModel : ()=>{
|
||||
return {
|
||||
title : Data.rand(Data.titles),
|
||||
description : Data.rand(Data.subtitles),
|
||||
text : BrewSnippets.brew(),
|
||||
|
||||
authors : _.sampleSize(['userA','userB','userC','userD'], _.random(0, 3)),
|
||||
systems : _.sampleSize(['5e', '4e', '3.5e', 'Pathfinder'], _.random(0,2)),
|
||||
views : _.random(0,1000),
|
||||
published : !!_.random(0,1)
|
||||
}
|
||||
},
|
||||
brew : ()=>{
|
||||
return _.times(_.random(1,10), ()=>BrewSnippets.page()).join('\n\n\\page\n\n');
|
||||
return _.times(_.random(1,10), ()=>_.sample([
|
||||
BrewSnippets.page1,
|
||||
BrewSnippets.page2
|
||||
])()).join('\n\n\\page\n\n');
|
||||
},
|
||||
|
||||
page : ()=>{
|
||||
page1 : ()=>{
|
||||
return BrewSnippets.filler(_.random(10, 15), [Snips.monster, Snips.table]);
|
||||
},
|
||||
|
||||
const base = [
|
||||
page2 : ()=>{
|
||||
const title = '# ' + Data.rand('titles');
|
||||
let table = Snips.noncasterTable();
|
||||
|
||||
if(Data.chance(3)){
|
||||
table = Snips.casterTable();
|
||||
if(Data.chance(2)) table = Snips.halfcasterTable();
|
||||
return `${title}\n\n${table}\n\n${BrewSnippets.paragraph(true)}\n\n${BrewSnippets.filler(3)}`;
|
||||
}
|
||||
return `${title}\n\n${table}\n\n${BrewSnippets.paragraph(true)}\n\n${BrewSnippets.filler(5)}`;
|
||||
},
|
||||
|
||||
filler : (count = 1, additional = [])=>{
|
||||
const base = _.concat([
|
||||
BrewSnippets.paragraph, BrewSnippets.paragraph, BrewSnippets.paragraph, BrewSnippets.paragraph,
|
||||
BrewSnippets.paragraph, BrewSnippets.paragraph, BrewSnippets.paragraph, BrewSnippets.paragraph,
|
||||
Snips.table, Snips.table,
|
||||
Snips.note, Snips.note, Snips.altnote,
|
||||
Snips.monster,
|
||||
BrewSnippets.title,BrewSnippets.title,BrewSnippets.title
|
||||
|
||||
]
|
||||
|
||||
const fns = Data.mix(base, 15, 10);
|
||||
|
||||
return _.map(fns, (fn)=>fn()).join('\n\n');
|
||||
Snips.table,
|
||||
Snips.note, Snips.note, Snips.altnote
|
||||
], additional);
|
||||
return _.times(count, ()=>{
|
||||
let res = _.sample(base)();
|
||||
if(Data.chance(8)) res = BrewSnippets.title() + '\n\n' + res;
|
||||
return res;
|
||||
}).join('\n\n');
|
||||
},
|
||||
|
||||
paragraph : (dropcap = false)=>{
|
||||
|
||||
@@ -11,6 +11,52 @@ const getFeature = (level)=>{
|
||||
return res.join(', ');
|
||||
};
|
||||
|
||||
const spellLevels = [
|
||||
[2,'―','―','―','―','―','―','―','―'],
|
||||
[3,'―','―','―','―','―','―','―','―'],
|
||||
[4, 2 ,'―','―','―','―','―','―','―'],
|
||||
[4, 3 ,'―','―','―','―','―','―','―'],
|
||||
[4, 3 , 2 ,'―','―','―','―','―','―'],
|
||||
[4, 3 , 3 ,'―','―','―','―','―','―'],
|
||||
[4, 3 , 3 , 1 ,'―','―','―','―','―'],
|
||||
[4, 3 , 3 , 2 ,'―','―','―','―','―'],
|
||||
[4, 3 , 3 , 3 , 1 ,'―','―','―','―'],
|
||||
[4, 3 , 3 , 3 , 2 ,'―','―','―','―'],
|
||||
[4, 3 , 3 , 3 , 2 , 1 ,'―','―','―'],
|
||||
[4, 3 , 3 , 3 , 2 , 1 ,'―','―','―'],
|
||||
[4, 3 , 3 , 3 , 2 , 1 , 1 ,'―','―'],
|
||||
[4, 3 , 3 , 3 , 2 , 1 , 1 ,'―','―'],
|
||||
[4, 3 , 3 , 3 , 2 , 1 , 1 , 1 ,'―'],
|
||||
[4, 3 , 3 , 3 , 2 , 1 , 1 , 1 ,'―'],
|
||||
[4, 3 , 3 , 3 , 2 , 1 , 1 , 1 , 1 ],
|
||||
[4, 3 , 3 , 3 , 3 , 1 , 1 , 1 , 1 ],
|
||||
[4, 3 , 3 , 3 , 3 , 2 , 1 , 1 , 1 ],
|
||||
[4, 3 , 3 , 3 , 3 , 2 , 2 , 1 , 1 ]
|
||||
];
|
||||
|
||||
const halfspellLevels = [
|
||||
['―','―','―','―','―'],
|
||||
[ 2 ,'―','―','―','―'],
|
||||
[ 3 ,'―','―','―','―'],
|
||||
[ 3 ,'―','―','―','―'],
|
||||
[ 4 , 2 ,'―','―','―'],
|
||||
[ 4 , 2 ,'―','―','―'],
|
||||
[ 4 , 3 ,'―','―','―'],
|
||||
[ 4 , 3 ,'―','―','―'],
|
||||
[ 4 , 3 , 2 ,'―','―'],
|
||||
[ 4 , 3 , 2 ,'―','―'],
|
||||
[ 4 , 3 , 3 ,'―','―'],
|
||||
[ 4 , 3 , 3 ,'―','―'],
|
||||
[ 4 , 3 , 3 , 1 ,'―'],
|
||||
[ 4 , 3 , 3 , 1 ,'―'],
|
||||
[ 4 , 3 , 3 , 2 ,'―'],
|
||||
[ 4 , 3 , 3 , 2 ,'―'],
|
||||
[ 4 , 3 , 3 , 3 , 1 ],
|
||||
[ 4 , 3 , 3 , 3 , 1 ],
|
||||
[ 4 , 3 , 3 , 3 , 2 ],
|
||||
[ 4 , 3 , 3 , 3 , 2 ]
|
||||
];
|
||||
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -23,13 +69,15 @@ module.exports = {
|
||||
lvlText,
|
||||
'+'+Math.floor(level/4 + 2),
|
||||
getFeature(level),
|
||||
'+'+featureScore
|
||||
].join(' | ') + ' |';
|
||||
'??'
|
||||
].join(' | ') + ' | ' +
|
||||
spellLevels[level].join(' | ')
|
||||
+ ' |';
|
||||
}).join('\n');
|
||||
|
||||
return `{{frame,wide
|
||||
##### ${Data.rand('classes')}
|
||||
| Level | Proficiency Bonus | Features | Cantrips Known | Spells Known | 1st | 2nd | 3rd | 4th | 5th | 6th | 7th | 8th | 9th |
|
||||
| Level | Proficiency Bonus | Features | Spells Known | 1st | 2nd | 3rd | 4th | 5th | 6th | 7th | 8th | 9th |
|
||||
|:---:|:---:|:---|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
|
||||
${rows}
|
||||
}}`;
|
||||
@@ -43,9 +91,10 @@ ${rows}
|
||||
return '| ' + [
|
||||
lvlText,
|
||||
'+'+Math.floor(level/4 + 2),
|
||||
getFeature(level),
|
||||
'+'+featureScore
|
||||
].join(' | ') + ' |';
|
||||
getFeature(level)
|
||||
].join(' | ') + ' | ' +
|
||||
halfspellLevels[level].join(' | ')
|
||||
+ ' |'
|
||||
}).join('\n');
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user