From 41045cb4829ed7ddc44914728dfd7363a6511021 Mon Sep 17 00:00:00 2001 From: macniel Date: Thu, 2 Oct 2025 20:43:50 +0200 Subject: [PATCH] Repairs XML-Import for Advantages/Vornachteile --- src/module/xml-import/xml-import.mjs | 36 ++++++++++++++++++---------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/module/xml-import/xml-import.mjs b/src/module/xml-import/xml-import.mjs index 18c70fc7..5d9af9b6 100644 --- a/src/module/xml-import/xml-import.mjs +++ b/src/module/xml-import/xml-import.mjs @@ -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) {