[Refactor] Interface to python cleanup.

This commit is contained in:
Wiktor Mazur
2019-10-05 15:07:55 +02:00
parent 9307663d86
commit 5839b99b75
10 changed files with 184 additions and 145 deletions
+27 -1
View File
@@ -9,10 +9,12 @@ use std::time::Instant;
use cpython::PythonObject;
use cpython::ToPyObject;
use cpython::FromPyObject;
use cpython::Python;
use cpython::PyObject;
use cpython::PyDict;
use cpython::PyList;
use cpython::PyResult;
use super::traits::DamageStats;
use super::traits::FameStats;
@@ -57,6 +59,14 @@ pub struct PlayerStatisticsVec {
_vec: Vec<PlayerStatistics>
}
#[derive(Debug, PartialEq, Copy, Clone)]
pub enum StatType {
LastFight,
Zone,
Overall,
Unknown
}
impl PlayerStatisticsVec {
pub fn new() -> Self {
Self {
@@ -162,4 +172,20 @@ impl ToPyObject for PlayerStatisticsVec {
fn to_py_object(&self, py: Python) -> Self::ObjectType {
self._vec.clone().into_py_object(py)
}
}
}
impl <'source> FromPyObject<'source> for StatType {
fn extract(py: Python, obj: &'source PyObject) -> PyResult<Self> {
match obj.extract(py) {
Ok(n) => {
match n {
1 => Ok(StatType::LastFight),
2 => Ok(StatType::Zone),
3 => Ok(StatType::Overall),
_ => Ok(StatType::Unknown)
}
},
Err(e) => Err(e)
}
}
}