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?
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?
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.
or do i have to do something with the https://shadow-cljs.github.io/docs/UsersGuide.html#js-provider ?
> 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.
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.
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.
yeah, that’s the one.
awesome.. that worked. and i see that now—the gameControl.init() adds event handlers to window and doesn’t actually create anything.
thanks for your help @p-himik