historic , undo and redo

This commit is contained in:
2025-07-19 18:56:06 +02:00
parent be71a22248
commit bb15aeabb3
5 changed files with 206 additions and 23 deletions

View File

@@ -31,6 +31,8 @@ pub struct Music {
teta: f32,
#[serde(skip)]
pub current_delta: f32,
#[serde(skip)]
point_removed: Vec<(f32, PolygonFrame)>,
}
impl Music {
@@ -77,6 +79,7 @@ impl Music {
length: 60.0,
teta: 0.,
current_delta: 0.,
point_removed: vec![],
}
}
@@ -116,19 +119,25 @@ impl Music {
index: usize,
sound: StaticSoundData,
sound_name: String,
) {
) -> String {
let current_frame = self.find_poly_frame(delta);
current_frame.polygons[index].sound = sound;
let out = current_frame.polygons[index].sound_name.clone();
current_frame.polygons[index].sound_name = sound_name;
out
}
pub fn set_teta(&mut self, delta: f32, index: usize, teta: f32) {
pub fn set_teta(&mut self, delta: f32, index: usize, teta: f32) -> f32 {
let out = self.find_poly_frame(delta).polygons[index].global_teta;
self.find_poly_frame(delta).polygons[index].global_teta = teta;
out
}
pub fn set_color(&mut self, delta: f32, index: usize, color: Color) {
pub fn set_color(&mut self, delta: f32, index: usize, color: Color) -> Color {
let current_frame = self.find_poly_frame(delta);
let out = current_frame.polygons[index].color.clone();
current_frame.polygons[index].color = color;
out
}
pub fn set_color_picker(&mut self, delta: f32, i: usize, b: bool) {
@@ -146,9 +155,19 @@ impl Music {
self.poly_frame
.insert(pos, (delta, self.current_frame(delta).clone()));
}
pub fn add_point_old(&mut self) {
if let Some(pair) = self.point_removed.pop() {
let pos = self
.poly_frame
.binary_search_by(|(d, _)| d.partial_cmp(&pair.0).unwrap())
.unwrap_or_else(|e| e);
self.poly_frame.insert(pos, pair);
}
}
pub fn remove_point(&mut self, delta: f32) {
let i = self.find_index_frame(delta);
if i != 0 {
self.point_removed.push(self.poly_frame[i].clone());
self.poly_frame.remove(i);
}
}
@@ -159,8 +178,15 @@ impl Music {
current_frame.polygons.push(poly);
}
pub fn remove_polygon(&mut self, delta: f32, i: usize) {
self.find_poly_frame(delta).polygons.remove(i);
pub fn remove_polygon(&mut self, delta: f32, i: usize) -> String {
let pf = self.find_poly_frame(delta);
let mut i = i;
if i == usize::MAX {
i = pf.polygons.len() - 1
}
let out = pf.polygons[i].name.clone();
pf.polygons.remove(i);
out
}
pub fn slide_to_left(&mut self, delta: f32) {