diff --git a/src/module/data/spell.mjs b/src/module/data/spell.mjs index 1ef17008..31ec11cc 100644 --- a/src/module/data/spell.mjs +++ b/src/module/data/spell.mjs @@ -7,9 +7,11 @@ export class SpellDataModel extends BaseItem { static defineSchema() { return { seite: new NumberField(), + zfw: new NumberField(), name: new StringField({required: true}), probe: new ArrayField(new StringField(), {required: true, exact: 3}), probeMod: new StringField(), + hauszauber: new BooleanField(), technik: new StringField(), zauberdauer: new StringField(), wirkung: new StringField(), diff --git a/src/module/sheets/characterSheet.mjs b/src/module/sheets/characterSheet.mjs index f04ee3cb..f8335ae8 100644 --- a/src/module/sheets/characterSheet.mjs +++ b/src/module/sheets/characterSheet.mjs @@ -41,6 +41,7 @@ export class CharacterSheet extends ActorSheet { this.#addEquipmentsToContext(context) await this.#addCombatStatistics(context) this.#addActionsToContext(context) + this.#addSpellsToContext(context) return context; } @@ -96,6 +97,38 @@ export class CharacterSheet extends ActorSheet { ); } + #cleanUpMerkmal(merkmale) { + return merkmale.split(",").map((merkmal) => merkmal.trim()) + } + + #addSpellsToContext(context) { + const actorData = context.data; + context.spells = []; + Object.values(actorData.items).forEach((item, index) => { + if (item.type === "Spell") { + const eigenschaften = item.system.probe; + const werte = [ + {name: eigenschaften[0], value: this.prepareEigenschaftRoll(actorData, eigenschaften[0])}, + {name: eigenschaften[1], value: this.prepareEigenschaftRoll(actorData, eigenschaften[1])}, + {name: eigenschaften[2], value: this.prepareEigenschaftRoll(actorData, eigenschaften[2])} + ] + context.spells.push({ + id: item._id, + name: item.name, + zfw: item.system.zfw, + hauszauber: item.system.hauszauber, + merkmal: this.#cleanUpMerkmal(item.system.merkmal), + rollEigenschaft1: werte[0].value, + rollEigenschaft2: werte[1].value, + rollEigenschaft3: werte[2].value, + eigenschaft1: werte[0].name, + eigenschaft2: werte[1].name, + eigenschaft3: werte[2].name, + }) + } + }) + } + #addAttributesToContext(context) { const actorData = context.data; context.attributes = [ @@ -267,7 +300,7 @@ export class CharacterSheet extends ActorSheet { } prepareEigenschaftRoll(actorData, name) { - if (name) { + if (name && name !== "*") { return actorData.system.attribute[name.toLowerCase()].aktuell } else { return 0 @@ -555,21 +588,32 @@ export class CharacterSheet extends ActorSheet { this._onRoll(evt); }); + // TODO: merge into click.clickable handler html.on('click', '.talent .name', (evt) => { this.openEmbeddedDocument(evt.target.dataset.id); evt.stopPropagation(); }) + // TODO: merge into click.clickable handler html.on('click', '.advantage .name', (evt) => { this.openEmbeddedDocument(evt.target.dataset.id); evt.stopPropagation(); }) + // TODO: merge into click.clickable handler html.on('click', '.equipment', (evt) => { this.openEmbeddedDocument(evt.target.parentElement.dataset.id); evt.stopPropagation(); }) + html.on('click', '.clickable', async (evt) => { + const {id, operation} = evt.currentTarget.dataset; + if (operation === "openActorSheet") { + this.openEmbeddedDocument(id); + evt.stopPropagation(); + } + }) + html.on('dragstart', '.equipment', (evt) => { evt.originalEvent.dataTransfer.setData("application/json", JSON.stringify({ documentId: evt.currentTarget.dataset.id diff --git a/src/module/xml-import/xml-import.mjs b/src/module/xml-import/xml-import.mjs index c2e19552..0f2b15a6 100644 --- a/src/module/xml-import/xml-import.mjs +++ b/src/module/xml-import/xml-import.mjs @@ -102,6 +102,23 @@ async function addAdvantageFromCompendiumByNameToActor(advantageName, advantageV } } +async function addSpellsFromCompendiumByNameToActor(spellName, zfw, representation, hauszauber, actor) { + const compendiumOfSpells = game.packs.get('DSA_4-1.spells'); + const SCREAMING_NAME = spellName.toUpperCase() + const spellId = compendiumOfSpells.index.find(spell => spell.name === SCREAMING_NAME) + if (spellId) { + + const spell = await compendiumOfSpells.getDocument(spellId._id); + + try { + const embeddedDocument = (await actor.createEmbeddedDocuments('Item', [spell]))[0] + embeddedDocument.update({system: {zfw: zfw, hauszauber: hauszauber, repräsentation: representation}}); + } catch (error) { + console.error(`${spell} not found in items`, error) + } + } +} + /** * gets the text content of a file * @param file the file with the desired content @@ -147,6 +164,13 @@ function mapAdvantages(actor, held) { } } +function mapSpells(actor, held) { + for (let spell in held.zauberliste.zauber) { + spell = held.zauberliste.zauber[spell] + addSpellsFromCompendiumByNameToActor(spell.name, spell.value, spell.repraesentation, spell.hauszauber === "true", actor) + } +} + /** * parses a json into a fitting character-json * @param rawJson the json parsed from the Helden-Software XML @@ -266,19 +290,7 @@ function mapRawJson(actor, rawJson) { json.liturgien = liturgies mapSkills(actor, held) - let spells = [] - /*for (let spell in held.zauberliste.zauber) { - spell = held.zauberliste.zauber[spell] - spells.push({ - name: spell.name, - rep: spell.repraesentation, - hauszauber: spell.hauszauber === "true", - zfw: spell.value, - anmerkungen: spell.zauberkommentar, - komplexitaet: spell.k, - }) - }*/ - json.zauber = spells + mapSpells(actor, held) let combatValues = [] for (let combatValue in held.kampf.kampfwerte) { combatValue = held.kampf.kampfwerte[combatValue] diff --git a/src/style/_character-sheet.scss b/src/style/_character-sheet.scss index beddb2ab..3417b8bd 100644 --- a/src/style/_character-sheet.scss +++ b/src/style/_character-sheet.scss @@ -1,3 +1,8 @@ +@use "sass:color"; +@use "_numbers"; +@use "_colours" as colour; + + .dsa41.sheet.actor.character { .window-header.flexrow.draggable.resizable { @@ -127,6 +132,58 @@ } + .tab.spells { + + .spell.rollable svg { + width: 24px; + height: 24px; + + .border { + fill: #0000; + } + + $color: #05f; + + .center { + fill: $color; + stroke: colour.$rollable-die-border-color; + } + + .topleft { + fill: color.adjust($color, $lightness: numbers.$lighter_factor); + stroke: colour.$rollable-die-border-color; + } + + .bottomleft { + fill: color.adjust($color, $lightness: numbers.$lightest_factor); + stroke: colour.$rollable-die-border-color; + } + + .topright { + fill: color.adjust($color, $lightness: numbers.$darken_factor); + stroke: colour.$rollable-die-border-color; + } + + .bottomright, .bottom { + fill: color.adjust($color, $lightness: numbers.$darkest_factor); + stroke: colour.$rollable-die-border-color; + } + } + + .merkmal-list { + list-style: none; + margin: 0; + padding: 0; + text-indent: 0; + + li { + display: inline-block; + padding: 0 4px; + } + } + + } + } } diff --git a/src/style/_creature-sheet.scss b/src/style/_creature-sheet.scss index 57ddaf3a..6c222a63 100644 --- a/src/style/_creature-sheet.scss +++ b/src/style/_creature-sheet.scss @@ -109,34 +109,35 @@ svg { stroke-width: 0.5; + $color: #f30; + .border { - fill: colour.$harm-fill-color; - stroke: colour.$harm-border-color; + fill: #0000; } .center { - fill: colour.$harm-fill-color; - stroke: colour.$harm-border-color; + fill: $color; + stroke: colour.$rollable-die-border-color; } .topleft { - fill: color.adjust(colour.$harm-fill-color, $lightness: numbers.$lighter_factor); - stroke: colour.$harm-border-color; + fill: color.adjust($color, $lightness: numbers.$lighter_factor); + stroke: colour.$rollable-die-border-color; } .bottomleft { - fill: color.adjust(colour.$harm-fill-color, $lightness: numbers.$lightest_factor); - stroke: colour.$harm-border-color; + fill: color.adjust($color, $lightness: numbers.$lightest_factor); + stroke: colour.$rollable-die-border-color; } .topright { - fill: color.adjust(colour.$harm-fill-color, $lightness: numbers.$darken_factor); - stroke: colour.$harm-border-color; + fill: color.adjust($color, $lightness: numbers.$darken_factor); + stroke: colour.$rollable-die-border-color; } .bottomright, .bottom { - fill: color.adjust(colour.$harm-fill-color, $lightness: numbers.$darkest_factor); - stroke: colour.$harm-border-color; + fill: color.adjust($color, $lightness: numbers.$darkest_factor); + stroke: colour.$rollable-die-border-color; } } diff --git a/src/system.json b/src/system.json index 4b27e752..5129e5ca 100644 --- a/src/system.json +++ b/src/system.json @@ -34,7 +34,7 @@ "private": false }, { - "name": "Spell", + "name": "spells", "label": "Basiszauber", "system": "DSA_4-1", "type": "Item", diff --git a/src/templates/actor/actor-character-sheet.hbs b/src/templates/actor/actor-character-sheet.hbs index 2db13cd5..87404223 100644 --- a/src/templates/actor/actor-character-sheet.hbs +++ b/src/templates/actor/actor-character-sheet.hbs @@ -255,6 +255,36 @@
+ + + + + + + + + + + + {{#each this.spells}} + + + + + + + + + + {{/each}} + +
ZaubernameProbeZfWMerkmale
+ {{> 'systems/DSA_4-1/templates/ui/partial-die.hbs' }} + {{this.name}}{{this.eigenschaft1}}{{this.eigenschaft2}}{{this.eigenschaft3}}{{this.zfw}} +
    {{#each this.merkmal}} +
  • {{this}}
  • {{/each}}
+
+