diff --git a/dash-frontend/src/tab/home.rs b/dash-frontend/src/tab/home.rs index abc9f0e0..c71a8c2d 100644 --- a/dash-frontend/src/tab/home.rs +++ b/dash-frontend/src/tab/home.rs @@ -39,7 +39,13 @@ fn get_supporter_anim( prev_supporter_name: String, ) -> Animation { let username = loop { - let random_supporter = &supporters.supporters[rand::random_range(0..supporters.supporters.len() - 1)]; + let total_tickets: u32 = supporters.supporters.iter().map(|s| s.tickets()).sum(); + let jackpot = rand::random_range(0..total_tickets); + let mut cumulative = 0u32; + let random_supporter = supporters.supporters.iter().find(|s| { + cumulative += s.tickets(); + cumulative >= jackpot + }).unwrap(); let username = random_supporter.username.clone(); if username != prev_supporter_name { break username; diff --git a/dash-frontend/src/util/cached_fetcher.rs b/dash-frontend/src/util/cached_fetcher.rs index 27fda485..f2a3c1e2 100644 --- a/dash-frontend/src/util/cached_fetcher.rs +++ b/dash-frontend/src/util/cached_fetcher.rs @@ -24,7 +24,7 @@ impl SupporterTier { format!("{self:?} Tier") } - pub fn color_str(self) -> &'static str { + pub const fn color_str(self) -> &'static str { match self { Self::Platinum => "#aaffff", Self::Gold => "#ffffaa", @@ -32,6 +32,15 @@ impl SupporterTier { Self::Bronze => "#ffaa66", } } + + pub const fn tickets(self) -> u32 { + match self { + Self::Platinum => 20, + Self::Gold => 10, + Self::Silver => 5, + Self::Bronze => 1, + } + } } #[derive(Serialize, Deserialize)] @@ -42,6 +51,12 @@ pub struct Supporter { pub contribution_count: u32, } +impl Supporter { + pub const fn tickets(&self) -> u32 { + self.tier.tickets() + } +} + #[derive(Serialize, Deserialize)] pub struct Supporters { pub time_window_days: u32,