#macros #micro #game #bevy #derive #assets #games

macro micro_games_macros

Utility macros to make it easier to build complex systems with Bevy

4 releases

new 0.3.1 Feb 24, 2024
0.3.0 Nov 19, 2023
0.1.1 Oct 22, 2023
0.1.0 Oct 22, 2023

#318 in Procedural macros

Download history 1/week @ 2023-11-02 2/week @ 2023-11-09 32/week @ 2023-11-16 10/week @ 2023-11-23 10/week @ 2023-11-30 2/week @ 2023-12-07 3/week @ 2023-12-14 6/week @ 2023-12-21 3/week @ 2023-12-28 1/week @ 2024-01-11 1/week @ 2024-01-18 3/week @ 2024-01-25 3/week @ 2024-02-01 4/week @ 2024-02-08 46/week @ 2024-02-15

57 downloads per month

Apache-2.0

45KB
930 lines

Micro Game Macros

docs.rs Crates.io

A collection of utility macros for building games

Current Version Support: 0.2.x -> Bevy 0.12

Macros

For executable examples, visit the rustdoc and/or read the doctests in src/lib.rs

JSON Loader

Generate a Bevy asset loader for a given asset, supporting JSON files that define a single instance of that asset type, or a list of that asset type. Instances of an asset need to be identifiable, though the property that is used to identify a particular asset is customisable

#[derive(JsonLoader, TypePath, TypeUuid, Serialize, Deserialize, Asset)]
#[loader(
    extension = "asset.json", uuid = "00000000-0000-0000-0000-000000000000",
    storage = inner_module::SimpleAssetLocator,
    asset_name = some_asset_prop, index_name = set_of_assets
)]
#[uuid = "00000000-0000-0000-0000-000000000001"]
pub struct MyAsset {
  /// The asset identifier needs to implement [std::fmt::Display]
  #[asset_id]
  uniq_ident: usize,
}

Asset System

Generate a set of structs and systems for managed loading in a Bevy game

use bevy::prelude::{Image, Res, Resource};
use micro_games_macros::asset_system;

#[asset_system]
pub struct AssetHandles {
  my_asset: Image,
}

pub fn loading_system(mut loader: AssetHandlesLoader) {
  loader.load_my_asset("path/to/asset.png", "Asset");
}
pub fn use_asset_system(assets: Res<AssetHandles>) {
  let handle = assets.my_asset("Asset");
}

From Inner

Derive an impl of From<T> for structs that wrap a single inner type (Tuple and Named Property structs are supported)

use micro_game_macros::FromInner;

#[derive(FromInner)]
struct MyType(usize);

fn example() {
    let value = MyType::from(123usize);
}

Kayak Widget

A simple derive for Kayak UI's "Widget" trait

use micro_game_macros::Widget;

#[derive(Widget)]
struct MyComponent;

// ... Other Kayak Setup ...

Dependencies

~325–770KB
~18K SLoC