switch to toml
This commit is contained in:
parent
2187994616
commit
a44039325d
@ -18,3 +18,5 @@ once_cell = "1.21.3"
|
|||||||
serde = { version = "1.0.219", features = ["derive"] }
|
serde = { version = "1.0.219", features = ["derive"] }
|
||||||
serde_json = "1.0.140"
|
serde_json = "1.0.140"
|
||||||
bevy = "0.13"
|
bevy = "0.13"
|
||||||
|
serde_toml = "0.0.1"
|
||||||
|
toml = "0.8.23"
|
||||||
|
30
config/planets.toml
Normal file
30
config/planets.toml
Normal 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]
|
@ -1,6 +1,7 @@
|
|||||||
// Standard library
|
// Standard library
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
use std::fs;
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::time::{Duration,Instant};
|
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>> {
|
fn read_config<P: AsRef<Path>>(path: P) -> Result<orbital_simulator::config::ConfigFile, Box<dyn Error>> {
|
||||||
let file = File::open(path)?;
|
let content = fs::read_to_string(&path)?;
|
||||||
let reader = BufReader::new(file);
|
let conf = toml::from_str(&content)?;
|
||||||
|
|
||||||
let u = serde_json::from_reader(reader)?;
|
Ok(conf)
|
||||||
|
|
||||||
Ok(u)
|
|
||||||
}
|
}
|
||||||
//fn parse_time(arg: &str)
|
//fn parse_time(arg: &str)
|
||||||
|
|
||||||
|
@ -13,6 +13,17 @@ pub struct Body {
|
|||||||
pub acceleration: types::Acceleration,
|
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)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct ConfigFile {
|
pub struct ConfigFile {
|
||||||
pub bodies: Vec<Body>,
|
pub bodies: Vec<Body>,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user