diff --git a/check.sh b/check.sh index 18d7f7c1..31a157ed 100755 --- a/check.sh +++ b/check.sh @@ -6,5 +6,5 @@ CURRENT_DIR=$(basename "$PWD") if [[ "$CURRENT_DIR" == "bevy_api_gen" ]]; then cargo +nightly-2024-11-05 clippy --all-targets --message-format=json else - cargo clippy --workspace --all-targets --message-format=json --features="lua54 rhai teal rune bevy/file_watcher bevy/multi_threaded" + cargo clippy --workspace --all-targets --message-format=json --features="lua54 rhai rune bevy/file_watcher bevy/multi_threaded" fi diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index 7390c828..a85f9090 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -1,3 +1,4 @@ # Summary -- [Chapter 1](./chapter_1.md) +- [Installation](./installation.md) +- [Managing Scripts](./managing-scripts.md) \ No newline at end of file diff --git a/docs/src/chapter_1.md b/docs/src/chapter_1.md deleted file mode 100644 index 93f9d239..00000000 --- a/docs/src/chapter_1.md +++ /dev/null @@ -1,7 +0,0 @@ -# Chapter 1 - - -## Introduction - -Welcome to the greatest documentation of all time WIP -test \ No newline at end of file diff --git a/docs/src/installation.md b/docs/src/installation.md new file mode 100644 index 00000000..c0bae898 --- /dev/null +++ b/docs/src/installation.md @@ -0,0 +1,51 @@ +# Installation + +## Cargo + +First you need to install the crate by adding this entry to your `Cargo.toml` dependencies list: + +```toml +bevy_mod_scripting = { version = "0.9.0", features = ["lua54"]} +``` + +Choose the language features you wish enabled and add them to the features block. + + +## Bevy Plugin + +The next step is to add the BMS plugin to your application, on top of any other extras you want included in your app: + +```rust,ignore +app.add_plugins(LuaScriptingPlugin::<()>::default()); +``` + +The above is how you'd setup BMS for Lua, if you want to use another language, simply use a corresponding plugin from the integration crate. + + +## Language Features + +Each language supported by BMS can be switched-on via feature flag as below: + +| Language | Feature Flag | +| ---- | ---- | +| Lua51 | lua51 | +| Lua52 | lua54 | +| Lua53 | lua53 | +| Lua54 | lua54 | +| Luajit | luajit | +| Luajit52 | luajit52 | +| Luau | luau | +| Rhai | rhai | +| Rune | rune | + +## Extra Features + +In order to fit as many use cases as possible, BMS allows you to disable a lot of its functionality. + +By default all of the useful features are enabled, but you may disable them if you wish if you are only needing BMS for script lifecycle management, and want to populate the bindings yourself. + +| Feature | Description | +| ---- | ---- | +| core_functions | If enabled, will enable all core functions, i.e. bevy integrations which let you interact with Bevy via reflection | +| bevy_bindings | If enabled, populates the function registry with additiona automatically generated bevy bindings. This includes functions on `glam` and `bevy::ecs` types. These are useful but will slow down compilation considerably. | + diff --git a/docs/src/managing-scripts.md b/docs/src/managing-scripts.md new file mode 100644 index 00000000..36635d79 --- /dev/null +++ b/docs/src/managing-scripts.md @@ -0,0 +1,45 @@ +# Managing Scripts + +Scripts live in the standard bevy `assets` directory. Loading a script means: +- Parsing the script body +- Creating or updating the resources which store script state +- Assigning a name/id to the script so it can be referred to by the rest of the application. + +## Loading +BMS listens to `ScriptAsset` events and reacts accordingly. In order to load a script, all you need to do is request a handle to it via the asset server and store it somewhere. + +Below is an example system which loads a script called `assets/my_script.lua` and stores the handle in a local system parameter: + +```rust,ignore +fn load_script(server: Res, mut handle: Local>) { + let handle_ = server.load::("my_script.lua"); + *handle = handle_; +} +``` + +In practice you will likely store this handle in a resource or component, when your load all the scripts necessary for your application. + + +## Deleting scripts +In order to delete a previously loaded script, you will need to issue a `DeleteScript` command like so: + +```rust,ignore +DeleteScript::new("my_script.lua".into()) +``` + +This will delete references to the script and remove any internal handles to the asset. You will also need to clean up any handles to the asset you hold in your application in order for the asset to be unloaded. + +## Hot-loading scripts +To enable hot-loading of assets, you need to enable the necessary bevy features as normal [see the bevy cheatbook for instructions](https://bevy-cheatbook.github.io/assets/hot-reload.html). + +Assuming that hot-reloading is enabled for your app, any changes to script assets will automatically be picked up and the scripts re-loaded. + +## Manually (re)loading scripts +In order to manually re-load or load a script you can issue the `CreateOrUpdateScript` command: + +```rust,ignore +CreateOrUpdateScript::new("my_script.lua".into(), "print(\"hello world from new script body\")".into(), asset_handle) +``` + +## Loading timeframe +Scripts are processed via commands, so any asset events will be processed at the next command execution point running after BMS internal asset systems. \ No newline at end of file