diff --git a/grimoire_engine_types/src/spell/mod.rs b/grimoire_engine_types/src/spell/mod.rs index 646ce42b7808b3e56d601187f6672d8ae80c3367..35fd600f5db86c16027dfce7e58d48d9afcd9abd 100644 --- a/grimoire_engine_types/src/spell/mod.rs +++ b/grimoire_engine_types/src/spell/mod.rs @@ -1,3 +1,5 @@ +//! The definition of Spells in the Grimoire engine. + mod factory; mod arguments; mod traits; diff --git a/grimoire_engine_types/src/spell/traits.rs b/grimoire_engine_types/src/spell/traits.rs index 8c6c830139104ec91a904220e08c2cc40c378c55..c180e62f805f95ec7e79e968bd17e9ab887f8862 100644 --- a/grimoire_engine_types/src/spell/traits.rs +++ b/grimoire_engine_types/src/spell/traits.rs @@ -1,27 +1,36 @@ use crate::{error::SpellError, spell::SpellArguments, state::State}; +/// A spell, can be casted or reverted if we need to. pub trait Spell { - fn cast(&self, state: State) -> Result<State, SpellError>; + /// Cast the spell on a [State]. Returns a new [State]. + fn cast(&mut self, state: State) -> Result<State, SpellError>; - fn uncast(&self, state: State) -> Result<State, SpellError>; + /// UnCast the spell from a [State]. Returns the previous [State]. + fn uncast(&mut self, state: State) -> Result<State, SpellError>; } +/// A [Spell] that we can create. Is used to be able to register it into a +/// [crate::spell::SpellFactory]. pub trait BuildableSpell where Self: Spell + TryFrom<SpellArguments, Error = SpellError> + 'static, { + /// The name of the spell. fn name() -> &'static str; + /// Aliases for this spell. fn aliases() -> &'static [&'static str] { &[] } + /// The list of names: the name and all the aliases. fn name_list() -> impl Iterator<Item = &'static str> { [Self::name()] .into_iter() .chain(Self::aliases().iter().copied()) } + /// Create a spell from a set of arguments. May fail. fn create(arguments: SpellArguments) -> Result<Box<dyn Spell>, SpellError> { Self::try_from(arguments) .map(Box::new)