Compare commits

...

2 Commits

Author SHA1 Message Date
macniel b6814c9f74 Repairs XML-Import for SKills/Talents 2025-10-02 20:28:31 +02:00
macniel e47deaf938 Implements simple advantage template that is then placed on the character sheet.
also fixes rollable partial and skills can be rolled on again.
2025-10-02 18:14:35 +02:00
8 changed files with 58 additions and 156 deletions

View File

@ -14,7 +14,8 @@ async function preloadHandlebarsTemplates() {
'systems/DSA_4-1/templates/ui/partial-rollable-button.hbs', 'systems/DSA_4-1/templates/ui/partial-rollable-button.hbs',
'systems/DSA_4-1/templates/ui/partial-attribute-button.hbs', 'systems/DSA_4-1/templates/ui/partial-attribute-button.hbs',
'systems/DSA_4-1/templates/ui/partial-talent-editable.hbs', 'systems/DSA_4-1/templates/ui/partial-talent-editable.hbs',
'systems/DSA_4-1/templates/ui/partial-die.hbs' 'systems/DSA_4-1/templates/ui/partial-die.hbs',
'systems/DSA_4-1/templates/ui/partial-advantage-button.hbs'
]); ]);
} }

View File

@ -34,110 +34,4 @@ export class Character extends Actor {
console.log(data); console.log(data);
return 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

@ -80,25 +80,20 @@ export class CharacterSheet extends ActorSheet {
} }
#addAdvantagesToContext(context) { #addAdvantagesToContext(context) {
const actorAdvantages = {} context.advantages = [];
const actorData = context.data; const actorData = context.data;
Object.values(actorData.items).forEach( (item) => { Object.values(actorData.items).forEach( (item) => {
if (item.type === "Advantage") { if (item.type === "Advantage") {
actorAdvantages[item._id] = item; context.advantages.push({
id: item._id,
name: item.name,
value: item.system.value,
options: item.system.auswahl,
description: item.system.description,
});
} }
} }
); );
if ( context.system.vornachteile.length >= 0) {
context.system.vornachteile.forEach( ( { vornachteil }, index) => {
context.vornachteile.push(
{
name: vornachteil.name,
value: vornachteil.value,
auswahl: vornachteil.auswahl,
}
)
})
}
} }
#addAttributesToContext(context) { #addAttributesToContext(context) {
@ -193,18 +188,6 @@ export class CharacterSheet extends ActorSheet {
} }
} }
_onDropDocument(event, item) {
console.log(item)
}
_onDragStart(event) {
super._onDragStart(event);
const src = event.target
console.log(event)
event.dataTransfer.setData("plain/text", src.dataset.name);
}
_evaluateRoll(rolledDice, { taw, lowerThreshold = 1, upperThreshold = 20, countToMeisterlich = 3, countToPatzer = 3, werte = [] } ) { _evaluateRoll(rolledDice, { taw, lowerThreshold = 1, upperThreshold = 20, countToMeisterlich = 3, countToPatzer = 3, werte = [] } ) {
let tap = taw; let tap = taw;
let meisterlichCounter = 0; let meisterlichCounter = 0;
@ -262,8 +245,7 @@ export class CharacterSheet extends ActorSheet {
} }
} }
_onOpenSkill(documentId) { openEmbeddedDocument(documentId) {
console.log(this.object.items.get(documentId).sheet);
this.object.items.get(documentId).sheet.render(true) this.object.items.get(documentId).sheet.render(true)
} }
@ -315,7 +297,12 @@ export class CharacterSheet extends ActorSheet {
}); });
html.on('click', '.talent .name', (evt) => { html.on('click', '.talent .name', (evt) => {
this._onOpenSkill(evt.target.dataset.id); this.openEmbeddedDocument(evt.target.dataset.id);
evt.stopPropagation();
})
html.on('click', '.advantage .name', (evt) => {
this.openEmbeddedDocument(evt.target.dataset.id);
evt.stopPropagation(); evt.stopPropagation();
}) })
@ -342,7 +329,6 @@ export class CharacterSheet extends ActorSheet {
} }
]); ]);
let handler = ev => this._onDragStart(ev); let handler = ev => this._onDragStart(ev);
// Find all items on the character sheet. // Find all items on the character sheet.
html.find('.talent.rollable').each((i, li) => { html.find('.talent.rollable').each((i, li) => {
@ -362,6 +348,15 @@ export class CharacterSheet extends ActorSheet {
} }
} }
#handleDroppedAdvantage(actor, advantage) {
const array = Array.from(actor.items);
for ( let i = 0; i < array.length; i++ ) {
if (array[i].name === advantage.name) { // TODO: adjust for uniqueness
return false;
}
}
}
static getElementByName(collection, id) { static getElementByName(collection, id) {
const array = Array.from(collection); const array = Array.from(collection);
for (const element of array) { for (const element of array) {
@ -383,6 +378,8 @@ export class CharacterSheet extends ActorSheet {
switch (type) { switch (type) {
case "Skill": case "Skill":
return characterSheet.#handleDroppedSkill(actor, document); // on false cancel this whole operation return characterSheet.#handleDroppedSkill(actor, document); // on false cancel this whole operation
case "Advantage":
return characterSheet.#handleDroppedAdvantage(actor, document);
default: default:
return false; return false;
} }

View File

@ -27,7 +27,7 @@ export async function importCharacter(actorId, file) {
let dom = domParser.parseFromString(xmlString, 'application/xml') let dom = domParser.parseFromString(xmlString, 'application/xml')
let rawJson = getJsonFromXML(dom) let rawJson = getJsonFromXML(dom)
let characterJson = mapRawJson(rawJson) let characterJson = mapRawJson(actor, rawJson)
actor.update(characterJson) actor.update(characterJson)
} }
@ -70,6 +70,22 @@ function getJsonFromXML(dom) {
return jsonResult; 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 * gets the text content of a file
* @param file the file with the desired content * @param file the file with the desired content
@ -101,20 +117,11 @@ function calculateBirthdate(json) {
return `${day}. ${month} ${year} BF` return `${day}. ${month} ${year} BF`
} }
function mapSkills(rawJson) { function mapSkills(actor, held) {
let talents = []
for (let talent in held.talentliste.talent) { for (let talent in held.talentliste.talent) {
talent = held.talentliste.talent[talent] talent = held.talentliste.talent[talent]
let talentItem = game.items.getName(talent.name) addSkillFromCompendiumByNameToActor(talent.name, talent.value, actor)
if (talentItem) {
let talentJson = {
talent: talentItem,
taw: talent.value,
}
talents.push(talentJson)
}
} }
return talents
} }
/** /**
@ -122,7 +129,7 @@ function mapSkills(rawJson) {
* @param rawJson the json parsed from the Helden-Software XML * @param rawJson the json parsed from the Helden-Software XML
* @returns {{}} a json representation of the character * @returns {{}} a json representation of the character
*/ */
function mapRawJson(rawJson) { function mapRawJson(actor, rawJson) {
let json = {} let json = {}
let held = rawJson.helden.held; let held = rawJson.helden.held;
json.name = held.name json.name = held.name
@ -265,7 +272,7 @@ function mapRawJson(rawJson) {
json.sonderfertigkeiten = specialAbilities json.sonderfertigkeiten = specialAbilities
json.liturgien = liturgies json.liturgien = liturgies
json.talente = mapSkills(rawJson) mapSkills(actor, held)
let spells = [] let spells = []
/*for (let spell in held.zauberliste.zauber) { /*for (let spell in held.zauberliste.zauber) {
spell = held.zauberliste.zauber[spell] spell = held.zauberliste.zauber[spell]

View File

@ -61,8 +61,8 @@
</div> </div>
<div class="tab attributes" data-group="primary" data-tab="attributes"> <div class="tab attributes" data-group="primary" data-tab="attributes">
<ul> <ul>
{{#each items}} {{#each this.advantages}}
<li>{{this.name}}</li> <li>{{> "systems/DSA_4-1/templates/ui/partial-advantage-button.hbs" this}}</li>
{{/each}} {{/each}}
</ul> </ul>
</div> </div>
@ -161,4 +161,4 @@
</div> </div>
</section> </section>
</form> </form>

View File

@ -8,7 +8,7 @@
{{!-- Sheet Body --}} {{!-- Sheet Body --}}
<section class="sheet-body" style="flex: 1"> <section class="sheet-body" style="flex: 1">
<div class="tab json" data-group="primary" data-tab="json"> <div class="tab json" data-group="primary" data-tab="json">
<pre style="overflow: auto">{{json}}</pre> <pre style="overflow: auto; white-space: normal; position: relative; top: 8px; bottom: 8px; left: 8px; right: 8px">{{json}}</pre>
</div> </div>
</section> </section>
</form> </form>

View File

@ -0,0 +1,3 @@
<div class="advantage">
<span class="name" data-id="{{this.id}}">{{this.name}}</span>
</div>

View File

@ -1,4 +1,4 @@
<div class="block rollable {{this.type}} {{this.gruppe}}" data-id="{{this.id}}" data-taw="{{this.taw}}'data-name="{{this.name}}" data-eigenschaft1="{{this.eigenschaft1}}" data-eigenschaft2="{{this.eigenschaft2}}" data-eigenschaft3="{{this.eigenschaft3}}" data-taw="{{this.taw}}" data-rollEigenschaft1="{{this.rollEigenschaft1}}" data-rollEigenschaft2="{{this.rollEigenschaft2}}" data-rollEigenschaft3="{{this.rollEigenschaft3}}"> <div class="block rollable {{this.type}} {{this.gruppe}}" data-id="{{this.id}}" data-taw="{{this.taw}}" data-name="{{this.name}}" data-eigenschaft1="{{this.eigenschaft1}}" data-eigenschaft2="{{this.eigenschaft2}}" data-eigenschaft3="{{this.eigenschaft3}}" data-taw="{{this.taw}}" data-rollEigenschaft1="{{this.rollEigenschaft1}}" data-rollEigenschaft2="{{this.rollEigenschaft2}}" data-rollEigenschaft3="{{this.rollEigenschaft3}}">
<div class="die"> <div class="die">
{{> 'systems/DSA_4-1/templates/ui/partial-die.hbs' }} {{> 'systems/DSA_4-1/templates/ui/partial-die.hbs' }}