add color picker and better buttons

This commit is contained in:
2025-07-10 15:07:52 +02:00
parent 984cec5741
commit 607cf17888
7 changed files with 314 additions and 241 deletions

View File

@@ -2,6 +2,7 @@
name = "polygomusic" name = "polygomusic"
version = "0.1.0" version = "0.1.0"
edition = "2024" edition = "2024"
build = "build.rs"
[dependencies] [dependencies]
iced = { version = "0.13.1", features = ["canvas", "tokio"] } iced = { version = "0.13.1", features = ["canvas", "tokio"] }

39
build.rs Normal file
View File

@@ -0,0 +1,39 @@
use std::env;
use std::fs;
use std::path::Path;
fn main() {
println!("cargo:rerun-if-changed=assets");
println!("cargo:rerun-if-changed=fonts");
// Chemin vers target/debug ou target/release
let out_dir = env::var("OUT_DIR").unwrap();
let target_dir = Path::new(&out_dir)
.ancestors()
.nth(3) // On remonte pour arriver dans target/debug ou target/release
.unwrap();
// Copie assets/
let _ = fs::remove_dir_all(target_dir.join("assets"));
fs::create_dir_all(target_dir.join("assets")).unwrap();
copy_dir("assets", target_dir.join("assets"));
// Copie fonts/
let _ = fs::remove_dir_all(target_dir.join("fonts"));
fs::create_dir_all(target_dir.join("fonts")).unwrap();
copy_dir("fonts", target_dir.join("fonts"));
}
fn copy_dir(src: impl AsRef<Path>, dst: impl AsRef<Path>) {
for entry in fs::read_dir(src).unwrap() {
let entry = entry.unwrap();
let ty = entry.file_type().unwrap();
let dst_path = dst.as_ref().join(entry.file_name());
if ty.is_dir() {
fs::create_dir_all(&dst_path).unwrap();
copy_dir(entry.path(), &dst_path);
} else {
fs::copy(entry.path(), &dst_path).unwrap();
}
}
}

View File

