Merge branch 'v1.4-split' into 'v1.4'
Séparer les piles d'éléments #169 See merge request LeRatierBretonnien/foundryvtt-reve-de-dragon!198
This commit is contained in:
commit
6e29f497eb
@ -12,6 +12,7 @@ import { Misc } from "./misc.js";
|
|||||||
import { RdDCombatManager } from "./rdd-combat.js";
|
import { RdDCombatManager } from "./rdd-combat.js";
|
||||||
import { RdDCarac } from "./rdd-carac.js";
|
import { RdDCarac } from "./rdd-carac.js";
|
||||||
import { RdDItem } from "./item.js";
|
import { RdDItem } from "./item.js";
|
||||||
|
import { DialogSplitItem } from "./dialog-split-item.js";
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
export class RdDActorSheet extends ActorSheet {
|
export class RdDActorSheet extends ActorSheet {
|
||||||
@ -240,6 +241,11 @@ export class RdDActorSheet extends ActorSheet {
|
|||||||
// Everything below here is only needed if the sheet is editable
|
// Everything below here is only needed if the sheet is editable
|
||||||
if (!this.options.editable) return;
|
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 => {
|
html.find('.item-edit').click(ev => {
|
||||||
const li = $(ev.currentTarget).parents(".item");
|
const li = $(ev.currentTarget).parents(".item");
|
||||||
const item = this.actor.items.get(li.data("item-id"));
|
const item = this.actor.items.get(li.data("item-id"));
|
||||||
@ -632,4 +638,20 @@ export class RdDActorSheet extends ActorSheet {
|
|||||||
// Update the Actor
|
// Update the Actor
|
||||||
return this.object.update(formData);
|
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])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { Grammar } from "./grammar.js";
|
|
||||||
import { Misc } from "./misc.js";
|
import { Misc } from "./misc.js";
|
||||||
|
|
||||||
export class DialogConsommer extends Dialog {
|
export class DialogConsommer extends Dialog {
|
||||||
|
51
module/dialog-split-item.js
Normal file
51
module/dialog-split-item.js
Normal file
@ -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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -6,7 +6,11 @@
|
|||||||
{{else}}
|
{{else}}
|
||||||
<span class="item-name flex-grow">{{item.name}}</span>
|
<span class="item-name flex-grow">{{item.name}}</span>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
<span class="item-quantite">{{item.data.quantite}}</span>
|
<span class="item-quantite">{{item.data.quantite}}
|
||||||
|
{{#if (gt item.data.quantite 1)}}
|
||||||
|
<a class="item-control item-split" title="Séparer"><i class="fas fa-unlink"></i></a>
|
||||||
|
{{/if}}
|
||||||
|
</span>
|
||||||
<span class="item-quantite">{{numberFormat item.data.encTotal decimals=2}}</span>
|
<span class="item-quantite">{{numberFormat item.data.encTotal decimals=2}}</span>
|
||||||
<div class="item-controls flex-grow">
|
<div class="item-controls flex-grow">
|
||||||
{{#unless item.estContenu}}
|
{{#unless item.estContenu}}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
<form class="rdddialog">
|
<form class="rdddialog">
|
||||||
|
<img class="chat-icon" src="{{item.img}}" title="{{item.name}}" alt="{{item.name}}" />
|
||||||
<div class="flexrow">
|
<div class="flexrow">
|
||||||
<label>Quantité de {{item.name}} à {{#if item.data.boisson}}boire{{else}}manger{{/if}}</label>
|
<label class="flex-grow">Quantité de {{item.name}} à {{#if item.data.boisson}}boire{{else}}manger{{/if}}</label>
|
||||||
<input class="attribute-value consommer-doses" type="text" name="doses" value="{{choix.doses}}"
|
<input class="attribute-value consommer-doses flex-shrink" type="number" name="doses" value="{{choix.doses}}"
|
||||||
size="3" min="0" max="{{item.data.quantite}}"
|
min="0" max="{{item.data.quantite}}" data-dtype="Number" />
|
||||||
data-dtype="Number" />
|
|
||||||
</div>
|
</div>
|
||||||
{{#if item.data.sust}}
|
{{#if item.data.sust}}
|
||||||
<p>Cette {{#if item.data.boisson}}boisson{{else}}nourriture{{/if}} vous apportera <span
|
<p>Cette {{#if item.data.boisson}}boisson{{else}}nourriture{{/if}} vous apportera <span
|
||||||
|
11
templates/dialog-item-split.html
Normal file
11
templates/dialog-item-split.html
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<form class="rdddialog">
|
||||||
|
<img class="chat-icon" src="{{item.img}}" title="{{item.name}}" alt="{{item.name}}" />
|
||||||
|
<h4>{{item.name}}</h4>
|
||||||
|
<label>Quantité totale : {{item.data.quantite}}</label>
|
||||||
|
<div class="flexrow">
|
||||||
|
<label class="flex-grow">Quantité à séparer</label>
|
||||||
|
<input class="attribute-value choix-quantite flex-shrink" type="number" name="choix.quantite" value="{{choix.quantite}}"
|
||||||
|
min="1" max="{{choix.max}}" data-dtype="Number" />
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user