Added the still empty level gen plugin

Development
Johannes Hendrik Gerard van der Weide 2023-12-12 19:58:54 +01:00
parent 5f72edba96
commit 92d37cbfcf
3 changed files with 28 additions and 19 deletions

17
data/levels/default.yml Normal file
View File

@ -0,0 +1,17 @@
# Enemies can only be set if they exist in data/enemies/
# for example data/enemies/grunt.yml
enemies: [
grunt
]
# 0 means no enemies
waves: 0
# 0 is no treasure
treasure: 0
doors: [
true, # North
true, # East
true, # South
true, # West
]

View File

@ -1,7 +1,8 @@
use bevy::prelude::*; use bevy::prelude::*;
use serde::{Serialize, Deserialze}; use serde::{Serialize, Deserialize};
use std::fs; use std::fs;
use std::path::Path; use std::path::Path;
use crate::load_yaml_folder;
pub struct LevelgenPlugin; pub struct LevelgenPlugin;
@ -34,14 +35,14 @@ pub struct LevelGenerator {
fn setup_levels(mut commands: Commands) { fn setup_levels(mut commands: Commands) {
let mut initial_level: String = " let default_level: String = "
# Enemies can only be set if they exist in data/enemies/ # Enemies can only be set if they exist in data/enemies/
# for example data/enemies/grunt.yml # for example data/enemies/grunt.yml
enemies: [ enemies: [
grunt grunt
] ]
# 0 means no enemies # 0 means no enemies
waves: 1 waves: 0
# 0 is no treasure # 0 is no treasure
treasure: 0 treasure: 0
doors: [ doors: [
@ -51,22 +52,10 @@ fn setup_levels(mut commands: Commands) {
true, # West true, # West
] ]
".to_string(); ".to_string();
let initial_level_path = Path::new("./data/levels/initial_level.yml");
if initial_level_path.exists() {
initial_level =
fs::read_to_string("./data/levels/initial_level.yml").expect("Error reading data/levels/initial_level.yml");
} else {
fs::write("./data/levels/initial_level.yml", initial_level.clone())
.expect("Error writing data/levels/initial_level.yml");
}
let paths = fs::read_dir("./data/levels/").unwrap();
for path in paths { let level_yaml: Vec<String> = load_yaml_folder(default_level, Path::new("./data/levels"));
}
commands.spawn(( let starting_level_data = serde_yaml::from_str::<Level>(&fs::read_to_string("./data/levels/default.yml").expect("Error reading data/levels/default.yml"));
LevelGenerator {
},
));
} }
fn level_generation() { fn level_generation() {

View File

@ -3,6 +3,7 @@ use player::PlayerPlugin;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::path::Path; use std::path::Path;
use crate::player::Player; use crate::player::Player;
use crate::levelgen::LevelgenPlugin;
use crate::setup::config_loader::load_yaml_folder; use crate::setup::config_loader::load_yaml_folder;
#[derive(Component, Serialize, Deserialize)] #[derive(Component, Serialize, Deserialize)]
@ -24,6 +25,7 @@ pub struct InputVisual {
pub mod setup; pub mod setup;
mod player; mod player;
mod levelgen;
fn main() { fn main() {
App::new() App::new()
@ -42,6 +44,7 @@ fn main() {
.build(), .build(),
) )
.add_plugins(PlayerPlugin) .add_plugins(PlayerPlugin)
.add_plugins(LevelgenPlugin)
.add_systems(Startup, setup) .add_systems(Startup, setup)
.add_systems(Update, get_input) .add_systems(Update, get_input)
.add_systems(Update, draw_input) .add_systems(Update, draw_input)