Repairs XML-Import for Advantages/Vornachteile

pull/47/head
macniel 2025-10-02 20:43:50 +02:00
parent b6814c9f74
commit 41045cb482
1 changed files with 24 additions and 12 deletions

View File

@ -86,6 +86,22 @@ async function addSkillFromCompendiumByNameToActor(talentName, taw, actor) {
}
}
async function addAdvantageFromCompendiumByNameToActor(advantageName, advantageValue, actor) {
const compendiumOfAdvantages = game.packs.get('DSA_4-1.Advantage');
const advantageId = compendiumOfAdvantages.index.find( skill => skill.name === advantageName)
if (advantageId) {
const advantage = await compendiumOfAdvantages.getDocument(advantageId._id);
try {
const embeddedDocument = (await actor.createEmbeddedDocuments('Item', [advantage]))[0]
embeddedDocument.update({system: {value: advantageValue}});
} catch (error) {
console.error(`${advantageName} not found in items`, error)
}
}
}
/**
* gets the text content of a file
* @param file the file with the desired content
@ -124,6 +140,13 @@ function mapSkills(actor, held) {
}
}
function mapAdvantages(actor, held) {
for (let advantage in held.vt.vorteil) {
advantage = held.vt.vorteil[advantage]
addAdvantageFromCompendiumByNameToActor(advantage.name, advantage.value, actor)
}
}
/**
* parses a json into a fitting character-json
* @param rawJson the json parsed from the Helden-Software XML
@ -224,18 +247,7 @@ function mapRawJson(actor, rawJson) {
aktuell: attribute.value
}
json.attribute.so = getAttributeJson(attributes, "Sozialstatus")
let benefits = []
for (let benefit in held.vt.vorteil) {
benefit = held.vt.vorteil[benefit]
let benefitJson = {
name: benefit.name,
}
if (benefit.value !== undefined) {
benefitJson.wert = benefit.value
}
benefits.push(benefitJson)
}
json.vornachteile = benefits
mapAdvantages(actor, held)
let specialAbilities = []
let liturgies = []
for (let specialAbility in held.sf.sonderfertigkeit) {