use super::config::ResearchConfig;
use super::hook::{DefaultResearchHook, ResearchHook};
use super::research_projects::ResearchProjects;
use super::state::ResearchState;
use super::system::ResearchSystem;
use crate::Plugin;
use std::sync::Arc;
#[derive(Plugin)]
#[plugin(name = "issun:research")]
pub struct ResearchPlugin {
#[plugin(skip)]
hook: Arc<dyn ResearchHook>,
#[plugin(resource)]
projects: ResearchProjects,
#[plugin(resource)]
config: ResearchConfig,
#[plugin(runtime_state)]
#[allow(dead_code)]
state: ResearchState,
#[plugin(system)]
system: ResearchSystem,
}
impl ResearchPlugin {
pub fn new() -> Self {
let hook = Arc::new(DefaultResearchHook);
Self {
hook: hook.clone(),
projects: ResearchProjects::new(),
config: ResearchConfig::default(),
state: ResearchState::new(),
system: ResearchSystem::new(hook),
}
}
pub fn with_hook<H: ResearchHook + 'static>(mut self, hook: H) -> Self {
let hook = Arc::new(hook);
self.hook = hook.clone();
self.system = ResearchSystem::new(hook);
self
}
pub fn with_projects(mut self, projects: ResearchProjects) -> Self {
self.projects = projects;
self
}
pub fn with_config(mut self, config: ResearchConfig) -> Self {
self.config = config;
self
}
}
impl Default for ResearchPlugin {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_plugin_creation() {
let _plugin = ResearchPlugin::new();
}
#[test]
fn test_plugin_with_custom_hook() {
struct CustomHook;
#[async_trait::async_trait]
impl ResearchHook for CustomHook {}
let _plugin = ResearchPlugin::new().with_hook(CustomHook);
}
#[test]
fn test_plugin_with_custom_config() {
let config = ResearchConfig {
allow_parallel_research: true,
max_parallel_slots: 3,
..Default::default()
};
let _plugin = ResearchPlugin::new().with_config(config);
}
}