Fork me on GitHub
#clojurescript
<
2021-05-16
>
winkywooster14:05:36

i’m trying to use some javascript game libraries from clojurescript. i have a simple shadow-cljs project, and an npm install of https://www.pixijs.com/, and I’ve successfully been able use it to draw sprites. now i’m trying to use https://github.com/alvaromontoro/gamecontroller.js, but when i require that library it’s namespace is empty. how do i debug this issue?

p-himik14:05:56

Shadow-cljs documentation has a table on how to convert JS requires into CLJS requires. Have you tried other ways of requiring the second library?

winkywooster15:05:11

this is where my javascript knowledge shows gaps. i’m looking at https://shadow-cljs.github.io/docs/UsersGuide.html#_using_npm_packages , and i’ve tried a require as both ["gamecontroller.js" :as gcjs] and ["gamecontroller.js" :refer (gameControl)], but gcjs is an empty map in the first case, and gameControl is undefined in the second case.

p-himik15:05:10

> but gcjs is an empty map in the first case This seems very wrong. Open up gamecontroller.js and see how it actually exports things.

p-himik15:05:30

If the contents of this file here https://github.com/alvaromontoro/gamecontroller.js/blob/master/dist/gamecontroller.js are the same as what you have locally, then I think the author of the library didn't export it correctly.

p-himik15:05:51

Same with the minified version - it just modifies window instead of exporting stuff. You can try to access it in your code as (.-gameControl js/window) after you require that library. But it's still not great.

winkywooster15:05:00

yeah, that’s the one.

winkywooster15:05:58

awesome.. that worked. and i see that now—the gameControl.init() adds event handlers to window and doesn’t actually create anything.

winkywooster15:05:03

thanks for your help @U2FRKM4TW

👍 3