ianfhunter / GNOLL

GNOLL is an efficient dice notation parser for multiple programming languages that supports a wide set of dice notation
https://www.ianhunter.ie/GNOLL/
GNU General Public License v3.0
40 stars 24 forks source link

Browser JavaScript Support #468

Closed michaeljmcd closed 6 months ago

michaeljmcd commented 6 months ago

This change makes it possible to call GNOLL from a web page with the use of some glue code. This is something of a rough pass, so any feedback is appreciated.

Description

How Has This Been Tested

Change Type

Checklist

ianfhunter commented 6 months ago

Thanks! I'm looking forward to trying this out

michaeljmcd commented 6 months ago

Experimenting further, I was able to get the bundle down to a single file (embedded WASM) and wrote a wrapper similar to the Python one.

Code is in: https://github.com/michaeljmcd/GNOLL/tree/javascript-bundle

If this looks like a good direction, I can merge these changes into the PR.

The one feature I couldn't readily port was showing a dice breakdown because the browser version doesn't use the temporary file and the breakdown isn't written to stdout.

ianfhunter commented 6 months ago

Just had a go at setting it up - looks great! Very easy to play around with. :) 🚀

The bundled version looks good - the index.html code is very concise if someone wanted to integrate it. If you want to update this PR we can include it

I'll make a ticket for myself to look at allowing dice breakdown to go to stdout in the future + I'll see if I can get some sort of selenium test so any other contributions can be automatically verified.

michaeljmcd commented 6 months ago

Excellent. I went ahead and merged javascript-bundle into javascript-web.

ianfhunter commented 6 months ago

Fantastic! Thanks for contributing, this should make the library a lot more accessible for people