Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scripting MVP #255

Merged
merged 11 commits into from
Oct 6, 2022
Merged

Scripting MVP #255

merged 11 commits into from
Oct 6, 2022

Conversation

zicklag
Copy link
Member

@zicklag zicklag commented Sep 18, 2022

Closes #253.

@zicklag zicklag force-pushed the scripting-mvp-2 branch 8 times, most recently from f64d6ff to 6907ab8 Compare September 22, 2022 21:44
@zicklag zicklag marked this pull request as ready for review September 22, 2022 22:12
@zicklag
Copy link
Member Author

zicklag commented Sep 22, 2022

OK, this is ready for review!

We want to wait for jakobhellermann/bevy_mod_js_scripting#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.

@zicklag
Copy link
Member Author

zicklag commented Sep 24, 2022

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:

  • Added a .editorconfig file. This just helps VSCode play nicer with the indent size difference between Rust and JS depending on the formatters you have installed.
  • Updated the version of wasm_bindgen
  • Allowed you to specify a list of scripts in the .game.yaml file that not specifically tied to any specific item or attack.
    • Added a demo script of this kind
  • Added events that are emitted when a script item is grabbed or thrown. This is used in scripts to carry out their logic when their item is interacted with.
    • Many items still cannot be implemented with scripts. This is work-in-progress so we still have non-scripted items.
  • Changed the health item type to a script item type and re-implemented it with a script.
  • Added typescript definitions for the scripting API and a TypeScript config file to enable auto-completion and type checking for scripts in VSCode.

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!

Copy link
Collaborator

@odecay odecay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went over the code, I dont understand the ops.rs file. The api for scripting as I understand it seems pretty nice though. 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?

assets/items/health/health.item.yaml Show resolved Hide resolved
lib.bevy.types.ts Show resolved Hide resolved
src/scripting.rs Show resolved Hide resolved
@zicklag
Copy link
Member Author

zicklag commented Sep 27, 2022

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 ScriptItemGrabEvents 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? 🤔 ).


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.

@erlend-sh
Copy link
Member

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

@zicklag
Copy link
Member Author

zicklag commented Sep 27, 2022

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.

@erlend-sh
Copy link
Member

I updated the wiki with your Deno explanations over in Jumpy-land 👌

LGTM?

@zicklag
Copy link
Member Author

zicklag commented Oct 5, 2022

Looks great, and good idea, thanks!

@odecay
Copy link
Collaborator

odecay commented Oct 6, 2022

bors merge

bors bot added a commit that referenced this pull request Oct 6, 2022
255: Scripting MVP r=odecay a=zicklag

Closes #253.

Co-authored-by: Zicklag <zicklag@katharostech.com>
@bors
Copy link
Contributor

bors bot commented Oct 6, 2022

@zicklag
Copy link
Member Author

zicklag commented Oct 6, 2022

bors retry

bors bot added a commit that referenced this pull request Oct 6, 2022
255: Scripting MVP r=odecay a=zicklag

Closes #253.

Co-authored-by: Zicklag <zicklag@katharostech.com>
@bors
Copy link
Contributor

bors bot commented Oct 6, 2022

Canceled.

@zicklag
Copy link
Member Author

zicklag commented Oct 6, 2022

bors retry

@bors
Copy link
Contributor

bors bot commented Oct 6, 2022

@bors bors bot merged commit 841985f into fishfolk:master Oct 6, 2022
@zicklag zicklag deleted the scripting-mvp-2 branch October 6, 2022 02:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create Scripted In-Game Item
4 participants