Spawn LevelGenerator and fill it
parent
92d37cbfcf
commit
a415a32012
|
@ -13,7 +13,7 @@ impl Plugin for LevelgenPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
pub struct Level {
|
||||
enemies: Vec<String>,
|
||||
waves: u32,
|
||||
|
@ -23,11 +23,11 @@ pub struct Level {
|
|||
|
||||
#[derive(Component)]
|
||||
pub struct LevelGenerator {
|
||||
levels_exit_north: Vec<String>,
|
||||
levels_exit_east: Vec<String>,
|
||||
levels_exit_south: Vec<String>,
|
||||
levels_exit_west: Vec<String>,
|
||||
path: Vec<String>,
|
||||
levels_north: Vec<Level>,
|
||||
levels_east: Vec<Level>,
|
||||
levels_south: Vec<Level>,
|
||||
levels_west: Vec<Level>,
|
||||
path: Vec<Level>,
|
||||
current_enemies: Vec<u32>,
|
||||
current_waves: u32,
|
||||
current_treasure: i32,
|
||||
|
@ -55,7 +55,42 @@ fn setup_levels(mut commands: Commands) {
|
|||
|
||||
let level_yaml: Vec<String> = load_yaml_folder(default_level, Path::new("./data/levels"));
|
||||
|
||||
let starting_level_data = serde_yaml::from_str::<Level>(&fs::read_to_string("./data/levels/default.yml").expect("Error reading data/levels/default.yml"));
|
||||
let starting_level = serde_yaml::from_str::<Level>(&fs::read_to_string("./data/levels/default.yml").expect("Error reading data/levels/default.yml")).unwrap();
|
||||
|
||||
let mut levels_north_loaded: Vec<Level> = vec![];
|
||||
let mut levels_east_loaded: Vec<Level> = vec![];
|
||||
let mut levels_south_loaded: Vec<Level> = vec![];
|
||||
let mut levels_west_loaded: Vec<Level> = vec![];
|
||||
|
||||
for level_data in level_yaml {
|
||||
let level: Level = serde_yaml::from_str::<Level>(&level_data).expect("Error reading level");
|
||||
|
||||
if level.doors[0] == true {
|
||||
levels_north_loaded.push(level.clone());
|
||||
}
|
||||
if level.doors[1] == true {
|
||||
levels_east_loaded.push(level.clone());
|
||||
}
|
||||
if level.doors[2] == true {
|
||||
levels_south_loaded.push(level.clone());
|
||||
}
|
||||
if level.doors[3] == true {
|
||||
levels_west_loaded.push(level.clone());
|
||||
}
|
||||
}
|
||||
|
||||
commands.spawn((
|
||||
LevelGenerator {
|
||||
levels_north: levels_north_loaded,
|
||||
levels_east: levels_east_loaded,
|
||||
levels_south: levels_south_loaded,
|
||||
levels_west: levels_west_loaded,
|
||||
path: vec![starting_level.clone()],
|
||||
current_enemies: Vec::new(),
|
||||
current_waves: starting_level.waves,
|
||||
current_treasure: starting_level.treasure,
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
fn level_generation() {
|
||||
|
|
Loading…
Reference in New Issue