external config
This commit is contained in:
Generated
+34
-2
@@ -2342,6 +2342,8 @@ dependencies = [
|
||||
"rand 0.10.0",
|
||||
"rayon",
|
||||
"rustc-hash 2.1.1",
|
||||
"serde",
|
||||
"toml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2650,9 +2652,9 @@ checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6"
|
||||
|
||||
[[package]]
|
||||
name = "futures-lite"
|
||||
version = "2.6.0"
|
||||
version = "2.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f5edaec856126859abb19ed65f39e90fea3a9574b9707f13539acf4abf7eb532"
|
||||
checksum = "f78e10609fe0e0b3f4157ffab1876319b5b0db102a2c60dc4626306dc46b44ad"
|
||||
dependencies = [
|
||||
"fastrand",
|
||||
"futures-core",
|
||||
@@ -4729,6 +4731,15 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_spanned"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8bbf91e5a4d6315eee45e704372590b30e260ee83af6639d64557f51b067776"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sharded-slab"
|
||||
version = "0.1.7"
|
||||
@@ -5055,6 +5066,21 @@ version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.9.12+spec-1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf92845e79fc2e2def6a5d828f0801e29a2f8acc037becc5ab08595c7d5e9863"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"serde_core",
|
||||
"serde_spanned",
|
||||
"toml_datetime 0.7.5+spec-1.1.0",
|
||||
"toml_parser",
|
||||
"toml_writer",
|
||||
"winnow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_datetime"
|
||||
version = "0.6.9"
|
||||
@@ -5102,6 +5128,12 @@ dependencies = [
|
||||
"winnow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_writer"
|
||||
version = "1.0.7+spec-1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f17aaa1c6e3dc22b1da4b6bba97d066e354c7945cac2f7852d4e4e7ca7a6b56d"
|
||||
|
||||
[[package]]
|
||||
name = "tracing"
|
||||
version = "0.1.44"
|
||||
|
||||
+3
-1
@@ -10,11 +10,13 @@ rand = "0.10.0"
|
||||
bevy_rand = { version = "0.14.2", features = ["wyrand"] }
|
||||
image = "0.25.10"
|
||||
bevy_platform = "0.18.1"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
toml = "0.9.8"
|
||||
rayon = "1.11.0"
|
||||
rustc-hash = "2.1.1"
|
||||
ahash = "0.8.12"
|
||||
nohash-hasher = "0.2.0"
|
||||
futures-lite = "2.6"
|
||||
futures-lite = "2.6.1"
|
||||
|
||||
# Enable max optimizations for dependencies, but not for our code:
|
||||
[profile.dev.package."*"]
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
initial_chunk_radius = 7
|
||||
|
||||
[spawn_counts]
|
||||
dorfs = 500
|
||||
pigs = 5
|
||||
rabbits = 50
|
||||
@@ -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