foundryvtt-reve-de-dragon/module/rdd-compendium-organiser.js

30 lines
1.0 KiB
JavaScript
Raw Normal View History

2022-01-29 22:49:34 +01:00
import { SYSTEM_RDD } from "./constants.js";
2021-01-26 00:25:41 +01:00
import { Misc } from "./misc.js";
export class RddCompendiumOrganiser {
static init() {
Hooks.on('renderCompendium', async (pack, html, compendiumData) => RddCompendiumOrganiser.onRenderCompendium(pack, html, compendiumData))
2021-01-26 00:25:41 +01:00
}
static async onRenderCompendium(compendium, html, compendiumData) {
console.log('onRenderCompendium', compendium, html, compendiumData);
const pack = compendium.collection
2022-01-29 22:49:34 +01:00
if (pack.metadata.system === SYSTEM_RDD) {
2021-01-26 00:25:41 +01:00
html.find('.directory-item').each((i, element) => {
RddCompendiumOrganiser.setEntityTypeName(pack, element);
2021-01-26 00:25:41 +01:00
});
}
}
static async setEntityTypeName(pack, element) {
const label = Misc.getEntityTypeLabel(await pack.getDocument(element.dataset.documentId));
RddCompendiumOrganiser.insertEntityType(element, label);
}
static insertEntityType(element, label) {
if (label) {
element.children[1].insertAdjacentHTML('afterbegin', `<label class="type-compendium">${label}: </label>`);
}
2021-01-26 00:25:41 +01:00
}
}