Skip to content

Commit

Permalink
allow campaign exports without loading campaign frist, try to handle …
Browse files Browse the repository at this point in the history
…410 on loading campaign menu
  • Loading branch information
rrgeorge committed Oct 11, 2024
1 parent 968cb2c commit db4e63d
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 136 deletions.
38 changes: 27 additions & 11 deletions ddb.js
Original file line number Diff line number Diff line change
Expand Up @@ -2833,19 +2833,35 @@ ${background.flaws.map(r=>`| ${r.diceRoll} | ${r.description} |`).join('\n')}
}
}

async getCampaignCharacters(campaignId,campaignChars,filename) {
let zip = new AdmZip()
let prog = new ProgressBar({title: "Please wait...",text: "Converting Characters...", detail: "Please wait...", indeterminate: false, maxValue: 100})
//process.once('unhandledRejection', (reason, _) => {
// if (prog) prog.close()
// dialog.showErrorBox('Unexpected error', `An unexpected error occurred while trying to convert the module: ${reason.stack||reason}`)
//});
await new Promise(resolve=>{
prog.on('ready',()=>resolve())
})
prog.value = 0
async getCampaignCharacters(campaignId,campaignChars,filename,prog) {
let zip
if (!prog) {
zip = new AdmZip()
prog = new ProgressBar({title: "Please wait...",text: "Converting Characters...", detail: "Please wait...", indeterminate: false, maxValue: 100})
//process.once('unhandledRejection', (reason, _) => {
// if (prog) prog.close()
// dialog.showErrorBox('Unexpected error', `An unexpected error occurred while trying to convert the module: ${reason.stack||reason}`)
//});
await new Promise(resolve=>{
prog.on('ready',()=>resolve())
})
prog.value = 0
}
let characters = []
await this.getRuleData()
if (campaignId && !campaignChars) {
prog.detail = "Retrieving campaign characters..."
const url = `https://www.dndbeyond.com/api/campaign/characters/${campaignId}`
await this.getCobaltAuth()
if (!this.ruledata) await this.getRuleData().catch(e=>{throw new Error(e)})
const response = await this.getRequest(url,true).catch((e)=>{ console.log(`Error getting campaign characters: ${e}`); throw `Error getting campaign characters: ${e}`; })
campaignChars = response.data
for (let character of campaignChars) {
prog.detail = `Retrieving character ${character.name}`
character.sheet = await this.getCharacterSheet(character.id)
}
}
if (!filename) return campaignChars
for (const character of campaignChars) {
if (!character.sheet) continue
if (character.sheet.isAssignedToPlayer === false) continue
Expand Down
Loading

0 comments on commit db4e63d

Please sign in to comment.