Open jackwlee01 opened 5 days ago
I am just going to say up-front: I have come to be a bit of a typescript-hater.
That said, I am totally hip to adding it, if it helps others, and doesn't hurt things (especially if it's a separate file like this, which is perfect, because I don't have to change build-setup or anything.)
You want to make a PR, so your face is attached to the commit? Happy to merge it. Maybe we could also auto-gen this sort of thing, similar to what I do here.
There are also these classes:
UniformFloat
UniformVector2
UniformVector3
UniformVector4
UniformColor
UniformInt
UniformTexture
which are special classes for doing stuff with shaders, that are not in C raylib.
I have also been thinking about simplifying the build in general. I have been playing with some sort of related ideas over here. It's got a long way to go, but the code-gen and the C build setup is much nicer.
I am not totally positive what types you hope for, but I build everything from these defs so feel free to feed that to AI to get typescript defs. They probably won't be perfect (since it's C types) but maybe I could generate a more standalone js file you can use regular typescript tooling on?
Awesome, thanks for linking those defs. I’ll give it a try with those, and your codegen code, to see how that works.
The types that I would hope for is at least everything on the Raylib cheat sheet.
Just quickly looking through your examples, it appears that the JavaScript interface is basically the same as the C interface. Are there many instances where the interface deviates?
Also, I really like that your lib does not need a build step. This makes it absolutely fantastic as a teaching tool.
I’ll mention how I intend to use your lib. I have node.js installed on my system. My project does not have a package.json or any dependencies, but I run the command npx vite
in my project directory. This gives me a nice minimal development setup with auto reloading, and also facilitates using typescript source files. This feels like writing vanilla javascript, but with a few extra nice development tools.
The types that I would hope for is at least everything on the Raylib cheat sheet.
That makes perfect sense to me. I should be able to help with the code-gen in a bit. I think we can probly leverage some of the js mapping that I already have, and as I said, I have some ideas to simplify/improve, anyway. Give it a go first, if you want, but I am happy to help.
Are there many instances where the interface deviates?
Anything that loads files should use a promise (use await
) so it can load images & things from URLs, but otherwise it should all match.
This gives me a nice minimal development setup with auto reloading, and also facilitates using typescript source files. This feels like writing vanilla javascript, but with a few extra nice development tools.
Exactly! I have been doing this with a bunch of my personal projects, lately, because I miss that immediacy and spirit of play. I don't need to plan out a project/build/deploy to just get things working quickly, and I can try out ideas and move on to other things.
Here are a couple other related tricks for that sort of workflow:
npx -y live-server
. I also like vite for built projects, but with live-server
, you get the same hot-reloading, but faster, and no need to install anything (npx
works without a package.json even.) Basically, it's vite without the build-step. Your HTML should have a head
tag, but otherwise it works great, with no modification.Thanks! I’ll see if I get time this week to look at the typings again.
I hadn’t heard of ems.sh, but it looks really awesome. I’m not sure how it would play with Typescript but seems ideal for my quick, one off experiments. Thanks for the tip :)
Thanks for the great lib! I am glad I found it. I was hoping it would have Typescript typings though.
I had a go at generating Typescript typings with AI (see attached) but there are some issues.
It doesn't seem like it would be too difficult to generate the proper typings for someone with more knowledge of the lib.
raylib.d.ts.txt