2022-01-29 22:49:34 +01:00
|
|
|
import { SYSTEM_RDD } from "./constants.js";
|
2021-01-26 00:25:41 +01:00
|
|
|
|
2023-01-18 01:37:22 +01:00
|
|
|
export class RdDCompendiumOrganiser {
|
2021-01-26 00:25:41 +01:00
|
|
|
static init() {
|
2023-01-18 01:37:22 +01:00
|
|
|
Hooks.on('renderCompendium', async (pack, html, compendiumData) => RdDCompendiumOrganiser.onRenderCompendium(pack, html, compendiumData))
|
2021-01-26 00:25:41 +01:00
|
|
|
}
|
|
|
|
|
2022-09-07 18:47:56 +02:00
|
|
|
static async onRenderCompendium(compendium, html, compendiumData) {
|
|
|
|
console.log('onRenderCompendium', compendium, html, compendiumData);
|
2021-05-24 00:43:46 +02:00
|
|
|
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) => {
|
2023-01-18 01:37:22 +01:00
|
|
|
RdDCompendiumOrganiser.setEntityTypeName(pack, element);
|
2021-01-26 00:25:41 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-24 00:43:46 +02:00
|
|
|
static async setEntityTypeName(pack, element) {
|
2023-01-18 01:37:22 +01:00
|
|
|
const label = RdDCompendiumOrganiser.getEntityTypeLabel(await pack.getDocument(element.dataset.documentId));
|
|
|
|
RdDCompendiumOrganiser.insertEntityType(element, label);
|
2021-05-24 00:43:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-10-07 19:06:43 +02:00
|
|
|
|
|
|
|
static getEntityTypeLabel(entity) {
|
|
|
|
const documentName = entity?.documentName
|
2022-11-05 18:06:30 +01:00
|
|
|
const type = entity?.type
|
2022-10-07 19:06:43 +02:00
|
|
|
if (documentName === 'Actor' || documentName === 'Item') {
|
|
|
|
const label = CONFIG[documentName]?.typeLabels?.[type] ?? type;
|
2022-11-05 18:06:30 +01:00
|
|
|
if (game.i18n.has(label)) {
|
|
|
|
return game.i18n.localize(label);
|
|
|
|
}
|
2022-10-07 19:06:43 +02:00
|
|
|
}
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2021-01-26 00:25:41 +01:00
|
|
|
}
|