Skip to content

Instantly share code, notes, and snippets.

@wychwitch
Last active February 18, 2023 08:18
Show Gist options
  • Save wychwitch/d64d24e820b9b5527d1ed7a1bd08c515 to your computer and use it in GitHub Desktop.
Save wychwitch/d64d24e820b9b5527d1ed7a1bd08c515 to your computer and use it in GitHub Desktop.
spaghetti code to make a table of all monsters saved/imported with statblock plugin
const bestiary = Array.from(app.plugins.plugins["obsidian-5e-statblocks"].bestiary.entries())
var monsters = []
var header = ['Monster',
'Type',
'CR',
'Hit Dice',
'AC',
'speed'
]
var tableValues = []
for (var i = 0; i < bestiary.length; i++){
monsters.push(bestiary[i][1])
}
//this is setting up the tableValues by creating and inserting each row
for (var i = 0; i < (monsters.length); i++){
var row = []
var type = ""
if (typeof monsters[i].type !== 'undefined'){
type = monsters[i].type?.charAt(0).toUpperCase() + monsters[i].type?.slice(1)
}
else{
type = "undefined"
}
if (monsters[i].subtype !== "" && typeof monsters[i].subtype !== 'undefined'){
type += "; " + monsters[i].subtype?.charAt(0).toUpperCase() + monsters[i].subtype?.slice(1)
}
if(typeof monsters[i].name !== 'undefined'){
row.push(monsters[i].name)
}
else{
row.push("undefined")
}
row.push(type)
if(typeof monsters[i].cr !== 'undefined'){
row.push(monsters[i].cr)
}
else{
row.push("undefined")
}
if(typeof monsters[i].hit_dice !== 'undefined'){
row.push(monsters[i].hit_dice)
}
else{
row.push("undefined")
}
if(typeof monsters[i].ac !== 'undefined'){
row.push(monsters[i].ac)
}
else{
row.push("undefined")
}
if(typeof monsters[i].speed !== 'undefined'){
row.push(monsters[i].speed)
}
else{
row.push("undefined")
}
tableValues.push(row);
}
dv.table(header, tableValues)
const bestiary = Array.from(app.plugins.plugins["obsidian-5e-statblocks"].bestiary.entries())
var monsters = []
var header = ['Monster',
'Type',
'CR',
'Hit Dice',
'AC',
'speed'
]
var tableValues = []
for (var i = 0; i < bestiary.length; i++){
monsters.push(bestiary[i][1])
}
monsters.sort((a, b) => a.cr.split("/").map(n => Number(n)).reduce((a,b) => a / b) - b.cr.split("/").map(n => Number(n)).reduce((a,b) => a / b))
//this is setting up the tableValues by creating and inserting each row
for (var i = 0; i < (monsters.length); i++){
var row = []
var type = ""
if (typeof monsters[i].type !== 'undefined'){
type = monsters[i].type?.charAt(0).toUpperCase() + monsters[i].type?.slice(1)
}
else{
type = "undefined"
}
if (monsters[i].subtype !== "" && typeof monsters[i].subtype !== 'undefined'){
type += "; " + monsters[i].subtype?.charAt(0).toUpperCase() + monsters[i].subtype?.slice(1)
}
if(typeof monsters[i].name !== 'undefined'){
row.push(monsters[i].name)
}
else{
row.push("undefined")
}
row.push(type)
if(typeof monsters[i].cr !== 'undefined'){
row.push(monsters[i].cr)
}
else{
row.push("undefined")
}
if(typeof monsters[i].hit_dice !== 'undefined'){
row.push(monsters[i].hit_dice)
}
else{
row.push("undefined")
}
if(typeof monsters[i].ac !== 'undefined'){
row.push(monsters[i].ac)
}
else{
row.push("undefined")
}
if(typeof monsters[i].speed !== 'undefined'){
row.push(monsters[i].speed)
}
else{
row.push("undefined")
}
tableValues.push(row);
}
dv.table(header, tableValues)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment