geoidesic / foundryvtt-actor-studio

A FoundryVTT module for creating Actors
MIT License
3 stars 1 forks source link

Donation tracker integration #32

Closed geoidesic closed 1 month ago

geoidesic commented 1 month ago
  1. [x] Check for donation-tracker module. If enabled, add game setting with button to open new application
  2. [x] Add TJS application for this setting
  3. [x] The first setting in the new application should be a checkbox to enable / disable donation-tracker integration.
  4. [x] The application should read values from game.membership.RANKS and create a text field setting per RANK
  5. [x] Each text field should contain a folder name, which will define which folders in a compendium contain content for that RANK.
  6. [x] Anything not in a folder, or in an unnamed folder need not be filtered by RANK
  7. [x] When this is enabled, users of Actor Studio will have their content filtered by RANK where appropriate (i.e. from compendiums where the named folders exist).
geoidesic commented 1 month ago

Specifically I want a custom type to register a component via game.settings.register e.g. a multi-select or checkbox list.

E.g. I currently have this:

game.settings.registerMenu(MODULE_ID, SettingKeys.SOURCES, {
    name: 'compendiums'),
    label: 'Compendiums'),
    icon: 'fas fa-atlas',
    type: CompendiumSourcesSubmenu,
    restricted: true,
  });

But I would like that CompendiumSourcesSubmenu to be a svelte component, rather than the TypeScript / Handlebars extension to FormApplication that it currently is (as it has been ported from an existing module) TyphonJS (Michael) — 05/31/2024 2:20 PM It's highly recommended to use the "dummy FormApplication" route to register an app / menu setting.

You create a fake FormApplication and launch a normal SvelteApplication instead from this fake FormApplication. You can also make this fake FormApplication be a static way to launch the settings config from elsewhere.

You can see this in the unreleased mce-everywhere package:

The fake FormApplication: https://github.com/typhonjs-fvtt/mce-everywhere/blob/main/src/view/ConfigSettingButton.js https://github.com/FaeyUmbrea/obs-utils/blob/main/src/applications/settingsShell.js https://github.com/typhonjs-fvtt/mce-everywhere/tree/main/src/view https://github.com/typhonjs-fvtt/mce-everywhere/blob/main/src/model/mceGameSettings.js#L49-L62 https://github.com/typhonjs-fvtt/mce-everywhere/blob/main/src/view/ConfigSettingButton.js

Registering a hook to open the Svelte settings app and registering a menu: https://github.com/typhonjs-fvtt/mce-everywhere/blob/main/src/model/mceGameSettings.js#L49-L62 TyphonJS (Michael) — 05/31/2024 3:24 PM

However, a better solution that likely is available on a recent v11 / v12? install is if a function can be directly registered. The fake FormApplication approach is how you do it before a version of Foundry that can accept a function for the settings menu registration. I haven't followed up when / if function registration may have been implemented in core. I know it was put in as a feature request 1-2 years ago, so might be the best way to do things now.

geoidesic commented 1 month ago

Morning all. Does v11 or v12 core support registering a function for the settings menu registration? (I believe it was put in as a feature request 1-2 years ago). esheyw — Today at 10:44 AM

register(namespace, key, data) {
  //...
  // Validate type
    if ( data.type ) {
      const allowedTypes = [foundry.data.fields.DataField, foundry.abstract.DataModel, Function];
      if ( !allowedTypes.some(t => data.type instanceof t) ) {
        throw new Error(`Setting ${key} type must be a DataField, DataModel, or callable function`);
      }

from v12's client/core/settings.js the built-in type functions are functions and weren't whitelisted in v11 or anything, so it should take an arbitrary function just as well

geoidesic commented 1 month ago

Folder assignment for permissions gets complicated:

So to make this happen we have to first extract the folder ids from the pack and then compare the item's folder id with those

This is complicated and it obfuscates the meaning of the code, for those who don't know what Donation Tracker is. I'm starting tothink it's a bad idea to integrate it directly into Actor Studio.

I think what would be better is to make Actor Studio expect plugins by calling custom hooks at integration points. The first step is to identify all those points:

  1. Mostly it's filtering pack indexes I think. Just that.

Option 1

Then we publish Actor Studio Donation Tracker Integration as a separate module. This is better because it makes it more likely that other contributors can contribute to Actor Studio and understand its code.

Option 2

We build it as a built-in plugin.