60 lines
1.1 KiB
Rust
Raw Normal View History

2023-12-27 20:13:39 -08:00
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 Gun {
pub projectile: Projectile,
}
#[derive(Debug, Deserialize)]
pub struct Projectile {
pub sprite: String,
pub size: f32,
pub speed: f32,
pub lifetime: f32,
}
}
#[derive(Debug, Clone)]
pub struct Gun {
pub name: String,
pub projectile: Projectile,
}
#[derive(Debug, Clone)]
pub struct Projectile {
pub sprite: String,
pub size: f32,
pub speed: f32,
pub lifetime: f32,
}
impl super::Build for Gun {
fn build(root: &super::syntax::Root) -> Result<Vec<Self>> {
let gun = if let Some(gun) = &root.gun {
gun
} else {
return Ok(vec![]);
};
let mut out = Vec::new();
for (gun_name, gun) in gun {
out.push(Self {
name: gun_name.to_owned(),
projectile: Projectile {
sprite: gun.projectile.sprite.to_owned(),
size: gun.projectile.size,
speed: gun.projectile.speed,
lifetime: gun.projectile.lifetime,
},
});
}
return Ok(out);
}
}