Les rencontres sont configurables #572
@ -37,6 +37,7 @@ import { RdDSigneDraconiqueItemSheet } from "./item-signedraconique-sheet.js";
|
|||||||
import { Misc } from "./misc.js";
|
import { Misc } from "./misc.js";
|
||||||
import { Migrations } from './migrations.js';
|
import { Migrations } from './migrations.js';
|
||||||
import { DialogChronologie } from "./dialog-chronologie.js";
|
import { DialogChronologie } from "./dialog-chronologie.js";
|
||||||
|
import { SystemCompendiums } from "./settings/system-compendiums.js";
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
/* Foundry VTT Initialization */
|
/* Foundry VTT Initialization */
|
||||||
@ -195,6 +196,7 @@ Hooks.once("init", async function () {
|
|||||||
CONFIG.Combat.documentClass = RdDCombatManager;
|
CONFIG.Combat.documentClass = RdDCombatManager;
|
||||||
|
|
||||||
// préparation des différents modules
|
// préparation des différents modules
|
||||||
|
SystemCompendiums.init();
|
||||||
DialogChronologie.init();
|
DialogChronologie.init();
|
||||||
ReglesOptionelles.init();
|
ReglesOptionelles.init();
|
||||||
RdDUtility.init();
|
RdDUtility.init();
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import { SystemCompendiums } from "./settings/system-compendiums.js";
|
||||||
|
|
||||||
export class RdDRollTables {
|
export class RdDRollTables {
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
@ -14,7 +16,7 @@ export class RdDRollTables {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async getSystemTable(tableName) {
|
static async getSystemTable(tableName) {
|
||||||
const pack = game.packs.get("foundryvtt-reve-de-dragon.tables-diverses");
|
const pack = SystemCompendiums.getPack("tables-diverses");
|
||||||
const index = await pack.getIndex();
|
const index = await pack.getIndex();
|
||||||
const entry = index.find(e => e.name === tableName);
|
const entry = index.find(e => e.name === tableName);
|
||||||
return await pack.getDocument(entry._id);
|
return await pack.getDocument(entry._id);
|
||||||
@ -24,8 +26,7 @@ export class RdDRollTables {
|
|||||||
static async drawItemFromRollTable(tableName, toChat = false) {
|
static async drawItemFromRollTable(tableName, toChat = false) {
|
||||||
const drawResult = await RdDRollTables.genericGetTableResult(tableName, toChat);
|
const drawResult = await RdDRollTables.genericGetTableResult(tableName, toChat);
|
||||||
const pack = game.packs.get(drawResult.documentCollection)
|
const pack = game.packs.get(drawResult.documentCollection)
|
||||||
let doc = await pack.getDocument(drawResult.documentId)
|
return await pack.getDocument(drawResult.documentId)
|
||||||
return doc
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
|
116
module/settings/system-compendiums.js
Normal file
116
module/settings/system-compendiums.js
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
import { SYSTEM_RDD } from "../constants.js";
|
||||||
|
|
||||||
|
const COMPENDIUM_SETTING_PREFIX = 'compendium-';
|
||||||
|
|
||||||
|
const CONFIGURABLE_COMPENDIUMS = {
|
||||||
|
'tables-diverses': { label: "Tables aléatoires", type: "RollTable" },
|
||||||
|
'competences': { label: "Compétences", type: "Item" },
|
||||||
|
'queues-de-dragon': { label: "Queues de dragon", type: "Item" },
|
||||||
|
'ombres-de-thanatos': { label: "Ombres de Thanatos", type: "Item" },
|
||||||
|
'souffles-de-dragon': { label: "Souffles de Dragon", type: "Item" },
|
||||||
|
'tarot-draconique': { label: "Tarots draconiques", type: "Item" },
|
||||||
|
'tetes-de-dragon-pour-haut-revants': { label: "Têtes de dragons (haut-rêvant)", type: "Item" },
|
||||||
|
'tetes-de-dragon-pour-tous-personnages': { label: "Têtes de dragons (tous)", type: "Item" },
|
||||||
|
}
|
||||||
|
|
||||||
|
export class SystemCompendiums extends FormApplication {
|
||||||
|
static init() {
|
||||||
|
Object.keys(CONFIGURABLE_COMPENDIUMS).forEach(compendium => {
|
||||||
|
const definition = CONFIGURABLE_COMPENDIUMS[compendium];
|
||||||
|
mergeObject(definition, {
|
||||||
|
compendium: compendium,
|
||||||
|
default: SystemCompendiums._getDefaultCompendium(compendium),
|
||||||
|
setting: SystemCompendiums._getSettingCompendium(compendium)
|
||||||
|
});
|
||||||
|
|
||||||
|
game.settings.register(SYSTEM_RDD, definition.setting, {
|
||||||
|
name: definition.label,
|
||||||
|
default: definition.default,
|
||||||
|
scope: "world",
|
||||||
|
config: false,
|
||||||
|
type: String
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
game.settings.registerMenu(SYSTEM_RDD, "compendium-settings", {
|
||||||
|
name: "Choisir les compendiums système",
|
||||||
|
label: "Compendiums système",
|
||||||
|
hint: "Ouvre la fenêtre de sélection des compendiums système",
|
||||||
|
icon: "fas fa-bars",
|
||||||
|
type: SystemCompendiums
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
static getPack(compendium) {
|
||||||
|
return game.packs.get(SystemCompendiums.getCompendium(compendium));
|
||||||
|
}
|
||||||
|
|
||||||
|
static async getContent(compendium, docType) {
|
||||||
|
const pack = SystemCompendiums.getPack(compendium);
|
||||||
|
if (pack.metadata.type == docType)
|
||||||
|
{
|
||||||
|
return await pack.getDocuments();
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
static async getItems(compendium) {
|
||||||
|
return await SystemCompendiums.getContent(compendium, 'Item')
|
||||||
|
}
|
||||||
|
|
||||||
|
static getCompendium(compendium) {
|
||||||
|
const setting = CONFIGURABLE_COMPENDIUMS[compendium]?.setting;
|
||||||
|
return setting ? game.settings.get(SYSTEM_RDD, setting) : SystemCompendiums._getDefaultCompendium(compendium);
|
||||||
|
}
|
||||||
|
|
||||||
|
static _getSettingCompendium(compendium) {
|
||||||
|
return COMPENDIUM_SETTING_PREFIX + compendium;
|
||||||
|
}
|
||||||
|
|
||||||
|
static _getDefaultCompendium(compendium) {
|
||||||
|
return `${SYSTEM_RDD}.${compendium}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(...args) {
|
||||||
|
super(...args);
|
||||||
|
}
|
||||||
|
|
||||||
|
static get defaultOptions() {
|
||||||
|
const options = super.defaultOptions;
|
||||||
|
mergeObject(options, {
|
||||||
|
id: "system-compendiums",
|
||||||
|
template: "systems/foundryvtt-reve-de-dragon/templates/settings/system-compendiums.html",
|
||||||
|
height: 'fit-content',
|
||||||
|
width: 600,
|
||||||
|
minimizable: false,
|
||||||
|
closeOnSubmit: true,
|
||||||
|
title: "Compendiums système"
|
||||||
|
});
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
|
getData() {
|
||||||
|
const systemCompendiums = Object.values(CONFIGURABLE_COMPENDIUMS)
|
||||||
|
.map(it => mergeObject(it, { value: SystemCompendiums.getCompendium(it.compendium) }));
|
||||||
|
const availableCompendiums = game.packs.map(pack => { return {
|
||||||
|
name: pack.collection,
|
||||||
|
path: pack.collection.replace('.', " / "),
|
||||||
|
type: pack.metadata.type
|
||||||
|
} });
|
||||||
|
return mergeObject(super.getData(), {
|
||||||
|
systemCompendiums: systemCompendiums,
|
||||||
|
availableCompendiums: availableCompendiums
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
activateListeners(html) {
|
||||||
|
html.find("select.system-compendium-setting").change((event) => {
|
||||||
|
const compendium = $(event.currentTarget).data('compendium')
|
||||||
|
const value = $(event.currentTarget).val();
|
||||||
|
const systemCompendium = CONFIGURABLE_COMPENDIUMS[compendium];
|
||||||
|
|
||||||
|
game.settings.set(SYSTEM_RDD, systemCompendium.setting, value);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
21
templates/settings/system-compendiums.html
Normal file
21
templates/settings/system-compendiums.html
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<form autocomplete="off" onsubmit="event.preventDefault();">
|
||||||
|
{{log 'systemCompendiums'systemCompendiums}}
|
||||||
|
{{log 'availableCompendiums' availableCompendiums}}
|
||||||
|
<ul>
|
||||||
|
{{#each systemCompendiums as |definition key|}}
|
||||||
|
<li class="flexrow">
|
||||||
|
<label>{{definition.label}}</label>
|
||||||
|
<select data-dtype="String" class="system-compendium-setting flex-grow-2" data-compendium="{{definition.compendium}}" >
|
||||||
|
{{#select definition.value}}
|
||||||
|
{{#each @root.availableCompendiums as |available key|}}
|
||||||
|
{{#if (eq available.type definition.type)}}
|
||||||
|
<option value="{{available.name}}">{{available.path }}</option>
|
||||||
|
{{/if}}
|
||||||
|
{{/each}}
|
||||||
|
{{/select}}
|
||||||
|
</select>
|
||||||
|
</li>
|
||||||
|
{{/each}}
|
||||||
|
</ul>
|
||||||
|
</form>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user