adding texturing, getting sidetracked by config loading
This commit is contained in:
@@ -17,11 +17,55 @@ use crate::components::{Collider, LoopState, Mesh, Physics, Position};
|
||||
use crate::geometry::{load_obj, RawMesh};
|
||||
use std::io::Read;
|
||||
|
||||
pub struct EntityMeta {
|
||||
|
||||
|
||||
#[derive(Deserialize, Clone)]
|
||||
pub struct TomlBallPhysicsBodyDescription {
|
||||
pub radius: String
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Clone)]
|
||||
pub struct TomlCuboidPhysicsBodyDescription {
|
||||
pub x: f32,
|
||||
pub y: f32,
|
||||
pub z: f32,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Clone)]
|
||||
pub struct TomlPhysicsDescription {
|
||||
pub body_status: String,
|
||||
pub ball: Option<TomlBallPhysicsBodyDescription>,
|
||||
pub cuboid: Option<TomlCuboidPhysicsBodyDescription>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Clone)]
|
||||
pub struct TomlRotationDescription {
|
||||
pub x: f32,
|
||||
pub y: f32,
|
||||
pub z: f32,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Clone)]
|
||||
pub struct TomlPositionDescription {
|
||||
pub x: f32,
|
||||
pub y: f32,
|
||||
pub z: f32,
|
||||
pub rot: Option<TomlRotationDescription>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Clone)]
|
||||
pub struct TomlEntityDescription {
|
||||
pub name: String,
|
||||
pub ent_type: String,
|
||||
#[serde(rename = "type")]
|
||||
pub type_name: String,
|
||||
pub mesh: Option<String>,
|
||||
pub position: Option<Position>
|
||||
pub position: Option<TomlPositionDescription>,
|
||||
pub physics: Option<TomlPhysicsDescription>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Clone)]
|
||||
pub struct TomlEntityContainer {
|
||||
pub entities: Vec<TomlEntityDescription>,
|
||||
}
|
||||
|
||||
pub struct RuntimeState {
|
||||
@@ -29,38 +73,15 @@ pub struct RuntimeState {
|
||||
mesh_cache: HashMap<String, RawMesh>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct TomlPositionDescription {
|
||||
pub x: f32,
|
||||
pub y: f32,
|
||||
pub z: f32,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct TomlEntityDescription {
|
||||
pub name: String,
|
||||
#[serde(rename = "type")]
|
||||
pub type_name: String,
|
||||
pub mesh: Option<String>,
|
||||
pub position: Option<TomlPositionDescription>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct TomlEntityContainer {
|
||||
pub entities: Vec<TomlEntityDescription>,
|
||||
}
|
||||
|
||||
|
||||
impl RuntimeState {
|
||||
pub fn new() -> RuntimeState {
|
||||
// TODO: Hook this file to the gui
|
||||
let mut file = fs::File::open("./conf/entity_spawns.toml").unwrap();
|
||||
let mut content = String::new();
|
||||
file.read_to_string(&mut content).unwrap();
|
||||
|
||||
// TODO: gracefully fail
|
||||
let mut settings : TomlEntityContainer = toml::from_str(content.as_str()).unwrap();
|
||||
// settings
|
||||
// // File::with_name(..) is shorthand for File::from(Path::new(..))
|
||||
// .merge(File::with_name("conf/entity_spawns.toml"))
|
||||
// .unwrap();
|
||||
|
||||
RuntimeState {
|
||||
config_db: settings,
|
||||
@@ -72,40 +93,8 @@ impl RuntimeState {
|
||||
self.mesh_cache.get(mesh)
|
||||
}
|
||||
|
||||
pub fn get_configured_entities(&mut self) -> Vec<EntityMeta> {
|
||||
let mut out = Vec::new();
|
||||
for entity in &self.config_db.entities {
|
||||
|
||||
let position = match &entity.position {
|
||||
None => { None }
|
||||
Some(pos) => {
|
||||
|
||||
Some(Position {
|
||||
x: pos.x,
|
||||
y: pos.y,
|
||||
z: pos.z,
|
||||
rot: Euler {
|
||||
x: Deg(0.0),
|
||||
y: Deg(0.0),
|
||||
z: Deg(0.0)
|
||||
}
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
// log::info!("{:?}", position);
|
||||
// log::info!("{:?}", entity);
|
||||
// log::info!("{:?}", entity.into_table());
|
||||
// log::info!("{:?}", entity.into_array());
|
||||
|
||||
out.push(EntityMeta {
|
||||
name: entity.name.clone(),
|
||||
ent_type: entity.type_name.clone(),
|
||||
mesh: entity.mesh.clone(),
|
||||
position: position
|
||||
});
|
||||
}
|
||||
out
|
||||
pub fn get_entities(&mut self) -> Vec<TomlEntityDescription> {
|
||||
self.config_db.entities.clone()
|
||||
}
|
||||
|
||||
pub fn preload_meshes(&mut self, resources_path: PathBuf) {
|
||||
|
||||
Reference in New Issue
Block a user