diff --git a/src/main.mjs b/src/main.mjs index a5618d70..1992fa77 100644 --- a/src/main.mjs +++ b/src/main.mjs @@ -14,7 +14,8 @@ async function preloadHandlebarsTemplates() { '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-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' ]); } diff --git a/src/module/sheets/characterSheet.mjs b/src/module/sheets/characterSheet.mjs index 73f24e17..66b453fd 100644 --- a/src/module/sheets/characterSheet.mjs +++ b/src/module/sheets/characterSheet.mjs @@ -80,25 +80,20 @@ export class CharacterSheet extends ActorSheet { } #addAdvantagesToContext(context) { - const actorAdvantages = {} + context.advantages = []; const actorData = context.data; Object.values(actorData.items).forEach( (item) => { 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) { @@ -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 = [] } ) { let tap = taw; let meisterlichCounter = 0; @@ -262,8 +245,7 @@ export class CharacterSheet extends ActorSheet { } } - _onOpenSkill(documentId) { - console.log(this.object.items.get(documentId).sheet); + openEmbeddedDocument(documentId) { this.object.items.get(documentId).sheet.render(true) } @@ -315,7 +297,12 @@ export class CharacterSheet extends ActorSheet { }); 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(); }) @@ -342,7 +329,6 @@ export class CharacterSheet extends ActorSheet { } ]); - let handler = ev => this._onDragStart(ev); // Find all items on the character sheet. 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) { const array = Array.from(collection); for (const element of array) { @@ -383,6 +378,8 @@ export class CharacterSheet extends ActorSheet { switch (type) { case "Skill": return characterSheet.#handleDroppedSkill(actor, document); // on false cancel this whole operation + case "Advantage": + return characterSheet.#handleDroppedAdvantage(actor, document); default: return false; } diff --git a/src/templates/actor/actor-character-sheet.hbs b/src/templates/actor/actor-character-sheet.hbs index a4f65d6e..a6852343 100644 --- a/src/templates/actor/actor-character-sheet.hbs +++ b/src/templates/actor/actor-character-sheet.hbs @@ -61,8 +61,8 @@
@@ -161,4 +161,4 @@ - \ No newline at end of file + diff --git a/src/templates/item/item-advantage-sheet.hbs b/src/templates/item/item-advantage-sheet.hbs index 7902b570..d50d00ce 100644 --- a/src/templates/item/item-advantage-sheet.hbs +++ b/src/templates/item/item-advantage-sheet.hbs @@ -8,7 +8,7 @@ {{!-- Sheet Body --}}
-
{{json}}
+
{{json}}
- \ No newline at end of file + diff --git a/src/templates/ui/partial-advantage-button.hbs b/src/templates/ui/partial-advantage-button.hbs new file mode 100644 index 00000000..8e1ff713 --- /dev/null +++ b/src/templates/ui/partial-advantage-button.hbs @@ -0,0 +1,3 @@ +
+ {{this.name}} +
diff --git a/src/templates/ui/partial-rollable-button.hbs b/src/templates/ui/partial-rollable-button.hbs index 3764e086..9d2aa61e 100644 --- a/src/templates/ui/partial-rollable-button.hbs +++ b/src/templates/ui/partial-rollable-button.hbs @@ -1,4 +1,4 @@ -
+
{{> 'systems/DSA_4-1/templates/ui/partial-die.hbs' }}