export and import function for importing characters
parent
d68f757d63
commit
b8fa37532c
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { importCharacter } from '../xml-import/xml-import.mjs'
|
||||||
|
|
||||||
export class DsaActor extends Actor {
|
export class DsaActor extends Actor {
|
||||||
|
|
||||||
import() {
|
import() {
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ let months = [
|
||||||
* @param actorId the actor-id of the character
|
* @param actorId the actor-id of the character
|
||||||
* @param file the file from which the character should be imported
|
* @param file the file from which the character should be imported
|
||||||
*/
|
*/
|
||||||
async function importCharacter(actorId, file) {
|
export async function importCharacter(actorId, file) {
|
||||||
let actor = game.actors.get(actorId)
|
let actor = game.actors.get(actorId)
|
||||||
let xmlString = await parseFileToString(file)
|
let xmlString = await parseFileToString(file)
|
||||||
let domParser = new DOMParser()
|
let domParser = new DOMParser()
|
||||||
|
|
@ -108,13 +108,13 @@ function calculateBirthdate(json) {
|
||||||
*/
|
*/
|
||||||
function mapRawJson(rawJson) {
|
function mapRawJson(rawJson) {
|
||||||
let json = {}
|
let json = {}
|
||||||
with (rawJson.held) {
|
let held = rawJson.held;
|
||||||
json.name = name
|
json.name = held.name
|
||||||
json.meta = {}
|
json.meta = {}
|
||||||
json.meta.spezies = basis.rasse.string
|
json.meta.spezies = held.basis.rasse.string
|
||||||
json.meta.kultur = basis.kultur.string
|
json.meta.kultur = held.basis.kultur.string
|
||||||
let professions = []
|
let professions = []
|
||||||
for (ausbildung in basis.ausbildungen) {
|
for (let ausbildung in held.basis.ausbildungen) {
|
||||||
if (ausbildung.tarnidentitaet) {
|
if (ausbildung.tarnidentitaet) {
|
||||||
professions = [ausbildung.tarnidentitaet]
|
professions = [ausbildung.tarnidentitaet]
|
||||||
break;
|
break;
|
||||||
|
|
@ -123,82 +123,82 @@ function mapRawJson(rawJson) {
|
||||||
professions.push(ausbildungString)
|
professions.push(ausbildungString)
|
||||||
}
|
}
|
||||||
json.meta.profession = professions
|
json.meta.profession = professions
|
||||||
json.geschlecht = basis.geschlecht.name
|
json.geschlecht = held.basis.geschlecht.name
|
||||||
json.haarfarbe = basis.rasse.aussehen.haarfarbe
|
json.haarfarbe = held.basis.rasse.aussehen.haarfarbe
|
||||||
json.groesse = basis.rasse.groesse.value
|
json.groesse = held.basis.rasse.groesse.value
|
||||||
json.augenfarbe = basis.rasse.aussehen.augenfarbe
|
json.augenfarbe = held.basis.rasse.aussehen.augenfarbe
|
||||||
json.geburtstag = calculateBirthdate(basis.rasse.aussehen)
|
json.geburtstag = calculateBirthdate(held.basis.rasse.aussehen)
|
||||||
json.alter = basis.rasse.aussehen.alter
|
json.alter = held.basis.rasse.aussehen.alter
|
||||||
json.gewicht = basis.rasse.groesse.gewicht
|
json.gewicht = held.basis.rasse.groesse.gewicht
|
||||||
json.aussehen = [
|
json.aussehen = [
|
||||||
basis.rasse.aussehen.aussehentext0,
|
held.basis.rasse.aussehen.aussehentext0,
|
||||||
basis.rasse.aussehen.aussehentext1,
|
held.basis.rasse.aussehen.aussehentext1,
|
||||||
basis.rasse.aussehen.aussehentext2,
|
held.basis.rasse.aussehen.aussehentext2,
|
||||||
basis.rasse.aussehen.aussehentext3,
|
held.basis.rasse.aussehen.aussehentext3,
|
||||||
]
|
]
|
||||||
json.familie = [
|
json.familie = [
|
||||||
basis.rasse.aussehen.familietext0,
|
held.basis.rasse.aussehen.familietext0,
|
||||||
basis.rasse.aussehen.familietext1,
|
held.basis.rasse.aussehen.familietext1,
|
||||||
basis.rasse.aussehen.familietext2,
|
held.basis.rasse.aussehen.familietext2,
|
||||||
basis.rasse.aussehen.familietext3,
|
held.basis.rasse.aussehen.familietext3,
|
||||||
basis.rasse.aussehen.familietext4,
|
held.basis.rasse.aussehen.familietext4,
|
||||||
basis.rasse.aussehen.familietext5,
|
held.basis.rasse.aussehen.familietext5,
|
||||||
]
|
]
|
||||||
json.titel = basis.rasse.aussehen.titel
|
json.titel = held.basis.rasse.aussehen.titel
|
||||||
json.stand = basis.rasse.aussehen.stand
|
json.stand = held.basis.rasse.aussehen.stand
|
||||||
json.attribute = {}
|
json.attribute = {}
|
||||||
json.attribute.mu = getAttributeJson(eigenschaften, "Mut")
|
json.attribute.mu = getAttributeJson(held.eigenschaften, "Mut")
|
||||||
json.attribute.kl = getAttributeJson(eigenschaften, "Klugheit")
|
json.attribute.kl = getAttributeJson(held.eigenschaften, "Klugheit")
|
||||||
json.attribute.in = getAttributeJson(eigenschaften, "Intuition")
|
json.attribute.in = getAttributeJson(held.eigenschaften, "Intuition")
|
||||||
json.attribute.ch = getAttributeJson(eigenschaften, "Charisma")
|
json.attribute.ch = getAttributeJson(held.eigenschaften, "Charisma")
|
||||||
json.attribute.ff = getAttributeJson(eigenschaften, "Fingerfertigkeit")
|
json.attribute.ff = getAttributeJson(held.eigenschaften, "Fingerfertigkeit")
|
||||||
json.attribute.ge = getAttributeJson(eigenschaften, "Gewandtheit")
|
json.attribute.ge = getAttributeJson(held.eigenschaften, "Gewandtheit")
|
||||||
json.attribute.ko = getAttributeJson(eigenschaften, "Konstitution")
|
json.attribute.ko = getAttributeJson(held.eigenschaften, "Konstitution")
|
||||||
json.attribute.kk = getAttributeJson(eigenschaften, "Körperkraft")
|
json.attribute.kk = getAttributeJson(held.eigenschaften, "Körperkraft")
|
||||||
json.attribute.mr = {
|
json.attribute.mr = {
|
||||||
mod: filterAttribute(eigenschaften ,"Magieresistenz").mod
|
mod: filterAttribute(held.eigenschaften ,"Magieresistenz").mod
|
||||||
}
|
}
|
||||||
json.attribute.lep = {
|
json.attribute.lep = {
|
||||||
mod: filterAttribute(eigenschaften ,"Lebensenergie").mod
|
mod: filterAttribute(held.eigenschaften ,"Lebensenergie").mod
|
||||||
}
|
}
|
||||||
json.attribute.aup = {
|
json.attribute.aup = {
|
||||||
mod: filterAttribute(eigenschaften ,"Ausdauer").mod
|
mod: filterAttribute(held.eigenschaften ,"Ausdauer").mod
|
||||||
}
|
}
|
||||||
json.attribute.asp = {
|
json.attribute.asp = {
|
||||||
mod: filterAttribute(eigenschaften ,"Astralenergie").mod
|
mod: filterAttribute(held.eigenschaften ,"Astralenergie").mod
|
||||||
}
|
}
|
||||||
json.attribute.kap = {
|
json.attribute.kap = {
|
||||||
mod: filterAttribute(eigenschaften ,"Karmaenergie").mod
|
mod: filterAttribute(held.eigenschaften ,"Karmaenergie").mod
|
||||||
}
|
}
|
||||||
let attribute = filterAttribute(eigenschaften ,"Karmaenergie")
|
let attribute = filterAttribute(held.eigenschaften ,"Karmaenergie")
|
||||||
json.attribute.at = {
|
json.attribute.at = {
|
||||||
mod: attribute.mod,
|
mod: attribute.mod,
|
||||||
aktuell: attribute.value
|
aktuell: attribute.value
|
||||||
}
|
}
|
||||||
attribute = filterAttribute(eigenschaften ,"at")
|
attribute = filterAttribute(held.eigenschaften ,"at")
|
||||||
json.attribute.pa = {
|
json.attribute.pa = {
|
||||||
mod: attribute.mod,
|
mod: attribute.mod,
|
||||||
aktuell: attribute.value
|
aktuell: attribute.value
|
||||||
}
|
}
|
||||||
attribute = filterAttribute(eigenschaften ,"pa")
|
attribute = filterAttribute(held.eigenschaften ,"pa")
|
||||||
json.attribute.at = {
|
json.attribute.at = {
|
||||||
mod: attribute.mod,
|
mod: attribute.mod,
|
||||||
aktuell: attribute.value
|
aktuell: attribute.value
|
||||||
}
|
}
|
||||||
attribute = filterAttribute(eigenschaften ,"fk")
|
attribute = filterAttribute(held.eigenschaften ,"fk")
|
||||||
json.attribute.fk = {
|
json.attribute.fk = {
|
||||||
mod: attribute.mod,
|
mod: attribute.mod,
|
||||||
aktuell: attribute.value
|
aktuell: attribute.value
|
||||||
}
|
}
|
||||||
attribute = filterAttribute(eigenschaften ,"ini")
|
attribute = filterAttribute(held.eigenschaften ,"ini")
|
||||||
json.attribute.ini = {
|
json.attribute.ini = {
|
||||||
mod: attribute.mod,
|
mod: attribute.mod,
|
||||||
aktuell: attribute.value
|
aktuell: attribute.value
|
||||||
}
|
}
|
||||||
json.attribute.so = getAttributeJson(eigenschaften, "Sozialstatus")
|
json.attribute.so = getAttributeJson(held.eigenschaften, "Sozialstatus")
|
||||||
let specialAbilities = []
|
let specialAbilities = []
|
||||||
let liturgies = []
|
let liturgies = []
|
||||||
for (specialAbility in sf) {
|
for (let specialAbility in held.sf) {
|
||||||
if (specialAbility.name.startsWith("Liturgie:")) {
|
if (specialAbility.name.startsWith("Liturgie:")) {
|
||||||
liturgies.push({
|
liturgies.push({
|
||||||
name: specialAbility.name.replace("Liturgie:", "").trim(),
|
name: specialAbility.name.replace("Liturgie:", "").trim(),
|
||||||
|
|
@ -210,13 +210,13 @@ function mapRawJson(rawJson) {
|
||||||
}
|
}
|
||||||
let fields = Object.keys(specialAbility)
|
let fields = Object.keys(specialAbility)
|
||||||
if (fields.length > 1) {
|
if (fields.length > 1) {
|
||||||
for (field in fields) {
|
for (let field in fields) {
|
||||||
if (field !== "name") {
|
if (field !== "name") {
|
||||||
let choices = specialAbility[field]
|
let choices = specialAbility[field]
|
||||||
if (choices.hasOwnProperty("name")) {
|
if (choices.hasOwnProperty("name")) {
|
||||||
specialAbilityJson.auswahlen.push(choices.name)
|
specialAbilityJson.auswahlen.push(choices.name)
|
||||||
} else {
|
} else {
|
||||||
for (choice in choices) {
|
for (let choice in choices) {
|
||||||
specialAbilityJson.auswahlen.push(choice.value)
|
specialAbilityJson.auswahlen.push(choice.value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -229,7 +229,7 @@ function mapRawJson(rawJson) {
|
||||||
json.sonderfertigkeiten = specialAbilities
|
json.sonderfertigkeiten = specialAbilities
|
||||||
json.liturgien = liturgies
|
json.liturgien = liturgies
|
||||||
let talents = []
|
let talents = []
|
||||||
for (talent in talentliste) {
|
for (let talent in held.talentliste) {
|
||||||
talents.push({
|
talents.push({
|
||||||
name: talent.name,
|
name: talent.name,
|
||||||
taw: talent.value,
|
taw: talent.value,
|
||||||
|
|
@ -240,7 +240,7 @@ function mapRawJson(rawJson) {
|
||||||
}
|
}
|
||||||
json.talente = talents
|
json.talente = talents
|
||||||
let spells = []
|
let spells = []
|
||||||
for (spell in zauberliste) {
|
for (let spell in held.zauberliste) {
|
||||||
spells.push({
|
spells.push({
|
||||||
name: spell.name,
|
name: spell.name,
|
||||||
rep: spell.repraesentation,
|
rep: spell.repraesentation,
|
||||||
|
|
@ -252,7 +252,7 @@ function mapRawJson(rawJson) {
|
||||||
}
|
}
|
||||||
json.zauber = spells
|
json.zauber = spells
|
||||||
let combatValues = []
|
let combatValues = []
|
||||||
for (combatValue in kampfwerte) {
|
for (let combatValue in held.kampfwerte) {
|
||||||
combatValues.push({
|
combatValues.push({
|
||||||
name: combatValue.name,
|
name: combatValue.name,
|
||||||
at: combatValue.attacke.value,
|
at: combatValue.attacke.value,
|
||||||
|
|
@ -261,7 +261,7 @@ function mapRawJson(rawJson) {
|
||||||
}
|
}
|
||||||
json.kampfwerte = combatValues
|
json.kampfwerte = combatValues
|
||||||
let notes = []
|
let notes = []
|
||||||
for (note in kommentare) {
|
for (let note in held.kommentare) {
|
||||||
if (note.hasOwnProperty("key")) {
|
if (note.hasOwnProperty("key")) {
|
||||||
notes.push({
|
notes.push({
|
||||||
key: note.key,
|
key: note.key,
|
||||||
|
|
@ -270,7 +270,6 @@ function mapRawJson(rawJson) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
json.notizen = notes
|
json.notizen = notes
|
||||||
}
|
|
||||||
|
|
||||||
return json
|
return json
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue