Refactoring renderCompendium
Added "hide disabled source" option
This commit is contained in:
@@ -35,8 +35,12 @@
|
|||||||
"Hint": "Set the default height for 'Items' windows types (techniques, weapons...), in pixels"
|
"Hint": "Set the default height for 'Items' windows types (techniques, weapons...), in pixels"
|
||||||
},
|
},
|
||||||
"Compendium": {
|
"Compendium": {
|
||||||
|
"HideDisabledSources": {
|
||||||
|
"Title": "[Compendium] Hide sources filter without reference",
|
||||||
|
"Hint": "Hide empty source with no elements in source filter."
|
||||||
|
},
|
||||||
"HideEmptySourcesFromPlayers": {
|
"HideEmptySourcesFromPlayers": {
|
||||||
"Title": "[Compendium] Hide sources without a reference",
|
"Title": "[Compendium] Hide elements with empty reference",
|
||||||
"Hint": "Basically require a reference to be set in order for players to view the content in compendiums"
|
"Hint": "Basically require a reference to be set in order for players to view the content in compendiums"
|
||||||
},
|
},
|
||||||
"AllowedOfficialSources": {
|
"AllowedOfficialSources": {
|
||||||
@@ -91,6 +95,7 @@
|
|||||||
"placeholder": "Filter Sources",
|
"placeholder": "Filter Sources",
|
||||||
"player_filter_label": "Player filter",
|
"player_filter_label": "Player filter",
|
||||||
"player_filter_tooltip": "Apply player filter",
|
"player_filter_tooltip": "Apply player filter",
|
||||||
|
"already_in_filter": "Already in filter",
|
||||||
"sources_categories": {
|
"sources_categories": {
|
||||||
"rules": "Rules",
|
"rules": "Rules",
|
||||||
"adventures": "Adventures",
|
"adventures": "Adventures",
|
||||||
|
|||||||
@@ -35,9 +35,13 @@
|
|||||||
"Hint": "Set the default height for 'Items' windows types (techniques, weapons...), in pixels"
|
"Hint": "Set the default height for 'Items' windows types (techniques, weapons...), in pixels"
|
||||||
},
|
},
|
||||||
"Compendium": {
|
"Compendium": {
|
||||||
|
"HideDisabledSources": {
|
||||||
|
"Title": "[Compendium] Hide sources filter without reference",
|
||||||
|
"Hint": "Hide empty source with no elements in source filter."
|
||||||
|
},
|
||||||
"HideEmptySourcesFromPlayers": {
|
"HideEmptySourcesFromPlayers": {
|
||||||
"Title": "[Compendium] Hide sources without a reference",
|
"Title": "[Compendium] Hide elements with empty reference",
|
||||||
"Hint": "Useful for hiding items etc. that are partially done"
|
"Hint": "Basically require a reference to be set in order for players to view the content in compendiums"
|
||||||
},
|
},
|
||||||
"AllowedOfficialSources": {
|
"AllowedOfficialSources": {
|
||||||
"Title": "[Compendium] Available official resources",
|
"Title": "[Compendium] Available official resources",
|
||||||
@@ -91,6 +95,7 @@
|
|||||||
"placeholder": "Filter Sources",
|
"placeholder": "Filter Sources",
|
||||||
"player_filter_label": "Player filter",
|
"player_filter_label": "Player filter",
|
||||||
"player_filter_tooltip": "Apply player filter",
|
"player_filter_tooltip": "Apply player filter",
|
||||||
|
"already_in_filter": "Already in filter",
|
||||||
"sources_categories": {
|
"sources_categories": {
|
||||||
"rules": "Rules",
|
"rules": "Rules",
|
||||||
"adventures": "Adventures",
|
"adventures": "Adventures",
|
||||||
|
|||||||
@@ -35,8 +35,12 @@
|
|||||||
"Hint": "Définir la hauteur par défaut des fenêtres de type Item (techniques, armes...) en pixels"
|
"Hint": "Définir la hauteur par défaut des fenêtres de type Item (techniques, armes...) en pixels"
|
||||||
},
|
},
|
||||||
"Compendium": {
|
"Compendium": {
|
||||||
|
"HideDisabledSources": {
|
||||||
|
"Title": "[Compendium] Cacher les sources vides",
|
||||||
|
"Hint": "Cache les sources sans éléments du filtre source."
|
||||||
|
},
|
||||||
"HideEmptySourcesFromPlayers": {
|
"HideEmptySourcesFromPlayers": {
|
||||||
"Title": "[Compendium] Cacher les sources sans référence",
|
"Title": "[Compendium] Cacher les éléments ayant une référence vide",
|
||||||
"Hint": "Utile pour cacher les éléments qui sont partiellement terminés."
|
"Hint": "Utile pour cacher les éléments qui sont partiellement terminés."
|
||||||
},
|
},
|
||||||
"AllowedOfficialSources": {
|
"AllowedOfficialSources": {
|
||||||
@@ -91,6 +95,7 @@
|
|||||||
"placeholder": "Sources à filtrer",
|
"placeholder": "Sources à filtrer",
|
||||||
"player_filter_label": "Filtre joueur",
|
"player_filter_label": "Filtre joueur",
|
||||||
"player_filter_tooltip": "Applique le filtre des joueurs",
|
"player_filter_tooltip": "Applique le filtre des joueurs",
|
||||||
|
"already_in_filter": "Filtre déjà appliqué",
|
||||||
"sources_categories": {
|
"sources_categories": {
|
||||||
"rules": "Règles",
|
"rules": "Règles",
|
||||||
"adventures": "Aventures",
|
"adventures": "Aventures",
|
||||||
|
|||||||
@@ -35,9 +35,13 @@
|
|||||||
"Hint": "Set the default height for 'Items' windows types (techniques, weapons...), in pixels"
|
"Hint": "Set the default height for 'Items' windows types (techniques, weapons...), in pixels"
|
||||||
},
|
},
|
||||||
"Compendium": {
|
"Compendium": {
|
||||||
|
"HideDisabledSources": {
|
||||||
|
"Title": "[Compendium] Hide sources filter without reference",
|
||||||
|
"Hint": "Hide empty source with no elements in source filter."
|
||||||
|
},
|
||||||
"HideEmptySourcesFromPlayers": {
|
"HideEmptySourcesFromPlayers": {
|
||||||
"Title": "[Compendium] Hide sources without a reference",
|
"Title": "[Compendium] Hide elements with empty reference",
|
||||||
"Hint": "Useful for hiding items etc. that are partially done"
|
"Hint": "Basically require a reference to be set in order for players to view the content in compendiums"
|
||||||
},
|
},
|
||||||
"AllowedOfficialSources": {
|
"AllowedOfficialSources": {
|
||||||
"Title": "[Compendium] Available official resources",
|
"Title": "[Compendium] Available official resources",
|
||||||
@@ -91,6 +95,7 @@
|
|||||||
"placeholder": "Filter Sources",
|
"placeholder": "Filter Sources",
|
||||||
"player_filter_label": "Player filter",
|
"player_filter_label": "Player filter",
|
||||||
"player_filter_tooltip": "Apply player filter",
|
"player_filter_tooltip": "Apply player filter",
|
||||||
|
"already_in_filter": "Already in filter",
|
||||||
"sources_categories": {
|
"sources_categories": {
|
||||||
"rules": "Rules",
|
"rules": "Rules",
|
||||||
"adventures": "Adventures",
|
"adventures": "Adventures",
|
||||||
|
|||||||
@@ -226,230 +226,183 @@ export default class HooksL5r5e {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compendium display
|
* Compendium display (Add filters)
|
||||||
*/
|
*/
|
||||||
static async renderCompendium(app, html, data) {
|
static async renderCompendium(app, html, data) {
|
||||||
if (app.collection.documentName === "Item") {
|
if (app.collection.documentName === "Item") {
|
||||||
const content = await app.collection.getDocuments();
|
const content = await app.collection.getDocuments();
|
||||||
let sources_in_this_compendium = new Set([]);
|
const sourcesInThisCompendium = new Set([]);
|
||||||
let filters_to_show = {
|
const filtersToShow = {
|
||||||
rank: false,
|
rank: false,
|
||||||
rarity: false,
|
rarity: false,
|
||||||
source: false,
|
source: false,
|
||||||
ring: false,
|
ring: false,
|
||||||
}
|
};
|
||||||
|
|
||||||
|
// Cache
|
||||||
|
const header = html.find(".directory-header");
|
||||||
|
const entries = html.find(".directory-item");
|
||||||
|
|
||||||
// Add additional data to the entries to make it faster to lookup.
|
// Add additional data to the entries to make it faster to lookup.
|
||||||
// Add Ring/rank/rarity information
|
// Add Ring/rank/rarity information
|
||||||
for (const document of content) {
|
for (const document of content) {
|
||||||
const entry = html.find(`[data-document-id="${document.id}"]`);
|
const entry = entries.filter(`[data-document-id="${document.id}"]`);
|
||||||
if(document.system?.rank) {
|
|
||||||
|
if (document.system?.rank) {
|
||||||
|
filtersToShow.rank = true;
|
||||||
entry.data("rank", document.system.rank);
|
entry.data("rank", document.system.rank);
|
||||||
filters_to_show.rank = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(document.system?.source_reference) {
|
if (document.system?.source_reference) {
|
||||||
sources_in_this_compendium.add(document.system.source_reference.source);
|
filtersToShow.source = true;
|
||||||
|
sourcesInThisCompendium.add(document.system.source_reference.source);
|
||||||
entry.data("source", document.system.source_reference);
|
entry.data("source", document.system.source_reference);
|
||||||
filters_to_show.source = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(document.system?.ring) {
|
if (document.system?.ring) {
|
||||||
|
filtersToShow.ring = true;
|
||||||
entry.data("ring", document.system.ring);
|
entry.data("ring", document.system.ring);
|
||||||
filters_to_show.ring = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(document.system?.rarity) {
|
if (document.system?.rarity) {
|
||||||
|
filtersToShow.rarity = true;
|
||||||
entry.data("rarity", document.system.rarity);
|
entry.data("rarity", document.system.rarity);
|
||||||
filters_to_show.rarity = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add ring/rank/rarity information on the item in the compendium view
|
// Add ring/rank/rarity information on the item in the compendium view
|
||||||
if(document.system?.ring || document.system?.rarity || document.system?.ring) {
|
if (document.system?.ring || document.system?.rarity || document.system?.rank) {
|
||||||
const ring_rarity_rank = await renderTemplate(`${CONFIG.l5r5e.paths.templates}compendium/ring-rarity-rank.html`, document.system);
|
const ringRarityRank = await renderTemplate(`${CONFIG.l5r5e.paths.templates}compendium/ring-rarity-rank.html`, document.system);
|
||||||
entry.append(ring_rarity_rank);
|
entry.append(ringRarityRank);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Setup what the player cannot see.
|
// Setup filters
|
||||||
const officialContent = game.settings.get(CONFIG.l5r5e.namespace, "compendium-official-content-for-players");
|
const officialContent = game.settings.get(CONFIG.l5r5e.namespace, "compendium-official-content-for-players");
|
||||||
const unofficialContent = game.settings.get(CONFIG.l5r5e.namespace, "compendium-unofficial-content-for-players");
|
const unofficialContent = game.settings.get(CONFIG.l5r5e.namespace, "compendium-unofficial-content-for-players");
|
||||||
const unavailableSourceForPlayers = game.settings.get(CONFIG.l5r5e.namespace, "all-compendium-references")
|
const allCompendiumReferences = game.settings.get(CONFIG.l5r5e.namespace, "all-compendium-references")
|
||||||
.filter((element) => {
|
const hideEmptySourcesFromPlayers = game.settings.get(CONFIG.l5r5e.namespace, "compendium-hide-empty-sources-from-players");
|
||||||
if(CONFIG.l5r5e.sourceReference[element]) {
|
|
||||||
|
const unavailableSourceForPlayers = allCompendiumReferences.filter((element) => {
|
||||||
|
if (CONFIG.l5r5e.sourceReference[element]) {
|
||||||
return officialContent.length > 0 ? !officialContent.includes(element) : false;
|
return officialContent.length > 0 ? !officialContent.includes(element) : false;
|
||||||
}
|
}
|
||||||
return unofficialContent.length > 0 ? !unofficialContent.includes(element) : false;
|
return unofficialContent.length > 0 ? !unofficialContent.includes(element) : false;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create the function that will hide/show elements based on various factors
|
// Create filter function
|
||||||
const header = html.find(".directory-header");
|
const applyCompendiumFilter = () => {
|
||||||
const applyCompendiumFilter = function() {
|
const userFilter = header.find("l5r5e-multi-select").val();
|
||||||
const rank_filter = header.find(".rank-filter").find(".selected").data("rank");
|
const rankFilter = header.find(".rank-filter .selected").data("rank");
|
||||||
const user_filter = header.find("l5r5e-multi-select").val();
|
const ringFilter = header.find(".ring-filter .selected").data("ring");
|
||||||
const ring_filter = header.find(".ring-filter").find(".selected").data("ring");
|
const rarityFilter = header.find(".rarity-filter .selected").data("rarity");
|
||||||
const rarity_filter = header.find(".rarity-filter").find(".selected").data("rarity");
|
|
||||||
|
|
||||||
$(html).find(".directory-item").each(function() {
|
entries.each(function () {
|
||||||
const lineSource = $(this).data("source")?.source;
|
const lineSource = $(this).data("source")?.source;
|
||||||
if(lineSource === null || lineSource === undefined) {
|
|
||||||
return; // We might have stuff in the compendium view that does not have a source (folders etc.) Ignore those.
|
// We might have stuff in the compendium view that does not have a source (folders etc.) Ignore those.
|
||||||
|
if (lineSource === null || lineSource === undefined) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let should_show = true;
|
let shouldShow = true;
|
||||||
if(unavailableSourceForPlayers.includes(lineSource)) {
|
|
||||||
if(game.user.isGM) {
|
|
||||||
should_show &= true;
|
|
||||||
$(this).addClass("not-for-players");
|
|
||||||
$(this).attr("data-tooltip", game.i18n.localize("l5r5e.compendium.not_for_players"));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
should_show &= false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(lineSource === "" && game.settings.get(CONFIG.l5r5e.namespace, "compendium-hide-empty-sources-from-players")) {
|
// Handle unavailable sources
|
||||||
if(game.user.isGM) {
|
if (unavailableSourceForPlayers.includes(lineSource)) {
|
||||||
should_show &= true;
|
if (game.user.isGM) {
|
||||||
$(this).addClass("not-for-players");
|
shouldShow &= true;
|
||||||
$(this).attr("data-tooltip", game.i18n.localize("l5r5e.compendium.not_for_players"))
|
$(this)
|
||||||
}
|
.addClass("not-for-players")
|
||||||
else {
|
.attr("data-tooltip", game.i18n.localize("l5r5e.compendium.not_for_players"));
|
||||||
should_show &= false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(rank_filter) {
|
|
||||||
should_show &= $(this).data("rank") == rank_filter;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(user_filter.length) {
|
|
||||||
should_show &= user_filter.includes(lineSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ring_filter) {
|
|
||||||
should_show &= $(this).data("ring") == ring_filter
|
|
||||||
}
|
|
||||||
|
|
||||||
if(rarity_filter >= 0) {
|
|
||||||
should_show &= $(this).data("rarity") == rarity_filter
|
|
||||||
}
|
|
||||||
|
|
||||||
if(should_show) {
|
|
||||||
$(this).show();
|
|
||||||
} else {
|
} else {
|
||||||
$(this).hide();
|
shouldShow &= false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle empty sources
|
||||||
|
if (lineSource === "" && hideEmptySourcesFromPlayers) {
|
||||||
|
if (game.user.isGM) {
|
||||||
|
shouldShow &= true;
|
||||||
|
$(this)
|
||||||
|
.addClass("not-for-players")
|
||||||
|
.attr("data-tooltip", game.i18n.localize("l5r5e.compendium.not_for_players"));
|
||||||
|
} else {
|
||||||
|
shouldShow &= false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply filters
|
||||||
|
if (rankFilter) {
|
||||||
|
shouldShow &= $(this).data("rank") == rankFilter;
|
||||||
|
}
|
||||||
|
if (userFilter.length) {
|
||||||
|
shouldShow &= userFilter.includes(lineSource);
|
||||||
|
}
|
||||||
|
if (ringFilter) {
|
||||||
|
shouldShow &= $(this).data("ring") == ringFilter;
|
||||||
|
}
|
||||||
|
if (rarityFilter >= 0) {
|
||||||
|
shouldShow &= $(this).data("rarity") == rarityFilter;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show or hide this entry based on the result
|
||||||
|
shouldShow ? $(this).show() : $(this).hide();
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
// Rank filter: Add the HTML element and on click handling
|
// Filter setup
|
||||||
if (filters_to_show.rank) {
|
const addFilter = async (filterType, templateFile, templateData) => {
|
||||||
header.append(await renderTemplate(`${CONFIG.l5r5e.paths.templates}compendium/rank-filter.html`, {type: "rank", number:[1,2,3,4,5]}));
|
if (!filtersToShow[filterType]) {
|
||||||
header.find(".rank-filter").children().each(function() {
|
return;
|
||||||
$(this).on("click", (event, rank=$(this).data("rank")) => {
|
|
||||||
const already_selected = $(event.target).hasClass("selected");
|
|
||||||
$(html).find(".rank-filter").children().each(function() {
|
|
||||||
$(this).removeClass("selected");
|
|
||||||
});
|
|
||||||
|
|
||||||
// Only select valid values
|
|
||||||
if(rank) {
|
|
||||||
$(event.target).addClass("selected");
|
|
||||||
}
|
|
||||||
// we click the same button to unselect
|
|
||||||
if(already_selected) {
|
|
||||||
$(event.target).removeClass("selected");
|
|
||||||
}
|
}
|
||||||
|
const filterTemplate = await renderTemplate(
|
||||||
|
`${CONFIG.l5r5e.paths.templates}compendium/${templateFile}.html`,
|
||||||
|
templateData
|
||||||
|
);
|
||||||
|
header.append(filterTemplate);
|
||||||
|
|
||||||
|
header.find(`.${filterType}-filter`).children().each(function () {
|
||||||
|
$(this).on("click", (event) => {
|
||||||
|
const selected = $(event.target).hasClass("selected");
|
||||||
|
header.find(`.${filterType}-filter`).children().removeClass("selected");
|
||||||
|
$(event.target).toggleClass("selected", !selected);
|
||||||
applyCompendiumFilter();
|
applyCompendiumFilter();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
if(filters_to_show.rarity) {
|
// Add Rank, Rarity, Ring Filters
|
||||||
header.append(await renderTemplate(`${CONFIG.l5r5e.paths.templates}compendium/rank-filter.html`, {type: "rarity", number:[0,1,2,3,4,5,6,7,8,9,10]}));
|
await Promise.all([
|
||||||
header.find(".rarity-filter").children().each(function() {
|
addFilter('rank' , 'rank-filter', { type: "rank", number: [1, 2, 3, 4, 5] }),
|
||||||
$(this).on("click", (event, rarity=$(this).data("rarity")) => {
|
addFilter('rarity', 'rank-filter', { type: "rarity", number: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }),
|
||||||
const already_selected = $(event.target).hasClass("selected");
|
addFilter('ring' , 'ring-filter', {}),
|
||||||
$(html).find(".rarity-filter").children().each(function() {
|
]);
|
||||||
$(this).removeClass("selected");
|
|
||||||
});
|
|
||||||
|
|
||||||
// Only select valid values
|
if (filtersToShow.source) {
|
||||||
if(Number.isInteger(rarity)) {
|
// Build the source select
|
||||||
$(event.target).addClass("selected");
|
const selectableSources = allCompendiumReferences.map((reference) => ({
|
||||||
}
|
value: reference,
|
||||||
// we click the same button to unselect
|
label: CONFIG.l5r5e.sourceReference[reference]?.label ?? reference,
|
||||||
if(already_selected) {
|
|
||||||
$(event.target).removeClass("selected");
|
|
||||||
}
|
|
||||||
|
|
||||||
applyCompendiumFilter();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if(filters_to_show.ring) {
|
|
||||||
header.append(await renderTemplate(`${CONFIG.l5r5e.paths.templates}compendium/ring-filter.html`));
|
|
||||||
header.find(".ring-filter").children().each(function() {
|
|
||||||
$(this).on("click", (event, ring=$(this).data("ringid")) => {
|
|
||||||
const already_selected = $(event.target).hasClass("selected");
|
|
||||||
$(html).find(".ring-filter").children().each(function() {
|
|
||||||
$(this).removeClass("selected");
|
|
||||||
});
|
|
||||||
|
|
||||||
if(ring) { // Do not keep the "reset" button highlighted
|
|
||||||
$(event.target).addClass("selected");
|
|
||||||
}
|
|
||||||
// we click the same button to unselect
|
|
||||||
if(already_selected) {
|
|
||||||
$(event.target).removeClass("selected");
|
|
||||||
}
|
|
||||||
|
|
||||||
applyCompendiumFilter();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if(filters_to_show.source) {
|
|
||||||
// Setup the source select and add it to the document with change callback
|
|
||||||
const selectable_sources = game.settings.get(CONFIG.l5r5e.namespace, "all-compendium-references")
|
|
||||||
.map((reference) => {
|
|
||||||
return {
|
|
||||||
disable: !sources_in_this_compendium.has(reference),
|
|
||||||
source: reference
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.map((reference) => {
|
|
||||||
return {
|
|
||||||
value: reference.source,
|
|
||||||
label: CONFIG.l5r5e.sourceReference[reference.source]?.label ?? reference.source,
|
|
||||||
translate: true,
|
translate: true,
|
||||||
group: CONFIG.l5r5e.sourceReference[reference.source]?.type.split(",")[0] ?? "l5r5e.multiselect.sources_categories.others",
|
group: CONFIG.l5r5e.sourceReference[reference]?.type.split(",")[0] ?? "l5r5e.multiselect.sources_categories.others",
|
||||||
disabled: reference.disable
|
disabled: !sourcesInThisCompendium.has(reference) || (!game.user.isGM && unavailableSourceForPlayers.includes(reference))
|
||||||
}
|
}));
|
||||||
});
|
|
||||||
|
|
||||||
const filterSourcesBox = L5r5eHtmlMultiSelectElement.create({
|
const filterSourcesBox = L5r5eHtmlMultiSelectElement.create({
|
||||||
name: "filter-sources",
|
name: "filter-sources",
|
||||||
options: selectable_sources,
|
options: selectableSources,
|
||||||
localize: true,
|
localize: true,
|
||||||
});
|
});
|
||||||
header.append(filterSourcesBox.outerHTML);
|
header.append(filterSourcesBox.outerHTML);
|
||||||
$("l5r5e-multi-select").on("change", (event) => {
|
$("l5r5e-multi-select").on("change", applyCompendiumFilter);
|
||||||
applyCompendiumFilter();
|
|
||||||
});
|
|
||||||
|
|
||||||
// If gm add a extra button to easily filter the content to see the same stuff as a player
|
// If gm add an extra button to easily filter the content to see the same stuff as a player
|
||||||
if (game.user.isGM && unavailableSourceForPlayers.length > 0) {
|
if (game.user.isGM && unavailableSourceForPlayers.length > 0) {
|
||||||
const buttonHTML = `<button type="button" class="gm" data-tooltip="${game.i18n.localize('l5r5e.multiselect.player_filter_tooltip')}">`
|
const buttonHTML = `<button type="button" class="gm" data-tooltip="${game.i18n.localize('l5r5e.multiselect.player_filter_tooltip')}">`
|
||||||
+ game.i18n.localize('l5r5e.multiselect.player_filter_label')
|
+ game.i18n.localize('l5r5e.multiselect.player_filter_label')
|
||||||
+ '</button>'
|
+ '</button>'
|
||||||
|
|
||||||
const filterPlayerView = game.settings.get(CONFIG.l5r5e.namespace, "all-compendium-references")
|
const filterPlayerView = allCompendiumReferences
|
||||||
.filter((item) => !unavailableSourceForPlayers.includes(item))
|
.filter((item) => !unavailableSourceForPlayers.includes(item))
|
||||||
.filter((item) => sources_in_this_compendium.has(item));
|
.filter((item) => sourcesInThisCompendium.has(item));
|
||||||
|
|
||||||
$(buttonHTML).appendTo($(header).find("l5r5e-multi-select")).click(function() {
|
$(buttonHTML).appendTo($(header).find("l5r5e-multi-select")).click(function() {
|
||||||
header.find("l5r5e-multi-select")[0].value = filterPlayerView;
|
header.find("l5r5e-multi-select")[0].value = filterPlayerView;
|
||||||
@@ -457,18 +410,31 @@ export default class HooksL5r5e {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO find a better way
|
// TODO: This delay is a workaround and should be addressed in another way.
|
||||||
// This is ugly but if we hide the content too early then it won't be hidden for some reason.
|
// This is ugly but if we hide the content too early then it won't be hidden for some reason.
|
||||||
// Current guess is that the foundry search filter is doing something.
|
// Current guess is that the foundry search filter is doing something.
|
||||||
// Adding a delay here so that we hide the content. This will fail on slow computers/network...
|
// Adding a delay here so that we hide the content. This will fail on slow computers/network...
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
applyCompendiumFilter();
|
applyCompendiumFilter();
|
||||||
}, 250)
|
}, 250);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static updateCompendium(pack, documents, options, userId) {
|
||||||
|
documents.forEach((document) => {
|
||||||
|
const inc_reference = document?.system?.source_reference?.source?.trim();
|
||||||
|
if (!!inc_reference) {
|
||||||
|
const references = game.settings.get(CONFIG.l5r5e.namespace, "all-compendium-references");
|
||||||
|
if (!references.includes(inc_reference)) {
|
||||||
|
references.push(inc_reference);
|
||||||
|
game.settings.set(CONFIG.l5r5e.namespace, "all-compendium-references", references);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DiceSoNice - Add L5R DicePresets
|
* DiceSoNice - Add L5R DicePresets
|
||||||
*/
|
*/
|
||||||
@@ -530,19 +496,6 @@ export default class HooksL5r5e {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static updateCompendium(pack, documents, options, userId) {
|
|
||||||
documents.forEach((document) => {
|
|
||||||
const inc_reference = document?.system?.source_reference?.source;
|
|
||||||
if(inc_reference) {
|
|
||||||
const references = game.settings.get(CONFIG.l5r5e.namespace, "all-compendium-references");
|
|
||||||
if(!references.includes(inc_reference)) {
|
|
||||||
references.push(inc_reference);
|
|
||||||
game.settings.set(CONFIG.l5r5e.namespace, "all-compendium-references", references);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempt to create a macro from the dropped data. Will use an existing macro if one exists.
|
* Attempt to create a macro from the dropped data. Will use an existing macro if one exists.
|
||||||
* @param {object} dropData The dropped data
|
* @param {object} dropData The dropped data
|
||||||
|
|||||||
@@ -334,9 +334,8 @@ export class MigrationL5r5e {
|
|||||||
updateData["system.source_reference.page"] = bookReference[2];
|
updateData["system.source_reference.page"] = bookReference[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO uncomment before release
|
|
||||||
// Delete the old key
|
// Delete the old key
|
||||||
//updateData["system.-=book_reference"] = null;
|
updateData["system.-=book_reference"] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ***** End of 1.12.3 *****
|
// ***** End of 1.12.3 *****
|
||||||
|
|||||||
@@ -117,6 +117,7 @@ export class L5r5eHtmlMultiSelectElement extends AbstractMultiSelectElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Disable selected options
|
// Disable selected options
|
||||||
|
const hideDisabled = game.settings.get(CONFIG.l5r5e.namespace, "compendium-hide-disabled-sources");
|
||||||
for (const option of this.#select) {
|
for (const option of this.#select) {
|
||||||
if (this._value.has(option.value)) {
|
if (this._value.has(option.value)) {
|
||||||
option.disabled = true;
|
option.disabled = true;
|
||||||
@@ -125,6 +126,7 @@ export class L5r5eHtmlMultiSelectElement extends AbstractMultiSelectElement {
|
|||||||
}
|
}
|
||||||
if (this.#disabledValues.has(option.value)) {
|
if (this.#disabledValues.has(option.value)) {
|
||||||
option.disabled = true;
|
option.disabled = true;
|
||||||
|
option.hidden = hideDisabled;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
option.disabled = false;
|
option.disabled = false;
|
||||||
|
|||||||
@@ -98,6 +98,15 @@ export const RegisterSettings = function () {
|
|||||||
scope: "world",
|
scope: "world",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
game.settings.register(CONFIG.l5r5e.namespace, "compendium-hide-disabled-sources", {
|
||||||
|
name: "SETTINGS.Compendium.HideDisabledSources.Title",
|
||||||
|
hint: "SETTINGS.Compendium.HideDisabledSources.Hint",
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
config: true,
|
||||||
|
scope: "world",
|
||||||
|
});
|
||||||
|
|
||||||
/* ------------------------------------ */
|
/* ------------------------------------ */
|
||||||
/* Client preferences */
|
/* Client preferences */
|
||||||
/* ------------------------------------ */
|
/* ------------------------------------ */
|
||||||
|
|||||||
Reference in New Issue
Block a user