diff --git a/configs/main.toml b/configs/main.toml
index 2a6ae9b..400236e 100644
--- a/configs/main.toml
+++ b/configs/main.toml
@@ -7,8 +7,8 @@ fonts_folder = "libs/fonts"
[window]
style = "None"
-width = 1954
-height = 1266
+width = 1683
+height = 1474
visible = true
gui_scale = 1
caption = "Difficult Rocket v{DR_version}|DR_rs v{DR_Rust_get_version}"
diff --git a/docs/src/change_log/dr_game.md b/docs/src/change_log/dr_game.md
index a1b4c71..f18587a 100644
--- a/docs/src/change_log/dr_game.md
+++ b/docs/src/change_log/dr_game.md
@@ -18,6 +18,14 @@
- 基于 `PyConsole`
- 用于替换 `DR sdk` 的默认控制台方法
+## DR rs 0.2.9.2
+
+### `sr1_data`
+
+### Bug 修复
+
+- [#20](https://github.com/shenjackyuanjie/Difficult-Rocket/issues/20) ``
+
## DR rs 0.2.9.1
### 实现
diff --git a/mods/dr_game/Difficult_Rocket_rs/src/setup.py b/mods/dr_game/Difficult_Rocket_rs/src/setup.py
index 17dff12..1030175 100644
--- a/mods/dr_game/Difficult_Rocket_rs/src/setup.py
+++ b/mods/dr_game/Difficult_Rocket_rs/src/setup.py
@@ -12,7 +12,7 @@ package_path = 'Difficult_Rocket_rs'
setup(
name='Difficult_Rocket_rs',
- version="0.2.9.2",
+ version="0.2.9.3",
author='shenjackyuanjie',
author_email='3695888@qq.com',
rust_extensions=[RustExtension(target="Difficult_Rocket_rs.Difficult_Rocket_rs",
diff --git a/mods/dr_game/Difficult_Rocket_rs/src/src/lib.rs b/mods/dr_game/Difficult_Rocket_rs/src/src/lib.rs
index 3f0f8a1..4ec9772 100644
--- a/mods/dr_game/Difficult_Rocket_rs/src/src/lib.rs
+++ b/mods/dr_game/Difficult_Rocket_rs/src/src/lib.rs
@@ -28,7 +28,7 @@ enum LoadState {
}
#[pyfunction]
-fn get_version_str() -> String { "0.2.9.2".to_string() }
+fn get_version_str() -> String { "0.2.9.3".to_string() }
#[pyfunction]
fn test_call(py_obj: &PyAny) -> PyResult {
diff --git a/mods/dr_game/Difficult_Rocket_rs/src/src/python.rs b/mods/dr_game/Difficult_Rocket_rs/src/src/python.rs
index 12ab425..48b8b70 100644
--- a/mods/dr_game/Difficult_Rocket_rs/src/src/python.rs
+++ b/mods/dr_game/Difficult_Rocket_rs/src/src/python.rs
@@ -112,6 +112,18 @@ pub mod data {
#[getter]
fn get_touch_ground(&self) -> bool { self.ship.touch_ground.to_owned() }
+
+ fn iter_parts(&self) -> HashMap {
+ let mut parts = HashMap::new();
+ for part_data in self.ship.parts.iter() {
+ let part_type = self.part_list.get_part_type(part_data.part_type_id.clone()).unwrap();
+ parts.insert(
+ part_data.id,
+ (PySR1PartType::new(part_type), PySR1PartData { data: part_data.clone() }),
+ );
+ }
+ parts
+ }
}
}
diff --git a/mods/dr_game/Difficult_Rocket_rs/src/src/sr1_data.rs b/mods/dr_game/Difficult_Rocket_rs/src/src/sr1_data.rs
index 9e6f075..89792c1 100644
--- a/mods/dr_game/Difficult_Rocket_rs/src/src/sr1_data.rs
+++ b/mods/dr_game/Difficult_Rocket_rs/src/src/sr1_data.rs
@@ -495,7 +495,7 @@ pub mod ship {
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct DisconnectedParts {
#[serde(rename = "DisconnectedPart")]
- pub parts: Vec,
+ pub parts: Option>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
@@ -556,17 +556,20 @@ pub mod ship {
parts.push(part.to_sr_part_data());
}
let disconnected = match &self.disconnected {
- Some(disconnect) => {
- let mut disconnect_parts = Vec::new();
- for disconnected_part in &disconnect.parts {
- let mut parts_vec = Vec::new();
- for part in &disconnected_part.parts.parts {
- parts_vec.push(part.to_sr_part_data());
+ Some(disconnect) => match &disconnect.parts {
+ Some(disconnected_parts) => {
+ let mut disconnected_parts_vec = Vec::new();
+ for disconnected_part in disconnected_parts {
+ let mut parts_vec = Vec::new();
+ for part in &disconnected_part.parts.parts {
+ parts_vec.push(part.to_sr_part_data());
+ }
+ disconnected_parts_vec.push((parts_vec, disconnected_part.connects.connects.clone()));
}
- disconnect_parts.push((parts_vec, disconnected_part.connects.connects.clone()));
+ Some(disconnected_parts_vec)
}
- Some(disconnect_parts)
- }
+ None => None,
+ },
_ => None,
};
let connections = match &self.connects.connects {
diff --git a/mods/dr_game/Difficult_Rocket_rs/src/src/types.rs b/mods/dr_game/Difficult_Rocket_rs/src/src/types.rs
index 904d528..b1eef10 100644
--- a/mods/dr_game/Difficult_Rocket_rs/src/src/types.rs
+++ b/mods/dr_game/Difficult_Rocket_rs/src/src/types.rs
@@ -198,8 +198,7 @@ pub mod sr1 {
impl SR1PartType {
pub fn get_box(&self) -> (f64, f64, f64, f64) {
let x = self.width as f64 / 2.0;
- let y = self.height as f64 / 2.0;
- (-x, -y, x, y)
+ (-x, 0.0, x, self.height as f64)
}
}
@@ -749,7 +748,9 @@ pub mod sr1 {
},
});
}
- Some(RawDisconnectedParts { parts: disconnected_vec })
+ Some(RawDisconnectedParts {
+ parts: Some(disconnected_vec),
+ })
}
_ => None,
};
@@ -778,11 +779,14 @@ pub mod sr1 {
let p2 = p2.add(part.x, part.y);
let (x1, y1, x2, y2) = (p1.x, p1.y, p2.x, p2.y);
// get max box
- max_box.0 = max_box.0.min(x1);
- max_box.1 = max_box.1.min(y1);
- max_box.2 = max_box.2.max(x2);
- max_box.3 = max_box.3.max(y2);
+ max_box.0 = max_box.0.min(x1).min(part.x);
+ max_box.1 = max_box.1.min(y1).min(part.y);
+ max_box.2 = max_box.2.max(x2).max(part.x);
+ max_box.3 = max_box.3.max(y2).max(part.y);
+ // * 60 print again
+ // println!("{} {} {} {} id:{}", x1 * 60.0, y1 * 60.0, x2 * 60.0, y2 * 60.0, part.id)
}
+
max_box
}
}
diff --git a/mods/dr_game/__init__.py b/mods/dr_game/__init__.py
index 75514c2..c8b257c 100644
--- a/mods/dr_game/__init__.py
+++ b/mods/dr_game/__init__.py
@@ -15,7 +15,7 @@ from Difficult_Rocket.api.mod import ModInfo
from Difficult_Rocket.api.types import Options
from Difficult_Rocket.client import ClientWindow
-DR_rust_version = Version("0.2.9.2") # DR_mod 的 Rust 编写部分的兼容版本
+DR_rust_version = Version("0.2.9.3") # DR_mod 的 Rust 编写部分的兼容版本
class _DR_mod_runtime(Options):
diff --git a/mods/dr_game/sr1_ship.py b/mods/dr_game/sr1_ship.py
index b863725..172f09c 100644
--- a/mods/dr_game/sr1_ship.py
+++ b/mods/dr_game/sr1_ship.py
@@ -4,6 +4,7 @@
# All rights reserved
# -------------------------------
+import math
import time
import random
import logging
@@ -117,9 +118,10 @@ class SR1ShipRender(BaseScreen):
x=main_window.width / 2, y=main_window.height / 2)
self.debug_mouse_label.visible = SR1ShipRender_Option.debug_mouse_pos
self.textures: Union[SR1Textures, None] = None
- self.xml_name = 'configs/dock1.xml'
- self.xml_doc: ElementTree = parse('configs/dock1.xml')
- self.xml_root: ElementTree.Element = self.xml_doc.getroot()
+ # self.xml_name = 'configs/dock1.xml'
+ # self.xml_doc: ElementTree = parse('configs/dock1.xml')
+ # self.xml_root: ElementTree.Element = self.xml_doc.getroot()
+ self.load_xml('configs/dock1.xml')
self.part_batch = Batch()
self.part_group = Group()
self.debug_label = Label(x=20, y=main_window.height - 20, font_size=DR_option.std_font_size,
@@ -373,9 +375,37 @@ class SR1ShipRender(BaseScreen):
elif command.find('gen_img'):
if not self.rendered:
return
- # ship_size = self.ship.size
- base_textures = Texture.create(100, 100)
- ...
+ if not DR_mod_runtime.use_DR_rust:
+ # 这个功能依赖于 DR rs (简称,我懒得在Python端实现)
+ return
+ img_box = self.rust_ship.img_pos
+ img_size = (img_box[2] - img_box[0] + 1000, img_box[3] - img_box[1] + 1000)
+ # img_center = (abs(img_box[0]), abs(img_box[1]))
+ # 中心点是左上角坐标
+ img_center = (abs(img_box[0]), abs(img_box[3]))
+ print(f"img_box: {img_box} img_size: {img_size} img_center: {img_center}")
+ try:
+ from pyglet.image.codecs.pil import PILImageEncoder
+ from PIL import Image
+ except ImportError:
+ traceback.print_exc()
+ print('PIL not found')
+ return
+ img = Image.new('RGBA', img_size)
+ for part, sprite in self.parts_sprite.items():
+ img_data = sprite.image.get_image_data()
+ fmt = img_data.format
+ if fmt != 'RGB':
+ fmt = 'RGBA'
+ pitch = -(img_data.width * len(fmt))
+ pil_image = Image.frombytes(fmt, (img_data.width, img_data.height), img_data.get_data(fmt, pitch))
+ pil_image = pil_image.rotate(-SR1Rotation.get_rotation(self.part_data[part].angle), expand=True)
+ if self.part_data[part].flip_y:
+ pil_image.transpose(Image.FLIP_TOP_BOTTOM)
+ if self.part_data[part].flip_x:
+ pil_image.transpose(Image.FLIP_LEFT_RIGHT)
+ img.paste(pil_image, (int(self.part_data[part].x*60 + img_center[0]), int(-self.part_data[part].y*60 + img_center[1])), pil_image)
+ img.save(f'test{time.time()}.png', 'PNG')
def on_mouse_drag(self, x: int, y: int, dx: int, dy: int, buttons: int, modifiers: int, window: "ClientWindow"):
if not self.focus: