fvtt-vadentis/modules/vadentis-utility.js

102 lines
3.1 KiB
JavaScript
Raw Normal View History

2021-04-01 21:18:36 +02:00
/* -------------------------------------------- */
import { VadentisCombat } from "./vadentis-combat.js";
/* -------------------------------------------- */
export class VadentisUtility extends Entity {
/* -------------------------------------------- */
static async preloadHandlebarsTemplates() {
const templatePaths = [
'systems/foundryvtt-vadentis/templates/actor-sheet.html',
2021-04-01 22:35:03 +02:00
'systems/foundryvtt-vadentis/templates/item-sheet.html',
'systems/foundryvtt-vadentis/templates/score-option-list.html',
2021-04-01 22:52:41 +02:00
'systems/foundryvtt-vadentis/templates/malus-option-list.html',
'systems/foundryvtt-vadentis/templates/bonus-option-list.html',
2021-04-01 22:35:03 +02:00
'systems/foundryvtt-vadentis/templates/editor-notes-gm.html'
2021-04-01 21:18:36 +02:00
]
return loadTemplates(templatePaths);
}
2021-04-01 22:35:03 +02:00
/* -------------------------------------------- */
static registerChatCallbacks( ) {
}
2021-04-01 21:18:36 +02:00
/* -------------------------------------------- */
static fillRange (start, end) {
return Array(end - start + 1).fill().map((item, index) => start + index);
}
/* -------------------------------------------- */
static onSocketMesssage( msg ) {
if( !game.user.isGM ) return; // Only GM
if (msg.name == 'msg_declare_actions' ) {
}
}
/* -------------------------------------------- */
static async loadCompendiumNames(compendium) {
const pack = game.packs.get(compendium);
let competences;
await pack.getIndex().then(index => competences = index);
return competences;
}
/* -------------------------------------------- */
static async loadCompendium(compendium, filter = item => true) {
let compendiumItems = await SoSUtility.loadCompendiumNames(compendium);
const pack = game.packs.get(compendium);
let list = [];
for (let compendiumItem of compendiumItems) {
await pack.getEntity(compendiumItem._id).then(it => {
const item = it.data;
if (filter(item)) {
list.push(item);
}
});
};
return list;
}
2021-04-02 16:47:38 +02:00
/* -------------------------------------------- */
static getDonnees( ) {
return this.loadCompendiumNames('foundryvtt-vadentis.donnees');
}
/* -------------------------------------------- */
static getEglises( ) {
return this.loadCompendiumNames('foundryvtt-vadentis.eglises');
}
2021-04-02 14:59:58 +02:00
/* -------------------------------------------- */
static async confirmDelete(actorSheet, li) {
let itemId = li.data("item-id");
let objet = actorSheet.actor.items.find(item => item._id == itemId);
let msgTxt = "<p>Etes vous certain de souhaiter supprimer cet item ?";
let buttons = {
delete: {
icon: '<i class="fas fa-check"></i>',
label: "Oui, à supprimer",
callback: () => {
actorSheet.actor.deleteOwnedItem(itemId);
li.slideUp(200, () => actorSheet.render(false));
}
},
cancel: {
icon: '<i class="fas fa-times"></i>',
label: "Annuler"
}
}
msgTxt += "</p>";
let d = new Dialog({
title: "Confirmer la suppression",
content: msgTxt,
buttons: buttons,
default: "cancel"
});
d.render(true);
}
2021-04-01 21:18:36 +02:00
}