47 lines
862 B
Rust
47 lines
862 B
Rust
use anyhow::Result;
|
|
|
|
pub(super) mod syntax {
|
|
use serde::Deserialize;
|
|
// Raw serde syntax structs.
|
|
// These are never seen by code outside this crate.
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
pub struct Engine {
|
|
pub thrust: f32,
|
|
pub flare: Flare,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
pub struct Flare {
|
|
pub sprite: String,
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct Engine {
|
|
pub name: String,
|
|
pub thrust: f32,
|
|
pub flare_sprite: String,
|
|
}
|
|
|
|
impl super::Build for Engine {
|
|
fn build(root: &super::syntax::Root) -> Result<Vec<Self>> {
|
|
let engine = if let Some(engine) = &root.engine {
|
|
engine
|
|
} else {
|
|
return Ok(vec![]);
|
|
};
|
|
|
|
let mut out = Vec::new();
|
|
for (engine_name, engine) in engine {
|
|
out.push(Self {
|
|
name: engine_name.to_owned(),
|
|
thrust: engine.thrust,
|
|
flare_sprite: engine.flare.sprite.clone(),
|
|
});
|
|
}
|
|
|
|
return Ok(out);
|
|
}
|
|
}
|