CristianVasile23 / conversation-hud

A simple FoundryVTT module that adds a nice HUD that display the portraits of all the characters present in a conversation.
MIT License
14 stars 2 forks source link

Allow saving the minimization state between conversations #44

Closed Mystler closed 3 months ago

Mystler commented 4 months ago

Hello and first of all thanks for this amazing module. This is not directly an issue but more of a feedback report of my use case for this module and how I went about fitting it to my needs. If this helps make adjustments to the module this can be used for tracking, otherwise it can also be closed again.

So, when GMing my own PF2E group, I noticed that I am not the best at changing my voice well enough to clearly separate multiple NPCs involved in a conversation. In order to show visual separation, I checked out this module so I can highlight who is the current speaker. In the last session with the module installed I found myself too lazy to either prepare conversations in advance or configure them while in the middle of things. For my case, a simple macro to just show the actor of the token I have currently selected, would be perfect to skip any set up.

After looking at the source of the module I found a way to make this work mostly as I wanted to. I unchecked that non-GM players can see the list of participants and then wrote the following macro based on the one shipped with the module:

const actor = canvas.tokens.controlled[0]?.actor;
if (actor) {
  const participant = {
    faction: {
      factionName: "",
      factionLogo: "",
      factionBannerEnabled: false,
      factionBannerShape: "shape-1",
      factionBannerTint: "#000000",
    },
    img: actor.img,
    linkedJournal: "",
    name: actor.name,
  };
  game.ConversationHud.startConversationFromData({
    participants: [participant],
    defaultActiveParticipant: 0
  });
} else if (game.ConversationHud.conversationIsActive) {
  game.ConversationHud.onToggleConversation(false);
} else {
  game.ConversationHud.onToggleConversation(true);
}

This macro starts a new conversation or updates the current one to show just the selected token. If none is selected, the conversation is ended. If used without any conversation active and no token selected, it shows the setup dialog. It works pretty well, the only hack in there being that I had to hard-code the participant setup because the convertActorToParticipant function is not publicly accessible.

It works great for my needs. If this report or macro helps adding some better solution for it to the module itself, that could be cool, but I am also fine to just continue with this.

One final piece of related feedback I have is that I noticed that the conversation minimization resets when a conversation is ended fully and a new one is started. I think it would be really useful to have an option to store the minimization state between conversations. Especially as the GM running this based on selecting tokens in the scene, it requires me to be in the minimized state to do so.

Thanks again for the module and keep up the great work.

CristianVasile23 commented 4 months ago

Hey, and thanks for the feedback I appreciate it!

Regarding the convertActorToParticipant function, I will be adding a way to access in the upcoming version of the module as I agree it is very useful to have when writing macros (as a matter of fact, many of the helper functions are useful). I have wanted for a while to improve on the API, so feedback is more than welcome for gradual improvements. However, what will most likely happen is that I will rewrite the module entirely once the Foundry team finish the UI upgrade they are have clearly started integrating. The module is starting to get clunky and the code is getting overly complex as it was never meant to do what it is currently doing. Furthermore, at the start I wasn't really that familiar with the Foundry API and how everything worked, so I think a rework is in order and once that will happen I will make sure that there will be a proper API with all these useful functions available for macro use.

As to the persistent minimization state, I will se what I can do about that, I can see the value in adding such a feature (probably a toggle), but this addition will probably come a bit later.

Until then, if there are other things that I can help with, feel free to reach out and I will answer as soon as possible!

Mystler commented 4 months ago

To give an update on my fiddling with the module, I have since made some adjustments to my macro as well as tested some quick code hacks to allow saving the minimization state.

For the macro, I quickly realized that, instead of selecting the token, i can just go one step further and turn it into a mouseover macro. On top of that I also added an anonymity shortcut. To explain, first the code I'm currently using for it:

const actor = canvas.tokens.hover?.actor;
const shift = game.keyboard.isModifierActive(KeyboardManager.MODIFIER_KEYS.SHIFT);
if (actor) {
  const participant = {
    faction: {
      factionName: "",
      factionLogo: "",
      factionBannerEnabled: false,
      factionBannerShape: "shape-1",
      factionBannerTint: "#000000",
    },
    img: actor.img,
    linkedJournal: "",
    name: shift ? "???" : actor.name,
  };
  game.ConversationHud.startConversationFromData({
    participants: [participant],
    defaultActiveParticipant: 0
  });
} else if (game.ConversationHud.conversationIsActive) {
  game.ConversationHud.onToggleConversation(false);
}

How this works now:

On top of that, I made the following simple code edits so that the minimization state of the conversation does not reset when a new conversation is started in the same login session:

This has been working great on my end and seems like it is sufficient as an implementation. To integrate it into the module, it would probably just need conditional application based on a setting.

I will go ahead and rename this issue into being about the minimization state since the rest of what I brought up was just general feedback or reports from my end but no real issues.

Mystler commented 3 months ago

I'm happy my pull requests were useful! I will close this issue now to mark it as resolved. Thanks again for all the effort and good work with this module. I hope you have a great weekend!