Skip to content

Commit

Permalink
Fix homebrew monsters & spells
Browse files Browse the repository at this point in the history
  • Loading branch information
rrgeorge committed Jul 29, 2021
1 parent db0b5e9 commit 30d034d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
15 changes: 8 additions & 7 deletions ddb.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,13 +569,13 @@ class DDB {
return compendium
}
}
async getMonsterCount(source = 0) {
async getMonsterCount(source = 0,homebrew = false) {
const url = "https://monster-service.dndbeyond.com/v1/Monster"
var params
if (source) {
params = qs.stringify({ 'skip': 0, 'take': 1, 'sources': source })
} else {
params = qs.stringify({ 'skip': 0, 'take': 1 })
params = qs.stringify({ 'skip': 0, 'take': 1, 'showHomebrew': (homebrew)?'t':'f' })
}
await this.getCobaltAuth()
const response = await this.getRequest(`${url}?${params}`,true).catch((e)=>console.log(`Error getting monster count for source id ${source}: ${e}`))
Expand All @@ -584,7 +584,7 @@ class DDB {
async getMonsters(source = 0,filename,zip=null,imageMap=null,prog=null,homebrew=false) {
const url = "https://monster-service.dndbeyond.com/v1/Monster"
var params
const count = await this.getMonsterCount(source).catch((e)=>console.log(e))
const count = await this.getMonsterCount(source,homebrew).catch((e)=>console.log(e))
console.log(`Source ${source} has ${count} monsters`)
let pos = 0
if(!prog) prog = new ProgressBar({title: "Please wait...",text: "Converting monsters...", detail: "Please wait...", indeterminate: false, maxValue: count})
Expand All @@ -599,13 +599,14 @@ class DDB {
if (source) {
params = qs.stringify({ 'skip': pos, 'take': 100, 'sources': source })
} else {
params = qs.stringify({ 'skip': pos, 'take': 100 })
params = qs.stringify({ 'skip': pos, 'take': 100, 'showHomebrew': (homebrew)?'t':'f' })
}
const response = await this.getRequest(`${url}?${params}`,true).catch((e)=>console.log(`Error getting monster count for source id ${source}: ${e}`))
console.log(`Retrieved ${response.data.length}`)
for (const monster of response.data) {
if (!monster.isReleased) {
if (!monster.isReleased&&monster.isHomebrew!==homebrew) {
prog.value += (!filename)? (15*(1/count)) : 1
console.log(`Skipping ${monster.isReleased} ${monster.isHomebrew}`)
continue
}
if (monster.isHomebrew !== homebrew) {
Expand Down Expand Up @@ -739,9 +740,9 @@ class DDB {
handleTraits(monster.legendaryActionsDescription,"legendary")
handleTraits(monster.mythicActionsDescription,"legendary","Mythic Action: ")
monsterEntry._content.push({
description: `${(monster.lairDescription)?sanitize(monster.lairDescription+'<hr/>',this.ruledata):''}${sanitize(monster.characteristicsDescription,this.ruledata)}
description: `${(monster.lairDescription)?sanitize(monster.lairDescription+'<hr/>',this.ruledata)+'\n':''}${sanitize(monster.characteristicsDescription,this.ruledata)}
<i>Source: ${this.ruledata.sources.find((s)=> monster.sourceId === s.id).description}${(monster.sourcePageNumber)? ` p. ${monster.sourcePageNumber}` : '' }</i>`
${(monster.sourceId)?`<i>Source: ${this.ruledata.sources.find((s)=> monster.sourceId === s.id)?.description}${(monster.sourcePageNumber)? ` p. ${monster.sourcePageNumber}` : '' }</i>`:''}`
})
try{
if (monster.basicAvatarUrl||monster.largeAvatarUrl) {
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ app.on('ready', () => {
defaultPath: `homebrew_spells.compendium`,
}).then((save) => {
if (save.filePath)
ddb.getSpells(null,save.filePath,null,null,null,true)
ddb.getSpells(null,save.filePath,null,null,true)
}
)
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "EncounterLog",
"version": "2.0.0",
"version": "2.0.1",
"description": "Connect D&D Beyond to EncounterPlus",
"repository": {
"type": "git",
Expand Down

0 comments on commit 30d034d

Please sign in to comment.