From dca91ff67884f4ebac7468dea9ad648c79ea5866 Mon Sep 17 00:00:00 2001
From: Kubat <maelle.martin@proton.me>
Date: Sat, 19 Apr 2025 14:13:02 +0200
Subject: [PATCH] Add spell arguments

---
 grimoire_engine_types/src/expr/mod.rs        |  2 +
 grimoire_engine_types/src/lib.rs             |  1 +
 grimoire_engine_types/src/spell/arguments.rs | 49 +++++++++++++++++++-
 3 files changed, 51 insertions(+), 1 deletion(-)
 create mode 100644 grimoire_engine_types/src/expr/mod.rs

diff --git a/grimoire_engine_types/src/expr/mod.rs b/grimoire_engine_types/src/expr/mod.rs
new file mode 100644
index 0000000..29a991e
--- /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 46bc08d..61907f0 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 6fb7e74..32807b7 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())
+    }
+}
-- 
GitLab