Skip to content

Commit

Permalink
refactor(utils/codename): use hashmap
Browse files Browse the repository at this point in the history
  • Loading branch information
kwaa committed Jul 16, 2024
1 parent bc2b5d9 commit 9cca570
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions crates/utils/src/codename.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
use std::collections::HashMap;

use crate::VERSION;

/// https://github.com/importantimport/hatsu/milestones
pub fn codename() -> &'static str {
match String::from(VERSION) {
v if v.starts_with("0.1") => "01_ballade",
v if v.starts_with("0.2") => "celluloid",
v if v.starts_with("0.3") => "Strobe Nights",
v if v.starts_with("0.4") => "Clover Club",
v if v.starts_with("0.5") => "Sakura No Kisetsu",
v if v.starts_with("0.6") => "World Is Mine",
v if v.starts_with("0.7") => "Nisoku Hokou",
v if v.starts_with("0.8") => "Sweet Devil",
v if v.starts_with("0.9") => "Unfragment",
v if v.starts_with("1.0") => "Hoshi No Kakera",
// easter egg
_ => "Cat Food",
}
let version = String::from(VERSION);
let hashmap: HashMap<&str, &str> = HashMap::from([
("0.1", "01_ballade"),
("0.2", "celluloid"),
("0.3", "Strobe Nights"),
("0.4", "Clover Club"),
("0.5", "Sakura No Kisetsu"),
("0.6", "World Is Mine"),
("0.7", "Nisoku Hokou"),
("0.8", "Sweet Devil"),
("0.9", "Unfragment"),
("1.0", "Hoshi No Kakera"),
]);

hashmap
.iter()
.find(|(major_minor, _)| version.starts_with(*major_minor))
.map_or("Cat Food", |(_, codename)| codename)
}

0 comments on commit 9cca570

Please sign in to comment.