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
//! Fades out the screen, switches the location of the player and then fades
//! the screen back in. This is the preferred event for doing any kind of warp
//! between maps. The fade in will only occur when the map finishes loading.

use amethyst::ecs::World;

use crate::map::MapCoordinates;

use super::{
    BoxedGameEvent,
    ChainedEvents,
    ExecutionConditions,
    FadeInEvent,
    FadeOutEvent,
    GameEvent,
    SwitchMapEvent,
};

#[derive(Clone)]
pub struct WarpEvent {
    executor: ChainedEvents,
}

impl WarpEvent {
    pub fn new<T>(map: T, tile: MapCoordinates) -> WarpEvent
    where
        T: Into<String>
    {
        let mut executor = ChainedEvents::default();
        executor.add_event(Box::new(FadeOutEvent::default()));
        executor.add_event(Box::new(SwitchMapEvent::new(map, tile)));
        executor.add_event(Box::new(FadeInEvent::default()));

        WarpEvent {
            executor,
        }
    }
}

impl GameEvent for WarpEvent {
    fn boxed_clone(&self) -> BoxedGameEvent {
        Box::new(self.clone())
    }

    fn get_execution_conditions(&self) -> ExecutionConditions {
        self.executor.get_execution_conditions()
    }

    fn start(&mut self, world: &mut World) {
        self.executor.start(world);
    }

    fn tick(&mut self, world: &mut World, disabled_inputs: bool) {
        self.executor.tick(world, disabled_inputs);
    }

    fn is_complete(&self, world: &mut World) -> bool {
        self.executor.is_complete(world)
    }
}