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