-
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
120 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use mona::artifacts::Artifact; | ||
use mona::artifacts::effect_config::ArtifactConfigInterface; | ||
use mona_wasm::applications::common::{BuffInterface, CharacterInterface, EnemyInterface, SkillInterface, WeaponInterface}; | ||
use pyo3::prelude::*; | ||
|
||
#[derive(Debug, Clone)] | ||
#[pyclass] | ||
pub struct CalculatorConfig { | ||
pub character: CharacterInterface, | ||
// pub weapon: WeaponInterface, | ||
// pub buffs: Vec<BuffInterface>, | ||
// pub artifacts: Vec<Artifact>, | ||
// pub artifact_config: Option<ArtifactConfigInterface>, | ||
// pub skill: SkillInterface, | ||
// pub enemy: Option<EnemyInterface>, | ||
} | ||
|
||
#[pymethods] | ||
impl CalculatorConfig { | ||
#[new] | ||
// #[args(buffs="Vec::new()", artifacts="Vec::new()", artifact_config="None", enemy="None")] | ||
fn new(character: CharacterInterface, | ||
// weapon: WeaponInterface, | ||
// buffs: Vec<BuffInterface>, | ||
// artifacts: Vec<Artifact>, | ||
// artifact_config: Option<ArtifactConfigInterface>, | ||
// skill: SkillInterface, | ||
// enemy: Option<EnemyInterface>, | ||
) -> Self { | ||
CalculatorConfig { | ||
character, | ||
// weapon, | ||
// buffs, | ||
// artifacts, | ||
// artifact_config, | ||
// skill, | ||
// enemy, | ||
} | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
python_genshin_artifact_core/src/applications/input/common.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,74 @@ | ||
use std::str::FromStr; | ||
use mona::character::{CharacterConfig, CharacterName}; | ||
use mona_wasm::applications::common::CharacterInterface; | ||
use pyo3::exceptions::PyValueError; | ||
use pyo3::prelude::*; | ||
use pyo3::types::PyDict; | ||
|
||
#[derive(Clone)] | ||
#[pyclass(name = "CharacterInterface")] | ||
pub struct PyCharacterInterface { | ||
pub name: String, | ||
pub level: usize, | ||
pub ascend: bool, | ||
pub constellation: i32, | ||
pub skill1: usize, | ||
pub skill2: usize, | ||
pub skill3: usize, | ||
pub params: Option<PyDict>, | ||
} | ||
|
||
#[pymethods] | ||
impl PyCharacterInterface { | ||
#[new] | ||
fn new(name: String, | ||
level: usize, | ||
ascend: bool, | ||
constellation: i32, | ||
skill1: usize, | ||
skill2: usize, | ||
skill3: usize, | ||
params: Option<PyDict>, | ||
) -> Self { | ||
PyCharacterInterface { | ||
name, | ||
level, | ||
ascend, | ||
constellation, | ||
skill1, | ||
skill2, | ||
skill3, | ||
params, | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
impl PyCharacterInterface { | ||
|
||
fn py_dict_to_character_config(py_dict: &PyDict) -> PyResult<CharacterConfig> { | ||
let json_str = py_dict.to_string()?; | ||
let json_value = serde_json::from_str(&json_str)?; | ||
let character_config: CharacterConfig = serde_json::from_value(json_value)?; | ||
Ok(character_config) | ||
} | ||
|
||
pub fn to_rust(&self) -> CharacterInterface { | ||
let name = CharacterName::from_str(&self.name).map_err(|e| PyValueError::new_err((e.to_string(), &self.name, 0)))?; | ||
let params = self.params.as_ref().map_or(Ok(CharacterConfig::NoConfig), |py_dict| { | ||
self.py_dict_to_character_config(py_dict).map_err(|e| PyValueError::new_err((e.to_string(), &self.params, 0)))? | ||
})?; | ||
CharacterInterface { | ||
name, | ||
level: self.level.clone(), | ||
ascend: self.ascend.clone(), | ||
constellation: self.constellation.clone(), | ||
skill1: self.skill1.clone(), | ||
skill2: self.skill2.clone(), | ||
skill3: self.skill3.clone(), | ||
params, | ||
} | ||
} | ||
} | ||
|
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,3 @@ | ||
pub mod calculator; | ||
pub mod common; | ||
pub mod character; |
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,3 @@ | ||
pub mod generate; | ||
pub mod wasm; | ||
pub mod input; |
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