asacolips-projects / pbta

Run games for any PbtA system in Foundry VTT!
https://asacolips.gitbook.io/pbta-system
MIT License
3 stars 7 forks source link

Question about tags and possible bug #251

Closed fe5hua closed 3 months ago

fe5hua commented 3 months ago

Hi, I noticed that tags are a thing, but the only place I find them are the tag settings and items. Is it possible to add tags to characters esp. NPCs. The documentation shows a tags field on a npc character sheet screenshot and being able to define tags for characters in the settings indicates that it is somehow possible. Do I need to define a special tags field in the config-sheet?

The text input in the item sheet does not seem to properly work. I look different from the on in the tag settings and it is not interactive in any way the label indicates.

thanks.

mclemente commented 3 months ago

There is support for tags on actor sheets, but the base system itself doesn't display them anywhere.

You can display them by subclassing the PbtA Actor Sheet and overriding activateListeners like this

// FooActorSheet extends pbta.applications.actor.PbtaActorSheet
activateListeners(html) {
  super.activateListeners(html);
  const tagify = this._activateTagging(html);
  tagify.on("edit:start", ({ detail: { tag, data } }) => game.pbta.utils.TagHandler.onEdit(tagify, { tag, data }));
}

And adding this to the html:

<input name='system.tags' class='tags' placeholder='{{localize "PBTA.TagsPlaceholder"}}' value='{{ system.tags }}'/>

The text input in the item sheet does not seem to properly work. I look different from the on in the tag settings and it is not interactive in any way the label indicates.

What browser are you using? It works just fine for me on Firefox/Chrome.

fe5hua commented 3 months ago

thanks, I'm on Arc Version 1.52.0 (51895) based on Chromium Version 126.0.6478.183. In Brave Version 1.68.128 based on Chromium 127.0.6533.73 it is working.

fe5hua commented 3 months ago

For reference: this._activateTagging(html) did not work because it doesn't return anything. I instead copied the this._tagify(html) function from item-sheet.js and it worked.

/**
 * Extend the PbtaActorNpcSheet with tags
 * @extends {pbta.applications.actor.PbtaActorNpcSheet}
 */
class FooActorNpcSheet extends pbta.applications.actor.PbtaActorNpcSheet {
  /**
   * Add tagging widget.
   * @param {HTMLElement} html
   * @returns {Tagify | undefined}
   */
  _tagify(html) {
    let $input = html.find('input[name="system.tags"]');
    if ($input.length > 0) {
      if (!this.isEditable) {
        $input.attr("readonly", true);
      }
      const whitelist = game.pbta.utils.getTagList(this.actor);

      // init Tagify script on the above inputs
      return new Tagify($input[0], {
        whitelist,
        dropdown: {
          maxItems: 20, // <- mixumum allowed rendered suggestions
          classname: "tags-look", // <- custom classname for this dropdown, so it could be targeted
          enabled: 0, // <- show suggestions on focus
          closeOnSelect: false, // <- do not hide the suggestions dropdown once an item has been selected
        },
        ...game.pbta.utils.TagHandler.config,
      });
    }
  }

  /** @override */
  async activateListeners(html) {
    super.activateListeners(html);
    const tagify = this._tagify(html);
    tagify.on("edit:start", ({ detail: { tag, data } }) =>
      game.pbta.utils.TagHandler.onEdit(tagify, { tag, data }),
    );
    console.log("tagify", tagify);
  }
}

and then registered it:

Hooks.once("init", () => {
  Actors.registerSheet("foo", FooActorNpcSheet, {
    types: ["npc"],
    makeDefault: false,
    label: game.i18n.localize("foo.sheets.npc"),
  });
});

thank you, for pointing me in the right direction.

mclemente commented 3 months ago

It has been a while since I've played with the tags on actor sheets, so I'm sorry it didn't work out for you, I thought it would work fine for you.

What game are you trying to create on the system? The main reason I haven't worked on improving Tags for actors is that I'm not aware of any games that absolutely need it to exist.