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
use bevy::prelude::*;

use super::{
    events::{
        LoadedParticleData, LoadedRealmData, LoadedSimpleObjectData, LoadedSpellData,
        LoadedTilesetData,
    },
    load_data_file_dir,
    particles::load_particle_effects,
    realms::load_realms,
    simple_objects::load_simple_objects,
    spells::load_spells,
    storage::GameData,
    tilesets::load_tilesets,
};

/// The plugin for the data loader.
///
/// This takes care of adding the required events and the system to load the data.
#[allow(clippy::module_name_repetitions)]
pub struct DataLoaderPlugin;

impl Plugin for DataLoaderPlugin {
    fn build(&self, app: &mut App) {
        app.add_event::<LoadedSpellData>()
            .add_event::<LoadedTilesetData>()
            .add_event::<LoadedParticleData>()
            .add_event::<LoadedRealmData>()
            .add_event::<LoadedSimpleObjectData>();

        // Set up the resources used and the systems to store the data
        app.init_resource::<GameData>().add_systems(
            Update,
            (
                load_tilesets,
                load_simple_objects,
                load_particle_effects,
                load_realms,
                load_spells,
            ),
        );

        // Add the system to load the data
        app.add_systems(Startup, load_data_file_dir);
    }
}