diff --git a/python_genshin_artifact_core/src/applications/input/buff.rs b/python_genshin_artifact_core/src/applications/input/buff.rs new file mode 100644 index 0000000..be9cf2e --- /dev/null +++ b/python_genshin_artifact_core/src/applications/input/buff.rs @@ -0,0 +1,57 @@ +use anyhow::anyhow; +use pyo3::prelude::*; +use pythonize::depythonize; +use mona::buffs::BuffConfig; +use mona::buffs::buff_name::BuffName; + +use pyo3::types::{PyDict, PyString}; + +use mona_wasm::applications::common::BuffInterface as MonaBuffInterface; + +#[pyclass(name = "BuffInterface")] +#[derive(Clone)] +pub struct PyBuffInterface { + pub name: Py, + pub config: Option>, +} + +#[pymethods] +impl PyBuffInterface { + #[new] + pub fn py_new( + name: Py, + config: Option>, + ) -> PyResult { + Ok(Self { + name, + config, + }) + } +} + +impl TryInto for PyBuffInterface { + type Error = anyhow::Error; + + fn try_into(self) -> Result { + let name:BuffName = Python::with_gil(|py| { + let _string: &PyString = self.name.as_ref(py); + depythonize(_string).map_err(|err| anyhow!("Failed to deserialize name: {}", err)) + })?; + + let config: BuffConfig = if let Some(value) = self.config { + Python::with_gil(|py| { + let _dict: &PyDict = value.as_ref(py); + depythonize(_dict).map_err(|err| anyhow!("Failed to deserialize config: {}", err)) + })? + } else { + BuffConfig::NoConfig + }; + + Ok(MonaBuffInterface { + name, + config, + }) + } +} + + diff --git a/python_genshin_artifact_core/src/applications/input/calculator.rs b/python_genshin_artifact_core/src/applications/input/calculator.rs index 33f5d15..cecd0fc 100644 --- a/python_genshin_artifact_core/src/applications/input/calculator.rs +++ b/python_genshin_artifact_core/src/applications/input/calculator.rs @@ -1,15 +1,23 @@ -use crate::applications::input::common::PyCharacterInterface; +use crate::applications::input::character::PyCharacterInterface; +use crate::applications::input::weapon::PyWeaponInterface; +use crate::applications::input::buff::PyBuffInterface; use pyo3::prelude::*; #[pyclass] pub struct CalculatorConfig { pub character: PyCharacterInterface, + pub weapon: PyWeaponInterface, + pub buffs: Vec, } #[pymethods] impl CalculatorConfig { #[new] - pub fn py_new(character: PyCharacterInterface) -> PyResult { - Ok(Self { character }) + pub fn py_new( + character: PyCharacterInterface, + weapon: PyWeaponInterface, + buffs: Vec, + ) -> PyResult { + Ok(Self { character, weapon, buffs }) } } diff --git a/python_genshin_artifact_core/src/applications/input/common.rs b/python_genshin_artifact_core/src/applications/input/character.rs similarity index 96% rename from python_genshin_artifact_core/src/applications/input/common.rs rename to python_genshin_artifact_core/src/applications/input/character.rs index 835a3e2..b1d2f4e 100644 --- a/python_genshin_artifact_core/src/applications/input/common.rs +++ b/python_genshin_artifact_core/src/applications/input/character.rs @@ -1,10 +1,11 @@ use anyhow::Context; -use mona::character::{CharacterConfig, CharacterName}; -use mona_wasm::applications::common::CharacterInterface as MonaCharacterInterface; -use pyo3::prelude::*; use pythonize::depythonize; use std::str::FromStr; use pyo3::types::PyDict; +use pyo3::prelude::*; + +use mona::character::{CharacterConfig, CharacterName}; +use mona_wasm::applications::common::CharacterInterface as MonaCharacterInterface; #[pyclass(name = "CharacterInterface")] #[derive(Clone)] @@ -54,7 +55,8 @@ impl TryInto for PyCharacterInterface { if let Some(value) = self.params { Python::with_gil(|py| { let _dict: &PyDict = value.as_ref(py); - params = depythonize(_dict).unwrap();; + params = depythonize(_dict).unwrap(); + ; }) } Ok(MonaCharacterInterface { diff --git a/python_genshin_artifact_core/src/applications/input/mod.rs b/python_genshin_artifact_core/src/applications/input/mod.rs index 9072717..97e3cba 100644 --- a/python_genshin_artifact_core/src/applications/input/mod.rs +++ b/python_genshin_artifact_core/src/applications/input/mod.rs @@ -1,2 +1,4 @@ pub mod calculator; -pub mod common; +pub mod character; +pub mod weapon; +pub mod buff; \ No newline at end of file diff --git a/python_genshin_artifact_core/src/applications/input/weapon.rs b/python_genshin_artifact_core/src/applications/input/weapon.rs new file mode 100644 index 0000000..69ab2ad --- /dev/null +++ b/python_genshin_artifact_core/src/applications/input/weapon.rs @@ -0,0 +1,64 @@ +use anyhow::anyhow; +use mona_wasm::applications::common::WeaponInterface as MonaWeaponInterface; +use pyo3::prelude::*; +use pythonize::depythonize; +use mona::weapon::{WeaponConfig, WeaponName}; +use pyo3::types::{PyDict, PyString}; + +#[pyclass(name = "WeaponInterface")] +#[derive(Clone)] +pub struct PyWeaponInterface { + pub name: Py, + pub level: i32, + pub ascend: bool, + pub refine: i32, + pub params: Option>, +} + +#[pymethods] +impl PyWeaponInterface { + #[new] + pub fn py_new( + name: Py, + level: i32, + ascend: bool, + refine: i32, + params: Option>, + ) -> PyResult { + Ok(Self { + name, + level, + ascend, + refine, + params, + }) + } +} + + +impl TryInto for PyWeaponInterface { + type Error = anyhow::Error; + + fn try_into(self) -> Result { + let name: WeaponName = Python::with_gil(|py| { + let _string: &PyString = self.name.as_ref(py); + depythonize(_string).map_err(|err| anyhow!("Failed to deserialize name: {}", err)) + })?; + + let params: WeaponConfig = if let Some(value) = self.params { + Python::with_gil(|py| { + let _dict: &PyDict = value.as_ref(py); + depythonize(_dict).map_err(|err| anyhow!("Failed to deserialize params: {}", err)) + })? + } else { + WeaponConfig::NoConfig + }; + Ok(MonaWeaponInterface { + name, + level: self.level, + ascend: self.ascend, + refine: self.refine, + params, + }) + } +}