mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-13 04:22:40 +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 BrewData = require('../server/brew.data.js');
|
||||||
//const BrewGen = require('../tests/brew.gen.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()
|
return Promise.resolve()
|
||||||
.then(DB.connect)
|
.then(DB.connect)
|
||||||
.then(BrewData.removeAll)
|
.then(BrewData.removeAll)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log('Adding random brews...');
|
return _.reduce(_.times(BREW_COUNT, BrewGen.brewModel), (flow, model)=>{
|
||||||
return BrewGen.populateDB(BrewGen.random(50));
|
return flow.then(()=>BrewData.create(model))
|
||||||
|
}, Promise.resolve());
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log('Adding specific brews...');
|
console.log(`Added ${BREW_COUNT} brews`);
|
||||||
return BrewGen.populateDB(BrewGen.static());
|
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return DB.close();
|
return DB.close();
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ renderer.paragraph = function(text){
|
|||||||
if(!matches) return `\n<p>${text}</p>\n`;
|
if(!matches) return `\n<p>${text}</p>\n`;
|
||||||
let matchIndex = 0;
|
let matchIndex = 0;
|
||||||
const res = _.reduce(text.split(blockReg), (r, text) => {
|
const res = _.reduce(text.split(blockReg), (r, text) => {
|
||||||
console.log(text);
|
|
||||||
//if(text) r.push(text);
|
//if(text) r.push(text);
|
||||||
if(text) r.push(Markdown(text, {renderer : renderer, sanitize: true}));
|
if(text) r.push(Markdown(text, {renderer : renderer, sanitize: true}));
|
||||||
|
|
||||||
|
|||||||
@@ -11,25 +11,53 @@ const Snips = _.merge(
|
|||||||
);
|
);
|
||||||
|
|
||||||
const BrewSnippets = {
|
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 : ()=>{
|
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,
|
||||||
BrewSnippets.paragraph, BrewSnippets.paragraph, BrewSnippets.paragraph, BrewSnippets.paragraph,
|
BrewSnippets.paragraph, BrewSnippets.paragraph, BrewSnippets.paragraph, BrewSnippets.paragraph,
|
||||||
Snips.table, Snips.table,
|
Snips.table,
|
||||||
Snips.note, Snips.note, Snips.altnote,
|
Snips.note, Snips.note, Snips.altnote
|
||||||
Snips.monster,
|
], additional);
|
||||||
BrewSnippets.title,BrewSnippets.title,BrewSnippets.title
|
return _.times(count, ()=>{
|
||||||
|
let res = _.sample(base)();
|
||||||
]
|
if(Data.chance(8)) res = BrewSnippets.title() + '\n\n' + res;
|
||||||
|
return res;
|
||||||
const fns = Data.mix(base, 15, 10);
|
}).join('\n\n');
|
||||||
|
|
||||||
return _.map(fns, (fn)=>fn()).join('\n\n');
|
|
||||||
},
|
},
|
||||||
|
|
||||||
paragraph : (dropcap = false)=>{
|
paragraph : (dropcap = false)=>{
|
||||||
|
|||||||
@@ -11,6 +11,52 @@ const getFeature = (level)=>{
|
|||||||
return res.join(', ');
|
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 = {
|
module.exports = {
|
||||||
|
|
||||||
@@ -23,13 +69,15 @@ module.exports = {
|
|||||||
lvlText,
|
lvlText,
|
||||||
'+'+Math.floor(level/4 + 2),
|
'+'+Math.floor(level/4 + 2),
|
||||||
getFeature(level),
|
getFeature(level),
|
||||||
'+'+featureScore
|
'??'
|
||||||
].join(' | ') + ' |';
|
].join(' | ') + ' | ' +
|
||||||
|
spellLevels[level].join(' | ')
|
||||||
|
+ ' |';
|
||||||
}).join('\n');
|
}).join('\n');
|
||||||
|
|
||||||
return `{{frame,wide
|
return `{{frame,wide
|
||||||
##### ${Data.rand('classes')}
|
##### ${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}
|
${rows}
|
||||||
}}`;
|
}}`;
|
||||||
@@ -43,9 +91,10 @@ ${rows}
|
|||||||
return '| ' + [
|
return '| ' + [
|
||||||
lvlText,
|
lvlText,
|
||||||
'+'+Math.floor(level/4 + 2),
|
'+'+Math.floor(level/4 + 2),
|
||||||
getFeature(level),
|
getFeature(level)
|
||||||
'+'+featureScore
|
].join(' | ') + ' | ' +
|
||||||
].join(' | ') + ' |';
|
halfspellLevels[level].join(' | ')
|
||||||
|
+ ' |'
|
||||||
}).join('\n');
|
}).join('\n');
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user