generated from League-of-Foundry-Developers/FoundryVTT-Module-Template
-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Description
Describe the bug
Sheet export for Werewolf W5 doesn't work proper
I played around with the template a bit. But I don't know much about coding.
It works, but there are still some error messages.
Is it intentional that experience points must be entered before exporting is possible? ... Anyway.
`import baseMapping from "../../../../scripts/baseMapping.js";
class MappingClass extends baseMapping {
authors = [
{
name: 'gioppoluca',
url: 'https://github.com/gioppoluca',
github: 'https://github.com/gioppoluca',
},
];
// override createMappings method from base class
async createMappings() {
super.createMappings();
// Set the PDF files to use - MIND that the order of the files is important!
this.pdfFiles.push({
pdfUrl: '/modules/sheet-export/mappings/vtm5e/werewolf.pdf',
nameDownload: `${this.actor.name ?? "character"}.pdf`,
name: "werewolf.pdf",
});
this.setCalculated("Name", this.actor.name);
this.setCalculated("Concept", this.actor.system.headers.concept);
// Fixed: Proper filtering for tribe
const tribe = this.actor.items.find(item => item.type === 'tribe');
this.setCalculated("Patron", tribe?.system?.patronSpirit?.name);
this.setCalculated("Tribe", tribe?.name);
// Fixed: Proper filtering for auspice
const auspice = this.actor.items.find(item => item.type === 'auspice');
this.setCalculated("Auspice", auspice?.name);
this.setCalculated("Chron", this.htmlToText(this.actor.system.headers.chronicle));
this.setCalculated("Notes", this.htmlToText(this.actor.system.notes));
this.setCalculated("Appearance", this.htmlToText(this.actor.system.appearance));
this.setCalculated("History", this.htmlToText(this.actor.system.bio.history));
this.setCalculated("Chronicle Tenets", this.htmlToText(this.actor.system.headers.tenets));
// Fixed: Simplified htmlToText usage
this.setCalculated("Touchstones Convictions", this.htmlToText(this.actor.system.headers.touchstones));
this.setCalculated("totalxp", this.actor.system.derivedXP.totalXP);
this.setCalculated("spentxp", (this.actor.system.derivedXP.totalXP - this.actor.system.derivedXP.remainingXP));
// Attributes
Object.keys(this.actor.system.attributes).forEach(element => {
for (let index = 1; index < 6; index++) {
this.setCalculated(`${element}${index}`, this.actor.system.attributes[element].value >= index);
}
});
// Skills
Object.keys(this.actor.system.skills).forEach(element => {
for (let index = 1; index < 6; index++) {
this.setCalculated(`${element}${index}`, this.actor.system.skills[element].value >= index);
}
});
// Health
for (let index = 1; index < 11; index++) {
this.setCalculated(`H${index}`, this.actor.system.health.max >= index ? "" : "X");
}
// Willpower
for (let index = 1; index < 11; index++) {
this.setCalculated(`wi${index}`, this.actor.system.willpower.max >= index ? "" : "X");
}
// Harano
for (let index = 1; index < 6; index++) {
this.setCalculated(`har${index}`, this.actor.system.balance.harano.value >= index ? "X" : "");
}
// Hauglosk
for (let index = 1; index < 6; index++) {
this.setCalculated(`hau${index}`, this.actor.system.balance.hauglosk.value >= index ? "X" : "");
}
// Rage
for (let index = 1; index < 6; index++) {
this.setCalculated(`rg${index}`, this.actor.system.rage.value >= index ? "X" : "");
}
// Glory
for (let index = 1; index < 6; index++) {
this.setCalculated(`glo${index}`, this.actor.system.renown.glory.value >= index ? "X" : "");
}
// Honor
for (let index = 1; index < 6; index++) {
this.setCalculated(`ho${index}`, this.actor.system.renown.honor.value >= index ? "X" : "");
}
// Wisdom (fixed: was labeled as 'glory' again)
for (let index = 1; index < 6; index++) {
this.setCalculated(`wd${index}`, this.actor.system.renown.wisdom.value >= index ? "X" : "");
}
// Gifts
let pdfIndex = 1;
const gifts = this.actor.system.gifts;
const ownedGifts = Object.entries(gifts)
.filter(([key, gift]) => gift.powers && gift.powers.length > 0);
ownedGifts.forEach(([giftKey, gift]) => {
const powers = gift.powers || [];
powers.forEach(pow => {
// Extract dice pool information safely
let pool = "";
if (pow.system?.dicepool) {
const dpElements = Object.entries(pow.system.dicepool);
if (dpElements.length >= 2) {
const attr1 = dpElements[0][1]?.path?.split('.')[1] || '';
const attr2 = dpElements[1][1]?.path?.split('.')[1] || '';
pool = attr1 && attr2 ? `${attr1}+${attr2}` : '';
}
}
this.setCalculated(`Gifts-${pdfIndex}`, pow.name || '');
this.setCalculated(`GiftsC${pdfIndex}`, pow.system?.cost || '');
this.setCalculated(`GiftsP${pdfIndex}`, pool);
this.setCalculated(`GiftsN${pdfIndex}`, this.htmlToText(pow.system?.description || ''));
pdfIndex++;
});
});
// Advantages/Flaws/Merits/Backgrounds
const adflows = this.actor.items.filter(item => {
return item.type === 'feature' &&
(item.system.featuretype === 'flaw' ||
item.system.featuretype === 'merit' ||
item.system.featuretype === 'background');
});
const iterations = Math.min(adflows.length, 12);
for (let index = 0; index < iterations; index++) {
const element = adflows[index];
const displayIndex = index + 1;
this.setCalculated(`adflaw${displayIndex}`, element.name || '');
for (let i = 1; i < 6; i++) {
this.setCalculated(`adflaw${displayIndex}-${i}`, (element.system?.points || 0) >= i);
}
}
}
}
export default MappingClass;`
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels