bevywasmscripting

Adds support for wasm/wat assets in Bevy, and enables easy scripting. This is enabled through the wasmer crate.

Examples

For component-based scripts: ```rust fn main() { App::new() ... .addplugin(WasmPlugin) .addwasmscriptcomponent::() .addstartupsystem(spawnscriptentity) .addsystem(callscriptonentity) ... }

impl WasmScriptComponent for AdderScript { type ImportQueriedComponents = (); type ImportResources = (); fn getwasmscript_handle(&self) -> &Handle { &self.handle } }

fn spawnscriptentity(mut commands: Commands, assetserver: Res) { commands.spawn(AdderScript { handle: assetserver.load("add_one.wat"), accumulator: 0, }); }

// fn callscriptonentity( mut scriptedentities: Query<&mut AdderScript>, mut scriptenv: WasmScriptComponentEnv, ) { for mut scriptedentity in scriptedentities.itermut() { if let Ok(newval) = scriptenv.callifinstantiated( &scriptedentity.handle, "main", scriptedentity.accumulator, ) { scriptedentity.accumulator = newval; } println!("Accumulated value: {}", scripted_entity.accumulator); } } ```

More examples, for hot reloading, resource-based scripts, and script imports, are available in the examples directory.

Web Build Example

You can run the breakout example, very similar to the bevy examples: sh cargo build --release --example breakout --target wasm32-unknown-unknown --features js --no-default-features wasm-bindgen --out-name wasm_example --out-dir examples/wasm/target --target web target/wasm32-unknown-unknown/release/examples/breakout.wasm basic-http-server examples/wasm