Replace tiers with achievements

This commit is contained in:
2026-05-21 19:17:58 +03:00
parent 4765917be4
commit a6741da14c
4 changed files with 139 additions and 192 deletions

View File

@@ -15,37 +15,47 @@ pub mod l02_kv;
use serde::{Deserialize, Serialize};
/// Game-wide difficulty. Chosen once on the TierSelect screen; persisted
/// in `Progress.tier`. Maps to a fixed passing threshold per level.
/// Awarded per level based on the grade score. Replaces the old
/// game-wide difficulty tier. Thresholds:
/// - Gold ≥ 95 %
/// - Silver ≥ 80 %
/// - Bronze ≥ 70 %
/// - Below 70 % → no nugget (retry).
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub enum Difficulty {
Easy,
Medium,
Hard,
pub enum Nugget {
Bronze,
Silver,
Gold,
}
impl Difficulty {
pub fn threshold(self) -> f64 {
match self {
Self::Easy => 0.70,
Self::Medium => 0.80,
Self::Hard => 0.95,
impl Nugget {
/// Map a grade ratio (0.0..=1.0) to a nugget. `None` means the
/// player didn't clear the level — retry without advancing.
pub fn from_score(score: f64) -> Option<Self> {
if score >= 0.95 {
Some(Nugget::Gold)
} else if score >= 0.80 {
Some(Nugget::Silver)
} else if score >= 0.70 {
Some(Nugget::Bronze)
} else {
None
}
}
pub fn label(self) -> &'static str {
pub fn emoji(self) -> &'static str {
match self {
Self::Easy => "Easy (70%)",
Self::Medium => "Medium (80%)",
Self::Hard => "Hard (95%)",
Self::Bronze => "🥉",
Self::Silver => "🥈",
Self::Gold => "🥇",
}
}
pub fn name(self) -> &'static str {
match self {
Self::Easy => "Easy",
Self::Medium => "Medium",
Self::Hard => "Hard",
Self::Bronze => "Bronze",
Self::Silver => "Silver",
Self::Gold => "Gold",
}
}
}