mirror of
https://github.com/PaiGramTeam/python-genshin-artifact.git
synced 2024-12-04 11:40:10 +00:00
✨ Add __dict__
for CalculatorConfig
This commit is contained in:
parent
413be213be
commit
009124d4d2
@ -20,14 +20,13 @@
|
|||||||
|
|
||||||
## Build
|
## Build
|
||||||
|
|
||||||
- Navigate to core -> run cargo build
|
- (Optional) Run cargo build
|
||||||
```
|
```
|
||||||
$ cd python_genshin_artifact_core
|
$ cargo build --no-default-features
|
||||||
$ cargo build
|
|
||||||
...
|
...
|
||||||
Compiling pyo3-ffi v0.19.2
|
Compiling pyo3-ffi v0.19.2
|
||||||
Compiling pyo3 v0.19.2
|
Compiling pyo3 v0.19.2
|
||||||
Compiling genshin_artifact_core v0.1.1 (/home/kotori/projects/python/python-genshin-artifact/python_genshin_artifact_core)
|
Compiling python_genshin_artifact v0.1.1 (/home/kotori/projects/python/python-genshin-artifact/python_genshin_artifact_core)
|
||||||
Finished dev [unoptimized + debuginfo] target(s) in 3.12s
|
Finished dev [unoptimized + debuginfo] target(s) in 3.12s
|
||||||
```
|
```
|
||||||
- Use maturin to install the rust library into a python library
|
- Use maturin to install the rust library into a python library
|
||||||
@ -35,20 +34,18 @@
|
|||||||
$ maturin develop
|
$ maturin develop
|
||||||
...
|
...
|
||||||
📦 Built wheel for CPython 3.11 to /tmp/.tmpicGM3M/genshin_artifact_core-0.1.1-cp311-cp311-linux_x86_64.whl
|
📦 Built wheel for CPython 3.11 to /tmp/.tmpicGM3M/genshin_artifact_core-0.1.1-cp311-cp311-linux_x86_64.whl
|
||||||
🛠 Installed genshin_artifact_core-0.1.1
|
🛠 Installed python_genshin_artifact-0.1.1
|
||||||
```
|
```
|
||||||
- Navigate back to project root and build with poetry:
|
- Use maturin to build the wheel
|
||||||
```
|
```
|
||||||
$ poetry build
|
$ maturin build --out dist
|
||||||
Building Python-Genshin-Artifact (0.1.1)
|
...
|
||||||
- Building sdist
|
Finished dev [unoptimized + debuginfo] target(s) in 3.88s
|
||||||
- Built python_genshin_artifact-0.1.1.tar.gz
|
📦 Built wheel for CPython 3.11 to dist/python_genshin_artifact-0.1.4-cp311-cp311-manylinux_2_34_x86_64.whl
|
||||||
- Building wheel
|
|
||||||
- Built python_genshin_artifact-0.1.1-py3-none-any.whl
|
|
||||||
```
|
```
|
||||||
- Install the built wheel with pip:
|
- Install the built wheel with pip:
|
||||||
```
|
```
|
||||||
$ pip install dist/python_genshin_artifact-0.1.1-py3-none-any.whl
|
$ pip install dist/python_genshin_artifact-xxx.whl
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,12 +49,11 @@ pub fn get_damage_analysis(calculator_config: PyCalculatorConfig) -> PyResult<Py
|
|||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
let artifact_config =
|
let artifact_config = if let Some(artifact_config) = artifact_config_interface {
|
||||||
if let Some(artifact_config) = artifact_config_interface {
|
artifact_config.to_config()
|
||||||
artifact_config.to_config()
|
} else {
|
||||||
} else {
|
ArtifactEffectConfig::default()
|
||||||
ArtifactEffectConfig::default()
|
};
|
||||||
};
|
|
||||||
|
|
||||||
let buffs = calculator_config
|
let buffs = calculator_config
|
||||||
.buffs
|
.buffs
|
||||||
@ -124,12 +123,11 @@ pub fn get_transformative_damage(
|
|||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
let artifact_config =
|
let artifact_config = if let Some(artifact_config) = artifact_config_interface {
|
||||||
if let Some(artifact_config) = artifact_config_interface {
|
artifact_config.to_config()
|
||||||
artifact_config.to_config()
|
} else {
|
||||||
} else {
|
ArtifactEffectConfig::default()
|
||||||
ArtifactEffectConfig::default()
|
};
|
||||||
};
|
|
||||||
|
|
||||||
let buffs = calculator_config
|
let buffs = calculator_config
|
||||||
.buffs
|
.buffs
|
||||||
|
@ -65,10 +65,13 @@ impl PyArtifact {
|
|||||||
dict.set_item("slot", self.slot.as_ref(py))?;
|
dict.set_item("slot", self.slot.as_ref(py))?;
|
||||||
dict.set_item("level", self.level)?;
|
dict.set_item("level", self.level)?;
|
||||||
dict.set_item("star", self.star)?;
|
dict.set_item("star", self.star)?;
|
||||||
let sub_stats_pylist = PyList::new(py, self.sub_stats.iter().map(|(s, v)| {
|
let sub_stats_pylist = PyList::new(
|
||||||
let stat_str = s.as_ref(py).to_str().unwrap();
|
py,
|
||||||
(stat_str, *v)
|
self.sub_stats.iter().map(|(s, v)| {
|
||||||
}));
|
let stat_str = s.as_ref(py).to_str().unwrap();
|
||||||
|
(stat_str, *v)
|
||||||
|
}),
|
||||||
|
);
|
||||||
dict.set_item("sub_stats", sub_stats_pylist)?;
|
dict.set_item("sub_stats", sub_stats_pylist)?;
|
||||||
let main_stat_tuple = (self.main_stat.0.as_ref(py), self.main_stat.1);
|
let main_stat_tuple = (self.main_stat.0.as_ref(py), self.main_stat.1);
|
||||||
dict.set_item("main_stat", main_stat_tuple)?;
|
dict.set_item("main_stat", main_stat_tuple)?;
|
||||||
|
@ -30,7 +30,10 @@ impl PyBuffInterface {
|
|||||||
Some(config) => config.as_ref(py).repr()?.to_str()?.to_string(),
|
Some(config) => config.as_ref(py).repr()?.to_str()?.to_string(),
|
||||||
None => "None".to_string(),
|
None => "None".to_string(),
|
||||||
};
|
};
|
||||||
Ok(format!("BuffInterface(name={}, config={})", name, config_repr))
|
Ok(format!(
|
||||||
|
"BuffInterface(name={}, config={})",
|
||||||
|
name, config_repr
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[getter]
|
#[getter]
|
||||||
|
@ -6,7 +6,7 @@ use crate::applications::input::skill::PySkillInterface;
|
|||||||
use crate::applications::input::weapon::PyWeaponInterface;
|
use crate::applications::input::weapon::PyWeaponInterface;
|
||||||
|
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use pyo3::types::PyDict;
|
use pyo3::types::{PyDict, PyList};
|
||||||
|
|
||||||
#[pyclass(name = "CalculatorConfig")]
|
#[pyclass(name = "CalculatorConfig")]
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -50,4 +50,35 @@ impl PyCalculatorConfig {
|
|||||||
enemy,
|
enemy,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[getter]
|
||||||
|
pub fn __dict__(&self, py: Python) -> PyResult<PyObject> {
|
||||||
|
let dict = PyDict::new(py);
|
||||||
|
dict.set_item("character", self.character.__dict__(py)?)?;
|
||||||
|
dict.set_item("weapon", self.weapon.__dict__(py)?)?;
|
||||||
|
let buffs = self
|
||||||
|
.buffs
|
||||||
|
.iter()
|
||||||
|
.map(|b| b.__dict__(py))
|
||||||
|
.collect::<Result<Vec<PyObject>, PyErr>>()?;
|
||||||
|
dict.set_item("buffs", PyList::new(py, buffs))?;
|
||||||
|
let artifacts = self
|
||||||
|
.artifacts
|
||||||
|
.iter()
|
||||||
|
.map(|ar| ar.__dict__(py))
|
||||||
|
.collect::<Result<Vec<PyObject>, PyErr>>()?;
|
||||||
|
dict.set_item("artifacts", PyList::new(py, artifacts))?;
|
||||||
|
if let Some(artifact_config) = self.artifact_config.as_ref().map(|c| c.as_ref(py)) {
|
||||||
|
dict.set_item("artifact_config", artifact_config)?;
|
||||||
|
} else {
|
||||||
|
dict.set_item("artifact_config", py.None())?;
|
||||||
|
}
|
||||||
|
dict.set_item("skill", self.skill.__dict__(py)?)?;
|
||||||
|
if let Some(enemy) = self.enemy.as_ref().map(|e| e.__dict__(py)).transpose()? {
|
||||||
|
dict.set_item("enemy", enemy)?;
|
||||||
|
} else {
|
||||||
|
dict.set_item("enemy", py.None())?;
|
||||||
|
}
|
||||||
|
Ok(dict.into())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,10 @@ impl PySkillInterface {
|
|||||||
Ok(Self { index, config })
|
Ok(Self { index, config })
|
||||||
}
|
}
|
||||||
pub fn __repr__(&self) -> PyResult<String> {
|
pub fn __repr__(&self) -> PyResult<String> {
|
||||||
Ok(format!("SkillInterface(index: {}, config: {:?})", self.index, self.config))
|
Ok(format!(
|
||||||
|
"SkillInterface(index: {}, config: {:?})",
|
||||||
|
self.index, self.config
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[getter]
|
#[getter]
|
||||||
@ -36,7 +39,6 @@ impl PySkillInterface {
|
|||||||
}
|
}
|
||||||
Ok(dict.into())
|
Ok(dict.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryInto<MonaSkillInterface> for PySkillInterface {
|
impl TryInto<MonaSkillInterface> for PySkillInterface {
|
||||||
|
Loading…
Reference in New Issue
Block a user