Initial version

This commit is contained in:
WBHarry 2026-02-07 18:00:03 +01:00
parent c1f7866594
commit b053af21c6
13 changed files with 325 additions and 5 deletions

View file

@ -0,0 +1,135 @@
const { ApplicationV2, HandlebarsApplicationMixin } = foundry.applications.api;
export default class CompendiumBrowserSettings extends HandlebarsApplicationMixin(ApplicationV2) {
constructor() {
super();
this.browserSettings = game.settings
.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.CompendiumBrowserSettings)
.toObject();
}
static DEFAULT_OPTIONS = {
tag: 'form',
classes: ['daggerheart', 'dialog', 'dh-style', 'views', 'compendium-brower-settings'],
window: {
icon: 'fa-solid fa-book',
title: 'DAGGERHEART.APPLICATIONS.CompendiumBrowserSettings.title'
},
position: {
width: 500,
height: 'auto'
},
actions: {
finish: CompendiumBrowserSettings.#finish
},
form: {
handler: this.updateData,
submitOnChange: true,
submitOnClose: false
}
};
/** @override */
static PARTS = {
main: {
id: 'main',
template: 'systems/daggerheart/templates/dialogs/compendiumBrowserSettingsDialog.hbs'
}
};
static #browserPackTypes = ['Actor', 'Item'];
_attachPartListeners(partId, htmlElement, options) {
super._attachPartListeners(partId, htmlElement, options);
for (const element of htmlElement.querySelectorAll('.source-input')) {
element.addEventListener('change', this.toggleSource.bind(this));
}
}
getPackageName = pack => (pack.metadata.packageType === 'world' ? 'world' : pack.metadata.packageName);
async _prepareContext(_options) {
const context = await super._prepareContext(_options);
const { excludedCompendiumPacks } = this.browserSettings;
context.packOptions = game.packs.reduce((acc, pack) => {
const { type, name, label, packageType, id } = pack.metadata;
if (!CompendiumBrowserSettings.#browserPackTypes.includes(type)) return acc;
const packageName = this.getPackageName(pack);
if (!acc[packageName])
acc[packageName] = {
label:
packageType === 'world'
? game.i18n.localize('PACKAGE.Type.world')
: (game.modules.get(packageName)?.title ?? game.system.title),
types: {}
};
if (!acc[packageName].types[type])
acc[packageName].types[type] = {
label: game.i18n.localize(`DOCUMENT.${type}`),
checked: true,
packs: {}
};
if (id === 'daggerheart.ancestries') {
console.log('test');
}
acc[packageName].types[type].packs[id] = {
label: label,
checked: !excludedCompendiumPacks[packageName]?.[id]
};
acc[packageName].types[type].checked &&= acc[packageName].types[type].packs[id].checked;
return acc;
}, {});
return context;
}
static async updateData(_event, _, formData) {
const { excludedCompendiumPacks } = foundry.utils.expandObject(formData.object);
this.browserSettings.excludedCompendiumPacks = Object.keys(excludedCompendiumPacks).reduce(
(acc, packageKey) => {
const flattenedPack = foundry.utils.flattenObject(excludedCompendiumPacks[packageKey]);
acc[packageKey] = Object.keys(flattenedPack).reduce((acc, key) => {
acc[key] = !flattenedPack[key];
return acc;
}, {});
return acc;
},
{}
);
this.render();
}
toggleSource(event) {
event.stopPropagation();
const { excludedCompendiumPacks } = this.browserSettings;
const { source, type } = event.target.dataset;
const allIncluded = !event.target.checked;
const packs = game.packs.filter(pack => this.getPackageName(pack) === source && pack.metadata.type === type);
for (const pack of packs) {
if (!excludedCompendiumPacks[source]) excludedCompendiumPacks[source] = {};
excludedCompendiumPacks[source][pack.metadata.id] = allIncluded;
}
this.render();
}
static async #finish() {
const settings = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.CompendiumBrowserSettings);
await settings.updateSource(this.browserSettings);
await game.settings.set(
CONFIG.DH.id,
CONFIG.DH.SETTINGS.gameSettings.CompendiumBrowserSettings,
settings.toObject()
);
this.close();
}
}

