use super::config::CombatConfig;
use super::hook::{CombatHook, DefaultCombatHook};
use super::service::CombatService;
use super::state::CombatState;
use super::system::CombatSystem;
use crate::Plugin;
use std::sync::Arc;
#[derive(Plugin)]
#[plugin(name = "issun:combat")]
pub struct CombatPlugin {
hook: Arc<dyn CombatHook>,
#[resource]
config: CombatConfig,
#[state]
state: CombatState,
#[service]
service: CombatService,
#[system]
system: CombatSystem,
}
impl CombatPlugin {
pub fn new() -> Self {
let hook = Arc::new(DefaultCombatHook);
Self {
hook: hook.clone(),
config: CombatConfig::default(),
state: CombatState::new(),
service: CombatService::new(),
system: CombatSystem::new(hook),
}
}
pub fn with_hook<H: CombatHook + 'static>(mut self, hook: H) -> Self {
let hook = Arc::new(hook);
self.hook = hook.clone();
self.system = CombatSystem::new(hook);
self
}
pub fn with_config(mut self, config: CombatConfig) -> Self {
self.config = config;
self
}
}
impl Default for CombatPlugin {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::plugin::Plugin;
#[test]
fn test_plugin_creation() {
let plugin = CombatPlugin::new();
assert_eq!(plugin.name(), "issun:combat");
}
#[test]
fn test_plugin_with_custom_hook() {
struct CustomHook;
#[async_trait::async_trait]
impl CombatHook for CustomHook {}
let plugin = CombatPlugin::new().with_hook(CustomHook);
assert_eq!(plugin.name(), "issun:combat");
}
#[test]
fn test_plugin_with_custom_config() {
let config = CombatConfig {
enabled: true,
default_max_hp: 100,
difficulty_multiplier: 1.0,
enable_log: false,
max_log_entries: 50,
score_per_enemy: 20,
};
let plugin = CombatPlugin::new().with_config(config);
assert_eq!(plugin.name(), "issun:combat");
}
}