system of save
This commit is contained in:
@@ -7,6 +7,7 @@ use iced::widget::canvas::Stroke;
|
||||
use iced::widget::canvas::Style;
|
||||
use iced::{Color, Rectangle, Renderer, Theme};
|
||||
use kira::sound::static_sound::StaticSoundData;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub trait RotationExt {
|
||||
fn rotate(&mut self, teta: f32) -> Self;
|
||||
@@ -20,6 +21,7 @@ impl RotationExt for Vector {
|
||||
)
|
||||
}
|
||||
}
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct PolygonFrame {
|
||||
pub teta: f32,
|
||||
pub polygons: Vec<Polygon>,
|
||||
@@ -33,6 +35,11 @@ impl PolygonFrame {
|
||||
}
|
||||
all_sound
|
||||
}
|
||||
pub fn update(&mut self) {
|
||||
for poly in &mut self.polygons {
|
||||
poly.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<Message> canvas::Program<Message> for PolygonFrame {
|
||||
@@ -102,18 +109,33 @@ impl<Message> canvas::Program<Message> for PolygonFrame {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Polygon {
|
||||
pub global_teta: f32,
|
||||
pub points_teta: Vec<f32>,
|
||||
#[serde(skip, default = "dummy_sound")]
|
||||
pub sound: StaticSoundData,
|
||||
pub sound_name: String,
|
||||
pub name: String,
|
||||
#[serde(skip)]
|
||||
pub color: Color,
|
||||
pub color_name: String,
|
||||
}
|
||||
#[warn(dead_code)]
|
||||
impl Polygon {
|
||||
pub fn update(&mut self) {
|
||||
let path = format!("./assets/{0}", &self.sound_name);
|
||||
eprintln!("path:{path}");
|
||||
self.sound = StaticSoundData::from_file(&path).expect("fail to load the sound");
|
||||
self.color = match self.color_name.as_str() {
|
||||
"Green" => Color::from_rgb(0.0, 1.0, 0.0),
|
||||
"Blue" => Color::from_rgb(0.0, 0.0, 1.0),
|
||||
"Cyan" => Color::from_rgb(0.0, 1.0, 1.0),
|
||||
"Yellow" => Color::from_rgb(1.0, 1.0, 0.0),
|
||||
"Pink" => Color::from_rgb(1.0, 0.0, 1.0),
|
||||
_ => Color::BLACK,
|
||||
};
|
||||
}
|
||||
pub fn sound_to_play_btw(&self, before: f32, after: f32) -> Vec<&StaticSoundData> {
|
||||
let mut sound_to_play: Vec<&StaticSoundData> = vec![];
|
||||
if after < before {
|
||||
@@ -140,7 +162,7 @@ impl Polygon {
|
||||
global_teta: teta,
|
||||
points_teta: v,
|
||||
sound: sound,
|
||||
sound_name: "./assets/tick.ogg".to_string(),
|
||||
sound_name: "tick.ogg".to_string(),
|
||||
color_name: "Black".to_string(),
|
||||
name: "".to_string(),
|
||||
color: Color::BLACK,
|
||||
@@ -164,7 +186,7 @@ impl Polygon {
|
||||
name: "".to_string(),
|
||||
color: Color::BLACK,
|
||||
global_teta: teta,
|
||||
sound_name: "./assets/tick.ogg".to_string(),
|
||||
sound_name: "tick.ogg".to_string(),
|
||||
color_name: "Black".to_string(),
|
||||
points_teta: vec![
|
||||
2.0 * 5.0 * PI / 30.0,
|
||||
@@ -181,7 +203,7 @@ impl Polygon {
|
||||
sound: sound,
|
||||
name: "".to_string(),
|
||||
color: Color::BLACK,
|
||||
sound_name: "./assets/tick.ogg".to_string(),
|
||||
sound_name: "tick.ogg".to_string(),
|
||||
color_name: "Black".to_string(),
|
||||
global_teta: teta,
|
||||
points_teta: vec![
|
||||
@@ -200,7 +222,7 @@ impl Polygon {
|
||||
sound: sound,
|
||||
name: "".to_string(),
|
||||
color: Color::BLACK,
|
||||
sound_name: "./assets/tick.ogg".to_string(),
|
||||
sound_name: "tick.ogg".to_string(),
|
||||
color_name: "Black".to_string(),
|
||||
global_teta: teta,
|
||||
points_teta: vec![
|
||||
@@ -220,7 +242,7 @@ impl Polygon {
|
||||
sound: sound,
|
||||
name: "".to_string(),
|
||||
color: Color::BLACK,
|
||||
sound_name: "./assets/tick.ogg".to_string(),
|
||||
sound_name: "tick.ogg".to_string(),
|
||||
color_name: "Black".to_string(),
|
||||
global_teta: teta,
|
||||
points_teta: vec![
|
||||
@@ -241,7 +263,7 @@ impl Polygon {
|
||||
sound: sound,
|
||||
name: "".to_string(),
|
||||
color: Color::BLACK,
|
||||
sound_name: "./assets/tick.ogg".to_string(),
|
||||
sound_name: "tick.ogg".to_string(),
|
||||
color_name: "Black".to_string(),
|
||||
global_teta: teta,
|
||||
points_teta: vec![
|
||||
@@ -261,7 +283,7 @@ impl Polygon {
|
||||
sound: sound,
|
||||
name: "".to_string(),
|
||||
color: Color::BLACK,
|
||||
sound_name: "./assets/tick.ogg".to_string(),
|
||||
sound_name: "tick.ogg".to_string(),
|
||||
color_name: "Black".to_string(),
|
||||
global_teta: teta,
|
||||
points_teta: vec![
|
||||
@@ -282,7 +304,7 @@ impl Polygon {
|
||||
sound: sound,
|
||||
name: "".to_string(),
|
||||
color: Color::BLACK,
|
||||
sound_name: "./assets/tick.ogg".to_string(),
|
||||
sound_name: "tick.ogg".to_string(),
|
||||
color_name: "Black".to_string(),
|
||||
global_teta: teta,
|
||||
points_teta: vec![
|
||||
@@ -304,7 +326,7 @@ impl Polygon {
|
||||
sound: sound,
|
||||
name: "".to_string(),
|
||||
color: Color::BLACK,
|
||||
sound_name: "./assets/tick.ogg".to_string(),
|
||||
sound_name: "tick.ogg".to_string(),
|
||||
color_name: "Black".to_string(),
|
||||
global_teta: teta,
|
||||
points_teta: vec![
|
||||
@@ -322,3 +344,6 @@ impl Polygon {
|
||||
}
|
||||
}
|
||||
}
|
||||
fn dummy_sound() -> StaticSoundData {
|
||||
StaticSoundData::from_file("assets/tick.ogg").expect("Fail to load audio")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user