diff --git a/src/applications/mod.rs b/src/applications/mod.rs index 765cc61..58576f8 100644 --- a/src/applications/mod.rs +++ b/src/applications/mod.rs @@ -3,4 +3,3 @@ pub mod errors; pub mod generate; pub mod input; pub mod output; -pub mod wasm; diff --git a/src/applications/wasm.rs b/src/applications/wasm.rs deleted file mode 100644 index aecc56e..0000000 --- a/src/applications/wasm.rs +++ /dev/null @@ -1,149 +0,0 @@ -use crate::JSONDecodeError; -use anyhow::Context; -use mona::artifacts::effect_config::{ArtifactConfigInterface, ArtifactEffectConfig}; -use mona::artifacts::{Artifact, ArtifactList}; -use mona::attribute::{AttributeUtils, ComplicatedAttributeGraph, SimpleAttributeGraph2}; -use mona::buffs::Buff; -use mona::character::Character; -use mona::damage::transformative_damage::TransformativeDamage; -use mona::damage::DamageContext; -use mona::enemies::Enemy; -use mona::utils; -use mona_wasm::applications::common::{ - BuffInterface, CharacterInterface, EnemyInterface, SkillInterface, WeaponInterface, -}; -use mona_wasm::CalculatorInterface; -use pyo3::prelude::*; -use serde::{Deserialize, Serialize}; - -#[derive(Serialize, Deserialize)] -pub struct CalculatorConfigInterface { - pub character: CharacterInterface, - pub weapon: WeaponInterface, - pub buffs: Vec, - pub artifacts: Vec, - pub artifact_config: Option, - pub skill: SkillInterface, - pub enemy: Option, -} - -#[derive(Serialize, Deserialize)] -struct TransformativeDamageBridge { - swirl_cryo: f64, - swirl_hydro: f64, - swirl_pyro: f64, - swirl_electro: f64, - overload: f64, - electro_charged: f64, - shatter: f64, - superconduct: f64, - bloom: f64, - hyperbloom: f64, - burgeon: f64, - burning: f64, - crystallize: f64, -} - -impl From for TransformativeDamageBridge { - fn from(damage: TransformativeDamage) -> Self { - Self { - swirl_cryo: damage.swirl_cryo, - swirl_hydro: damage.swirl_hydro, - swirl_pyro: damage.swirl_pyro, - swirl_electro: damage.swirl_electro, - overload: damage.overload, - electro_charged: damage.electro_charged, - shatter: damage.shatter, - superconduct: damage.superconduct, - bloom: damage.bloom, - hyperbloom: damage.hyperbloom, - burgeon: damage.burgeon, - burning: damage.burning, - crystallize: damage.crystallize, - } - } -} - -#[pyfunction] -pub fn get_damage_analysis(value_str: String) -> PyResult { - let input: CalculatorConfigInterface = serde_json::from_str(&value_str) - .map_err(|e| JSONDecodeError::new_err((e.to_string(), value_str.to_owned(), 0)))?; - - let character: Character = input.character.to_character(); - let weapon = input.weapon.to_weapon(&character); - - let buffs: Vec>> = - input.buffs.iter().map(|x| x.to_buff()).collect(); - let artifacts: Vec<&Artifact> = input.artifacts.iter().collect(); - - let artifact_config = match input.artifact_config { - Some(x) => x.to_config(), - None => ArtifactEffectConfig::default(), - }; - - let enemy = if let Some(x) = input.enemy { - x.to_enemy() - } else { - Enemy::default() - }; - - let result = CalculatorInterface::get_damage_analysis_internal( - &character, - &weapon, - &buffs, - artifacts, - &artifact_config, - input.skill.index, - &input.skill.config, - &enemy, - None, - ); - - let result_str = serde_json::to_string(&result).context("Failed to serialize json")?; - Ok(result_str) -} - -#[pyfunction] -pub fn get_transformative_damage(value_str: String) -> PyResult { - utils::set_panic_hook(); - let input: CalculatorConfigInterface = serde_json::from_str(&value_str) - .map_err(|e| JSONDecodeError::new_err((e.to_string(), value_str.to_owned(), 0)))?; - - let character: Character = input.character.to_character(); - let weapon = input.weapon.to_weapon(&character); - - let buffs: Vec<_> = input.buffs.iter().map(|x| x.to_buff()).collect(); - let artifacts: Vec<&Artifact> = input.artifacts.iter().collect(); - - let artifact_config = match input.artifact_config { - Some(x) => x.to_config(), - None => ArtifactEffectConfig::default(), - }; - - let enemy = if let Some(x) = input.enemy { - x.to_enemy() - } else { - Enemy::default() - }; - - let attribute = AttributeUtils::create_attribute_from_big_config( - &ArtifactList { - artifacts: &artifacts, - }, - &artifact_config, - &character, - &weapon, - &buffs, - ); - - let context: DamageContext<'_, SimpleAttributeGraph2> = DamageContext { - character_common_data: &character.common_data, - enemy: &enemy, - attribute: &attribute, - }; - - let result = context.transformative(); - let bridge = TransformativeDamageBridge::from(result); - let result_str = serde_json::to_string(&bridge).context("Failed to serialize json")?; - Ok(result_str) -} diff --git a/src/lib.rs b/src/lib.rs index e2d6094..f5ca4aa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,7 @@ use applications::generate::artifact::gen_artifact_meta_as_json; use applications::generate::character::gen_character_meta_as_json; use applications::generate::locale::gen_generate_locale_as_json; use applications::generate::weapon::gen_weapon_meta_as_json; -use applications::wasm::{get_damage_analysis, get_transformative_damage}; +use applications::analysis::{get_damage_analysis, get_transformative_damage}; use crate::applications::input::artifact::PyArtifact; use crate::applications::input::buff::PyBuffInterface;