DEVELOPMENT ENVIRONMENT

~liljamo/bevy_dice

6de3acbc21c30f11a38ed6fbca70745fbaaeb280 — Jonni Liljamo 2 days ago 3a7fc24
feat: die scaling
2 files changed, 14 insertions(+), 1 deletions(-)

M crates/bevy_dice/src/lib.rs
M crates/bevy_dice_demo/src/main.rs
M crates/bevy_dice/src/lib.rs => crates/bevy_dice/src/lib.rs +8 -1
@@ 53,6 53,8 @@ pub struct DicePluginConfig {
    ///
    /// Can also be used to just override the values of faces.
    pub override_face_positions: HashMap<DieVariant, HashMap<u8, u8>>,
    /// Scale overrides, used to size the dice.
    pub override_scales: HashMap<DieVariant, f32>,
}

#[derive(Reflect, Debug, Clone, Copy, PartialEq, Eq, Hash)]


@@ 147,6 149,11 @@ fn throw_die(
        None => Quat::default(),
    };

    let scale = match r_config.override_scales.get(&trigger.variant) {
        Some(scale) => Vec3::splat(*scale),
        None => Vec3::splat(1.0),
    };

    let mut die = commands.spawn((
        Visibility::Inherited,
        // Place the mesh in a child to allow correcting the rotation.


@@ 163,7 170,7 @@ fn throw_die(
            rotation: trigger
                .rotation
                .unwrap_or_else(|| Quat::from_rng(rng.as_mut())),
            ..Default::default()
            scale,
        },
        RigidBody::Dynamic,
        Collider::convex_hull_from_mesh(mesh).unwrap(),

M crates/bevy_dice_demo/src/main.rs => crates/bevy_dice_demo/src/main.rs +6 -0
@@ 159,6 159,12 @@ fn setup(
                (100, 100),
            ]),
        )]),
        override_scales: HashMap::from([
            (DieVariant::D10, 0.8),
            (DieVariant::D10P, 0.8),
            (DieVariant::D12, 0.8),
            (DieVariant::D20, 0.8),
        ]),
    });
}