switch to toml

This commit is contained in:
Thomas Faour 2025-06-20 17:12:56 -04:00
parent 2187994616
commit a44039325d
4 changed files with 47 additions and 5 deletions

View File

@ -18,3 +18,5 @@ once_cell = "1.21.3"
serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.140"
bevy = "0.13"
serde_toml = "0.0.1"
toml = "0.8.23"

30
config/planets.toml Normal file
View File

@ -0,0 +1,30 @@
# Simulation body configuration
[[bodies]]
name = "Mercury"
mass = 3.30104e23 # kg
position = [46000000000.0, 0.0, 0.0] # meters
velocity = [0.0, 58970.0, 0.0] # m/s
[[bodies]]
name = "Venus"
mass = 4.867e24
position = [108941000000.0, 0.0, 0.0]
velocity = [0.0, 34780.0, 0.0]
[[bodies]]
name = "Earth"
mass = 5.972e24
position = [147095000000.0, 0.0, 0.0]
velocity = [0.0, 29290.0, 0.0]
[[bodies]]
name = "Moon"
mass = 7.34767309e22
position = [149982270700.0, 0.0, 0.0]
velocity = [0.0, 30822.0, 0.0]
[[bodies]]
name = "Sun"
mass = 1.989e30
position = [0.0, 0.0, 0.0]
velocity = [0.0, 0.0, 0.0]

View File

@ -1,6 +1,7 @@
// Standard library
use std::error::Error;
use std::fs::File;
use std::fs;
use std::io::BufReader;
use std::path::Path;
use std::time::{Duration,Instant};
@ -46,12 +47,10 @@ struct Args {
}
fn read_config<P: AsRef<Path>>(path: P) -> Result<orbital_simulator::config::ConfigFile, Box<dyn Error>> {
let file = File::open(path)?;
let reader = BufReader::new(file);
let content = fs::read_to_string(&path)?;
let conf = toml::from_str(&content)?;
let u = serde_json::from_reader(reader)?;
Ok(u)
Ok(conf)
}
//fn parse_time(arg: &str)

View File

@ -13,6 +13,17 @@ pub struct Body {
pub acceleration: types::Acceleration,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct Normalization {
pub name: String,
pub mass: types::Mass,
pub position: types::Position,
pub velocity: types::Velocity,
#[serde(default)]
pub acceleration: types::Acceleration,
}
#[derive(Debug, Deserialize)]
pub struct ConfigFile {
pub bodies: Vec<Body>,