League-of-Foundry-Developers / fvtt-module-theatre

GNU General Public License v3.0
30 stars 39 forks source link

BUG: "theatre is not defined " #146

Closed TheGreatRedDuke closed 9 months ago

TheGreatRedDuke commented 11 months ago

Hello,

I believe that since the latest, update any macros that reference theater no longer function.

This is true of both any custom code as well as the macros provided by this module.

Error in console:

28051:4 Uncaught (in promise) ReferenceError: Theatre is not defined
    at Macro.eval (eval at #executeScript (foundry.js:22859:16), <anonymous>:4:5)
    at #executeScript (foundry.js:22863:17)
    at Macro.execute (foundry.js:22811:35)
    at MacroConfig._onExecute (foundry.js:75485:17)

eval @ VM28051:4
#executeScript @ foundry.js:22863
execute @ foundry.js:22811
_onExecute @ foundry.js:75485
await in _onExecute (async)
dispatch @ jquery.min.js:2
y.handle @ jquery.min.js:2

To reproduce this exact error:

Add a token to a scene. Attempt to execute the macro "Add Selected Tokens to Stage" that is provided by this module.

I am testing on a fresh world, with no other modules active, and the latest version of Foundry and this module.

megahead11 commented 11 months ago

It seems like we might've missed something in the last update. I didn't notice this last time when I tried it out. Can you try 2.6.1? https://github.com/League-of-Foundry-Developers/fvtt-module-theatre/releases/tag/v2.6.1

TheGreatRedDuke commented 11 months ago

Can confirm, still not working in 2.6.1.

Customs macros that previously worked by calling theatre.SOMETHING and the macros provided by the module that call Theater.SOMETHING both are still not functioning.

theatre.SOMETHING:

Uncaught (in promise) ReferenceError: theatre is not defined
    at toggleTheatreActor (eval at #executeScript (foundry.js:22859:16), <anonymous>:16:5)
    at Macro.eval (eval at #executeScript (foundry.js:22859:16), <anonymous>:29:1)
    at #executeScript (foundry.js:22863:17)
    at Macro.execute (foundry.js:22811:35)
    at HotbarSFRPG._onClickMacro (foundry.js:78610:20)
    at HotbarSFRPG.clickMacro (monks-active-tiles.js:1901:24)
    at Hotbar._onClickMacro (monks-active-tiles.js:1909:35)
    at HTMLLIElement.dispatch (jquery.min.js:2:43184)
    at y.handle (jquery.min.js:2:41168)

Theatre.SOMETHING:

6737:7 Uncaught (in promise) TypeError: Theatre.addToNavBar is not a function
    at eval (eval at #executeScript (foundry.js:22859:16), <anonymous>:7:37)
    at Array.forEach (<anonymous>)
    at Macro.eval (eval at #executeScript (foundry.js:22859:16), <anonymous>:7:16)
    at #executeScript (foundry.js:22863:17)
    at Macro.execute (foundry.js:22811:35)
    at HotbarSFRPG._onClickMacro (foundry.js:78610:20)
    at HotbarSFRPG.clickMacro (monks-active-tiles.js:1901:24)
    at Hotbar._onClickMacro (monks-active-tiles.js:1909:35)
    at HTMLLIElement.dispatch (jquery.min.js:2:43184)
    at y.handle (jquery.min.js:2:41168)

If there's any other info I can provide to help, please let me know.

JulieWinchester commented 10 months ago

It looks like some functions are now available via Theatre.instance, like Theatre.instance.handleNavItemMouseUp(). But a number of important functions for use by macros like clearStage() and addToNavBar() are missing from Theatre.instance, so this isn't a full workaround.

This is using 2.6.1.

mclemente commented 10 months ago

@megahead11 try this on theatre_main.js

  if (!window.Theatre) {
-    window.Theatre = {};
+    window.Theatre = window.theatre = theatre;
  }
- window.Theatre.instance = theatre;

I'm not sure what the instance is meant to be here, I changed it and nothing seems to break.

megahead11 commented 10 months ago

@megahead11 try this on theatre_main.js

  if (!window.Theatre) {
-    window.Theatre = {};
+    window.Theatre = window.theatre = theatre;
  }
- window.Theatre.instance = theatre;

I'm not sure what the instance is meant to be here, I changed it and nothing seems to break.

Gave it a shot on my local copy but it doesn't seem to fix the issue either.

144 was supposed to have the following code on theatre_main.js, so I'm not quite sure if the window.Theatre.instance was required as a part of something he fixed with the webfontloader update he did. However, changing it to the code you put doesn't appear to fix the issue of the macro (add token to stage) not working.

This is what it was supposed to be?


if (data.cssId === "chat-popout") return;
theatre.initialize();

window.Theatre = {};
window.Theatre.instance = theatre;
mclemente commented 10 months ago

Ah, I just tried to fix theatre not being a thing, not the macro not running.

I have yet to understand what was the point of declaring Theatre.instance = theatre there when it probably meant to target theatre.constructor.instance instead.

Try the following inside the if condition

window.Theatre = Theatre;
window.theatre = theatre;

This should fix it, but I'm not sure if anything will break since there's a bunch of Theatre calls in the code, but they're most likely calling the class instead.

Alternatively, just use my earlier suggestion and change the macros to Theatre.constructor.addToNavBar.

megahead11 commented 10 months ago

That appears to have worked. However, I will keep the issue open JUST in case I might've missed something.

JulieWinchester commented 9 months ago

This is fixed now for me. Thanks a lot!

TheGreatRedDuke commented 9 months ago

My apologies for being very slow. I'm trying to also test this on my local also, but exactly what code is required where in theatre_main.js?

And will this fix make it into a upcoming release?