0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-12 21:52:42 +00:00

Merge branch 'randombrew' into home

This commit is contained in:
Scott Tolksdorf
2017-06-04 22:03:52 -04:00
16 changed files with 1562 additions and 107 deletions

View File

@@ -3,6 +3,7 @@
"description": "Create authentic looking D&D homebrews using only markdown",
"version": "3.0.0",
"scripts": {
"logs": "heroku logs -t --app=homebrewery",
"dev": "node scripts/dev.js",
"quick": "node scripts/quick.js",
"build": "node scripts/build.js",
@@ -29,7 +30,6 @@
"jwt-simple": "^0.5.1",
"lodash": "^4.17.3",
"loglevel": "^1.4.1",
"marked": "^0.3.5",
"moment": "^2.11.0",
"mongoose": "^4.3.3",
"nconf": "^0.8.4",

View File

@@ -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();

View File

@@ -1,5 +1,6 @@
const _ = require('lodash');
const Markdown = require('marked');
//const Markdown = require('marked');
const Markdown = require('./marked.lib.js');
const renderer = new Markdown.Renderer();
@@ -10,7 +11,9 @@ renderer.paragraph = function(text){
if(!matches) return `\n<p>${text}</p>\n`;
let matchIndex = 0;
const res = _.reduce(text.split(blockReg), (r, text) => {
//if(text) r.push(text);
if(text) r.push(Markdown(text, {renderer : renderer, sanitize: true}));
const block = matches[matchIndex];
if(block && block[0] == '{'){
r.push(`\n\n<div class="block ${block.substring(2).split(',').join(' ')}">`);
@@ -25,10 +28,14 @@ renderer.paragraph = function(text){
}, []).join('\n');
return res;
};
renderer.image = function(href, title, text){
return `<img src="${href}" class="${text.split(',').join(' ')}"></img>`;
};
renderer.list = function(list, isOrdered, isDef){
if(isDef) return `<ul class='alt'>${list}</ul>`;
if(isOrdered) return `<ol>${list}</ol>`;
return `<ul>${list}</ul>`;
}
module.exports = {
@@ -36,9 +43,12 @@ module.exports = {
render : (rawBrewText)=>{
blockCount = 0;
rawBrewText = rawBrewText.replace(/\\column/g, '{{columnSplit }}')
rawBrewText = rawBrewText.replace(/\\column/g, '{{columnSplit }}');
let html = Markdown(rawBrewText,{renderer : renderer, sanitize: true});
let html = Markdown(rawBrewText, {renderer : renderer, sanitize: true});
//Close all hanging block tags
html += _.times(blockCount, ()=>{return '</div>'}).join('\n');
return html;

File diff suppressed because it is too large Load Diff

View File

@@ -1,15 +1,7 @@
///////////////////
.spell{
ul:first-of-type{
margin-top : -0.5em;
margin-bottom : 0.5em;
list-style-type : none;
&+p{
text-indent : 0em;
}
}
}
.monster{
.breakAvoid();
@@ -23,10 +15,6 @@
tbody tr { background-color: transparent };
}
ul:nth-of-type(1),ul:nth-of-type(2){
list-style: none;
padding-left : 1em;
text-indent : -1em;
margin-bottom : 0.5em;
strong{
color : @crimson;
}
@@ -36,6 +24,7 @@
right : 7px;
bottom : 19px;
left : 7px;
//TODO: Swap out to variable color
background-color : #FDF1DC;
border-image-slice : 8;
border-image-source : @monsterBorder;
@@ -43,6 +32,7 @@
}
&.wide{
column-count : 2;
column-fill:auto;
}
}
.note{
@@ -104,7 +94,7 @@
z-index : 150;
width : 200px;
font-size : 0.9em;
color : @gold;
color : @brown;
text-align : right;
}
//*****************************
@@ -161,38 +151,44 @@
}
.wide{
column-span : all;
-webkit-column-span : all;
-moz-column-span : all;
}
.fullPage, .full{
column-span : all;
height: 100%;
}
.oneColumn{
column-count : 1;
column-fill:auto;
// column-gap : 1cm;
}
.twoColumn{
column-count : 2;
column-fill:auto;
//column-fill: auto;
////column-gap : 1cm;
}
.threeColumn{
column-count : 3;
column-fill:auto;
//column-gap : 1cm;
}
.fourColumn{
column-count : 4;
//column-gap : 1cm;
column-fill:auto;
}
.columnSplit{
visibility : hidden;
-webkit-column-break-bfore : always;
break-before : column;
}
.brushed{
border-image-outset : 25px 17px;
border-image-repeat : round;
border-image-slice : 1250 1250 1250 1250;
border-image-width : 1250px;
border-image-source : url('http : //i.imgur.com/nzPYZyD.png');
}
// .brushed{
// border-image-outset : 25px 17px;
// border-image-repeat : round;
// border-image-slice : 1250 1250 1250 1250;
// border-image-width : 1250px;
// border-image-source : url('http://i.imgur.com/nzPYZyD.png');
// }
//basics
.left{
text-align : left;
@@ -208,4 +204,13 @@
}
.sansSerif{
.useSansSerif();
}
.dropcap{
p::first-letter{
float : left;
font-family : Solbera;
font-size : 10em;
color : #222;
line-height : 0.8em;
}
}

View File

@@ -1,5 +1,13 @@
//TODO: come up with fun color names
@crimson : #58180D;
@red : #9c2b1b;
@brown : #c9ad6a; //brown?
@green : #e0e5c1;
@yellow : #faf7ea; //same as background?
@teal : blue;
@blue : blue;
@background : #EEE5CE;
@noteGreen : #e0e5c1;
@headerUnderline : #c9ad6a;
@@ -20,13 +28,7 @@
}
}
@crimson : #58180D;
@red : #9c2b1b;
@gold : #c9ad6a; //brown?
@green : #e0e5c1;
@yellow : #faf7ea; //same as background?
@teal : blue;
@blue : blue;
//TODO make a color mixin generator
@@ -34,5 +36,6 @@
.blue{ .colorElements(@blue); }
.green{ .colorElements(@green); }
.yellow{ .colorElements(@yellow); }
.gold{ .colorElements(@gold); }
.red{ .colorElements(@red); }
.brown{ .colorElements(fade(@brown, 50%)); }
.red{ .colorElements(fade(@red, 25%)); }
.crimson{ .colorElements(fade(@crimson, 20%)); }

View File

@@ -1,15 +1,14 @@
pre{
font-family : monospace;
background-color : @yellow;
padding : 12px;
border: 1px solid #bfbfbf;
white-space: pre-wrap;
color : #333;
padding : 12px;
background-color : @yellow;
font-family : monospace;
color : #333;
border : 1px solid #bfbfbf;
white-space : pre-wrap;
-webkit-column-break-inside : avoid;
column-break-inside : avoid;
}
hr{
visibility : visible;
height : 6px;
@@ -18,8 +17,6 @@ hr{
background-size : 100% 100%;
border : none;
}
p{
padding-bottom : 0.8em;
line-height : 1.3em;
@@ -27,35 +24,42 @@ p{
margin-top : -0.8em;
}
}
blockquote{
font-style : italic;
&>p{
line-height: 1.8em;
line-height : 1.8em;
//Why did I do this?
&:first-child::first-line{
font-family : ScalySansSmallCaps;
//TODO: Find the right font for block quotes
font-style: normal;
font-family: ScalySansSmallCaps;
font-style : normal;
}
}
.cite{
font-style: normal;
text-align: right;
font-style : normal;
text-align : right;
}
}
// IMAGE
img{
display : block;
z-index : -1;
mix-blend-mode : multiply;
&.center{
margin-right : auto;
margin-left : auto;
}
&.noBlend{
mix-blend-mode : normal;
}
&.bg, &.background{
position : absolute;
}
}
//Indents after p or lists
p+p, ul+p, ol+p{
text-indent : 1em;
}
img{
z-index : -1;
}
strong{
font-weight : bold;
letter-spacing : 0.03em;
@@ -88,13 +92,6 @@ h1{
font-size : 0.987cm;
-webkit-column-span : all;
-moz-column-span : all;
&+p::first-letter{
float : left;
font-family : Solbera;
font-size : 10em;
color : #222;
line-height : 0.8em;
}
}
h2{
font-size : 0.705cm;
@@ -113,8 +110,6 @@ h5{
font-size : 0.423cm;
font-weight : 900;
}
//******************************
// LISTS
//******************************
@@ -141,7 +136,19 @@ ol{
list-style-type : decimal;
}
p+ul.alt{
margin-top : -0.5em;
}
ul.alt{
margin-bottom : 0.5em;
padding-left : 0em;
list-style-position : outside;
list-style-type : none;
list-style-type : none;
&+p{
text-indent : 0em;
}
}
//*****************************
// * TABLE
// *****************************/
@@ -150,6 +157,7 @@ table{
width : 100%;
margin-bottom : 1em;
font-size : 10pt;
break-inside : avoid-column;
thead{
font-weight : 800;
th{

View File

@@ -57,7 +57,7 @@
background-size : cover;
padding: 28px 63px;
box-sizing: border-box;
color : lighten(@gold, 0%);
color : lighten(@brown, 0%);
font-size: 0.7em;
}
&:nth-child(even){
@@ -81,7 +81,7 @@
bottom : 22px;
width : 50px;
font-size : 0.9em;
color : @gold;
color : @brown;
text-align : center;
}

View File

@@ -0,0 +1,74 @@
const _ = require('lodash');
const Data = require('./random.data.js');
const Snips = _.merge(
require('./spell.snippet.js'),
require('./table.snippet.js'),
require('./class.snippet.js'),
require('./note.snippet.js'),
require('./monster.snippet.js')
);
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), ()=>_.sample([
BrewSnippets.page1,
BrewSnippets.page2
])()).join('\n\n\\page\n\n');
},
page1 : ()=>{
return BrewSnippets.filler(_.random(10, 15), [Snips.monster, Snips.table]);
},
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.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)=>{
let res = Data.rand(Data.sentences, 6, 3).join(' ');
if(dropcap || Data.chance(20)) res = `{{dropcap\n${res}\n}}`;
return res;
},
title : ()=>{
return _.sample(['##', '###', '##', '###','####', '#####']) + ' ' + Data.rand('titles');
}
}
module.exports = BrewSnippets;

View File

@@ -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');

View File

@@ -8,7 +8,8 @@ module.exports = _.merge(
require('./monster.snippet.js'),
require('./toc.snippet.js'),
require('./random.brew.js')
//require('./random.brew.js')
require('./brew.snippet.js')

View File

@@ -12,13 +12,10 @@ const getStats = function(){
const getAttributes = ()=>{
return `
- **Saving Throws**
- **Condition Immunities** " + genList(["groggy", "swagged", "weak-kneed", "buzzed", "groovy", "melancholy", "drunk"], 3),
- **Senses** passive Perception " + _.random(3, 20),
- **Condition Immunities** ${Data.rand(["groggy", "swagged", "weak-kneed", "buzzed", "groovy", "melancholy", "drunk"], 3).join(', ')},
- **Senses** passive Perception " ${_.random(3, 20)},
- **Languages** ${Data.rand(["Common", "Pottymouth", "Gibberish", "Latin", "Jive"], 2).join(', ')}
- **Challenge** ${_.random(0, 15)} (${_.random(10,10000)} XP)
`;
@@ -45,23 +42,16 @@ module.exports = {
*${Data.rand('sizes')}, ${Data.rand('alignments')}*
---
- **Armor Class** ${_.random(10,20)}
- **Hit Points** ${_.random(1, 150)} (1d4 + 5)
- **Speed** ${ _.random(0,50)} ft
---
|STR|DEX|CON|INT|WIS|CHA|
|:---:|:---:|:---:|:---:|:---:|:---:|
${getStats()}
---
${getAttributes()}
---
Abilities

View File

@@ -4,7 +4,7 @@ const Data = require('./random.data.js');
module.exports = {
note : ()=>{
return `{{note
return `{{note,red
##### ${Data.rand('abilities')}
${Data.rand('sentences', 6, 4).join(' ')}
}}`

View File

@@ -5,7 +5,9 @@ const Data = {
const data = (Data[name] ? Data[name] : name);
return _.sampleSize(data, _.random(min, max));
},
//Boolean of 1 in n chance
chance : (max = 20)=>_.random(1,max)== 1,
mix : (list, max = 1, min = 1)=>_.times(_.random(min, max), ()=>_.sample(list)),
titles : [
`The Burning Gallows`,
`The Ring of Nenlast`,

View File

@@ -26,7 +26,7 @@ module.exports = {
const description = Data.rand('effects', 2).concat(Data.rand('effects2')).join(' ');
return `{{spell
return `
#### ${_.sample(Data.spellNames)}
*${_.sample(levels)}-level ${_.sample(schools)}*
- **Casting Time:** ${_.sample(['1 action', 'Reaction', '10 minutes', '1 hour'])}
@@ -34,8 +34,18 @@ module.exports = {
- **Components:** ${components}
- **Duration:** ${duration}
${description}
}}`;
${description}`;
},
spellList : ()=>{
const levels = ['Cantrips (0 Level)', '2nd Level', '3rd Level', '4th Level', '5th Level', '6th Level', '7th Level', '8th Level', '9th Level'];
const content = _.map(levels, (level)=>{
const spells = _.map(Data.rand('spellNames', 15, 5), (spell)=>`- ${spell}`).join('\n');
return `##### ${level} \n${spells} \n`;
}).join('\n');
return `{{fourColumn,fullPage,sansSerif\n${content}\n}}`;
}
}

View File

@@ -43,15 +43,26 @@ const columns = {
module.exports = {
table : () => {
let title = '';
if(Data.chance(5)) title = `##### ${Data.rand(Data.abilities)}\n`;
const rows = _.sample([4,6,8,10]);
const cols = [
columns.roll(rows),
columns.level(rows),
columns.gear(rows)
];
let fns = [];
if(Data.chance(3)) fns.push(columns.roll);
return _.times(rows + 2, (i)=>{
fns = _.concat(fns, Data.rand([
columns.level,
columns.spell,
columns.cost,
columns.gear
], 3, 2 - fns.length))
const cols = _.map(fns, (fn)=>fn(rows));
return title + _.times(rows + 2, (i)=>{
if(i==1){
return '|' + _.map(cols, (col)=>col[i]).join('|') + '|';
}else{