mclemente / fvtt-module-polyglot

Talk to others using a language you can speak and scrambles text you can't understand.
MIT License
41 stars 48 forks source link

v10 chatBubbles API change impact #258

Closed napolitanod closed 2 years ago

napolitanod commented 2 years ago

Describe the bug I believe the API for the chatBubbles has changed in Foundry V10 so that the current method Polygot provides for passing in a language for the chat bubble is no longer working.

API for .say() and .broadcast(): https://foundryvtt.com/api/v10/classes/client.ChatBubbles.html#broadcast

in v9 the language was passed in on an emote key for the options object ( {emote: {language: 'elvish'}}) but with the v10 change I don't believe the emote will clear through on the hook options. The new cssClasses key may possibly be able to be leveraged here in place of emote, though I don't know how janky that is. adding an object to this key passes through to the chatBubble hook that I believe Polyglot is reading as show below

{cssClasses: {language: 'elvish'}}

To Reproduce See https://github.com/League-of-Foundry-Developers/fvtt-module-polyglot/wiki/Macros#canvashudbubblessay

Expected behavior I expect if on my session I invoke a chat bubble with the appropriate key set for the options data to pass in a language that on the player's session, if they don't speak the language, they will see the chat bubble in the polyglot markup

v10 285

mclemente commented 2 years ago

That cssClasses override was a good hint, but it would be super janky. It is sent to the chat bubble render template before it gets sent to the chatBubble hook, so the data would go to the bubble class before I had any chance to filter it out before. And chatBubbles hook wasn't getting sent a html object anymore, so it needed to be changed too.

My solution was to override ChatBubbles.prototype.say to have an options.languages parameter and adapted the old logic to make use of cssClasses properly.

napolitanod commented 2 years ago

brilliant! thank you!