Skip to content

Comments

Refactor Compendium Browser to use a Predicate for filtering entries#20492

Merged
CarlosFdez merged 3 commits intofoundryvtt:v13-devfrom
In3luki:comp-browser-predication-v2
Feb 12, 2026
Merged

Refactor Compendium Browser to use a Predicate for filtering entries#20492
CarlosFdez merged 3 commits intofoundryvtt:v13-devfrom
In3luki:comp-browser-predication-v2

Conversation

@In3luki
Copy link
Collaborator

@In3luki In3luki commented Oct 17, 2025

I finally had some more time to work on this. Pulled out from #20282

This PR only includes the switch to predication and no other additions or UI changes. If this is approved I can start to pull out the other changes from the old PR.

Current filter:
Current

Predicate filter:
CachedPredicate

@In3luki In3luki force-pushed the comp-browser-predication-v2 branch from fa2ad28 to 6c06c19 Compare October 17, 2025 20:38
@In3luki In3luki force-pushed the comp-browser-predication-v2 branch from 992c27b to d462bab Compare October 21, 2025 07:53
@CarlosFdez CarlosFdez self-requested a review October 28, 2025 23:22
@In3luki In3luki force-pushed the comp-browser-predication-v2 branch from d462bab to 26af6e3 Compare November 17, 2025 07:13
@In3luki In3luki force-pushed the comp-browser-predication-v2 branch from 429125f to 7c5c7f6 Compare January 30, 2026 23:06
@CarlosFdez
Copy link
Collaborator

Fix it one more time and poke me on discord.

Is this the smallest you can get it? Are there no refactors here you can section off?

@In3luki
Copy link
Collaborator Author

In3luki commented Feb 7, 2026

I may be able to do this without refactoring the options from objects to arrays. That should make the diff a bit smaller. I'll take another look over the weekend.

@In3luki In3luki force-pushed the comp-browser-predication-v2 branch 2 times, most recently from 811f50c to c3ed93e Compare February 8, 2026 11:53
}

options.add(`level:${system.level.value}`);
options.add(`rarity:${system.traits.rarity}`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most everything here is fine so far but this gives me pause. What is the purpose of using predicates if you end up having to add the roll options anyways?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a predicate should make it easier to implement new filters without the need for custom logic. It already covers pretty much anything that a filter could need and especially exclusion is much easier.
And for adding roll options, I'm pretty sure a predicate without options wouldn't do anything? I might be misunderstanding what you mean.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you're creating options, rather than using the item's existing options. So there's potential for desync or forgetting that an option has to be added for the predication to even work.

@CarlosFdez
Copy link
Collaborator

Maybe make the options an array? You might be able to cut down on a lot of lines of setup code if you use options.push(...traditions.map(stuff)).

@In3luki In3luki force-pushed the comp-browser-predication-v2 branch from c3ed93e to 8fb9796 Compare February 12, 2026 12:21
@In3luki
Copy link
Collaborator Author

In3luki commented Feb 12, 2026

Updated with the suggestion. Options are now converted to a Set as the last step. They could technically stay arrays in the filter data but the Predicate would convert them anyways on each filter operation.

The basic shape of the roll (or filter) options can't really be changed as the Predicate expects a colon as a separator for some things. The only thing I could think of would be to add a filter: prefix to all options to make it clear they are not normal roll options.

}

options.push(`type:${actionData.type}`);
options.push(`category:${system.category}`);
Copy link
Collaborator

@CarlosFdez CarlosFdez Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you keep the simple one liner additions together? In other words move this up to the other options.push? It saves only a bit of whitespace if you do it throughout, but right now the main wart of the new style is the manual addition of options, so if the code can be kept tight, I think it'll be fine.

You could do this as well I suppose to save on whitespace

const options: string[] = [
    `action-type:${system.actionType.value}`,
    ...system.traits.value.map((t: string) => `trait:${t.replace(/^hb_/, "")}`),
    `type:${actionData.type}`,
    `category:${system.category}`
];

Try to keep option initialization LOC tight for each object type if possible.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be better now.

@CarlosFdez
Copy link
Collaborator

The basic shape of the roll (or filter) options can't really be changed as the Predicate expects a colon as a separator for some things. The only thing I could think of would be to add a filter: prefix to all options to make it clear they are not normal roll options.

Don't worry about it. While it being confused for genuine roll options is a problem, I don't think making them different is going to help anyways, nor is it enough reason on its own to deviate for the sake of deviating.

@In3luki In3luki force-pushed the comp-browser-predication-v2 branch from 152d133 to 65df195 Compare February 12, 2026 21:28
Copy link
Collaborator

@CarlosFdez CarlosFdez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks fine to me, but I plan to check for bugs personally.

@CarlosFdez CarlosFdez merged commit 3f82cc2 into foundryvtt:v13-dev Feb 12, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants