definitions.rs 1.63 KB
Newer Older
1
2
use crate::svg_loader;

Rahix's avatar
Rahix committed
3
4
5
6
7
pub trait AngelShiftImpl {
    /// Return metadata about this shift.
    ///
    /// Used in heaven to display what task is up next.
    fn metadata(&self) -> ShiftMetadata;
Rahix's avatar
Rahix committed
8
9
10

    /// Return name of the selected level for this shift.
    fn level_name(&self) -> &str;
11
12
13
14
15
16
17
18
19
20
21
22
23

    /// Initialize the shift-specific bits of the game-world
    ///
    /// The world will already contain all common entities and resources.  The schedule is
    /// configured to run all "game world" systems like collision detection/movement before
    /// whatever is added here.  After the systems added here, rendering will be scheduled.
    fn init_gameworld(
        &self,
        world: &mut legion::World,
        resources: &mut legion::Resources,
        schedule_builder: &mut legion::systems::Builder,
        level: &svg_loader::SvgLevel,
    );
Rahix's avatar
Rahix committed
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
}

pub struct ShiftMetadata {
    /// Short name of this shift/task.
    pub title: String,
    /// Longer description of what needs to be done.
    pub description: String,
    /// Amount of hours that would be gained from working this shift.
    pub hours: usize,
}

pub struct AngelShift(pub Box<dyn AngelShiftImpl>);

impl AngelShift {
    pub fn metadata(&self) -> ShiftMetadata {
        self.0.metadata()
    }
Rahix's avatar
Rahix committed
41
42
43
44

    pub fn level_name(&self) -> &str {
        self.0.level_name()
    }
45
46
47
48
49
50
51
52
53
54
55

    pub fn init_gameworld(
        &self,
        world: &mut legion::World,
        resources: &mut legion::Resources,
        schedule_builder: &mut legion::systems::Builder,
        level: &svg_loader::SvgLevel,
    ) {
        self.0
            .init_gameworld(world, resources, schedule_builder, level);
    }
Rahix's avatar
Rahix committed
56
}