external config
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
use bevy::prelude::Resource;
|
||||
use serde::Deserialize;
|
||||
use std::fs;
|
||||
|
||||
#[derive(Debug, Deserialize, Clone, Resource)]
|
||||
pub struct GameConfig {
|
||||
pub initial_chunk_radius: i32,
|
||||
pub spawn_counts: SpawnCounts,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
pub struct SpawnCounts {
|
||||
pub dorfs: u32,
|
||||
pub pigs: u32,
|
||||
pub rabbits: u32,
|
||||
}
|
||||
|
||||
impl GameConfig {
|
||||
pub fn load() -> Self {
|
||||
let config_str = fs::read_to_string("config.toml").expect("Failed to find config.toml");
|
||||
toml::from_str(&config_str).expect("Failed to parse config.toml")
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::config::GameConfig;
|
||||
use crate::constants::TILE_SIZE;
|
||||
use crate::constants::*;
|
||||
use crate::entities::item::{spawn_prefab, MiscPrefab};
|
||||
@@ -47,9 +48,10 @@ pub fn spawn_pigs(
|
||||
mut commands: Commands,
|
||||
asset_server: Res<AssetServer>,
|
||||
mut rng_q: Query<&mut WyRand, With<GlobalRng>>,
|
||||
config: Res<GameConfig>,
|
||||
) {
|
||||
if let Ok(mut rng) = rng_q.single_mut() {
|
||||
for _ in 0..5 {
|
||||
for _ in 0..config.spawn_counts.pigs {
|
||||
let pig = commands
|
||||
.spawn(Pig::new(
|
||||
&asset_server,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::config::GameConfig;
|
||||
use crate::constants::TILE_SIZE;
|
||||
use crate::constants::*;
|
||||
use crate::entities::shared_components::Ambulatory;
|
||||
@@ -40,9 +41,10 @@ pub fn spawn_rabbits(
|
||||
mut commands: Commands,
|
||||
asset_server: Res<AssetServer>,
|
||||
mut rng_q: Query<&mut WyRand, With<GlobalRng>>,
|
||||
config: Res<GameConfig>,
|
||||
) {
|
||||
if let Ok(mut rng) = rng_q.single_mut() {
|
||||
for _ in 0..15 {
|
||||
for _ in 0..config.spawn_counts.rabbits {
|
||||
let rab = commands
|
||||
.spawn(Rabbit::new(
|
||||
&asset_server,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::config::GameConfig;
|
||||
use crate::constants::TILE_SIZE;
|
||||
use crate::constants::*;
|
||||
use crate::entities::shared_components::Ambulatory;
|
||||
@@ -40,10 +41,10 @@ pub fn spawn_dorfs(
|
||||
mut commands: Commands,
|
||||
asset_server: Res<AssetServer>,
|
||||
mut rng_q: Query<&mut WyRand, With<GlobalRng>>,
|
||||
config: Res<GameConfig>,
|
||||
) {
|
||||
if let Ok(mut rng) = rng_q.single_mut() {
|
||||
// Spawn a handful of dorfs
|
||||
for _ in 0..40 {
|
||||
for _ in 0..config.spawn_counts.dorfs {
|
||||
let cit = commands
|
||||
.spawn(Dorf::new(
|
||||
&asset_server,
|
||||
|
||||
@@ -7,6 +7,7 @@ use crate::entities::{
|
||||
};
|
||||
|
||||
mod camera;
|
||||
mod config;
|
||||
mod constants;
|
||||
mod cursor;
|
||||
mod entities;
|
||||
@@ -14,7 +15,10 @@ mod game;
|
||||
mod world;
|
||||
|
||||
fn main() {
|
||||
let game_config = config::GameConfig::load();
|
||||
|
||||
App::new()
|
||||
.insert_resource(game_config)
|
||||
.insert_resource(game::ZIndex(0.0))
|
||||
.insert_resource(world::tiles::CurrentWorldSpriteState {
|
||||
state: world::tiles::TerrainSpriteState::Inactive,
|
||||
|
||||
+8
-3
@@ -1,5 +1,6 @@
|
||||
use crate::{
|
||||
camera,
|
||||
config::GameConfig,
|
||||
world::generation::{
|
||||
generate_chunk_fauna, generate_chunk_foliage, generate_chunk_forrestry,
|
||||
generate_chunk_terrain, generate_chunk_weathering_and_precipitation,
|
||||
@@ -69,9 +70,13 @@ impl Plugin for WorldPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
fn setup_initial_chunks(mut event_writer: MessageWriter<GenerateChunkEvent>) {
|
||||
for x in -15..=15 {
|
||||
for y in -15..=15 {
|
||||
fn setup_initial_chunks(
|
||||
mut event_writer: MessageWriter<GenerateChunkEvent>,
|
||||
config: Res<GameConfig>,
|
||||
) {
|
||||
let radius = config.initial_chunk_radius;
|
||||
for x in -radius..=radius {
|
||||
for y in -radius..=radius {
|
||||
event_writer.write(GenerateChunkEvent {
|
||||
chunk_position: IVec2::new(x, y),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user