@@ -13,11 +13,12 @@ use utils::{is_delta_format_valid, str_to_sec};
use std::fs; use std::fs;
use iced::widget::{TextInput, column, text}; use iced::widget::{TextInput, column, text};
use iced::{Application, Element, Font, font}; use iced::{Application, Element, Font, Subscription, font};
use iced::{ use iced::{
Color, Length, Task, Theme, Color, Length, Task, Theme,
widget::{Column, button, canvas, container, pick_list, row, scrollable, slider}, widget::{Column, button, canvas, container, pick_list, row, scrollable, slider},
}; };
use iced_aw::widget::{ColorPicker, color_picker};
use std::f32::consts::PI; use std::f32::consts::PI;
use std::time::Instant; use std::time::Instant;
@@ -50,6 +51,7 @@ fn main() -> iced::Result {
}; };
iced::application("My App", MyApp::update, MyApp::view) iced::application("My App", MyApp::update, MyApp::view)
.theme(move |_| polytheme.clone()) .theme(move |_| polytheme.clone())
.font(iced_fonts::REQUIRED_FONT_BYTES)
.font(FONT_BYTES) .font(FONT_BYTES)
.default_font(FONT) .default_font(FONT)
.antialiasing(true) .antialiasing(true)
@@ -119,14 +121,12 @@ impl MyApp {
} }
} }
Message::Remove(i) => { Message::Remove(i) => {
self.music.remove_polygon(self.current_delta, i - 1); self.music.remove_polygon(self.current_delta, i);
} }
Message::ChangeTeta(i, teta) => { Message::ChangeTeta(i, teta) => {
self.music.set_teta(self.current_delta, i, teta); self.music.set_teta(self.current_delta, i, teta);
} }
Message::ChangeColor(i, s) => {
self.music.set_color(self.current_delta, i, s);
}
Message::ChangeSound(i, s) => { Message::ChangeSound(i, s) => {
let sound = StaticSoundData::from_file(format!("./assets/{s}")) let sound = StaticSoundData::from_file(format!("./assets/{s}"))
.expect("Fail to load audio"); .expect("Fail to load audio");
@@ -199,16 +199,52 @@ impl MyApp {
self.music.fix_teta(self.current_delta); self.music.fix_teta(self.current_delta);
self.update_canvas_if_paused(); self.update_canvas_if_paused();
} }
Message::ChangeDegree(i, s) => {
let mut mut_s = s;
if mut_s.len() == 0 {
mut_s = "0".to_string();
}
match mut_s.parse::<f32>() {
Ok(val) => {
if val <= 360. {
self.update(Message::ChangeTeta(i, (val).to_radians()))
}
}
Err(_) => {}
}
}
Message::ChangeNbPerSec(s) => {
let mut_s = s.trim_end_matches(" rev/sec");
if mut_s.len() != s.len() {
match mut_s.parse::<f32>() {
Ok(val) => {
let val = (val * 10.).floor() / 10.;
if val >= 1. {
self.music.nb_sec_for_rev = val
}
}
Err(_) => {}
}
}
}
Message::CancelColor(i) => {
self.music.set_color_picker(self.current_delta, i, false);
self.paused = false;
}
Message::SubmitColor(i) => {
if !self.paused {
self.update(Message::TogglePaused);
}
self.music.set_color_picker(self.current_delta, i, true);
}
Message::ChooseColor(i, color) => {
self.music.set_color(self.current_delta, i, color);
self.music.set_color_picker(self.current_delta, i, false);
}
} }
} }
fn view(&self) -> iced::Element<Message> { fn view(&self) -> iced::Element<Message> {
let txt_nb_rev = if self.music.nb_sec_for_rev % 1. != 0.0 {
format!("{} sec/revolution", self.music.nb_sec_for_rev)
} else {
format!("{}.0 sec/revolution", self.music.nb_sec_for_rev)
};
let mut i = 0; let mut i = 0;
let entries = self.all_sounds.clone(); let entries = self.all_sounds.clone();
//Create all polygon options //Create all polygon options
@@ -219,30 +255,44 @@ impl MyApp {
.iter() .iter()
.map(|polygon| { .map(|polygon| {
let current_index = i; let current_index = i;
i += 1; let but = button(text("").size(20).center()).on_press(Message::SubmitColor(i));
column![ let c = column![
row![ row![
text(&polygon.name).font(FONT), text(&polygon.name).size(24),
button("Remove").on_press(Message::Remove(i)), button(text("").size(20)).on_press(Message::Remove(i)),
pick_list( color_picker(
["Black", "Blue", "Green", "Pink", "Yellow", "Cyan"] polygon.show_color_picker,
.map(|s| s.to_string()) polygon.color,
.to_vec(), but,
Some(&polygon.color_name), Message::CancelColor(i),
move |s| { Message::ChangeColor(current_index, s) } move |color| Message::ChooseColor(i, color)
), ),
pick_list(entries.clone(), Some(&polygon.sound_name), move |s| { pick_list(entries.clone(), Some(&polygon.sound_name), move |s| {
Message::ChangeSound(current_index, s) Message::ChangeSound(current_index, s)
}), })
.text_size(20),
] ]
.spacing(20), .spacing(20),
row![
TextInput::new("90", &polygon.global_teta.to_degrees().floor().to_string())
.on_input(move |new_value| Message::ChangeDegree(
current_index,
new_value
))
.width(Length::FillPortion(1)),
slider(0.0..=2.0 * PI, polygon.global_teta, move |f| { slider(0.0..=2.0 * PI, polygon.global_teta, move |f| {
Message::ChangeTeta(current_index, f) Message::ChangeTeta(current_index, f)
}) })
.step(PI / 84f32), // 84 | 4 for do PI / 4 .step(PI / 84f32) // 84 | 4 for do PI / 4
.width(Length::FillPortion(9))
.height(32),
]
.spacing(10),
] ]
.spacing(10) .spacing(10)
.into() .into();
i += 1;
c
}) })
.collect(); .collect();
let ngon_options: Vec<String> = (5..=42).map(|sides| format!("Ngon{sides}")).collect(); let ngon_options: Vec<String> = (5..=42).map(|sides| format!("Ngon{sides}")).collect();
@@ -292,12 +342,6 @@ impl MyApp {
column![ column![
text("Polymusic").size(32.0), text("Polymusic").size(32.0),
row(save_panel).spacing(20), row(save_panel).spacing(20),
row![
text(txt_nb_rev).size(20),
button("Increment").on_press(Message::ButtonPressedIncrement),
button("Decrement").on_press(Message::ButtonPressedDecrement),
]
.spacing(20),
row![ row![
container( container(
canvas(self.music.current_frame(self.current_delta)) canvas(self.music.current_frame(self.current_delta))
@@ -305,10 +349,11 @@ impl MyApp {
.width(Length::FillPortion(1)) .width(Length::FillPortion(1))
), ),
column![ column![
text("Polygon options"), text("Polygon options").size(26),
pick_list(all_options, Some("Choose polygon".to_string()), |s| { pick_list(all_options, Some("Choose polygon".to_string()), |s| {
Message::AddPolygon(s) Message::AddPolygon(s)
}), })
.text_size(18),
polygon_column, polygon_column,
] ]
.spacing(10) .spacing(10)
@@ -319,8 +364,10 @@ impl MyApp {
.spacing(20), .spacing(20),
column![ column![
row![ row![
button(text(if self.paused { "󰐊" } else { "󰏤" }).size(28)) button(text(if self.paused { "󰐊" } else { "󰏤" }).size(28).center())
.on_press(Message::TogglePaused), .on_press(Message::TogglePaused)
.width(Length::FillPortion(1)),
row![
TextInput::new("MM:SS:CS", &self.str_time) TextInput::new("MM:SS:CS", &self.str_time)
.on_input(|new_value| Message::ChangeDeltaString(new_value)) .on_input(|new_value| Message::ChangeDeltaString(new_value))
.size(28), .size(28),
@@ -328,10 +375,24 @@ impl MyApp {
TextInput::new("MM:SS:CS", &self.str_music_length) TextInput::new("MM:SS:CS", &self.str_music_length)
.on_input(|new_value| Message::LengthChange(new_value)) .on_input(|new_value| Message::LengthChange(new_value))
.size(28), .size(28),
button(text("").size(28)).on_press(Message::AddPoint), ]
button(text("").size(28)).on_press(Message::RemovePoint), .width(Length::FillPortion(10)),
button(text("").size(28)).on_press(Message::SlidePointLeft), TextInput::new("1.0", &format!("{:.1} rev/sec", &self.music.nb_sec_for_rev))
button(text("").size(28)).on_press(Message::SlidePointRight), .on_input(|new_value| Message::ChangeNbPerSec(new_value))
.size(28)
.width(Length::FillPortion(2)),
button(text("").size(28).center())
.on_press(Message::SlidePointLeft)
.width(Length::FillPortion(1)),
button(text("").size(28).center())
.on_press(Message::AddPoint)
.width(Length::FillPortion(1)),
button(text("").size(28).center())
.on_press(Message::SlidePointRight)
.width(Length::FillPortion(1)),
button(text("").size(28).center())
.on_press(Message::RemovePoint)
.width(Length::FillPortion(1)),
] ]
.spacing(20), .spacing(20),
column![ column![
@@ -356,10 +417,11 @@ impl MyApp {
} }
fn subscription(&self) -> iced::Subscription<Message> { fn subscription(&self) -> iced::Subscription<Message> {
iced::Subscription::batch([ if self.paused {
//window::events().map(|(_id, event)| Message::WindowEvent(event)), Subscription::none() // ➝ désactive toutes les subscriptions
iced::time::every(std::time::Duration::from_millis(16)).map(|_| Message::Tick), } else {
]) iced::time::every(std::time::Duration::from_millis(16)).map(|_| Message::Tick)
}
} }
fn update_canvas_if_paused(&mut self) { fn update_canvas_if_paused(&mut self) {

View File

@@ -1,12 +1,14 @@
use iced::Color;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum Message { pub enum Message {
ButtonPressedIncrement, ButtonPressedIncrement,
ButtonPressedDecrement, ButtonPressedDecrement,
ChangeNbPerSec(String),
Tick, Tick,
AddPolygon(String), AddPolygon(String),
ChangeTeta(usize, f32), ChangeTeta(usize, f32),
Remove(usize), Remove(usize),
ChangeColor(usize, String),
ChangeSound(usize, String), ChangeSound(usize, String),
ToggleSavePanel, ToggleSavePanel,
Save, Save,
@@ -21,4 +23,9 @@ pub enum Message {
ChangeDeltaString(String), ChangeDeltaString(String),
SlidePointLeft, SlidePointLeft,
SlidePointRight, SlidePointRight,
ChangeDegree(usize, String),
ChooseColor(usize, Color),
CancelColor(usize),
SubmitColor(usize),
} }

View File

@@ -17,6 +17,7 @@ use iced::widget::canvas;
use iced::widget::canvas::Stroke; use iced::widget::canvas::Stroke;
use iced::widget::canvas::Style; use iced::widget::canvas::Style;
use iced::{Color, Rectangle, Renderer, Theme}; use iced::{Color, Rectangle, Renderer, Theme};
use std::env::current_dir;
use std::f32::consts::PI; use std::f32::consts::PI;
use std::mem::swap; use std::mem::swap;
use std::time::Duration; use std::time::Duration;
@@ -125,10 +126,14 @@ impl Music {
self.find_poly_frame(delta).polygons[index].global_teta = teta; self.find_poly_frame(delta).polygons[index].global_teta = teta;
} }
pub fn set_color(&mut self, delta: f32, index: usize, color_name: String) { pub fn set_color(&mut self, delta: f32, index: usize, color: Color) {
let current_frame = self.find_poly_frame(delta); let current_frame = self.find_poly_frame(delta);
current_frame.polygons[index].color = string_to_color(&color_name); current_frame.polygons[index].color = color;
current_frame.polygons[index].color_name = color_name; }
pub fn set_color_picker(&mut self, delta: f32, i: usize, b: bool) {
let current_frame = self.find_poly_frame(delta);
current_frame.polygons[i].show_color_picker = b;
} }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ADD/REMOVE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ADD/REMOVE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@@ -194,6 +194,7 @@ pub struct Polygon {
#[serde(skip)] #[serde(skip)]
pub color: Color, pub color: Color,
pub color_name: String, pub color_name: String,
pub show_color_picker: bool,
} }
#[warn(dead_code)] #[warn(dead_code)]
impl Polygon { impl Polygon {
@@ -218,61 +219,55 @@ impl Polygon {
} }
sound_to_play sound_to_play
} }
pub fn default(sound: StaticSoundData) -> Self {
Polygon {
global_teta: 0.,
points_teta: vec![],
sound: sound,
sound_name: "tick.ogg".to_string(),
color_name: "Black".to_string(),
name: "".to_string(),
color: Color::BLACK,
show_color_picker: false,
}
}
pub fn n_gon(teta: f32, n_side: u8, sound: StaticSoundData) -> Self { pub fn n_gon(n_side: u8, sound: StaticSoundData) -> Self {
let mut v: Vec<f32> = Vec::with_capacity(n_side as usize); let mut v: Vec<f32> = Vec::with_capacity(n_side as usize);
for i in 0..n_side { for i in 0..n_side {
v.push((i as f32 * 2.0 * PI) / n_side as f32); v.push((i as f32 * 2.0 * PI) / n_side as f32);
} }
Polygon { let mut p = Polygon::default(sound);
global_teta: teta, p.points_teta = v;
points_teta: v, p
sound: sound,
sound_name: "tick.ogg".to_string(),
color_name: "Black".to_string(),
name: "".to_string(),
color: Color::BLACK,
} }
} pub fn segment(sound: StaticSoundData) -> Self {
pub fn segment(teta: f32, sound: StaticSoundData) -> Self { Polygon::n_gon(2, sound)
Polygon::n_gon(teta, 2, sound)
} }
pub fn triangle(teta: f32, sound: StaticSoundData) -> Self { pub fn triangle(sound: StaticSoundData) -> Self {
Polygon::n_gon(teta, 3, sound) Polygon::n_gon(3, sound)
} }
pub fn square(teta: f32, sound: StaticSoundData) -> Self { pub fn square(sound: StaticSoundData) -> Self {
Polygon::n_gon(teta, 4, sound) Polygon::n_gon(4, sound)
} }
pub fn nr_6_in_30(teta: f32, sound: StaticSoundData) -> Self { pub fn nr_6_in_30(sound: StaticSoundData) -> Self {
Polygon { let mut p = Polygon::default(sound);
sound: sound, p.points_teta = vec![
name: "".to_string(),
color: Color::BLACK,
global_teta: teta,
sound_name: "tick.ogg".to_string(),
color_name: "Black".to_string(),
points_teta: vec![
2.0 * 5.0 * PI / 30.0, 2.0 * 5.0 * PI / 30.0,
2.0 * 6.0 * PI / 30.0, 2.0 * 6.0 * PI / 30.0,
2.0 * 12.0 * PI / 30.0, 2.0 * 12.0 * PI / 30.0,
2.0 * 18.0 * PI / 30.0, 2.0 * 18.0 * PI / 30.0,
2.0 * 24.0 * PI / 30.0, 2.0 * 24.0 * PI / 30.0,
2.0 * 25.0 * PI / 30.0, 2.0 * 25.0 * PI / 30.0,
], ];
p
} }
} pub fn nr_7_in_30(sound: StaticSoundData) -> Self {
pub fn nr_7_in_30(teta: f32, sound: StaticSoundData) -> Self { let mut p = Polygon::default(sound);
Polygon { p.points_teta = vec![
sound: sound,
name: "".to_string(),
color: Color::BLACK,
sound_name: "tick.ogg".to_string(),
color_name: "Black".to_string(),
global_teta: teta,
points_teta: vec![
0.0, 0.0,
2.0 * 6.0 * PI / 30.0, 2.0 * 6.0 * PI / 30.0,
2.0 * 7.0 * PI / 30.0, 2.0 * 7.0 * PI / 30.0,
@@ -280,18 +275,12 @@ impl Polygon {
2.0 * 17.0 * PI / 30.0, 2.0 * 17.0 * PI / 30.0,
2.0 * 23.0 * PI / 30.0, 2.0 * 23.0 * PI / 30.0,
2.0 * 24.0 * PI / 30.0, 2.0 * 24.0 * PI / 30.0,
], ];
p
} }
} pub fn nr_8_in_30(sound: StaticSoundData) -> Self {
pub fn nr_8_in_30(teta: f32, sound: StaticSoundData) -> Self { let mut p = Polygon::default(sound);
Polygon { p.points_teta = vec![
sound: sound,
name: "".to_string(),
color: Color::BLACK,
sound_name: "tick.ogg".to_string(),
color_name: "Black".to_string(),
global_teta: teta,
points_teta: vec![
2.0 * PI / 30.0, 2.0 * PI / 30.0,
2.0 * 5.0 * PI / 30.0, 2.0 * 5.0 * PI / 30.0,
2.0 * 11.0 * PI / 30.0, 2.0 * 11.0 * PI / 30.0,
@@ -300,18 +289,12 @@ impl Polygon {
2.0 * 19.0 * PI / 30.0, 2.0 * 19.0 * PI / 30.0,
2.0 * 25.0 * PI / 30.0, 2.0 * 25.0 * PI / 30.0,
2.0 * 29.0 * PI / 30.0, 2.0 * 29.0 * PI / 30.0,
], ];
p
} }
} pub fn nr_9_in_30(sound: StaticSoundData) -> Self {
pub fn nr_9_in_30(teta: f32, sound: StaticSoundData) -> Self { let mut p = Polygon::default(sound);
Polygon { p.points_teta = vec![
sound: sound,
name: "".to_string(),
color: Color::BLACK,
sound_name: "tick.ogg".to_string(),
color_name: "Black".to_string(),
global_teta: teta,
points_teta: vec![
0.0, 0.0,
2.0 * PI / 30.0, 2.0 * PI / 30.0,
2.0 * 7.0 * PI / 30.0, 2.0 * 7.0 * PI / 30.0,
@@ -321,18 +304,12 @@ impl Polygon {
2.0 * 19.0 * PI / 30.0, 2.0 * 19.0 * PI / 30.0,
2.0 * 23.0 * PI / 30.0, 2.0 * 23.0 * PI / 30.0,
2.0 * 29.0 * PI / 30.0, 2.0 * 29.0 * PI / 30.0,
], ];
p
} }
} pub fn nr_8_in_42(sound: StaticSoundData) -> Self {
pub fn nr_8_in_42(teta: f32, sound: StaticSoundData) -> Self { let mut p = Polygon::default(sound);
Polygon { p.points_teta = vec![
sound: sound,
name: "".to_string(),
color: Color::BLACK,
sound_name: "tick.ogg".to_string(),
color_name: "Black".to_string(),
global_teta: teta,
points_teta: vec![
2.0 * 3.0 * PI / 42.0, 2.0 * 3.0 * PI / 42.0,
2.0 * 9.0 * PI / 42.0, 2.0 * 9.0 * PI / 42.0,
2.0 * 14.0 * PI / 42.0, 2.0 * 14.0 * PI / 42.0,
@@ -341,18 +318,12 @@ impl Polygon {
2.0 * 28.0 * PI / 42.0, 2.0 * 28.0 * PI / 42.0,
2.0 * 33.0 * PI / 42.0, 2.0 * 33.0 * PI / 42.0,
2.0 * 39.0 * PI / 42.0, 2.0 * 39.0 * PI / 42.0,
], ];
p
} }
} pub fn nr_9_in_42(sound: StaticSoundData) -> Self {
pub fn nr_9_in_42(teta: f32, sound: StaticSoundData) -> Self { let mut p = Polygon::default(sound);
Polygon { p.points_teta = vec![
sound: sound,
name: "".to_string(),
color: Color::BLACK,
sound_name: "tick.ogg".to_string(),
color_name: "Black".to_string(),
global_teta: teta,
points_teta: vec![
0.0, 0.0,
2.0 * 6.0 * PI / 42.0, 2.0 * 6.0 * PI / 42.0,
2.0 * 11.0 * PI / 42.0, 2.0 * 11.0 * PI / 42.0,
@@ -362,18 +333,12 @@ impl Polygon {
2.0 * 30.0 * PI / 42.0, 2.0 * 30.0 * PI / 42.0,
2.0 * 31.0 * PI / 42.0, 2.0 * 31.0 * PI / 42.0,
2.0 * 36.0 * PI / 42.0, 2.0 * 36.0 * PI / 42.0,
], ];
p
} }
} pub fn nr_10a_in_42(sound: StaticSoundData) -> Self {
pub fn nr_10a_in_42(teta: f32, sound: StaticSoundData) -> Self { let mut p = Polygon::default(sound);
Polygon { p.points_teta = vec![
sound: sound,
name: "".to_string(),
color: Color::BLACK,
sound_name: "tick.ogg".to_string(),
color_name: "Black".to_string(),
global_teta: teta,
points_teta: vec![
2.0 * 6.0 * PI / 42.0, 2.0 * 6.0 * PI / 42.0,
2.0 * 7.0 * PI / 42.0, 2.0 * 7.0 * PI / 42.0,
2.0 * 11.0 * PI / 42.0, 2.0 * 11.0 * PI / 42.0,
@@ -384,18 +349,12 @@ impl Polygon {
2.0 * 31.0 * PI / 42.0, 2.0 * 31.0 * PI / 42.0,
2.0 * 35.0 * PI / 42.0, 2.0 * 35.0 * PI / 42.0,
2.0 * 36.0 * PI / 42.0, 2.0 * 36.0 * PI / 42.0,
], ];
p
} }
} pub fn nr_10b_in_42(sound: StaticSoundData) -> Self {
pub fn nr_10b_in_42(teta: f32, sound: StaticSoundData) -> Self { let mut p = Polygon::default(sound);
Polygon { p.points_teta = vec![
sound: sound,
name: "".to_string(),
color: Color::BLACK,
sound_name: "tick.ogg".to_string(),
color_name: "Black".to_string(),
global_teta: teta,
points_teta: vec![
0.0, 0.0,
2.0 * 1.0 * PI / 42.0, 2.0 * 1.0 * PI / 42.0,
2.0 * 5.0 * PI / 42.0, 2.0 * 5.0 * PI / 42.0,
@@ -406,8 +365,8 @@ impl Polygon {
2.0 * 29.0 * PI / 42.0, 2.0 * 29.0 * PI / 42.0,
2.0 * 30.0 * PI / 42.0, 2.0 * 30.0 * PI / 42.0,
2.0 * 41.0 * PI / 42.0, 2.0 * 41.0 * PI / 42.0,
], ];
} p
} }
} }
fn dummy_sound() -> StaticSoundData { fn dummy_sound() -> StaticSoundData {

View File

@@ -49,46 +49,46 @@ pub fn string_to_polygon<S: AsRef<str>>(str: S) -> Polygon {
let mut poly: Polygon; let mut poly: Polygon;
if s.starts_with("Ngon") { if s.starts_with("Ngon") {
if let Ok(sides) = s.trim_start_matches("Ngon").parse::<u8>() { if let Ok(sides) = s.trim_start_matches("Ngon").parse::<u8>() {
poly = Polygon::n_gon(0.0, sides, dummy_sound()); poly = Polygon::n_gon(sides, dummy_sound());
} else { } else {
poly = Polygon::n_gon(0.0, 0, dummy_sound()); poly = Polygon::n_gon(0, dummy_sound());
} }
} else { } else {
match s { match s {
"Segment" => { "Segment" => {
poly = Polygon::segment(0.0, dummy_sound()); poly = Polygon::segment(dummy_sound());
} }
"Triangle" => { "Triangle" => {
poly = Polygon::triangle(0.0, dummy_sound()); poly = Polygon::triangle(dummy_sound());
} }
"Square" => { "Square" => {
poly = Polygon::square(0.0, dummy_sound()); poly = Polygon::square(dummy_sound());
} }
"Nr6In30" => { "Nr6In30" => {
poly = Polygon::nr_6_in_30(0.0, dummy_sound()); poly = Polygon::nr_6_in_30(dummy_sound());
} }
"Nr7In30" => { "Nr7In30" => {
poly = Polygon::nr_7_in_30(0.0, dummy_sound()); poly = Polygon::nr_7_in_30(dummy_sound());
} }
"Nr8In30" => { "Nr8In30" => {
poly = Polygon::nr_8_in_30(0.0, dummy_sound()); poly = Polygon::nr_8_in_30(dummy_sound());
} }
"Nr9In30" => { "Nr9In30" => {
poly = Polygon::nr_9_in_30(0.0, dummy_sound()); poly = Polygon::nr_9_in_30(dummy_sound());
} }
"Nr8In42" => { "Nr8In42" => {
poly = Polygon::nr_8_in_42(0.0, dummy_sound()); poly = Polygon::nr_8_in_42(dummy_sound());
} }
"Nr9In42" => { "Nr9In42" => {
poly = Polygon::nr_9_in_42(0.0, dummy_sound()); poly = Polygon::nr_9_in_42(dummy_sound());
} }
"Nr10aIn42" => { "Nr10aIn42" => {
poly = Polygon::nr_10a_in_42(0.0, dummy_sound()); poly = Polygon::nr_10a_in_42(dummy_sound());
} }
"Nr10bIn42" => { "Nr10bIn42" => {
poly = Polygon::nr_10b_in_42(0.0, dummy_sound()); poly = Polygon::nr_10b_in_42(dummy_sound());
} }
_ => poly = Polygon::n_gon(0.0, 0, dummy_sound()), _ => poly = Polygon::n_gon(0, dummy_sound()),
} }
} }
poly.name = s.to_string(); poly.name = s.to_string();