From 4321d0d9d3c2ef1f6c1084bcf8f56588f2341642 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Wed, 22 May 2024 23:11:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=91=E5=85=B6=E5=AE=9E=E4=B8=8D=E5=A4=AA?= =?UTF-8?q?=E7=A1=AE=E5=AE=9A=E8=BF=99=E7=8E=A9=E6=84=8F=E8=83=BD=E4=B8=8D?= =?UTF-8?q?=E8=83=BD=E7=94=A8=EF=BC=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/src/python/data.rs | 48 +++++++++++++++++++ .../Difficult_Rocket_rs/src/src/sr1_parse.rs | 1 - 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/mods/dr_game/Difficult_Rocket_rs/src/src/python/data.rs b/mods/dr_game/Difficult_Rocket_rs/src/src/python/data.rs index 5ef38f0..754636d 100644 --- a/mods/dr_game/Difficult_Rocket_rs/src/src/python/data.rs +++ b/mods/dr_game/Difficult_Rocket_rs/src/src/python/data.rs @@ -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] #[derive(Clone, Debug)] #[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] fn get_img_pos(&self) -> (i64, i64, i64, i64) { // -x, -y, +x, +y diff --git a/mods/dr_game/Difficult_Rocket_rs/src/src/sr1_parse.rs b/mods/dr_game/Difficult_Rocket_rs/src/src/sr1_parse.rs index 9283120..5c0b6a9 100644 --- a/mods/dr_game/Difficult_Rocket_rs/src/src/sr1_parse.rs +++ b/mods/dr_game/Difficult_Rocket_rs/src/src/sr1_parse.rs @@ -881,7 +881,6 @@ impl SR1Ship { fn write_data(data: &SR1Ship, save_status: &SaveStatus) -> String { let mut writer: Writer>> = Writer::new(Cursor::new(Vec::new())); - { // ship attr let mut ship_elem = BytesStart::new("Ship");