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
53
54
55
56
57
58
59
60
61
62
63
use std::cell::RefCell;
use crate::engine::d2::{
swf::{MoviePlayer, MovieSprite},
Entity, EntityManager,
};
use super::Action;
struct PlayMovieProps {
name: String,
movie: Option<MovieSprite>,
}
/// An action that plays a movie once using the actor's MoviePlayer, completing when the movie
/// finishes.
pub struct PlayMovie {
props: RefCell<PlayMovieProps>,
}
impl PlayMovie {
/// @param The name of the movie to play.
pub fn new(name: String) -> Self {
Self {
props: RefCell::new(PlayMovieProps { name, movie: None }),
}
}
}
impl Action for PlayMovie {
fn update(&self, dt: f32, actor: &mut Entity) -> f32 {
let mut props = self.props.borrow_mut();
if let Some(mut player) = EntityManager::<MoviePlayer>::get(actor) {
match props.movie {
Some(ref movie) => match player.movie {
Some(ref player_movie) => {
// if movie != player_movie.get() { // DV watching movie progress
// self.movie = None;
// return 0.0;
// }
if movie != player_movie {
// DV without watching movie progress
props.movie = None;
return 0.0;
}
}
None => {
props.movie = None;
return 0.0;
}
},
None => {
player.play(props.name.clone(), true);
// self.movie = player.movie.map(|v| v.get()); // DV watching movie progress
props.movie = player.movie; // DV without watching movie progress
}
}
}
-1.0 // Keep going
}
}