From 57e8caa1b76043f142d271f581c300dee5941a2d Mon Sep 17 00:00:00 2001 From: "Elijah C. Voigt" Date: Sun, 9 Jun 2024 23:00:14 -0700 Subject: [PATCH] Multiple dice, but text below mesh... --- src/game/dice.rs | 50 +++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/src/game/dice.rs b/src/game/dice.rs index 707ef92..dd5daf2 100644 --- a/src/game/dice.rs +++ b/src/game/dice.rs @@ -72,28 +72,34 @@ fn init_dice( mut materials: ResMut>, mut commands: Commands ) { - commands.spawn(( - GameChoice::Dice, MenuState::Closed, - Die::new(["a", "b", "c", "d", "e", "f"]), - PickableBundle { ..default() }, - On::>::target_component_mut::(|m, transform| { - transform.translation.x += m.delta.x; - transform.translation.y -= m.delta.y; - }) - )).insert(Text2dBundle { - text: Text::from_section( - "", - TextStyle { - color: Color::BLACK, - font_size: 32.0, - ..default() - }, - ), - ..default() - }).insert(MaterialMesh2dBundle { - mesh: meshes.add(Rectangle { half_size: Vec2::splat(32.0) }).into(), - material: materials.add(Color::PINK), - ..default() + [ + ["a", "b", "c", "d", "e", "f"], + ["g", "h", "i", "j", "k", "l"], + ["m", "n", "o", "p", "q", "r"], + ].into_iter().enumerate().for_each(|(idx, set)| { + commands.spawn(( + GameChoice::Dice, MenuState::Closed, + Die::new(set), + PickableBundle { ..default() }, + On::>::target_component_mut::(|m, transform| { + transform.translation.x += m.delta.x; + transform.translation.y -= m.delta.y; + }) + )).insert(MaterialMesh2dBundle { + mesh: meshes.add(Rectangle { half_size: Vec2::splat(32.0) }).into(), + material: materials.add(Color::PINK), + ..default() + }).insert(Text2dBundle { + text: Text::from_section( + "", + TextStyle { + color: Color::BLACK, + font_size: 32.0, + ..default() + }, + ), + ..default() + }).insert(Transform::from_xyz(idx as f32 * 100.0, 100.0, 0.0)); }); }