From 0c420cabd5cb3de3c00b3cbdbe1a9513a3357ae8 Mon Sep 17 00:00:00 2001 From: Vlyan Date: Sun, 23 Jan 2022 14:04:15 +0100 Subject: [PATCH] Techniques Compendiums : Trying a cheap Rank filter --- CHANGELOG.md | 1 + system/scripts/hooks.js | 29 ++++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5dcd66a..76c82ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - PC & NPC Sheet : Added +/- button to add or subtract Fatigue and Strife. - Armies Sheet : Added +/- button to add or subtract Casualties and Panic. - GmMonitor : Added ability to add or subtract fatigue/strife/void/casualties/panic points on mouse clic (left/right). +- Techniques Compendiums : Trying a cheap Rank filter. ## 1.5.0 - FoundryVTT v9 Compatibility - Updated the System to FoundryVTT v9. diff --git a/system/scripts/hooks.js b/system/scripts/hooks.js index 29e1821..5b9c267 100644 --- a/system/scripts/hooks.js +++ b/system/scripts/hooks.js @@ -9,7 +9,7 @@ export default class HooksL5r5e { typeof Babele !== "undefined" && Babele.get().modules.every((module) => module.module !== "l5r5e-custom-compendiums") ) { - Babele.get().setSystemTranslationsDir("babele"); // Since Babele v2.0.4 + Babele.get().setSystemTranslationsDir("babele"); // Since Babele v2.0.7 } } @@ -178,10 +178,33 @@ export default class HooksL5r5e { * Compendium display */ static async renderCompendium(app, html, data) { - // templates "item" : add Rarity - // Techniques / Peculiarities : add Ring / Rank if (app.collection.documentName === "Item") { const content = await app.collection.getDocuments(); + + // Add rank filter for techniques + if ( + content[0].type === "technique" && + !["l5r5e.core-techniques-school", "l5r5e.core-techniques-mastery"].includes(data.collection.collection) + ) { + const rankFilter = (event, rank) => { + html[0].querySelectorAll(".directory-item").forEach((line) => { + $(line).css("display", rank === 0 || $(line)[0].innerText?.endsWith(rank) ? "flex" : "none"); + }); + }; + const elmt = html.find(".directory-header"); + if (elmt.length > 0) { + const div = $('
'); + for (let rank = 0; rank < 6; rank++) { + const bt = $(`${rank === 0 ? "x" : rank}`); + bt.on("click", (event) => rankFilter(event, rank)); + div.append(bt); + } + elmt.append(div); + } + } + + // Items : add Rarity + // Techniques / Peculiarities : add Ring / Rank content.forEach((document) => { if (["weapon", "armor", "item", "peculiarity", "technique", "peculiarity"].includes(document.type)) { html.find(`[data-document-id="${document.id}"]`).append(