sPOiDar / fvtt-module-stream-view

FoundryVTT module that provides a minimal UI view with automated camera work, ideal for streaming or recording games.
MIT License
11 stars 11 forks source link

feat(chat): Allow setting maximum height of the chat log #46

Closed magroader closed 1 year ago

magroader commented 1 year ago

Closes #33

sPOiDar commented 1 year ago

Sorry for the delay in reviewing this - haven't had a lot of time for personal projects this year.

Can you please update the commit message to read:

feat(chat): Allow setting maximum height of the chat log

so that it's correctly picked up by my CI workflow?

magroader commented 1 year ago

The code wasn't fully working - it would work at first but then revert. I added a second commit that fixes the problem.

I changed the PR name to be what you asked, and the docs say that if this is Squashed then the PR name will be the new commit message post-squash. But I think squashing is supposed to happen when the PR is pulled in?

I haven't dealt with squashing or rebasing before so I'm not sure how it works.

sPOiDar commented 1 year ago

No worries, I can sort out the squash/commit.

Can you tell me under what conditions the CSS method would revert? The following appears to be working fine for me, and I'm unable to make it fail:

diff --git a/lang/en.json b/lang/en.json
index 10f4f6a..0fc2e9c 100644
--- a/lang/en.json
+++ b/lang/en.json
@@ -43,6 +43,8 @@
        "stream-view.settings.chat-position-x.hint": "Horizontal screen position for chat log (negative numbers position from right of screen).",
        "stream-view.settings.chat-position-y.name": "Chat Position Y (pixels)",
        "stream-view.settings.chat-position-y.hint": "Vertical screen position for chat log (negative numbers position from bottom of screen).",
+       "stream-view.settings.chat-max-height.name": "Chat Maximum Height (pixels)",
+       "stream-view.settings.chat-max-height.hint": "Maximum height for the chat log (zero or negative for default size).",
        "stream-view.settings.auto-show-combat.name": "Auto Show Combat Tracker",
        "stream-view.settings.auto-show-combat.hint": "Show/hide combat tracker when combat starts/ends.",
        "stream-view.settings.combat-position-x.name": "Combat Tracker Position X (pixels)",
diff --git a/modules/stream_view.js b/modules/stream_view.js
index d6914e7..61801bd 100644
--- a/modules/stream_view.js
+++ b/modules/stream_view.js
@@ -228,6 +228,16 @@ class StreamView {
                        type: Number,
                });

+               game.settings.register('stream-view', 'chat-max-height', {
+                       name: game.i18n.localize('stream-view.settings.chat-max-height.name'),
+                       hint: game.i18n.localize('stream-view.settings.chat-max-height.hint'),
+                       scope: 'world',
+                       config: true,
+                       restricted: true,
+                       default: 0,
+                       type: Number,
+               });
+
                game.settings.register('stream-view', 'auto-show-combat', {
                        name: game.i18n.localize('stream-view.settings.auto-show-combat.name'),
                        hint: game.i18n.localize('stream-view.settings.auto-show-combat.hint'),
@@ -1298,7 +1308,13 @@ class StreamView {
                        // Extract chat log body.
                        html.find('#chat-controls').remove();
                        html.find('#chat-form').remove();
+                       html.find('#chat-log').css('height', '100%');
                        StreamView.hidePopoutHeaders(html);
+                       const maxHeight = game.settings.get('stream-view', 'chat-max-height');
+                       if (maxHeight > 0) {
+                               html.css('max-height', `${maxHeight}px`);
+                               html.css('min-height', 0);
+                       }
                        return;
                } else if (app instanceof CombatTracker) {
                        StreamView.hidePopoutHeaders(html);

The current approach in this PR will also affect all users currently.

magroader commented 1 year ago

I am not a web developer at all, and just whipped together something that worked. My first pass on this worked when the page was loaded, but then as soon as new chat was added, it reverted to the regular size. My second commit fixed that.

But if your method works - even when new chat is added - then that sounds fine to me!

sPOiDar commented 1 year ago

No worries, I'll commit that for inclusion in the next release, thanks for your efforts!