command : ajout fonction add

This commit is contained in:
Ahurac 2024-04-11 02:41:47 +02:00
parent d7f2de803d
commit 8d039e3de3

View file

@ -24,7 +24,7 @@ pub trait Command {
pub struct CommandSequence {
command: Box<dyn Command>,
next_command: Option<Box<dyn Command>>,
next_command: Option<Box<CommandSequence>>,
}
impl CommandSequence {
@ -34,6 +34,14 @@ impl CommandSequence {
next_command: None,
}
}
pub fn add(&mut self, command: impl Command + 'static) {
if self.next_command.is_none() {
self.next_command = Some(Box::new(CommandSequence::new(command)));
} else {
self.next_command.as_mut().unwrap().add(command);
}
}
}
impl Command for CommandSequence {