This commit is contained in:
parent
08e177dacd
commit
d505fb33aa
11 changed files with 2544 additions and 15 deletions
1
book/.gitignore
vendored
1
book/.gitignore
vendored
|
|
@ -1,2 +1,3 @@
|
|||
book
|
||||
doctest_cache
|
||||
target
|
||||
|
|
|
|||
2498
book/Cargo.lock
generated
Normal file
2498
book/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
6
book/Cargo.toml
Normal file
6
book/Cargo.toml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
[package]
|
||||
name = "bevy_scriptum_book"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
bevy_scriptum = { path = "../", features = ["ruby", "lua", "rhai"] }
|
||||
|
|
@ -4,9 +4,3 @@ language = "en"
|
|||
multilingual = false
|
||||
src = "src"
|
||||
title = "bevy_scriptum"
|
||||
|
||||
[preprocessor.keeper]
|
||||
command = "mdbook-keeper"
|
||||
manifest_dir = "../"
|
||||
externs = ["bevy", "bevy_scriptum"]
|
||||
build_features = ["lua", "rhai"]
|
||||
|
|
|
|||
0
book/src/lib.rs
Normal file
0
book/src/lib.rs
Normal file
|
|
@ -2,7 +2,10 @@
|
|||
|
||||
It is possible to split the definition of your callback functions up over multiple plugins. This enables you to split up your code by subject and keep the main initialization light and clean.
|
||||
This can be accomplished by using `add_scripting_api`. Be careful though, `add_scripting` has to be called before adding plugins.
|
||||
```rust
|
||||
```rust,no_run
|
||||
# extern crate bevy;
|
||||
# extern crate bevy_scriptum;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::prelude::*;
|
||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
|
|
|
|||
|
|
@ -20,14 +20,17 @@ bevy_scriptum provides following types that can be used in Lua:
|
|||
|
||||
### Example Lua usage
|
||||
|
||||
```
|
||||
```lua
|
||||
my_vec = Vec3(1, 2, 3)
|
||||
set_translation(entity, my_vec)
|
||||
```
|
||||
|
||||
### Example Rust usage
|
||||
|
||||
```rust
|
||||
```rust,no_run
|
||||
# extern crate bevy;
|
||||
# extern crate bevy_scriptum;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::prelude::*;
|
||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
|
|
@ -69,7 +72,10 @@ pass_to_rust(entity)
|
|||
|
||||
### Example Rust usage
|
||||
|
||||
```rust
|
||||
```rust,no_run
|
||||
# extern crate bevy;
|
||||
# extern crate bevy_scriptum;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::prelude::*;
|
||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,11 @@ That allows you to do anything you would do in a Bevy system.
|
|||
You could for example create a callback system function that prints names
|
||||
of all entities with `Player` component.
|
||||
|
||||
```rust
|
||||
```rust,no_run
|
||||
# extern crate bevy;
|
||||
# extern crate bevy_ecs;
|
||||
# extern crate bevy_scriptum;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::prelude::*;
|
||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
|
|
@ -42,7 +46,11 @@ You can use functions that interact with Bevy entities and resources and
|
|||
take arguments at the same time. It could be used for example to mutate a
|
||||
component.
|
||||
|
||||
```rust
|
||||
```rust,no_run
|
||||
# extern crate bevy;
|
||||
# extern crate bevy_ecs;
|
||||
# extern crate bevy_scriptum;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::prelude::*;
|
||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
|
|
@ -59,7 +67,7 @@ fn main() {
|
|||
runtime.add_function(
|
||||
String::from("hurt_player"),
|
||||
|In((hit_value,)): In<(i32,)>, mut players: Query<&mut Player>| {
|
||||
let mut player = players.single_mut();
|
||||
let mut player = players.single_mut().unwrap();
|
||||
player.health -= hit_value;
|
||||
},
|
||||
);
|
||||
|
|
|
|||
1
book/src/ruby/ruby.md
Normal file
1
book/src/ruby/ruby.md
Normal file
|
|
@ -0,0 +1 @@
|
|||
# Ruby
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
To enable live reload it should be enough to enable `file-watcher` feature
|
||||
within bevy dependency in `Cargo.toml`
|
||||
|
||||
```
|
||||
```toml
|
||||
bevy = { version = "0.16", features = ["file_watcher"] }
|
||||
```
|
||||
|
||||
|
|
@ -53,6 +53,9 @@ init()
|
|||
The function calls can be implemented on Rust side the following way:
|
||||
|
||||
```rust
|
||||
# extern crate bevy;
|
||||
# extern crate bevy_scriptum;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::prelude::*;
|
||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
|
|
@ -98,7 +101,10 @@ fn main() {}
|
|||
|
||||
And to tie this all together we do the following:
|
||||
|
||||
```rust
|
||||
```rust,no_run
|
||||
# extern crate bevy;
|
||||
# extern crate bevy_scriptum;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::prelude::*;
|
||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
|
|
@ -126,6 +132,9 @@ fn spawn_player() {} // Implemented elsewhere
|
|||
`despawn` can be implemented as:
|
||||
|
||||
```rust
|
||||
# extern crate bevy;
|
||||
# extern crate bevy_scriptum;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
|
||||
|
|
|
|||
3
book/test.sh
Executable file
3
book/test.sh
Executable file
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
CARGO_MANIFEST_DIR=$(pwd) cargo clean && cargo build && mdbook test -L target/debug/deps/
|
||||
Loading…
Reference in a new issue