(&mut self, command: Command)
| 472 | } |
| 473 | |
| 474 | let mut commands = Commands::EmptyCmd; |
| 475 | { |
| 476 | let scr = self.script.clone(); |
| 477 | let mut scr = scr.borrow_mut(); |
| 478 | if let Some(cmds) = scr.next_command() { |
| 479 | commands = cmds.clone(); |
| 480 | } |
| 481 | } |
| 482 | let delay = match commands { |
| 483 | Commands::EmptyCmd => unreachable!(), |
| 484 | Commands::OneCmd(command) => self.apply_command(command)?, |
| 485 | Commands::VarCmds(vars) => { |
| 486 | let mut delay = Duration::default(); |
| 487 | for command in vars { |
| 488 | delay += self.apply_command(command)?; |
| 489 | } |
| 490 | delay |
| 491 | } |
| 492 | }; |
| 493 | |
| 494 | if is_wait { |
| 495 | duration += delay; |
| 496 | } |
| 497 | |
| 498 | if is_auto { |
| 499 | self.auto_tx.clone().unwrap().try_send(duration)?; |
| 500 | } |
| 501 | |
| 502 | Ok(()) |
| 503 | } |
| 504 | |
| 505 | pub(crate) fn apply_command(&mut self, command: Command) -> Result<Duration, EngineError> { |
| 506 | let mut duration = Duration::from_secs(0); |
| 507 | |
| 508 | if let Some(window) = self.weak.upgrade() { |
| 509 | let pre_bg; |
| 510 | let pre_bgm; |
| 511 | let pre_fg; |
| 512 | |
| 513 | { |
| 514 | let mut scr = self.script.borrow_mut(); |
| 515 | pre_bg = scr.pre_bg(); |
| 516 | pre_bgm = scr.pre_bgm(); |
| 517 | pre_fg = scr.pre_figures(); |
| 518 | } |
| 519 | |
| 520 | if let Some(bg) = pre_bg { |
| 521 | self.show_bg(&bg)?; |
| 522 | } |
| 523 | if let Play(bgm) = pre_bgm { |
| 524 | self.play_bgm(bgm)?; |
| 525 | } else if let PreBgm::Stop = pre_bgm { |
| 526 | self.media_player.borrow().stop_bgm(); |
| 527 | } |
| 528 | if let Some(figures) = pre_fg { |
| 529 | for figure in figures.0.values() { |
| 530 | self.show_fg(&figure.clone())?; |
| 531 | } |
no test coverage detected