Giter Site home page Giter Site logo

bevy_common_assets's Introduction

Bevy common assets

crates.io docs license crates.io

Collection of Bevy plugins offering generic asset loaders for common file formats.

Supported formats:

format feature example
json json json.rs
msgpack msgpack msgpack.rs
postcard postcard postcard.rs
ron ron ron.rs
toml toml toml.rs
xml xml xml.rs
yaml yaml yaml.rs
csv csv csv.rs

Usage

Enable the feature(s) for the format(s) that you want to use.

Define the types that you would like to load from files and derive serde::Deserialize, bevy::reflect::TypePath, and bevy::asset::Asset for them.

#[derive(serde::Deserialize, bevy::asset::Asset, bevy::reflect::TypePath)]
struct Level {
    positions: Vec<[f32;3]>,
}

With the types ready, you can start adding asset plugins. Every plugin gets the asset type that it is supposed to load as a generic parameter. You can also configure custom file endings for each plugin:

use bevy::prelude::*;
use bevy_common_assets::json::JsonAssetPlugin;
use bevy_common_assets::msgpack::MsgPackAssetPlugin;
use bevy_common_assets::postcard::PostcardAssetPlugin;
use bevy_common_assets::ron::RonAssetPlugin;
use bevy_common_assets::toml::TomlAssetPlugin;
use bevy_common_assets::xml::XmlAssetPlugin;
use bevy_common_assets::yaml::YamlAssetPlugin;

fn main() {
    App::new()
        .add_plugins((
            DefaultPlugins,
            JsonAssetPlugin::<Level>::new(&["level.json", "custom.json"]),
            RonAssetPlugin::<Level>::new(&["level.ron"]),
            MsgPackAssetPlugin::<Level>::new(&["level.msgpack"]),
            PostcardAssetPlugin::<Level>::new(&["level.postcard"]),
            TomlAssetPlugin::<Level>::new(&["level.toml"]),
            XmlAssetPlugin::<Level>::new(&["level.xml"]),
            YamlAssetPlugin::<Level>::new(&["level.yaml"])
        ))
        // ...
        .run();
}

#[derive(serde::Deserialize, bevy::asset::Asset, bevy::reflect::TypePath)]
struct Level {
    positions: Vec<[f32; 3]>,
}

The example above will load Level structs from json files ending on .level.json or .custom.json, from ron files ending on .level.ron and so on...

See the examples for working Bevy apps using the different formats.

Compatible Bevy versions

The main branch is compatible with the latest Bevy release.

Compatibility of bevy_common_assets versions:

bevy_common_assets bevy
0.10 0.13
0.8 - 0.9 0.12
0.7 0.11
0.5 - 0.6 0.10
0.4 0.9
0.3 0.8
0.1 - 0.2 0.7
main 0.13
bevy_main main

License

Dual-licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

bevy_common_assets's People

Contributors

niklasei avatar seldom-se avatar boylede avatar jredow avatar striezel avatar eerii avatar sardap avatar

Stargazers

ℤiλ∀ avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.