From b6814c9f74bb0ee6aa7e0001a350a1bbe5922ed7 Mon Sep 17 00:00:00 2001 From: macniel Date: Thu, 2 Oct 2025 20:28:31 +0200 Subject: [PATCH] Repairs XML-Import for SKills/Talents --- src/module/documents/character.mjs | 106 --------------------------- src/module/xml-import/xml-import.mjs | 35 +++++---- 2 files changed, 21 insertions(+), 120 deletions(-) diff --git a/src/module/documents/character.mjs b/src/module/documents/character.mjs index fbea8dc0..e692fb6a 100644 --- a/src/module/documents/character.mjs +++ b/src/module/documents/character.mjs @@ -34,110 +34,4 @@ export class Character extends Actor { console.log(data); return data; } - - - static onDroppedData(character, characterSheet, uuid) { - - } - - - async addSkillFromCompendiumByNameToActor(talentName, actor) { - const compendiumOfSkills = game.packs.get('DSA_4-1.talente-brw'); - const talentId = compendiumOfSkills.index.find( skill => skill.name === talentName) - let talentObject = {} - const talent = await compendiumOfSkills.getDocument(talentId); - try { - const embeddedDocument = (await actor.createEmbeddedDocuments('Item', [talent]))[0] - if (embeddedDocument.type === "Skill") { - if (talent) { - talentObject = { - taw: 0, - talent: embeddedDocument.id, - } - } - } - } catch (error) { - console.error(`${talentName} not found in items`, error) - } - await actor.update({system: { talente: talentObject, ...actor.system.talente}}) - } - - /** - * Adds base skills according to the BRW to the given actor - * @param actor - * @returns {Promise} - */ - async #createBaseSkills(actor) { - const talentsByName = [ - "Athletik", "Klettern", "Körperbeherrschung", "Schleichen", "Schwimmen", "Selbstbeherrschung", "Sich Verstecken", "Singen", "Sinnenschärfe", "Tanzen", "Zechen", - "Menschenkenntnis", "Überreden", - "Fährtensuchen", "Orientierung", "Wildnisleben", - "Götter/Kulte", "Rechnen", "Sagen/Legenden", - "Heilkunde: Wunden", "Holzbearbeitung", "Kochen", "Lederverarbeitung", "Malen/Zeichnen", "Schneidern" - ] - - const talente = [] - - talentsByName.forEach(talentName => { - - this.addSkillFromCompendiumByNameToActor( - talentName, - ) - }) - - await actor.update({system: { talente: talente}}) - } - - /** - * Sets the attributes of the given actor to their default values - * @param actor - * @returns {Promise} - */ - async #setBaseAttributes(actor) { - const startEigenschaften = { - "mu": { - start: 10, - aktuell: 10, - mod: 0 - }, - "kl": { - start: 10, - aktuell: 10, - mod: 0 - }, - "in": { - start: 10, - aktuell: 10, - mod: 0 - }, - "ch": { - start: 10, - aktuell: 10, - mod: 0 - }, - "ff": { - start: 10, - aktuell: 10, - mod: 0 - }, - "ge": { - start: 10, - aktuell: 10, - mod: 0 - }, - "ko": { - start: 10, - aktuell: 10, - mod: 0 - }, - "kk": { - start: 10, - aktuell: 10, - mod: 0 - } - } - - await actor.update({system: {attribute: startEigenschaften}}) - } - } diff --git a/src/module/xml-import/xml-import.mjs b/src/module/xml-import/xml-import.mjs index 241aeef7..18c70fc7 100644 --- a/src/module/xml-import/xml-import.mjs +++ b/src/module/xml-import/xml-import.mjs @@ -27,7 +27,7 @@ export async function importCharacter(actorId, file) { let dom = domParser.parseFromString(xmlString, 'application/xml') let rawJson = getJsonFromXML(dom) - let characterJson = mapRawJson(rawJson) + let characterJson = mapRawJson(actor, rawJson) actor.update(characterJson) } @@ -70,6 +70,22 @@ function getJsonFromXML(dom) { return jsonResult; } +async function addSkillFromCompendiumByNameToActor(talentName, taw, actor) { + const compendiumOfSkills = game.packs.get('DSA_4-1.talente-brw'); + const talentId = compendiumOfSkills.index.find( skill => skill.name === talentName) + if (talentId) { + + const talent = await compendiumOfSkills.getDocument(talentId._id); + + try { + const embeddedDocument = (await actor.createEmbeddedDocuments('Item', [talent]))[0] + embeddedDocument.update({system: {taw: taw}}); + } catch (error) { + console.error(`${talentName} not found in items`, error) + } + } +} + /** * gets the text content of a file * @param file the file with the desired content @@ -101,20 +117,11 @@ function calculateBirthdate(json) { return `${day}. ${month} ${year} BF` } -function mapSkills(rawJson) { - let talents = [] +function mapSkills(actor, held) { for (let talent in held.talentliste.talent) { talent = held.talentliste.talent[talent] - let talentItem = game.items.getName(talent.name) - if (talentItem) { - let talentJson = { - talent: talentItem, - taw: talent.value, - } - talents.push(talentJson) - } + addSkillFromCompendiumByNameToActor(talent.name, talent.value, actor) } - return talents } /** @@ -122,7 +129,7 @@ function mapSkills(rawJson) { * @param rawJson the json parsed from the Helden-Software XML * @returns {{}} a json representation of the character */ -function mapRawJson(rawJson) { +function mapRawJson(actor, rawJson) { let json = {} let held = rawJson.helden.held; json.name = held.name @@ -265,7 +272,7 @@ function mapRawJson(rawJson) { json.sonderfertigkeiten = specialAbilities json.liturgien = liturgies - json.talente = mapSkills(rawJson) + mapSkills(actor, held) let spells = [] /*for (let spell in held.zauberliste.zauber) { spell = held.zauberliste.zauber[spell]