Here's a first second pass version: //
on('ready',function(){
'use strict';
var nameRoll='[[1t[first-name] ]]-[[1t[second-name] ]]',
attrs={
Starport: '[[1t[starport] ]]',
Size: '[[1t[size] ]]',
Atmosphere: '[[1t[atmosphere] ]]',
Hydrographics: '[[1t[hydrographics] ]]',
Population: '[[1t[population] ]]',
Government: '[[1t[government] ]]',
Law: '[[1t[law] ]]',
Tech: '[[1t[tech] ]]'
},
rowColor=['#ffffff','#eeeeff'],
clear='<span style="display:block;clear:both; margin-bottom: 0 !important;"></span>',
dataStyle="display:block;min-width: 2em; border:1px solid #A79D65; border-radius:1em; padding: .1em .3em; text-align: center; background-color: #FEF0A2 !important; float: right; margin-bottom: 0 !important;",
rowStyle=(color)=>`display:block;vertical-align: middle;border-top: 1px solid #A79D65; font-family: sans-serif; padding: .1em; font-weight: bold; background-color: ${color} !important; margin-bottom: 0 !important;`,
rowMaker=(label,data,color)=>`<span style="${rowStyle(color)}">${label}<span style="${dataStyle}">${data}</span>${clear}</span>`,
titleMaker=(title)=>`<span style="display:block;font-weight: bold; font-size: .6em; font-family: sans-serif;margin-bottom: -.3em !important;">World</span><span style="font-weight: bold; font-family: monospace; font-size: 2em; text-align:center;">${title}</span>`,
processInlinerolls = function(msg) {
if(_.has(msg,'inlinerolls')){
return _.chain(msg.inlinerolls)
.reduce(function(m,v,k){
var ti=_.reduce(v.results.rolls,function(m2,v2){
if(_.has(v2,'table')){
m2.push(_.reduce(v2.results,function(m3,v3){
m3.push(v3.tableItem.name);
return m3;
},[]).join(', '));
}
return m2;
},[]).join(', ');
m['$[['+k+']]']= (ti.length && ti) || v.results.total || 0;
return m;
},{})
.reduce(function(m,v,k){
return m.replace(k,v);
},msg.content)
.value();
} else {
return msg.content;
}
};
on('chat:message',function(msg){
if('api' === msg.type && msg.content.match(/^!worldgen/) && playerIsGM(msg.playerid) ){
let roll = _.union([`Name: ${nameRoll}`],_.map(attrs,(v,k)=>`${k}: ${v}`)).join('####');
sendChat('WorldGen',roll,function(msgs){
let vals=_.map(processInlinerolls(msgs[0]).split(/####/),(o)=>{
let s=o.match(/^(.*?): (.*)$/);
return {
label: s[1],
value: s[2]
};
}),
name=_.first(vals).value,
handout=createObj('handout',{
name: name
}),
text;
vals=_.rest(vals);
text=`<span style="display:block;border:1px solid #A79D65;background-color:#eeeeee;">${titleMaker(name)}${
_.map(vals,(data,key)=>rowMaker(data.label,data.value,rowColor[key%2])).join('')
}`;
handout.set( {notes: text});
sendChat('WorldGen',text);
});
}
});
});
Needs some formatting, but check and see if this does basically what you're after. Added some formatting. See what you think! !worldgen