Repairs XML-Import for SKills/Talents

pull/47/head
macniel 2025-10-02 20:28:31 +02:00
parent e47deaf938
commit b6814c9f74
2 changed files with 21 additions and 120 deletions

View File

@ -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<void>}
*/
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<void>}
*/
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}})
}
}

View File

@ -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]