mirror of
https://github.com/PaiGramTeam/PaiGramDocs.git
synced 2024-11-23 00:11:32 +00:00
2.6 KiB
2.6 KiB
python-genshin-artifact 伤害计算
PaiGram 通过调用 python-genshin-artifact (下文简称 PGA) 模块实现角色伤害计算,该模块将 Rust 实现的 genshin_artifact 库包装为 python 模块供 PaiGram 使用。
依赖
PGA 主要依赖 Rust 以及 PyO3 实现与 genshin_artifact
的对接:
PYPI 安装
pip install python-genshin-artifact
编译安装
- 克隆项目
$ git clone https://github.com/PaiGramTeam/python-genshin-artifact.git
Cloning into 'python-genshin-artifact'...
...
- 浏览至项目主目录下,用
cargo
编译 Rust 代码 (可选步骤)
$ cd python-genshin-artifact/
$ cargo build --no-default-features
...
Compiling python_genshin_artifact v1.0.0
Finished dev [unoptimized + debuginfo] target(s) in 25.67s
- 编译成功后用
pyo3/maturin
安装至当前 Python 虚拟环境 (env
)
(env) $ maturin develop
Compiling python_genshin_artifact v1.0.0
Finished dev [unoptimized + debuginfo] target(s) in 18.06s
📦 Built wheel for CPython 3.10 to /tmp/.tmpE21JWW/python_genshin_artifact-1.0.0-cp310-cp310-linux_x86_64.whl
🛠 Installed python_genshin_artifact-1.0.0
- 至此,
python-genshin-artifact
可被导入至项目中使用
from python_genshin_artifact import get_damage_analysis, CalculatorConfig
calculator_config = CalculatorConfig(...)
damage_analysis = get_damage_analysis(calculator_config)
编译 wheel
如果需要导出给其它项目测试或使用 (例如 PaiGram),需要通过 maturin
将模块编译成 .whl
格式以便其它 Python 虚拟环境安装。
maturin build
:
$ maturin build --out dist
Finished dev [unoptimized + debuginfo] target(s) in 0.12s
📦 Built wheel for CPython 3.10 to dist/python_genshin_artifact-1.0.0-xxx.whl
- 将上一步打包完成的
.whl
安装至另一个项目的虚拟环境中 (此处假定 PaiGram 用的虚拟环境名是 venv)
(venv) $ pip install dist/python_genshin_artifact-1.0.0-xxx.whl
- 至此,PaiGram 项目就能导入
python_genshin_artifact
模块调用其中的函数了,具体用法参考 PaiGram/plugins/genshin/player_cards.py