1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
use scene::{Project, Scene};
use crate::command::{Command, CommandError, CommandResult};
pub struct CreateSceneCommand {
name: String,
is_main: bool,
saved_scenes: Option<Vec<Scene>>,
created_scene_id: Option<String>,
}
impl CreateSceneCommand {
pub fn new(name: impl Into<String>, is_main: bool) -> Self {
Self {
name: name.into(),
is_main,
saved_scenes: None,
created_scene_id: None,
}
}
pub fn scene_id(&self) -> Option<&str> {
self.created_scene_id.as_deref()
}
}
impl Command for CreateSceneCommand {
fn execute(
&mut self,
project: &mut Project,
) -> Result<Option<CommandResult>, CommandError> {
self.saved_scenes = Some(project.scenes.clone());
let created = timeline::scenes::build_default_scene(
uuid::Uuid::new_v4().to_string(),
uuid::Uuid::new_v4().to_string(),
self.name.clone(),
self.is_main,
chrono::Utc::now(),
);
self.created_scene_id = Some(created.id.clone());
project.scenes.push(created);
Ok(None)
}
fn undo(&mut self, project: &mut Project) {
let Some(saved) = &self.saved_scenes else {
return;
};
project.scenes = saved.clone();
}
}
|