44 there is a part of how my game works that I actually want to replace more and more. But, I am not sure what the best option is.
Right now, species and terrain types are defined by json files. Which is great, as in theory this would make the game at least somewhat mod able. Except, there is a BIG catch. These json files aren't read at run time. Instead I have some typescript code that parses them and generates rust code based upon them.
As a result, despite me using nice json files for these things you still can't modify without rebuilding the game afterwards.
So, I want to remove this part of the code generation and replace it with something more flexible, but I have a hard time deciding how I want to replace it.
I seem to have 3 options:
- Keep using json files but load them in at run time instead of using them for code generation
- Make bindings to a scripting language and change the json files to the chosen language
- Make WASM bindings, and use the current code generation to make .wasm binaries based upon the json files
Number one is probably the easiest, but also the least flexible. As the behavior defined in those json files is limited to what I allow them to contain.
The second and third are basically the same option "Make bindings for another language" but have rather big differences in their pro's and con's.
Some pro's for WASM are:
- Native to the browser
- Is sandboxed by design
- Can be written in any language
- Can have assets compiled into them
Some cons for WASM are:
- Not easy to modify once compiled, or in other words: two steps forward one step back.
- Though, any language can be used that isn't to say that its easy in any language.
- Mods may end up being unreasonably big if they are written in "bad" languages (A mod written in C# will come with the whole Mono compiler/framework compiled)
- Probably not as easy to setup as lua bindings
Making bindings for a programming language like lua on the other hand:
- Is easily sandboxed (though, it is not save by design)
- no compile needed, always editable by users.
- Easier to setup for the user. Just place a .lua file at the correct place and you can mod the game
- No need for every mod to ship its own VM because the language it was written in happens to need one
- Probably easier to setup than WASM bindings (because someone already made bindings for lua and there are lua vm's written in rust)
But, it also comes with some big downsides:
- Not sandboxed by default
- Not native to the web
- Only one language is supported
- May require a dependency written in C depending on the state of the various lua vm's written in rust
- LuaJit is dead and probably unable to be used in the browser RIP One of the fastest, if not fastest scripting languages