Fix monnaie deletion
This commit is contained in:
parent
2cd607e199
commit
6508a529e5
@ -38,6 +38,9 @@ export class RdDActorSheet extends ActorSheet {
|
||||
/* -------------------------------------------- */
|
||||
async getData() {
|
||||
const objectData = Misc.data(this.object);
|
||||
|
||||
//this.actor.checkMonnaiePresence(this.actor.data.items); // Always check
|
||||
|
||||
let formData = {
|
||||
title: this.title,
|
||||
id: objectData.id,
|
||||
|
@ -80,6 +80,15 @@ export class RdDActorVehiculeSheet extends ActorSheet {
|
||||
await this.actor.createEmbeddedDocuments('Item', [{ name: name, type: type }], { renderSheet: true });
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async monnaieIncDec(id, value) {
|
||||
let monnaie = this.getMonnaie(id);
|
||||
if (monnaie) {
|
||||
const quantite = Math.max(0, Misc.templateData(monnaie).quantite + value);
|
||||
await this.updateEmbeddedDocuments('Item', [{ _id: monnaie.id, 'data.quantite': quantite }]);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/** @override */
|
||||
activateListeners(html) {
|
||||
@ -109,6 +118,15 @@ export class RdDActorVehiculeSheet extends ActorSheet {
|
||||
this.actor.nettoyerConteneurs();
|
||||
});
|
||||
|
||||
html.find('.monnaie-plus').click(async event => {
|
||||
const li = $(event.currentTarget).parents(".item");
|
||||
this.actor.monnaieIncDec(li.data("item-id"), 1);
|
||||
});
|
||||
html.find('.monnaie-moins').click(async event => {
|
||||
const li = $(event.currentTarget).parents(".item");
|
||||
this.actor.monnaieIncDec(li.data("item-id"), -1);
|
||||
});
|
||||
|
||||
// Display info about queue
|
||||
html.find('.conteneur-name a').click((event) => {
|
||||
let myID = event.currentTarget.attributes['data-item-id'].value;
|
||||
|
@ -198,6 +198,7 @@ export class RdDActor extends Actor {
|
||||
async checkMonnaiePresence(items) { // Ajout opportuniste si les pièces n'existent pas.
|
||||
if (!items) return; // Sanity check during import
|
||||
let manquantes = Monnaie.monnaiesManquantes(items);
|
||||
console.log("Manque : ", manquantes);
|
||||
if (manquantes.length > 0) {
|
||||
await this.createEmbeddedDocuments('Item', manquantes, { renderSheet: false });
|
||||
}
|
||||
|
@ -25,6 +25,11 @@ const monnaiesData = [
|
||||
|
||||
export class Monnaie {
|
||||
|
||||
static isSystemMonnaie(item) {
|
||||
let present = monnaiesData.find( monnaie => monnaie.data.valeur_deniers == item.data?.data?.valeur_deniers);
|
||||
return present;
|
||||
}
|
||||
|
||||
static monnaiesData() {
|
||||
return monnaiesData;
|
||||
}
|
||||
@ -35,9 +40,11 @@ export class Monnaie {
|
||||
|
||||
static monnaiesManquantes(items) {
|
||||
const valeurs = Monnaie.filtrerMonnaies(items)
|
||||
.map(it => Misc.templateData(it).valeur_deniers)
|
||||
.map(it => Misc.templateData(it).valeur_deniers);
|
||||
const manquantes = monnaiesData.filter(monnaie => !valeurs.find(v => v != Misc.templateData(monnaie).valeur_deniers));
|
||||
return manquantes;
|
||||
//const manquantes = monnaiesData.filter(monnaie => !valeurs.find(v => v != Misc.templateData(monnaie).valeur_deniers) );
|
||||
console.log("Valeurs : ", valeurs, manquantes);
|
||||
return []; //manquantes;
|
||||
}
|
||||
|
||||
static deValeur(monnaie, v) {
|
||||
|
@ -9,6 +9,7 @@ import { DialogItemAchat } from "./dialog-item-achat.js";
|
||||
import { ReglesOptionelles } from "./regles-optionelles.js";
|
||||
import { RdDDice } from "./rdd-dice.js";
|
||||
import { RdDItem } from "./item.js";
|
||||
import { Monnaie } from "./item-monnaie.js";
|
||||
|
||||
/* -------------------------------------------- */
|
||||
// This table starts at 0 -> niveau -10
|
||||
@ -781,6 +782,12 @@ export class RdDUtility {
|
||||
static async confirmerSuppression(actorSheet, li) {
|
||||
let itemId = li.data("item-id");
|
||||
let objet = actorSheet.actor.getObjet(itemId);
|
||||
|
||||
if ( objet.type == 'monnaie' && Monnaie.isSystemMonnaie(objet) ) {
|
||||
ui.notifications.warn("Suppression des monnaies de base impossible");
|
||||
return;
|
||||
}
|
||||
|
||||
let msgTxt = "<p>Etes vous certain de vouloir supprimer cet objet ?";
|
||||
let buttons = {
|
||||
delete: {
|
||||
|
Loading…
Reference in New Issue
Block a user