#default #bevy-ecs #impl #bundle #fields #macro #ldtk

yanked bevy_ecs_ldtk_default

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

1 unstable release

0.1.1 Aug 18, 2023
0.1.0 Aug 18, 2023

#15 in #ldtk

MIT/Apache

7KB

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.
    }
}

Dependencies

~220–660KB
~16K SLoC