Unfinished levelgen script

Development
Johannes Hendrik Gerard van der Weide 2023-12-12 16:59:37 +01:00
parent 2720215da7
commit adc11ec654
1 changed files with 74 additions and 0 deletions

74
src/levelgen.rs Normal file
View File

@ -0,0 +1,74 @@
use bevy::prelude::*;
use serde::{Serialize, Deserialze};
use std::fs;
use std::path::Path;
pub struct LevelgenPlugin;
impl Plugin for LevelgenPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Startup, setup_levels)
.add_systems(Update, level_generation);
}
}
#[derive(Serialize, Deserialize)]
pub struct Level {
enemies: Vec<String>,
waves: u32,
treasure: i32,
doors: Vec<bool>,
}
#[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>,
current_enemies: Vec<u32>,
current_waves: u32,
current_treasure: i32,
}
fn setup_levels(mut commands: Commands) {
let mut initial_level: String = "
# Enemies can only be set if they exist in data/enemies/
# for example data/enemies/grunt.yml
enemies: [
grunt
]
# 0 means no enemies
waves: 1
# 0 is no treasure
treasure: 0
doors: [
true, # North
true, # East
true, # South
true, # West
]
".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 {
}
commands.spawn((
LevelGenerator {
},
));
}
fn level_generation() {
}