From 345b383089e8bf2142969771ac3f97d8e9673462 Mon Sep 17 00:00:00 2001 From: PhantomMorrigan Date: Sat, 15 Nov 2025 19:23:51 +0100 Subject: [PATCH] leaderboard worst, and color based pretification --- src/leaderbord.rs | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/src/leaderbord.rs b/src/leaderbord.rs index 4d68a99..3ee94b6 100644 --- a/src/leaderbord.rs +++ b/src/leaderbord.rs @@ -5,13 +5,17 @@ use crate::BerriesEaten; #[derive(Component)] pub struct LeaderBoard; +#[derive(Component)] +pub struct Lowest; + pub fn setup(mut commands: Commands) { let id = commands .spawn(( children![Text::new("Ghost Leaderboard")], Node { position_type: PositionType::Absolute, - top: px(5), + top: px(10), + left: px(10), flex_direction: FlexDirection::Column, ..default() }, @@ -29,10 +33,21 @@ pub fn setup(mut commands: Commands) { )) .id(); - for _ in 0..10 { + commands.spawn(( + Text::new("Waiting for ghosts..."), + TextFont::from_font_size(17.5), + TextColor(Color::oklch(0.7, 0.2, 0.0)), + Lowest, + ChildOf(id), + )); + + for n in 0..10 { + let color = Color::oklch(0.7, 0.2, 90.0.lerp(135.0, (10 - n) as f32 / 10.0)); + commands.spawn(( Text::new("Waiting for ghosts..."), TextFont::from_font_size(17.5), + TextColor(color), ChildOf(list), )); } @@ -40,13 +55,15 @@ pub fn setup(mut commands: Commands) { pub fn update_leaderboard( board: Single<&Children, With>, - mut texts: Query<&mut Text>, + mut lowest: Single<&mut Text, With>, + mut texts: Query<&mut Text, Without>, ghosts: Query<(Entity, &BerriesEaten)>, ) { ghosts .iter() .sort_by_key::<(Entity, &BerriesEaten), usize>(|(_, e)| e.0) - .zip(board.iter().rev()) + .rev() + .zip(board.iter()) .for_each(|((ghost, eaten), text)| { texts.get_mut(text).unwrap().0 = format!( "Ghost {:>5} has eaten {} berries!", @@ -54,4 +71,16 @@ pub fn update_leaderboard( eaten.0 ); }); + + let low = ghosts + .iter() + .sort_by_key::<(Entity, &BerriesEaten), usize>(|(_, e)| e.0) + .next() + .unwrap(); + + lowest.0 = format!( + "Ghost {:>5} has eaten {} berries!", + low.0.to_string(), + low.1.0 + ); } -- 2.51.2