Unfinished levelgen script
parent
2720215da7
commit
adc11ec654
|
@ -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() {
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue