javieros105 / FVTT-TokenHUDWildcard

Module for FoundryVTT that expands functionality to Token HUD and Wildcard Images
GNU General Public License v3.0
13 stars 4 forks source link

Foundry v9 incompatibility #27

Open GambetTV opened 2 years ago

GambetTV commented 2 years ago

The module works for the most part in v9, but one critical aspect of it is no longer supported, which is you can no longer define a default token image. I suspect this is because of the updates done to the Token Configuration menu, as the layout now is significantly different.

NorthernPlague commented 2 years ago

I may have a conflict with another module, but the HUD is visible and working only when I'm GM. The button to access token selection is not present when I log in as the player/owner.

smoothingplane commented 2 years ago

same here

SirTman commented 2 years ago

I tried to make a pull request as the fix is quite trival but was unable.

https://github.com/javieros105/FVTT-TokenHUDWildcard/blob/59969d8f804df87fa691878f135687e4d2346c44/token-hud-wildcard/main.js#L68

Line 68 needs to changed to const imageDataTab = html.find('.tab[data-tab="appearance"]') As that tab was renamed in v9

NorthernPlague commented 2 years ago

Line 68 needs to changed to const imageDataTab = html.find('.tab[data-tab="appearance"]') As that tab was renamed in v9

I tried that change manually and cleared cache but the GM vs Player views still differ - maybe I've misconfigured something. image image

GrumpyVader commented 2 years ago

I don't even get the Randomize Wildcard Images check box in Foundry v9.

image

When I try to use the wild card, I get the following error in the console. image

cs96and commented 2 years ago

@GrumpyVader it looks like some other module is also fiddling with the token config dialog. Try disabling all modules apart from Token HUD Wildcard to see if it works.

cs96and commented 2 years ago

It seems that the players need the "Use File Browser" permission in order for the extra button to appear on the token HUD. This is due to a change in core Foundry. I raised a bug report for it here... https://gitlab.com/foundrynet/foundryvtt/-/issues/6575

shirkie commented 2 years ago

Updating the code manually to enable the default image options still gives me an issue to where it doesn't respect the selection. It will still be random even with a default set.

cs96and commented 2 years ago

@shirkie I noticed that too, it's actually a problem in v0.8 too. I actually have a fix for it, but I'm not at my PC right now to post it.

shirkie commented 2 years ago

@cs96and That's great news! I would LOVE to get that from you whenever you have time! Glad i wasn't the only one experiencing it. Thank you in advance.

cs96and commented 2 years ago

Here's the fix for the default token. On line 52 of main.js, replace this...

    _hookPreTokenCreate () {
        Hooks.on('createToken', (parent, options, userId) => {
            const defaultValue = parent?.actor?.data?.token?.flags['token-hud-wildcard'] ? parent.actor.data.token.flags['token-hud-wildcard'].default : ''

            if (defaultValue !== '' && parent?.actor?.data?.token?.randomImg) {
                const dimensions = getTokenDimensions(parent, defaultValue)
                let updateInfo = { img: defaultValue, ...dimensions }
                parent.object.document.update(updateInfo)
            }
        })
    },

With this...

    _hookPreTokenCreate () {
        Hooks.on('preCreateToken', (parent, data, options, userId) => {
            const defaultValue = parent?.actor?.data?.token?.flags['token-hud-wildcard'] ? parent.actor.data.token.flags['token-hud-wildcard'].default : ''

            if (defaultValue !== '' && parent?.actor?.data?.token?.randomImg) {
                const dimensions = getTokenDimensions(parent, defaultValue);
                let updateInfo = { img: defaultValue , ...dimensions };
                mergeObject(data, updateInfo);
                parent.data.update(updateInfo);
            }
        })
    },
shirkie commented 2 years ago

That works wonderfully! Thank you for posting it!

javieros105 commented 2 years ago

I'm so sorry, i missed all these notifications.

oh damn that's awesome. Gonna try to include it in a new version soon, I haven't updated to foundry v9

Gonna update foundry today and check the fix during the week to make a new version.

cs96and commented 2 years ago

Note there are two separate fixes above. @SirTman's fix is the fix to make it work with v9.

My fix actually fixes #24.

Also, you can improve on @SirTman's fix, to make it compatible with both v0.8 and v9...

const imageDataTab = html.find('.tab[data-tab="appearance"],.tab[data-tab="image"]')
GambetTV commented 2 years ago

Also, if there's a way to fix the current v9 requirement of having to give players File Browser permissions for them to be able to change their own tokens that would be ideal.

cs96and commented 2 years ago

@GambetTV that relies on fixing core foundry... https://gitlab.com/foundrynet/foundryvtt/-/issues/6575

javieros105 commented 2 years ago

Gonna try to add the fixes during this week, probably before friday. Regarding the issue with file picker, that definitely gonna have to wait unti there is a solution on the core side

javieros105 commented 2 years ago

Here's the fix for the default token. On line 52 of main.js, replace this...

    _hookPreTokenCreate () {
        Hooks.on('createToken', (parent, options, userId) => {
            const defaultValue = parent?.actor?.data?.token?.flags['token-hud-wildcard'] ? parent.actor.data.token.flags['token-hud-wildcard'].default : ''

            if (defaultValue !== '' && parent?.actor?.data?.token?.randomImg) {
                const dimensions = getTokenDimensions(parent, defaultValue)
                let updateInfo = { img: defaultValue, ...dimensions }
                parent.object.document.update(updateInfo)
            }
        })
    },

With this...

    _hookPreTokenCreate () {
        Hooks.on('preCreateToken', (parent, data, options, userId) => {
            const defaultValue = parent?.actor?.data?.token?.flags['token-hud-wildcard'] ? parent.actor.data.token.flags['token-hud-wildcard'].default : ''

            if (defaultValue !== '' && parent?.actor?.data?.token?.randomImg) {
                const dimensions = getTokenDimensions(parent, defaultValue);
                let updateInfo = { img: defaultValue , ...dimensions };
                mergeObject(data, updateInfo);
                parent.data.update(updateInfo);
            }
        })
    },

This fix works perfectly but I can't make the other one actually work. Need to check it a bit more

javieros105 commented 2 years ago

Oh ok,yeah I get the second fix, I was mixing it up

javieros105 commented 2 years ago

Hey guys, bit of an update, thanks to @cs96and for reporting the issue on getTokenImages it was added to the dev pipeline and apparently fixed for version 10 prototype 1. So I have high hopes we will recover full functionality of the module