shemetz / ZoomPanOptions

FoundryVTT module for zooming and panning better
MIT License
7 stars 8 forks source link

Error in foundry v11 #49

Closed strongpauly closed 1 year ago

strongpauly commented 1 year ago

When loading the module in v11 I see this error:

Zoom/Pan Options: Error detected in module. It is likely this module has not been updated for FVTT Version 11 Stable.

Then in the console, I see this error:

foundry.js:733 Foundry VTT | Error thrown in hooked function '' for hook 'ready'
#call @ foundry.js:733
foundry.js:753 TypeError: Error thrown in hooked function '' for hook 'ready'. Cannot read properties of undefined (reading 'options')
[Detected 1 package: zoom-pan-options]
    at updateDragResistance (zoom-pan-options.js:298:36)
    at Object.fn (zoom-pan-options.js:480:3)
    at #call (foundry.js:730:20)
    at Hooks.callAll (foundry.js:687:17)
    at Game.setupGame (foundry.js:8684:11)
    at async Game._initializeGameView (foundry.js:9925:5)
    at async Game.initialize (foundry.js:8588:5)
airbreather commented 1 year ago

Workaround for the immediate issue: make sure that you have a scene activated. When I tested a migration from v10 to v11, I noticed that it had deactivated my active scene. I'm not sure if v10 had a similar issue or not, but at least this got me past this immediate error.

However, beyond that, a more significant v11-related issue: it seems that the Foundry developers have modified several of their "private" members so that they are now actually private, as opposed to "we've put an underscore prefix to indicate the intent, so pretty-please don't use them". As I understand it, there is no way for something like this module to work around this and get access to private members directly, so it would need to find some other way to do what it's trying to do... or, perhaps, temporarily disable the "Middle-mouse to pan" behavior until a better approach can be found?

Specifically, _handleMouseDown (v10) seems to have become #handleMouseDown (v11).

strongpauly commented 1 year ago

Perhaps there's a need to get in touch with the foundry devs. They recently relaxed some methods from private to protected: https://github.com/foundryvtt/foundryvtt/issues/9471. Do you think a subclass of the MouseInteractionManager would work?

airbreather commented 1 year ago

Perhaps there's a need to get in touch with the foundry devs. They recently relaxed some methods from private to protected: foundryvtt/foundryvtt#9471. Do you think a subclass of the MouseInteractionManager would work?

foundryvtt/foundryvtt#9562

shemetz commented 1 year ago

Thanks for doing this deep dive and saving me some time!
Andrew's comment makes sense:

The correct way for a module like ZoomPanOptions to implement a middle-mouse-to-pan feature would be to register its own event listeners and handlers on the canvas stage and handle those events when appropriate, stopping propagation of the events to the underlying core mouse interaction manager.

I'll try to do exactly this, when I work on this compatibility fix. I'm currently on vacation, but you should expect a fix within 1-2 weeks (I'll go through all my modules and update them for v11).

If I find out that middle-mouse-to-pan is still broken and not easy to fix, I might have to temporarily remove the feature while researching how to correctly fix it.

shemetz commented 1 year ago

Fixed in v1.10.0, but my fix is really ugly: I had to copy paste and slightly edit a lot of foundry code. I'll ask Atropos if there's a better way.