View file

@ -16,3 +16,4 @@ export { default as ActionSelectionDialog } from './actionSelectionDialog.mjs';
export { default as GroupRollDialog } from './group-roll-dialog.mjs';
export { default as TagTeamDialog } from './tagTeamDialog.mjs';
export { default as RiskItAllDialog } from './riskItAllDialog.mjs';
export { default as CompendiumBrowserSettingsDialog } from './CompendiumBrowserSettings.mjs';

View file

@ -35,7 +35,8 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
selectFolder: this.selectFolder,
expandContent: this.expandContent,
resetFilters: this.resetFilters,
sortList: this.sortList
sortList: this.sortList,
openSettings: this.openSettings
},
position: {
left: 100,
@ -214,6 +215,10 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
loadItems() {
let loadTimeout = this.toggleLoader(true);
const excludedCompendiumPacks = game.settings.get(
CONFIG.DH.id,
CONFIG.DH.SETTINGS.gameSettings.CompendiumBrowserSettings
).excludedCompendiumPacks;
const promises = [];
game.packs.forEach(pack => {
@ -227,7 +232,13 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
Promise.all(promises).then(async result => {
this.items = ItemBrowser.sortBy(
result.flatMap(r => r),
result
.flatMap(r => r)
.filter(x => {
const pack = game.packs.get(x.pack);
const packageName = pack.metadata.packageType === 'world' ? 'world' : pack.metadata.packageName;
return !excludedCompendiumPacks[packageName]?.[x.pack];
}),
'name'
);
@ -512,6 +523,10 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
itemListContainer.replaceChildren(...newOrder);
}
static async openSettings() {
new game.system.api.applications.dialogs.CompendiumBrowserSettingsDialog().render({ force: true });
}
_createDragProcess() {
new foundry.applications.ux.DragDrop.implementation({
dragSelector: '.item-container',

View file

@ -30,6 +30,7 @@ export const gameSettings = {
LastMigrationVersion: 'LastMigrationVersion',
TagTeamRoll: 'TagTeamRoll',
SpotlightRequestQueue: 'SpotlightRequestQueue',
CompendiumBrowserSettings: 'CompendiumBrowserSettings'
};
export const actionAutomationChoices = {

View file

@ -3,6 +3,7 @@ export { default as DhCombatant } from './combatant.mjs';
export { default as DhTagTeamRoll } from './tagTeamRoll.mjs';
export { default as DhRollTable } from './rollTable.mjs';
export { default as RegisteredTriggers } from './registeredTriggers.mjs';
export { default as CompendiumBrowserSettings } from './compendiumBrowserSettings.mjs';
export * as countdowns from './countdowns.mjs';
export * as actions from './action/_module.mjs';

View file

@ -0,0 +1,16 @@
export default class CompendiumBrowserSettings extends foundry.abstract.DataModel {
static defineSchema() {
const fields = foundry.data.fields;
return {
excludedCompendiumPacks: new fields.TypedObjectField(
new fields.TypedObjectField(new fields.BooleanField({ required: true, initial: true }))
)
// excludedSources: new fields.ArrayField(new fields.StringField({ required: true, nullable: false })),
// excludedPacks: new fields.TypedObjectField(new fields.SchemaField({
// attributionKeys: new fields.ArrayField(new fields.StringField({ required: true, nullable: false })),
// excluded: new fields.BooleanField({ required: true, initial: false }),
// })),
};
}
}

View file

@ -7,7 +7,7 @@ import {
DhHomebrewSettings,
DhVariantRuleSettings
} from '../applications/settings/_module.mjs';
import { DhTagTeamRoll } from '../data/_module.mjs';
import { CompendiumBrowserSettings, DhTagTeamRoll } from '../data/_module.mjs';
export const registerDHSettings = () => {
registerMenuSettings();
@ -142,6 +142,12 @@ const registerNonConfigSettings = () => {
config: false,
type: DhTagTeamRoll
});
game.settings.register(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.CompendiumBrowserSettings, {
scope: 'client',
config: false,
type: CompendiumBrowserSettings
});
};
/**