diff --git a/grimoire_engine_types/src/expr/mod.rs b/grimoire_engine_types/src/expr/mod.rs new file mode 100644 index 0000000000000000000000000000000000000000..29a991e560a564b65f40f5b8d1096ff9b7619a70 --- /dev/null +++ b/grimoire_engine_types/src/expr/mod.rs @@ -0,0 +1,2 @@ +#[derive(Debug)] +pub enum Expression {} diff --git a/grimoire_engine_types/src/lib.rs b/grimoire_engine_types/src/lib.rs index 46bc08dfe30f0d9858f04de2a36dc136db55a584..61907f02b9e6fb9b43baa298917348af730d79ca 100644 --- a/grimoire_engine_types/src/lib.rs +++ b/grimoire_engine_types/src/lib.rs @@ -1,3 +1,4 @@ pub mod spell; +pub mod expr; pub mod state; pub mod error; diff --git a/grimoire_engine_types/src/spell/arguments.rs b/grimoire_engine_types/src/spell/arguments.rs index 6fb7e7494d056a2a61f168167f029f3b7433c2a0..32807b726c1512e748d092d49cd6a1db5931ba14 100644 --- a/grimoire_engine_types/src/spell/arguments.rs +++ b/grimoire_engine_types/src/spell/arguments.rs @@ -1 +1,48 @@ -pub struct SpellArguments {} +use crate::expr::Expression; +use std::collections::HashMap; + +/// Allowed types for arguments. +#[derive(Debug)] +pub enum ArgumentType { + Boolean, + Integer, + Identifier, + Actor, + Printer, +} + +/// The argument. +#[derive(Debug)] +pub enum Argument { + Expression(Expression), + Identifier(String), +} + +impl Argument { + pub fn into_a(&self, _into_type: ArgumentType) -> Option<Self> { + todo!() + } +} + +/// The arguments that may be passed to a spell for its instanciation. +#[derive(Debug, Default)] +pub struct SpellArguments(HashMap<String, Argument>); + +impl SpellArguments { + /// Set/Override the value in the [Argument] list. + pub fn set(&mut self, name: String, value: Argument) { + _ = self.0.insert(name, value); + } + + /// Pops the value of an [Argument], and try to cast it into the asked type. On success returns + /// [Option<Argument>::Some], otherwise [None]. + pub fn pop(&mut self, name: impl AsRef<str>, into_type: ArgumentType) -> Option<Argument> { + self.0.remove(name.as_ref())?.into_a(into_type) + } +} + +impl FromIterator<(String, Argument)> for SpellArguments { + fn from_iter<T: IntoIterator<Item = (String, Argument)>>(iter: T) -> Self { + Self(iter.into_iter().collect()) + } +}