-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
141 additions
and
8 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
python_genshin_artifact_core/src/applications/input/buff.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<PyString>, | ||
pub config: Option<Py<PyDict>>, | ||
} | ||
|
||
#[pymethods] | ||
impl PyBuffInterface { | ||
#[new] | ||
pub fn py_new( | ||
name: Py<PyString>, | ||
config: Option<Py<PyDict>>, | ||
) -> PyResult<Self> { | ||
Ok(Self { | ||
name, | ||
config, | ||
}) | ||
} | ||
} | ||
|
||
impl TryInto<MonaBuffInterface> for PyBuffInterface { | ||
type Error = anyhow::Error; | ||
|
||
fn try_into(self) -> Result<MonaBuffInterface, Self::Error> { | ||
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, | ||
}) | ||
} | ||
} | ||
|
||
|
14 changes: 11 additions & 3 deletions
14
python_genshin_artifact_core/src/applications/input/calculator.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<PyBuffInterface>, | ||
} | ||
|
||
#[pymethods] | ||
impl CalculatorConfig { | ||
#[new] | ||
pub fn py_new(character: PyCharacterInterface) -> PyResult<Self> { | ||
Ok(Self { character }) | ||
pub fn py_new( | ||
character: PyCharacterInterface, | ||
weapon: PyWeaponInterface, | ||
buffs: Vec<PyBuffInterface>, | ||
) -> PyResult<Self> { | ||
Ok(Self { character, weapon, buffs }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
pub mod calculator; | ||
pub mod common; | ||
pub mod character; | ||
pub mod weapon; | ||
pub mod buff; |
64 changes: 64 additions & 0 deletions
64
python_genshin_artifact_core/src/applications/input/weapon.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<PyString>, | ||
pub level: i32, | ||
pub ascend: bool, | ||
pub refine: i32, | ||
pub params: Option<Py<PyDict>>, | ||
} | ||
|
||
#[pymethods] | ||
impl PyWeaponInterface { | ||
#[new] | ||
pub fn py_new( | ||
name: Py<PyString>, | ||
level: i32, | ||
ascend: bool, | ||
refine: i32, | ||
params: Option<Py<PyDict>>, | ||
) -> PyResult<Self> { | ||
Ok(Self { | ||
name, | ||
level, | ||
ascend, | ||
refine, | ||
params, | ||
}) | ||
} | ||
} | ||
|
||
|
||
impl TryInto<MonaWeaponInterface> for PyWeaponInterface { | ||
type Error = anyhow::Error; | ||
|
||
fn try_into(self) -> Result<MonaWeaponInterface, Self::Error> { | ||
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, | ||
}) | ||
} | ||
} |