我其实不太确定这玩意能不能用(

This commit is contained in:
shenjack 2024-05-22 23:11:44 +08:00
parent bd151bd4d9
commit 4321d0d9d3
Signed by: shenjack
GPG Key ID: 7B1134A979775551
2 changed files with 48 additions and 1 deletions

View File

@ -206,6 +206,42 @@ impl PySR1PartData {
} }
} }
#[pyclass]
#[derive(Clone, Debug)]
#[pyo3(name = "SR1PartTypeArrayIterator_rs")]
pub struct PySR1PartDataIterator {
pub datas: Vec<(PySR1PartType, PySR1PartData)>,
pub index: usize,
}
#[pymethods]
impl PySR1PartDataIterator {
fn __next__(mut slf: PyRefMut<'_, Self>) -> Option<(PySR1PartType, PySR1PartData)> {
if slf.index < slf.datas.len() {
slf.index += 1;
Some(slf.datas[slf.index - 1].clone())
} else {
None
}
}
}
/// 用来存一堆 PartData 的数组
#[pyclass]
#[derive(Clone, Debug)]
#[pyo3(name = "SR1PartArray_rs")]
pub struct PySR1PartArray {
pub datas: Vec<(PySR1PartType, PySR1PartData)>,
pub part_list: SR1PartList,
}
#[pymethods]
impl PySR1PartArray {
fn __iter__(&self) -> PySR1PartDataIterator {
PySR1PartDataIterator { datas: self.datas.clone(), index: 0 }
}
}
#[pyclass] #[pyclass]
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
#[pyo3(name = "SR1Ship_rs")] #[pyo3(name = "SR1Ship_rs")]
@ -233,6 +269,18 @@ impl PySR1Ship {
} }
} }
fn parts(&self) -> PySR1PartArray {
let mut parts: Vec<(PySR1PartType, PySR1PartData)> = Vec::new();
for part_data in self.ship.parts.iter() {
if let Some(part_type) = self.part_list.get_part_type(&part_data.part_type_id) {
let part_type = PySR1PartType::new(part_type.clone());
let py_part_data = PySR1PartData::new(part_data.clone());
parts.push((part_type, py_part_data));
}
}
PySR1PartArray { datas: parts, part_list: self.part_list.clone() }
}
#[getter] #[getter]
fn get_img_pos(&self) -> (i64, i64, i64, i64) { fn get_img_pos(&self) -> (i64, i64, i64, i64) {
// -x, -y, +x, +y // -x, -y, +x, +y

View File

@ -881,7 +881,6 @@ impl SR1Ship {
fn write_data(data: &SR1Ship, save_status: &SaveStatus) -> String { fn write_data(data: &SR1Ship, save_status: &SaveStatus) -> String {
let mut writer: Writer<Cursor<Vec<u8>>> = Writer::new(Cursor::new(Vec::new())); let mut writer: Writer<Cursor<Vec<u8>>> = Writer::new(Cursor::new(Vec::new()));
{ {
// ship attr // ship attr
let mut ship_elem = BytesStart::new("Ship"); let mut ship_elem = BytesStart::new("Ship");