feat: created built-in functions for listing, loading, and unloading skills
This commit is contained in:
@@ -6,6 +6,7 @@ use indexmap::IndexMap;
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Clone, Default)]
|
||||
pub struct SkillRegistry {
|
||||
loaded: IndexMap<String, Skill>,
|
||||
}
|
||||
@@ -22,13 +23,24 @@ impl SkillRegistry {
|
||||
if self.loaded.contains_key(name) {
|
||||
bail!("Skill '{name}' is already loaded");
|
||||
}
|
||||
|
||||
let skill = Skill::load(name)?;
|
||||
self.loaded.insert(name.to_string(), skill);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, skill: Skill) -> Result<()> {
|
||||
let name = skill.name().to_string();
|
||||
|
||||
if self.loaded.contains_key(&name) {
|
||||
bail!("Skill '{name}' is already loaded");
|
||||
}
|
||||
|
||||
self.loaded.insert(name, skill);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn unload(&mut self, name: &str) -> Result<()> {
|
||||
if self.loaded.shift_remove(name).is_none() {
|
||||
bail!("Skill '{name}' is not loaded");
|
||||
@@ -85,12 +97,6 @@ impl SkillRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for SkillRegistry {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_csv(s: Option<&str>) -> BTreeSet<String> {
|
||||
let mut set = BTreeSet::new();
|
||||
if let Some(raw) = s {
|
||||
|
||||
Reference in New Issue
Block a user