dylanpiera / Foundry-Pokemon-Tabletop-United-System

PTU System for FoundryVTT
31 stars 31 forks source link

Compendium Enrichment #595

Closed Muhsigbokz closed 8 months ago

Muhsigbokz commented 9 months ago

The Compendium Browser can be called via In-Line Tags with Setting written in the Tag

Examples

@AbilitiesBrowser[search:e|order:dir:desc]{Abilties with E, descending by name}

@EdgesBrowser[search:of|search:art]{Edges, searching for art of}

@EdgesBrowser[search:art of]{Edges, searching for art of, alternative}

@FeatsBrowser[class:arcanist|class:berserker|order:by:name]{Arcanist or Berserker features, sortby name}

@MovesBrowser[type:nuclear|category:special|search:e]{Nuclear Special Moves with e}

@PokeEdgesBrowser[source:homebrew]{Homebrew PokeEdges}

@SpeciesBrowser[source:ptr-core-dex-megas|types:not:dragon|abilities:logic:or|abilities:memory-wipe|abilities:cruelty|abilities:blaze|sky:min:1|swim:max:5]{Species from PTR Core Dex Mega Mon that are 1) not dragon type and 2) can gain either of a) memory whipe or b) cruelty or b) blaze and 4) have a) at least 1 sky and b) max 5 swim}

@SpeciesBrowser[source:ptr-core-dex-megas|types:not:dragon|abilities:logic:or|abilities:memory-wipe|abilities:cruelty|abilities:blaze|sky:min:1|swim:max:5]

renders to image

Logic

Syntax

as per /@([A-Z][a-z]+)Browser\[([|:_0-9a-zA-Z\- ]*)\](:?{(:?[^\[\]\{\}@]*)?})?/gim

@<tabNameUpperCase>Browser[<settings>]{<explicitDisplayText>} | @<tabNameUpperCase>Browser[<settings>]

Misc Tech Details

The enrichment of all(?) visible content is done with a custom enricher in CONFIG.TextEditor.enrichers. Apparently there is no doc for those, or at least none easily findable (https://foundryvtt.com/api/classes/client.TextEditor.html), but thanks to some guidance https://discord.com/channels/170995199584108546/722559135371231352/1192834854614737068 it seems very simple and handy - if you know about it, like it is always the case.

A single Event Listener takes care of all tabs.

During development, tagify caused some trouble. Specifically, see #593. Thats why that has been touched together this feature.

I am not aware of a similar thing done in this code so far. CompendiumBrowserInlineEnricher.listen both adds the enrichers to CONFIG.TextEditor.enrichers as well as the Event Listeners to the respective hooks. There are likely other ways to structure this, but this way all logic stay in one place, both for Enrichment and Compendium opening. Seems fine to me.

Muhsigbokz commented 9 months ago

Some features that could later be added:

Muhsigbokz commented 8 months ago

updated for 1fed3a7581546e08250c2b60dddc7d610125c372

The Compendium Browser can be called via In-Line Tags with Setting written in the Tag

Examples

@CompSearch[Abqweilities  e]{I render, but you cant open me}

@CompSearch[Abqweilities] This also can't be opened

@CompSearch[Abilities idontexist=12 order-dir=desc e]{My setting idontexist does not exist}

@CompSearch[Abilities order-by=name order-dir=desc e]{Abilties with E, descending by name}

@CompSearch[Edges of art]{Edges, searching for art of}

@CompSearch[Feats class=arcanist class=berserk order-by=name]{Arcanist or Berserker features, sortby name}

@CompSearch[Moves type=nuclear category=special e]{Nuclear Special Moves with e}

@CompSearch[PokeEdges source=homebrew]{Homebrew PokeEdges}

@CompSearch[Species source=ptr-core-dex-megas types=not-dragon abilities-logic=or abilities=memory-wipe abilities=cruelty abilities=blaze sky-min=1 swim-max=5]{Species from PTR Core Dex Mega Mon that are 1) not dragon type and 2) can gain either of a) memory whipe or b) cruelty or c) blaze and 4) have a) at least 1 sky and b) max 5 swim}

@CompSearch[Species source=ptr-core-dex-megas types=not-dragon abilities-logic=or abilities=memory-wipe abilities=cruelty abilities=blaze sky-min=1 swim-max=5]

renders to image

Logic

Syntax

as per /@CompSearch\[([A-Za-z]+) ?([0-9a-zA-Z\-= ]*)\](:?{(:?[^\[\]\{\}@]*)?})?/gim

@CompSearch[<tabNameUpperCase> <settings> <searchWords>]{<explicitDisplayText>} | @<tabNameUpperCase>Browser[<settings>]

Special things:

Misc Tech Details

The enrichment of all(?) visible content is done with a custom enricher in CONFIG.TextEditor.enrichers. Apparently there is no doc for those, or at least none easily findable (https://foundryvtt.com/api/classes/client.TextEditor.html), but thanks to some guidance https://discord.com/channels/170995199584108546/722559135371231352/1192834854614737068 it seems very simple and handy - if you know about it, like it is always the case.

A single Event Listener takes care of all tabs.

During development, tagify caused some trouble. Specifically, see #593. Thats why that has been touched together this feature.

I am not aware of a similar thing done in this code so far. CompendiumBrowserInlineEnricher.listen both adds the enrichers to CONFIG.TextEditor.enrichers as well as the Event Listeners to the respective hooks. There are likely other ways to structure this, but this way all logic stay in one place, both for Enrichment and Compendium opening. Seems fine to me.