bevy_ecs_ldtk_default

Crates.iobevy_ecs_ldtk_default
lib.rsbevy_ecs_ldtk_default
version0.1.1
sourcesrc
created_at2023-08-18 11:27:08.544928
updated_at2023-08-18 11:34:16.95278
descriptionDerive macros for bevy_ecs_ldtk that use bundle's Default impl instead of it's fields'.
homepagehttps://lib.rs/bevy_ecs_ldtk_default
repositoryhttps://github.com/elenakrittik/tartarus/tree/master/crates/bevy_ecs_ldtk_default
max_upload_size
id947790
size17,833
lena (elenakrittik)

documentation

https://docs.rs/bevy_ecs_ldtk_default

README

bevy_ecs_ldtk_default

Derive macros for bevy_ecs_ldtk that use bundle's Default impl instead of it's fields'.

Usage

use bevy::prelude::*;
use bevy_rapier2d::prelude::*;
use bevy_ecs_ldtk::prelude::*;
use bevy_ecs_ldtk_default::*;

// Derive LdtkEntityDefault or LdtkIntCellDefault to make
// `bevy_ecs_ldtk` make use of your bundle's `Default` `impl`,
// instead of individual `Default` `impl`s of each of it's fields.

#[derive(Bundle, LdtkEntityDefault)]
pub struct PlayerBundle {
    rigid_body: RigidBody,
}

impl Default for PlayerBundle {
    fn default() -> Self {
        // `PlayerBundle` now will spawn with kinematic rigid body.
        Self { rigid_body: RigidBody::KinematicPositionBased }

        // If we would've not used `LdtkEntityDefault` along with
        // this `impl Default`, our `PlayerBundle` would've spawned
        // with `rigid_body: RigidBody::Dynamic` (since that's what
        // `impl Default` of `RigidBody` provides) instead, which is
        // undesired.
    }
}
Commit count: 0

cargo fmt