move all music data to struct, save this data now
This commit is contained in:
68
src/utils.rs
68
src/utils.rs
@@ -1,5 +1,8 @@
|
||||
use crate::Polygon;
|
||||
use iced::Color;
|
||||
|
||||
use kira::{
|
||||
AudioManager, AudioManagerSettings, DefaultBackend, sound::static_sound::StaticSoundData,
|
||||
};
|
||||
pub fn string_to_color<S: AsRef<str>>(s: S) -> Color {
|
||||
match s.as_ref() {
|
||||
"Green" => Color::from_rgb(0.0, 1.0, 0.0),
|
||||
@@ -10,3 +13,66 @@ pub fn string_to_color<S: AsRef<str>>(s: S) -> Color {
|
||||
_ => Color::BLACK,
|
||||
}
|
||||
}
|
||||
pub fn string_to_polygon<S: AsRef<str>>(str: S) -> Polygon {
|
||||
let s = str.as_ref();
|
||||
let mut poly: Polygon;
|
||||
if s.starts_with("Ngon") {
|
||||
if let Ok(sides) = s.trim_start_matches("Ngon").parse::<u8>() {
|
||||
return Polygon::n_gon(0.0, sides, dummy_sound());
|
||||
} else {
|
||||
return Polygon::n_gon(0.0, 0, dummy_sound());
|
||||
}
|
||||
} else {
|
||||
match s {
|
||||
"Segment" => {
|
||||
poly = Polygon::segment(0.0, dummy_sound());
|
||||
poly.name = "Segment".to_string();
|
||||
}
|
||||
"Triangle" => {
|
||||
poly = Polygon::triangle(0.0, dummy_sound());
|
||||
poly.name = "Triangle".to_string();
|
||||
}
|
||||
"Square" => {
|
||||
poly = Polygon::square(0.0, dummy_sound());
|
||||
poly.name = "Square".to_string();
|
||||
}
|
||||
"Nr6In30" => {
|
||||
poly = Polygon::nr_6_in_30(0.0, dummy_sound());
|
||||
poly.name = "Nr6In30".to_string();
|
||||
}
|
||||
"Nr7In30" => {
|
||||
poly = Polygon::nr_7_in_30(0.0, dummy_sound());
|
||||
poly.name = "Nr7In30".to_string();
|
||||
}
|
||||
"Nr8In30" => {
|
||||
poly = Polygon::nr_8_in_30(0.0, dummy_sound());
|
||||
poly.name = "Nr8In30".to_string();
|
||||
}
|
||||
"Nr9In30" => {
|
||||
poly = Polygon::nr_9_in_30(0.0, dummy_sound());
|
||||
poly.name = "Nr9In30".to_string();
|
||||
}
|
||||
"Nr8In42" => {
|
||||
poly = Polygon::nr_8_in_42(0.0, dummy_sound());
|
||||
poly.name = "Nr8In42".to_string();
|
||||
}
|
||||
"Nr9In42" => {
|
||||
poly = Polygon::nr_9_in_42(0.0, dummy_sound());
|
||||
poly.name = "Nr9In42".to_string();
|
||||
}
|
||||
"Nr10aIn42" => {
|
||||
poly = Polygon::nr_10a_in_42(0.0, dummy_sound());
|
||||
poly.name = "Nr10aIn42".to_string();
|
||||
}
|
||||
"Nr10bIn42" => {
|
||||
poly = Polygon::nr_10b_in_42(0.0, dummy_sound());
|
||||
poly.name = "Nr10bIn42".to_string();
|
||||
}
|
||||
_ => poly = Polygon::n_gon(0.0, 0, dummy_sound()),
|
||||
}
|
||||
poly
|
||||
}
|
||||
}
|
||||
fn dummy_sound() -> StaticSoundData {
|
||||
StaticSoundData::from_file("assets/tick.ogg").expect("Fail to load audio")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user