Added basic ship config
parent
1bd78d3cfd
commit
e5d399c3c5
|
@ -0,0 +1,7 @@
|
||||||
|
# content type: ship
|
||||||
|
[ship]
|
||||||
|
name = "Gypsum"
|
||||||
|
sprite = "ship::gypsum"
|
||||||
|
size = 100
|
||||||
|
|
||||||
|
engines = [{ x = 0.0, y = -105, size = 50.0 }]
|
|
@ -6,28 +6,29 @@ use super::{syntax, ContentType};
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Content {
|
pub struct Content {
|
||||||
pub systems: Vec<syntax::system::System>,
|
pub systems: Vec<syntax::system::System>,
|
||||||
|
pub ships: Vec<syntax::ship::Ship>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Content {
|
impl Content {
|
||||||
pub fn new(cv: Vec<(PathBuf, ContentType)>) -> Result<Self> {
|
pub fn new(cv: Vec<(PathBuf, ContentType)>) -> Result<Self> {
|
||||||
let mut content = Self {
|
let mut systems = Vec::new();
|
||||||
systems: Vec::new(),
|
let mut ships = Vec::new();
|
||||||
};
|
|
||||||
|
|
||||||
// These methods check intra-file consistency
|
// These methods check intra-file consistency
|
||||||
for (p, c) in cv {
|
for (p, c) in cv {
|
||||||
match c {
|
match c {
|
||||||
ContentType::System(v) => content
|
ContentType::System(v) => systems.push(
|
||||||
.add_system(v)
|
syntax::system::System::parse(v)
|
||||||
.with_context(|| format!("Could not parse {}", p.display()))?,
|
.with_context(|| format!("Could not parse {}", p.display()))?,
|
||||||
};
|
),
|
||||||
|
|
||||||
|
ContentType::Ship(v) => ships.push(
|
||||||
|
syntax::ship::Ship::parse(v)
|
||||||
|
.with_context(|| format!("Could not parse {}", p.display()))?,
|
||||||
|
),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(content);
|
return Ok(Self { systems, ships });
|
||||||
}
|
|
||||||
|
|
||||||
fn add_system(&mut self, toml: syntax::system::toml::SystemRoot) -> Result<()> {
|
|
||||||
self.systems.push(syntax::system::System::parse(toml)?);
|
|
||||||
return Ok(());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ use super::syntax;
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ContentType {
|
pub enum ContentType {
|
||||||
System(syntax::system::toml::SystemRoot),
|
System(syntax::system::toml::SystemRoot),
|
||||||
|
Ship(syntax::ship::toml::ShipRoot),
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: check content without loading game
|
// TODO: check content without loading game
|
||||||
|
@ -26,6 +27,7 @@ impl ContentType {
|
||||||
|
|
||||||
return Ok(match &type_spec[..] {
|
return Ok(match &type_spec[..] {
|
||||||
"system" => Some(Self::System(toml::from_str(&file_string)?)),
|
"system" => Some(Self::System(toml::from_str(&file_string)?)),
|
||||||
|
"ship" => Some(Self::Ship(toml::from_str(&file_string)?)),
|
||||||
_ => bail!("Invalid content type `{}`", type_spec),
|
_ => bail!("Invalid content type `{}`", type_spec),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ mod syntax;
|
||||||
|
|
||||||
pub use content::Content;
|
pub use content::Content;
|
||||||
pub use contenttype::ContentType;
|
pub use contenttype::ContentType;
|
||||||
|
pub use syntax::ship;
|
||||||
pub use syntax::system;
|
pub use syntax::system;
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
pub mod ship;
|
||||||
pub mod system;
|
pub mod system;
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
use anyhow::Result;
|
||||||
|
use cgmath::Point2;
|
||||||
|
|
||||||
|
/// Toml file syntax
|
||||||
|
pub(in crate::content) mod toml {
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
pub struct ShipRoot {
|
||||||
|
pub ship: Ship,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
pub struct Ship {
|
||||||
|
pub name: String,
|
||||||
|
pub sprite: String,
|
||||||
|
pub size: f32,
|
||||||
|
pub engines: Vec<Engine>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
pub struct Engine {
|
||||||
|
pub x: f32,
|
||||||
|
pub y: f32,
|
||||||
|
pub size: f32,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Ship {
|
||||||
|
pub name: String,
|
||||||
|
pub sprite: String,
|
||||||
|
pub size: f32,
|
||||||
|
pub engines: Vec<Engine>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Engine {
|
||||||
|
pub pos: Point2<f32>,
|
||||||
|
pub size: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Ship {
|
||||||
|
pub fn parse(value: toml::ShipRoot) -> Result<Self> {
|
||||||
|
return Ok(Self {
|
||||||
|
name: value.ship.name,
|
||||||
|
sprite: value.ship.sprite,
|
||||||
|
size: value.ship.size,
|
||||||
|
engines: value
|
||||||
|
.ship
|
||||||
|
.engines
|
||||||
|
.iter()
|
||||||
|
.map(|e| Engine {
|
||||||
|
pos: Point2 { x: e.x, y: e.y },
|
||||||
|
size: e.size,
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue