1
0
mirror of https://git.ngram.ca/OpenJam/rc-servers synced 2026-08-23 23:08:52 +00:00

Add minimal robot factory functionality and arc archive support for #6

This commit is contained in:
NG (Graham)
2025-05-17 23:06:07 -04:00
parent 3f0c30f6c3
commit 3f1438c068
34 changed files with 869 additions and 4 deletions

View File

@@ -0,0 +1,33 @@
pub enum Factory {
Arc(rc_factory::arc::ArcAdapter),
Custom(Box<dyn rc_factory::VehicleFactoryAdapter + Send + Sync + 'static>),
None,
}
#[async_trait::async_trait]
impl rc_factory::VehicleFactoryAdapter for Factory {
async fn vehicle(&self, id: u32) -> Result<Option<rc_factory::VehicleInfo>, Box<dyn std::error::Error>> {
match self {
Self::Arc(x) => x.vehicle(id).await,
Self::Custom(x) => x.vehicle(id).await,
Self::None => Ok(None),
}
}
async fn list(&self, query: libfj::robocraft::ListQuery) -> Result<Vec<rc_factory::VehicleQueryInfo>, Box<dyn std::error::Error>> {
match self {
Self::Arc(x) => x.list(query).await,
Self::Custom(x) => x.list(query).await,
Self::None => Ok(Vec::default()),
}
}
}
impl Factory {
pub async fn from_config(conf: &crate::persist::FactoryConfig) -> Result<Self, Box<dyn std::error::Error + 'static>> {
Ok(match &conf.adapter {
crate::persist::AdapterSettings::Arc(x) => Self::Arc(rc_factory::arc::ArcAdapter::init(&x.uri, x.show_expired).await?),
crate::persist::AdapterSettings::None => Self::None,
})
}
}

View File

@@ -0,0 +1,2 @@
mod adapter_enum;
pub use adapter_enum::Factory;