use bevy::{platform::collections::HashSet, prelude::*, reflect::Reflect};
#[derive(Component, Reflect, Default)]
#[reflect(Component)]
pub struct Guards {
pub guards: HashSet<String>,
}
impl Guards {
pub fn new() -> Self {
Self {
guards: HashSet::new(),
}
}
pub fn has_guard(&self, guard: impl Guard) -> bool {
self.guards.contains(&guard.name())
}
pub fn add_guard(&mut self, guard: impl Guard) {
self.guards.insert(guard.name());
}
pub fn remove_guard(&mut self, guard: impl Guard) {
self.guards.remove(&guard.name());
}
pub fn check(&self) -> bool {
self.guards.is_empty()
}
}
pub trait Guard {
fn name(&self) -> String;
}
impl Guard for String {
fn name(&self) -> String {
self.clone()
}
}
impl Guard for &str {
fn name(&self) -> String {
self.to_string()
}
}