add disconnect in dock1.xml

This commit is contained in:
shenjack 2023-04-08 23:42:52 +08:00
parent db114d2204
commit bf114ccdd5
4 changed files with 68 additions and 41 deletions

View File

@ -250,7 +250,11 @@ class SR1ShipRender(BaseScreen):
self.need_update_parts = False
with self.camera_rs:
from pyglet.gl import glEnable, glDisable, glDepthFunc, GL_DEPTH_TEST, GL_LEQUAL
glEnable(GL_DEPTH_TEST)
glDepthFunc(GL_LEQUAL)
self.part_batch.draw()
glDisable(GL_DEPTH_TEST)
self.debug_label.draw()
@ -288,7 +292,7 @@ class SR1ShipRender(BaseScreen):
else:
zoom_d = ((2 ** scroll_y) - 1) * 0.5 + 1
# 缩放的变换量
if not self.camera_rs.zoom == 10 or scroll_y > 0:
if not (self.camera_rs.zoom == 10 and scroll_y > 0):
if self.camera_rs.zoom * zoom_d >= 10:
zoom_d = 10 / self.camera_rs.zoom
self.camera_rs.zoom = 10

View File

@ -1,4 +1,14 @@
<Ship version="1" liftedOff="0" touchingGround="0">
<DisconnectedParts>
<DisconnectedPart>
<Parts>
<Part partType="fueltank-2" id="180" x="-43.000000" y="-55.500000" angle="0.000000" angleV="0.000000" editorAngle="0">
<Tank fuel="3000.000000"/>
</Part>
</Parts>
<Connections/>
</DisconnectedPart>
</DisconnectedParts>
<Parts>
<Part partType="pod-1" id="1" x="0.000000" y="3.250000" angle="0.000000" angleV="0.000000" editorAngle="0">
<Pod throttle="0.000000" name="">

View File

@ -383,6 +383,7 @@ pub mod part_list {
#[allow(unused)]
pub mod ship {
use std::error::Error;
use std::fs;
use pyo3::prelude::*;
@ -406,7 +407,7 @@ pub mod ship {
#[serde(rename = "touchingGround")]
pub touch_ground: i8,
#[serde(rename = "DisconnectedParts")]
pub disconnected: Option<Vec<DisconnectedParts>>,
pub disconnected: Option<DisconnectedParts>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
@ -418,7 +419,7 @@ pub mod ship {
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Connections {
#[serde(rename = "Connection")]
pub connects: Vec<Connection>,
pub connects: Option<Vec<Connection>>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
@ -504,15 +505,16 @@ pub mod ship {
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct DisconnectedParts {
#[serde(rename = "DisconnectedPart")]
pub parts: Vec<DisconnectedPart>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct DisconnectedPart {
#[serde(rename = "Parts")]
pub parts: Vec<Part>,
pub parts: Parts,
#[serde(rename = "Connections")]
pub connects: Vec<Connection>,
pub connects: Connections,
}
/// <DisconnectedParts>
/// <DisconnectedPart>
@ -543,15 +545,6 @@ pub mod ship {
impl SR1ShipTrait for RawShip {
#[inline]
fn to_sr_ship(&self, name: Option<String>) -> SR1Ship {
let connects: Vec<(i64, i64, i64, i64)> =
Vec::from_iter(self.connects.connects.iter().map(|connect| {
(
connect.parent_attach_point,
connect.child_attach_point,
connect.parent_part,
connect.child_part,
)
}));
todo!()
}
@ -575,8 +568,16 @@ pub mod ship {
#[pyo3(signature = (path = "./configs/dock1.xml".to_string()))]
pub fn py_raw_ship_from_file(path: String) -> PyResult<bool> {
let file = fs::read_to_string(path).unwrap();
let raw_ship: RawShip = from_str(&file).unwrap();
println!("{:?}", raw_ship);
let raw_ship = from_str::<RawShip>(&file);
match raw_ship {
Ok(ship) => {
println!("{:?}", ship);
}
Err(e) => {
println!("{:?}", e);
// println!("{:?}", e.provide());
}
}
Ok(true)
}
}

View File

@ -569,7 +569,7 @@ pub mod sr1 {
pub connections: Vec<Connection>,
pub lift_off: bool,
pub touch_ground: bool,
pub disconnected: Vec<(Vec<SR1PartData>, Vec<Connection>)>,
pub disconnected: Option<Vec<(Vec<SR1PartData>, Vec<Connection>)>>,
}
impl SR1ShipTrait for SR1Ship {
@ -586,30 +586,42 @@ pub mod sr1 {
#[inline]
fn to_raw_ship(&self) -> RawShip {
todo!();
// let mut parts = Vec::new();
// for part in &self.parts {
// parts.push(part.to_raw_part_data());
// }
// let connections = Connections {
// connects: self.connections.clone(),
// };
// let mut disconnected = Vec::new();
// for (parts, connections) in &self.disconnected {
// let mut parts = Vec::new();
// for part in parts {
// parts.push(part.to_raw_part_data());
// }
// disconnected.push((parts, connections.clone()));
// }
// RawShip {
// parts: RawParts { parts },
// connects: connections,
// version: 1,
// lift_off: bool_to_i8(self.lift_off),
// touch_ground: bool_to_i8(self.touch_ground),
// disconnected,
// }
let mut parts = Vec::new();
for part in &self.parts {
parts.push(part.to_raw_part_data());
}
let connections = Connections {
connects: Some(self.connections.clone()),
};
let disconnected = match &self.disconnected {
Some(disconnected) => {
let mut disconnected_vec: Vec<RawDisconnectedPart> = Vec::new();
for (parts, connections) in disconnected {
let mut raw_parts = Vec::new();
for part in parts {
raw_parts.push(part.to_raw_part_data());
}
disconnected_vec.push(RawDisconnectedPart {
parts: RawParts { parts: raw_parts },
connects: Connections {
connects: Some(connections.clone()),
},
});
}
Some(RawDisconnectedParts {
parts: disconnected_vec,
})
}
_ => None,
};
RawShip {
parts: RawParts { parts },
connects: connections,
version: 1,
lift_off: bool_to_i8(self.lift_off),
touch_ground: bool_to_i8(self.touch_ground),
disconnected,
}
}
}
}