Reorganize project to workspace

This commit is contained in:
Tony Klink 2024-04-01 20:51:39 -06:00
parent 92c0278ef0
commit 960e2f8a37
Signed by: klink
GPG key ID: 85175567C4D19231
39 changed files with 4420 additions and 1189 deletions

View file

@ -0,0 +1,16 @@
[package]
name = "khors-config"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
khors-core = { path = "../../khors-core", version = "0.1.0" }
anyhow = "1.0.80"
notify = "6.1.1"
notify-debouncer-mini = "0.4.1"
flax = { version = "0.6.2", features = ["derive", "serde", "tokio", "tracing"] }
serde = { version = "1.0.197", features = ["derive"] }
serde-lexpr = "0.1.3"

View file

@ -0,0 +1,9 @@
use flax::component;
use super::Config;
component! {
pub config: Config,
pub notify_file_event: notify::Event,
pub resources,
}

View file

@ -0,0 +1,53 @@
use flax::{Schedule, World};
use khors_core::module::Module;
use serde::{Deserialize, Serialize};
use self::systems::first_read_config_system;
pub mod components;
pub mod systems;
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
pub struct Config {
pub asset_path: String,
}
#[allow(dead_code)]
pub struct ConfigModule {
// watcher: INotifyWatcher,
// watcher_rx: std::sync::mpsc::Receiver<Result<notify::Event, notify::Error>>,
}
impl ConfigModule {
pub fn new(
schedule: &mut Schedule,
_world: &mut World,
_events: &mut khors_core::events::Events,
) -> Self {
let schedule_r = Schedule::builder()
// .with_system(read_config_system())
.with_system(first_read_config_system())
.build();
schedule.append(schedule_r);
Self {
// schedule,
// watcher,
// watcher_rx: rx,
}
}
}
impl Module for ConfigModule {
fn on_update(
&mut self,
_world: &mut World,
_events: &mut khors_core::events::Events,
_frame_time: std::time::Duration,
) -> anyhow::Result<()> {
// println!("ConfigModule on_update");
Ok(())
}
}

View file

@ -0,0 +1,53 @@
use std::{fs, path::Path};
use flax::{BoxedSystem, CommandBuffer, EntityBorrow, Query, System};
use serde_lexpr::from_str;
use super::{components::{config, notify_file_event, resources}, Config};
#[allow(dead_code)]
pub fn read_config_system() -> BoxedSystem {
let query = Query::new(notify_file_event()).entity(resources());
System::builder()
.with_name("read_config")
.with_cmd_mut()
.with_query(query)
.build(|cmd: &mut CommandBuffer, mut _q: EntityBorrow<_>| {
// if let Ok(n_event) = q.get() {
// println!("here");
// if (n_event as &notify::Event).kind.is_modify() {
// println!("file modified: {:?}", (n_event as &notify::Event).paths);
cmd.set(resources(), config(), read_engine_config());
// }
// }
})
.boxed()
}
fn read_engine_config() -> Config {
let config_path = Path::new("engine_config.scm");
let config_file = fs::read_to_string(config_path).unwrap();
let config: Config = from_str::<Config>(&config_file).expect("Failed to parse config file");
config
}
pub fn first_read_config_system() -> BoxedSystem {
let query = Query::new(config().as_mut()).entity(resources());
System::builder()
.with_name("first_read_config")
.with_cmd_mut()
.with_query(query)
.build(|cmd: &mut CommandBuffer, mut q: EntityBorrow<_>| {
if let Ok(_config) = q.get() {
return;
} else {
println!("read_notify_events_system: config read");
cmd.set(resources(), config(), read_engine_config());
}
std::thread::sleep(std::time::Duration::from_secs(3));
})
.boxed()
}