diff --git a/module/actor-sheet.js b/module/actor-sheet.js index 15f9adf5..46ccb270 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -12,6 +12,7 @@ import { Misc } from "./misc.js"; import { RdDCombatManager } from "./rdd-combat.js"; import { RdDCarac } from "./rdd-carac.js"; import { RdDItem } from "./item.js"; +import { DialogSplitItem } from "./dialog-split-item.js"; /* -------------------------------------------- */ export class RdDActorSheet extends ActorSheet { @@ -49,20 +50,20 @@ export class RdDActorSheet extends ActorSheet { // // Entity data // formData.actor = formData.entity; // formData.data = formData.entity.data; - + // // Owned items // formData.items = formData.actor.items; // formData.items.sort((a, b) => (a.sort || 0) - (b.sort || 0)); - + // -------------- version 0.8.0 - + // // Copy and sort Items // items.sort((a, b) => (a.sort || 0) - (b.sort || 0)); // data.items = items; - + // // Copy Active Effects // data.effects = effects; - + // // Return template data let formData = { title: this.title, @@ -203,7 +204,7 @@ export class RdDActorSheet extends ActorSheet { }); d.render(true); } - + /* -------------------------------------------- */ async selectTypeOeuvre() { let typeOeuvres = RdDItem.getTypesOeuvres(); @@ -240,6 +241,11 @@ export class RdDActorSheet extends ActorSheet { // Everything below here is only needed if the sheet is editable if (!this.options.editable) return; + html.find('.item-split').click(ev => { + const li = $(ev.currentTarget).parents(".item"); + const item = this.actor.items.get(li.data("item-id")); + this.splitItem(item); + }); html.find('.item-edit').click(ev => { const li = $(ev.currentTarget).parents(".item"); const item = this.actor.items.get(li.data("item-id")); @@ -632,4 +638,20 @@ export class RdDActorSheet extends ActorSheet { // Update the Actor return this.object.update(formData); } + + async splitItem(item) { + const dialog = await DialogSplitItem.create(item, (item, split) => this._onSplitItem(item, split)); + dialog.render(true); + } + + async _onSplitItem(item, split) { + const itemData = Misc.data(item); + if (split >= 1 && split < itemData.data.quantite) { + await item.diminuerQuantite(split); + itemData.data.quantite = split; + itemData.id = undefined; + await this.actor.createEmbeddedDocuments('Item', [itemData]) + } + } + } diff --git a/module/dialog-consommer.js b/module/dialog-consommer.js index d0bc81c5..03002f63 100644 --- a/module/dialog-consommer.js +++ b/module/dialog-consommer.js @@ -1,4 +1,3 @@ -import { Grammar } from "./grammar.js"; import { Misc } from "./misc.js"; export class DialogConsommer extends Dialog { diff --git a/module/dialog-split-item.js b/module/dialog-split-item.js new file mode 100644 index 00000000..a3521493 --- /dev/null +++ b/module/dialog-split-item.js @@ -0,0 +1,51 @@ +import { Misc } from "./misc.js"; + +export class DialogSplitItem extends Dialog { + + static async create(item, callback) { + const itemData = Misc.data(item); + const splitData = { + item: itemData, + choix: { quantite: 1, max: itemData.data.quantite - 1 } + }; + const html = await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/dialog-item-split.html`, splitData); + return new DialogSplitItem(item, splitData, html, callback) + } + + constructor(item, splitData, html, callback) { + let options = { classes: ["dialogsplit"], width: 300, height: 160, 'z-index': 99999 }; + + let conf = { + title: "Séparer en deux", + content: html, + default: "separer", + buttons: { + "separer": { + label: "Séparer", callback: it => { + this.onSplit(); + } + } + } + }; + + super(conf, options); + + this.callback = callback; + this.item = item; + this.splitData = splitData; + } + + async onSplit(){ + this.callback(this.item, this.splitData.choix.quantite); + } + + /* -------------------------------------------- */ + activateListeners(html) { + super.activateListeners(html); + + html.find(".choix-quantite").change(event => { + this.splitData.choix.quantite = Number(event.currentTarget.value); + }); + } + +} \ No newline at end of file diff --git a/templates/actor-inventaire-conteneur.html b/templates/actor-inventaire-conteneur.html index da3789c0..cfbd9a5a 100644 --- a/templates/actor-inventaire-conteneur.html +++ b/templates/actor-inventaire-conteneur.html @@ -6,7 +6,11 @@ {{else}} {{item.name}} {{/if}} - {{item.data.quantite}} + {{item.data.quantite}} + {{#if (gt item.data.quantite 1)}} + + {{/if}} + {{numberFormat item.data.encTotal decimals=2}}