strange things are afoot at the circle-K

This commit is contained in:
2021-02-20 03:02:38 -08:00
parent 26f2cf4836
commit f4c6391e37
5 changed files with 72 additions and 29 deletions

View File

@@ -2,10 +2,9 @@ use std::collections::HashMap;
use std::fs;
use std::path::PathBuf;
use std::time::Instant;
use serde_derive::Deserialize;
use cgmath::{Euler, Quaternion};
use config::{Config, Value};
use config::File;
use cgmath::{Euler, Quaternion, Deg};
use legion::world::SubWorld;
use legion::IntoQuery;
use legion::*;
@@ -13,10 +12,10 @@ use nalgebra::Quaternion as naQuaternion;
use rapier3d::dynamics::{IntegrationParameters, JointSet, RigidBodySet};
use rapier3d::geometry::{BroadPhase, ColliderSet, NarrowPhase};
use rapier3d::pipeline::PhysicsPipeline;
use crate::camera::{Camera, CameraController};
use crate::components::{Collider, LoopState, Mesh, Physics, Position};
use crate::geometry::{load_obj, RawMesh};
use std::io::Read;
pub struct EntityMeta {
pub name: String,
@@ -26,17 +25,42 @@ pub struct EntityMeta {
}
pub struct RuntimeState {
config_db: Config,
config_db: TomlEntityContainer,
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 {
let mut settings = Config::default();
settings
// File::with_name(..) is shorthand for File::from(Path::new(..))
.merge(File::with_name("conf/entity_spawns.toml"))
.unwrap();
let mut file = fs::File::open("./conf/entity_spawns.toml").unwrap();
let mut content = String::new();
file.read_to_string(&mut content).unwrap();
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,
@@ -50,24 +74,35 @@ impl RuntimeState {
pub fn get_configured_entities(&mut self) -> Vec<EntityMeta> {
let mut out = Vec::new();
for entity in self.config_db.get_array("entities").unwrap() {
let table = entity.into_table().unwrap();
for entity in &self.config_db.entities {
let mesh = match table.get("mesh") {
let position = match &entity.position {
None => { None }
Some(v) => { Some(v.kind.to_string())}
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)
}
})
}
};
// let position = match table.get("position") {
// None => { None }
// Some(v) => { Some(v.kind.to_string())}
// };
// log::info!("{:?}", position);
// log::info!("{:?}", entity);
// log::info!("{:?}", entity.into_table());
// log::info!("{:?}", entity.into_array());
out.push(EntityMeta {
name: table.get("name").unwrap().kind.to_string(),
ent_type: table.get("type").unwrap().kind.to_string(),
mesh: mesh,
position: None
name: entity.name.clone(),
ent_type: entity.type_name.clone(),
mesh: entity.mesh.clone(),
position: position
});
}
out