Expand description
Oxeon: a Rust-like scripting language for modding Bevy games.
Mods are .ox files loaded through Bevy’s asset system, compiled to
WebAssembly and run sandboxed in Wasmtime. Their systems use Bevy’s own
ECS: the game decides which components mods may see, and mod systems run
on the game’s schedule.
use bevy_app::{App, Startup, TaskPoolPlugin};
use bevy_asset::{AssetPlugin, AssetServer};
use bevy_ecs::prelude::*;
use bevy_reflect::Reflect;
use bevy_time::TimePlugin;
use oxeon::prelude::*;
#[derive(Component, Reflect)]
#[reflect(Component)]
struct Health(f32);
fn load_mods(mut commands: Commands, assets: Res<AssetServer>) {
commands.spawn(OxeonMod(assets.load("mods/regen.ox")));
}
App::new()
.add_plugins((TaskPoolPlugin::default(), TimePlugin, AssetPlugin::default()))
.add_plugins(OxeonPlugin::default())
.expose_to_mods::<Health>()
.add_systems(Startup, load_mods)
.run();A mod can then use Health like its own type:
fn heal(time: Res<Time>, mut q: Query<&mut Health>) {
for mut hp in &mut q {
hp.0 += 1.0 * time.delta_secs();
}
}
pub fn plugin(app: &mut App) {
app.add_systems(Update, heal);
}Status: early development. Mod systems can use Res/ResMut of
exposed resources, Commands (spawn, insert, despawn),
MessageReader/MessageWriter (the game’s messages and their own), and
Querys over exposed components and components the mod defines, with
Entity and With, Without, Changed and Added filters, and run in
Startup and Update. Fields must be numbers, bool, char, or
structs of those, such as Transform.
Modules§
Structs§
- Load
ModSource - Adds a mod from its source text, not a file: for editors and playgrounds that hold the source themselves. A mod with the same name is replaced, which recompiles it the way a hot reload does: if the new source doesn’t compile, the previous version keeps running.
- ModLog
- A message a mod logged with
info!,println!and the like. It’s also written to Bevy’s log (println!at the info level,eprintln!at the error level), prefixed with the mod’s name. - Oxeon
Bindings - The declarations mods are compiled with, and the types behind them.
- Oxeon
Mod - Marks an entity as an Oxeon mod, backed by a
.oxsource asset. Keeping the handle keeps the mod loaded. - Oxeon
Plugin - Adds Oxeon mods to a Bevy app. Requires Bevy’s
AssetPlugin, and itsTimePluginfor mods that useRes<Time>. - Oxeon
Runtime - The shared Wasmtime engine used for every mod.
- Oxeon
Source - A
.oxsource file. It’s compiled once loaded, together with the game’s bindings (seeOxeonBindings). - Oxeon
Source Loader - Loads
.oxfiles. Bevy’s file watcher (thehot-reloadfeature) reloads them on change, and the plugin recompiles them. - Unload
Mod - Removes a mod added with
LoadModSource.
Enums§
- LogLevel
- Which macro logged a message.
- ModReport
- What happened to a mod, for showing it to whoever wrote it. A mod is named by its asset path, or by the name it was loaded with.
Traits§
- Oxeon
AppExt - Lets a game choose which of its types mods can use.