Closed zicklag closed 2 years ago
OK, this is ready for review!
We want to wait for https://github.com/jakobhellermann/bevy_mod_js_scripting/pull/23 before merging, but we should have that done within a day.
This PR removes the Health
item kind and adds a new Script
item kind. Then we use a script to re-implement the health item.
Additionally, you can add scripts to the game without tying them to an item, just by listing them in the .game.yaml
. I added a nifty demo script to show how that can be used, and acts as a short tutorial to the basics of the scripting system.
I just updated to use the latest master version of bevy_mod_js_scripting
and this is ready to merge!
It's a big update, though, so I'll wait for @odecay to give at least a casual approval.
A quick summary of what's included:
.editorconfig
file. This just helps VSCode play nicer with the indent size difference between Rust and JS depending on the formatters you have installed..game.yaml
file that not specifically tied to any specific item or attack.
Also, all scripts can be hot reloaded, so I'm literally able to modify the game while it's running, which is quite fun and incredibly useful!
Maybe I overdid it, but I pushed a commit with a ton of comments to ops.rs
that hopefully helps explain the code.
There are a couple things in there, specifically around JsValueRefs
that kind of requires knowing how bevy_mod_js_scripting
works to fully understand, and it's not really documented yet because it's brand new. But hopefully the comments give a general overview of what's happening.
I was expecting to see some system that dealt with the events that were being registered like 'ScriptItemThrowEvent. I see they are fired in fighter_state`, am I missing another system that deals with those events on the rust side or is that all thats needed to run the js/ts?
That's what the ItemGetGrabEvents
op does in ops.rs
. Because the out-of-the-box scripting API from bevy_mod_js_scripting
doesn't have a way to read Bevy events, we have to add a custom JsRuntimeOp
that adds a punchy.getItemGrabEvents()
function to the JavaScript environment.
This function will read all the ScriptItemGrabEvent
s sent by the code in fighter_state
.
Later, we will also need to add another JS op for getting the throw events ( or maybe we should merge both events into the same struct so that we don't need two different kinds of events? :thinking: ).
For anything that the out-of-the-box scripting API doesn't do yet, we can just create our own custom JS ops that can do anything we want, so it's super easy to add new functionality to the scripting interface which is cool.
Does the scripting wiki need any updates?
And is this still valid?
Since the scripting API is in flux, we won't include a tutorial here
Does the scripting wiki need any updates?
I wrote it as if this was already merged so it's up-to-date as soon as this is merged.
And is this still valid?
Yeah, the demo script I linked to will exist once this is merged and that is heavily commented, acting somewhat like a tutorial.
Now that you mention it, though, I don't like the wording very much. I'll just refer to the demo script as the tutorial. That will also help make sure it stays up-to-date because the game will error when we run it if something is wrong in that file.
I updated the wiki with your Deno explanations over in Jumpy-land 👌
LGTM?
Looks great, and good idea, thanks!
bors merge
bors retry
Canceled.
bors retry
Closes #253.