openstranded_common_wasmcontract/contributions.rs
1/// Declarative interface from WASM plugin to Host.
2///
3/// A WASM plugin's `plugin_build()` returns a list of `Contribution`s
4/// describing what the plugin wants to add to the Bevy App. The Host
5/// applies these contributions after collecting them from all plugins.
6///
7/// The plugin never receives `&mut App` directly.
8#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
9pub enum Contribution {
10 /// Add a system to a Bevy schedule.
11 System(SystemDecl),
12
13 /// Add a resource with a default value.
14 Resource(ResourceDecl),
15
16 /// Add a known Bevy Plugin (referenced by name).
17 Plugin(String),
18
19 /// Reserve a service domain (prevents conflicts).
20 ServiceDomain(String),
21}
22
23/// Describes a system to be added to a Bevy schedule.
24///
25/// The actual system function lives in the WASM plugin and is called
26/// through the host bridge at runtime.
27#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
28pub struct SystemDecl {
29 /// Schedule label (e.g. "Update", "`FixedUpdate`", "Startup").
30 pub schedule: String,
31 /// Human-readable system name for logging / debugging.
32 pub name: String,
33}
34
35/// Describes a resource to be registered in the Bevy World.
36#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
37pub struct ResourceDecl {
38 /// Type name for dynamic registration (`TypeId` is unstable across WASM).
39 pub type_name: String,
40 /// Serialised default value (bincode / postcard).
41 pub default_value: Vec<u8>,
42}