use super::hook::{DefaultRoomBuffHook, RoomBuffHook};
use super::service::BuffService;
use super::system::BuffSystem;
use super::types::{ActiveBuffs, RoomBuffDatabase};
use crate::Plugin;
use std::sync::Arc;
#[derive(Plugin)]
#[plugin(name = "issun:room_buff")]
pub struct RoomBuffPlugin {
#[plugin(skip)]
hook: Arc<dyn RoomBuffHook>,
#[resource]
database: RoomBuffDatabase,
#[state]
active_buffs: ActiveBuffs,
#[service]
service: BuffService,
#[system]
system: BuffSystem,
}
impl RoomBuffPlugin {
pub fn new() -> Self {
let hook = Arc::new(DefaultRoomBuffHook);
Self {
hook: hook.clone(),
database: RoomBuffDatabase::default(),
active_buffs: ActiveBuffs::default(),
service: BuffService::new(),
system: BuffSystem::new(hook),
}
}
pub fn with_hook<H: RoomBuffHook + 'static>(mut self, hook: H) -> Self {
let hook = Arc::new(hook);
self.hook = hook.clone();
self.system = BuffSystem::new(hook);
self
}
pub fn with_database(mut self, database: RoomBuffDatabase) -> Self {
self.database = database;
self
}
}
impl Default for RoomBuffPlugin {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::plugin::Plugin;
#[test]
fn test_plugin_creation() {
let plugin = RoomBuffPlugin::new();
assert_eq!(plugin.name(), "issun:room_buff");
}
#[test]
fn test_plugin_with_custom_hook() {
struct CustomHook;
#[async_trait::async_trait]
impl RoomBuffHook for CustomHook {}
let plugin = RoomBuffPlugin::new().with_hook(CustomHook);
assert_eq!(plugin.name(), "issun:room_buff");
}
#[test]
fn test_plugin_with_database() {
let database = RoomBuffDatabase::new();
let plugin = RoomBuffPlugin::new().with_database(database);
assert_eq!(plugin.name(), "issun:room_buff");
}
}