大换血啊~~~~~~
This commit is contained in:
parent
2102bc2091
commit
637c3e5eca
@ -13,12 +13,12 @@ gitee: @shenjackyuanjie
|
||||
|
||||
import multiprocessing
|
||||
|
||||
from typing import List, Optional, Dict
|
||||
from typing import List, Optional, Dict, Type
|
||||
|
||||
from Difficult_Rocket.api.types import Options
|
||||
from Difficult_Rocket.mod.loader import ModManager
|
||||
from Difficult_Rocket.utils.thread import new_thread
|
||||
from Difficult_Rocket import client, server, DR_status
|
||||
from Difficult_Rocket import client as client_class, server as server_class, DR_status
|
||||
|
||||
from lib_not_dr.loggers import config
|
||||
from lib_not_dr.loggers.logger import Logger
|
||||
@ -59,10 +59,10 @@ class Console(Options):
|
||||
class Game(Options):
|
||||
name = "MainGame"
|
||||
|
||||
client: client.Client
|
||||
server: server.Server
|
||||
client: client_class.Client
|
||||
server: server_class.Server
|
||||
console: Console
|
||||
console_class: Console = Console
|
||||
console_class: Type[Console] = Console
|
||||
|
||||
main_config: Dict
|
||||
logger: Logger
|
||||
@ -103,8 +103,8 @@ class Game(Options):
|
||||
self.logger.info(f"\n{self.as_markdown()}")
|
||||
|
||||
def setup(self) -> None:
|
||||
self.client = client.Client(game=self, net_mode="local")
|
||||
self.server = server.Server(net_mode="local")
|
||||
self.client = client_class.Client(game=self, net_mode="local")
|
||||
self.server = server_class.Server(net_mode="local")
|
||||
|
||||
def init(self, **kwargs) -> bool:
|
||||
self.logger = config.get_logger("main")
|
||||
|
2
mods/dr_game/Difficult_Rocket_rs/src/Cargo.lock
generated
2
mods/dr_game/Difficult_Rocket_rs/src/Cargo.lock
generated
@ -135,7 +135,7 @@ checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80"
|
||||
|
||||
[[package]]
|
||||
name = "difficult_rocket_rs"
|
||||
version = "0.3.7"
|
||||
version = "0.4.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"nalgebra",
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "difficult_rocket_rs"
|
||||
version = "0.3.7"
|
||||
version = "0.4.0"
|
||||
edition = "2021"
|
||||
license-file = '../../LICENSE'
|
||||
authors = ["shenjackyuanjie <3695888@qq.com>"]
|
||||
|
@ -217,23 +217,23 @@ impl OneTimeLine {
|
||||
}
|
||||
|
||||
pub fn point1_k_b_new(point: &Point2D, k: Option<f64>, b: Option<f64>) -> Self {
|
||||
let k_: f64;
|
||||
let _k: f64;
|
||||
let b_: f64;
|
||||
match (k, b) {
|
||||
(Some(k), None) => {
|
||||
k_ = k;
|
||||
_k = k;
|
||||
b_ = point.y - (k * point.x)
|
||||
}
|
||||
(None, Some(b)) => {
|
||||
b_ = b;
|
||||
k_ = (point.y - b) / point.x;
|
||||
_k = (point.y - b) / point.x;
|
||||
}
|
||||
(Some(k), Some(b)) => {
|
||||
k_ = k;
|
||||
_k = k;
|
||||
b_ = b;
|
||||
}
|
||||
_ => {
|
||||
k_ = point.y / point.x;
|
||||
_k = point.y / point.x;
|
||||
b_ = 0.0;
|
||||
}
|
||||
}
|
||||
|
@ -42,8 +42,7 @@ pub struct DRObjectProps<'a> {
|
||||
/// 写了这么长一个玩意
|
||||
/// 形状参考
|
||||
/// https://rapier.rs/docs/user_guides/rust/colliders
|
||||
#[cfg(disable)]
|
||||
use rapier2d_f64::geometry::ColliderBuilder;
|
||||
// use rapier2d_f64::geometry::ColliderBuilder;
|
||||
pub enum BoxColliderEnum {
|
||||
/// 组合
|
||||
Compound(Vec<(Vector2<Real>, BoxColliderEnum)>),
|
||||
|
@ -229,18 +229,26 @@ pub struct PySR1Connections {
|
||||
impl PySR1Connections {
|
||||
/// 通过父节点获取连接
|
||||
fn search_connection_by_parent(&self, parent_id: IdType) -> Vec<RawConnectionData> {
|
||||
self.datas.iter().filter(|x| x.parent_part == parent_id).map(|x| x.as_raw_data()).collect()
|
||||
self.datas
|
||||
.iter()
|
||||
.filter(|x| x.get_parent() == parent_id && x.is_normal())
|
||||
.map(|x| x.as_normal_raw().unwrap())
|
||||
.collect()
|
||||
}
|
||||
/// 通过子节点获取连接
|
||||
fn search_by_child(&self, child_id: IdType) -> Vec<RawConnectionData> {
|
||||
self.datas.iter().filter(|x| x.child_part == child_id).map(|x| x.as_raw_data()).collect()
|
||||
self.datas
|
||||
.iter()
|
||||
.filter(|x| x.get_child() == child_id && x.is_normal())
|
||||
.map(|x| x.as_normal_raw().unwrap())
|
||||
.collect()
|
||||
}
|
||||
/// 通过父子中任意一个 id 搜索连接
|
||||
fn search_by_id(&self, any_id: IdType) -> Vec<RawConnectionData> {
|
||||
self.datas
|
||||
.iter()
|
||||
.filter(|x| x.parent_part == any_id || x.child_part == any_id)
|
||||
.map(|x| x.as_raw_data())
|
||||
.filter(|x| (x.get_parent() == any_id || x.get_child() == any_id) && x.is_normal())
|
||||
.map(|x| x.as_normal_raw().unwrap())
|
||||
.collect()
|
||||
}
|
||||
/// 通过父子双方 id 获取连接
|
||||
@ -251,15 +259,15 @@ impl PySR1Connections {
|
||||
fn search_by_both_id(&self, parent_id: IdType, child_id: IdType) -> Vec<RawConnectionData> {
|
||||
self.datas
|
||||
.iter()
|
||||
.filter(|x| x.parent_part == parent_id && x.child_part == child_id)
|
||||
.map(|x| x.as_raw_data())
|
||||
.filter(|x| x.get_parent() == parent_id && x.get_child() == child_id && x.is_normal())
|
||||
.map(|x| x.as_normal_raw().unwrap())
|
||||
.collect()
|
||||
}
|
||||
/// 获取所有连接的原始数据
|
||||
///
|
||||
/// 万一你确实需要吭哧吭哧去处理原始数据呢
|
||||
fn get_raw_data(&self) -> Vec<RawConnectionData> {
|
||||
self.datas.iter().map(|x| x.as_raw_data()).collect()
|
||||
self.datas.iter().filter(|x| x.is_normal()).map(|x| x.as_normal_raw().unwrap()).collect()
|
||||
}
|
||||
}
|
||||
|
||||
@ -291,32 +299,27 @@ impl PySR1Ship {
|
||||
}
|
||||
|
||||
fn disconnected_parts(&self) -> Vec<(Vec<(PySR1PartType, PySR1PartData)>, PySR1Connections)> {
|
||||
match self.ship.disconnected.as_ref() {
|
||||
Some(parts) => {
|
||||
if parts.is_empty() {
|
||||
return Vec::new();
|
||||
}
|
||||
let mut result = Vec::with_capacity(parts.len());
|
||||
for (part_group, connections) in parts.iter() {
|
||||
let mut group_parts = Vec::with_capacity(part_group.len());
|
||||
for part_data in part_group.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());
|
||||
group_parts.push((part_type, py_part_data));
|
||||
}
|
||||
}
|
||||
result.push((
|
||||
group_parts,
|
||||
PySR1Connections {
|
||||
datas: connections.clone().unwrap_or_default(),
|
||||
},
|
||||
));
|
||||
}
|
||||
result
|
||||
}
|
||||
None => Vec::new(),
|
||||
if self.ship.disconnected.is_empty() {
|
||||
return Vec::new();
|
||||
}
|
||||
let mut result = Vec::with_capacity(self.ship.disconnected.len());
|
||||
for (part_group, connections) in self.ship.disconnected.iter() {
|
||||
let mut group_parts = Vec::with_capacity(part_group.len());
|
||||
for part_data in part_group.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());
|
||||
group_parts.push((part_type, py_part_data));
|
||||
}
|
||||
}
|
||||
result.push((
|
||||
group_parts,
|
||||
PySR1Connections {
|
||||
datas: connections.clone(),
|
||||
},
|
||||
));
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
#[getter]
|
||||
@ -425,9 +428,8 @@ impl PySR1Ship {
|
||||
// 先搜链接到的部件
|
||||
// 这里的代码是 GitHub Copilot 帮我优化的
|
||||
// 赞美 GitHub Copilot !()
|
||||
let unconnected = self.ship.disconnected.as_ref().map_or(vec![], |disconnected| {
|
||||
disconnected.iter().flat_map(|(group, _)| group.iter()).filter(|part| part.id == part_id).collect()
|
||||
});
|
||||
let unconnected =
|
||||
self.ship.disconnected.iter().flat_map(|(group, _)| group.iter()).filter(|part| part.id == part_id);
|
||||
// 然后通过一个 chain 直接把他链接到这边
|
||||
self.ship
|
||||
.parts
|
||||
|
@ -8,10 +8,10 @@ use crate::sr1_parse::part_list::Damage as RawDamage;
|
||||
use crate::sr1_parse::part_list::{AttachPoint, AttachPoints, Engine, Lander, Rcs, Shape as RawShape, Solar, Tank};
|
||||
use crate::sr1_parse::part_list::{FuelType, RawPartList, RawPartType, SR1PartTypeEnum};
|
||||
use crate::sr1_parse::ship::{
|
||||
Activate as RawActivate, Connection, Connections, DisconnectedPart as RawDisconnectedPart,
|
||||
DisconnectedParts as RawDisconnectedParts, Engine as RawEngine, Part as RawPartData, Parts as RawParts,
|
||||
Pod as RawPod, RawShip, Staging as RawStaging, Step as RawStep, Tank as RawTank,
|
||||
Activate as RawActivate, Connection, Engine as RawEngine, Part as RawPartData, Pod as RawPod, RawShip,
|
||||
Staging as RawStaging, Step as RawStep, Tank as RawTank,
|
||||
};
|
||||
use crate::sr1_parse::ship::{Connections as RawConnections, DisconnectedParts, Parts as RawParts};
|
||||
use crate::IdType;
|
||||
|
||||
use std::cell::{Cell, RefCell};
|
||||
@ -22,7 +22,7 @@ use std::ops::Deref;
|
||||
use quick_xml::events::{BytesEnd, BytesStart, Event};
|
||||
use quick_xml::writer::Writer;
|
||||
|
||||
pub type ConnectionType = Vec<(Vec<SR1PartData>, Option<Vec<Connection>>)>;
|
||||
pub type PartsWithConnections = Vec<(Vec<SR1PartData>, Vec<Connection>)>;
|
||||
|
||||
pub fn radians_map_to_degrees(angle: f64) -> f64 {
|
||||
let angle_string = angle.to_string();
|
||||
@ -400,11 +400,11 @@ impl SR1PartDataTrait for SR1PartData {
|
||||
moved: active.1.to_owned() as i8,
|
||||
});
|
||||
}
|
||||
actives.push(RawStep { activates: Some(steps) });
|
||||
actives.push(RawStep { activates: steps });
|
||||
}
|
||||
let stages = RawStaging {
|
||||
current_stage: current_stage.to_owned(),
|
||||
steps: Some(actives),
|
||||
steps: actives,
|
||||
};
|
||||
RawPod {
|
||||
name: name.clone(),
|
||||
@ -600,22 +600,11 @@ impl SR1PartDataAttr {
|
||||
Some(pod.throttle),
|
||||
Some(pod.stages.current_stage),
|
||||
Some({
|
||||
let mut steps = Vec::new();
|
||||
match &pod.stages.steps {
|
||||
Some(step_vec) => {
|
||||
for step in step_vec {
|
||||
let mut step_vec = Vec::new();
|
||||
if let Some(active) = &step.activates {
|
||||
for act in active {
|
||||
step_vec.push((act.id, act.moved != 0));
|
||||
}
|
||||
}
|
||||
steps.push(step_vec);
|
||||
}
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
steps
|
||||
pod.stages
|
||||
.steps
|
||||
.iter()
|
||||
.map(|step| step.activates.iter().map(|act| (act.id, act.moved != 0)).collect())
|
||||
.collect()
|
||||
}),
|
||||
)
|
||||
} else {
|
||||
@ -655,7 +644,7 @@ pub struct SR1Ship {
|
||||
pub touch_ground: bool,
|
||||
pub parts: Vec<SR1PartData>,
|
||||
pub connections: Vec<Connection>,
|
||||
pub disconnected: Option<ConnectionType>,
|
||||
pub disconnected: Vec<(Vec<SR1PartData>, Vec<Connection>)>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
@ -696,17 +685,23 @@ impl SR1Ship {
|
||||
part.part_type = SR1PartTypeEnum::strut;
|
||||
}
|
||||
}
|
||||
for disconnects in self.disconnected.iter_mut() {
|
||||
for (parts, _) in disconnects.iter_mut() {
|
||||
for part in parts.iter_mut() {
|
||||
if let Some(part_type) = part_list.get_part_type(&part.part_type_id) {
|
||||
part.part_type = part_type.p_type;
|
||||
} else {
|
||||
part.part_type = SR1PartTypeEnum::strut;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
self.disconnected.iter_mut().for_each(|(disconnected_parts, _)| {
|
||||
disconnected_parts.iter_mut().for_each(|part| match part_list.get_part_type(&part.part_type_id) {
|
||||
Some(part_type) => part.part_type = part_type.p_type,
|
||||
None => part.part_type = SR1PartTypeEnum::strut,
|
||||
});
|
||||
})
|
||||
// for disconnects in self.disconnected.iter_mut() {
|
||||
// for (parts, _) in disconnects.iter_mut() {
|
||||
// for part in parts.iter_mut() {
|
||||
// if let Some(part_type) = part_list.get_part_type(&part.part_type_id) {
|
||||
// part.part_type = part_type.p_type;
|
||||
// } else {
|
||||
// part.part_type = SR1PartTypeEnum::strut;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
pub fn part_as_hashmap(&self) -> HashMap<IdType, Vec<SR1PartData>> {
|
||||
@ -733,7 +728,7 @@ impl SR1Ship {
|
||||
};
|
||||
}
|
||||
|
||||
fn write_parts(parts: &[SR1PartData], writer: &mut Writer<Cursor<Vec<u8>>>, save_status: &SaveStatus) {
|
||||
fn write_parts(parts: &Vec<SR1PartData>, writer: &mut Writer<Cursor<Vec<u8>>>, save_status: &SaveStatus) {
|
||||
writer.write_event(Event::Start(BytesStart::new("Parts"))).unwrap();
|
||||
for part in parts.iter() {
|
||||
let mut part_attr = BytesStart::new("Part");
|
||||
@ -844,39 +839,49 @@ impl SR1Ship {
|
||||
fn write_connections(connects: &[Connection], writer: &mut Writer<Cursor<Vec<u8>>>) {
|
||||
writer.write_event(Event::Start(BytesStart::new("Connections"))).unwrap();
|
||||
for connect in connects.iter() {
|
||||
let mut connect_elem = BytesStart::new("Connection");
|
||||
connect_elem.push_attribute(("parentAttachPoint", connect.parent_attach_point.to_string().as_str()));
|
||||
connect_elem.push_attribute(("childAttachPoint", connect.child_attach_point.to_string().as_str()));
|
||||
connect_elem.push_attribute(("parentPart", connect.parent_part.to_string().as_str()));
|
||||
connect_elem.push_attribute(("childPart", connect.child_part.to_string().as_str()));
|
||||
writer.write_event(Event::Empty(connect_elem)).unwrap();
|
||||
match connect {
|
||||
Connection::Dock {
|
||||
dock_part,
|
||||
parent_part,
|
||||
child_part,
|
||||
} => {
|
||||
let mut dock_elem = BytesStart::new("DockConnection");
|
||||
dock_elem.push_attribute(("dockPart", dock_part.to_string().as_str()));
|
||||
dock_elem.push_attribute(("parentPart", parent_part.to_string().as_str()));
|
||||
dock_elem.push_attribute(("childPart", child_part.to_string().as_str()));
|
||||
writer.write_event(Event::Empty(dock_elem)).unwrap();
|
||||
}
|
||||
Connection::Normal {
|
||||
parent_attach_point,
|
||||
child_attach_point,
|
||||
parent_part,
|
||||
child_part,
|
||||
} => {
|
||||
let mut connect_elem = BytesStart::new("Connection");
|
||||
connect_elem.push_attribute(("parentAttachPoint", parent_attach_point.to_string().as_str()));
|
||||
connect_elem.push_attribute(("childAttachPoint", child_attach_point.to_string().as_str()));
|
||||
connect_elem.push_attribute(("parentPart", parent_part.to_string().as_str()));
|
||||
connect_elem.push_attribute(("childPart", child_part.to_string().as_str()));
|
||||
writer.write_event(Event::Empty(connect_elem)).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
writer.write_event(Event::End(BytesEnd::new("Connections"))).unwrap();
|
||||
}
|
||||
|
||||
fn write_disconnect(
|
||||
data: &Option<ConnectionType>,
|
||||
data: &PartsWithConnections,
|
||||
writer: &mut Writer<Cursor<Vec<u8>>>,
|
||||
save_status: &SaveStatus,
|
||||
) {
|
||||
match data {
|
||||
Some(data) => {
|
||||
writer.write_event(Event::Start(BytesStart::new("DisconnectedParts"))).unwrap();
|
||||
for (parts, connects) in data.iter() {
|
||||
writer.write_event(Event::Start(BytesStart::new("DisconnectedPart"))).unwrap();
|
||||
write_parts(parts, writer, save_status);
|
||||
match connects {
|
||||
Some(connects) => write_connections(connects, writer),
|
||||
None => {
|
||||
writer.write_event(Event::Empty(BytesStart::new("Connections"))).unwrap();
|
||||
}
|
||||
}
|
||||
writer.write_event(Event::End(BytesEnd::new("DisconnectedPart"))).unwrap();
|
||||
}
|
||||
writer.write_event(Event::End(BytesEnd::new("DisconnectedParts"))).unwrap();
|
||||
}
|
||||
None => {}
|
||||
writer.write_event(Event::Start(BytesStart::new("DisconnectedParts"))).unwrap();
|
||||
for (parts, connects) in data.iter() {
|
||||
writer.write_event(Event::Start(BytesStart::new("DisconnectedPart"))).unwrap();
|
||||
write_parts(parts, writer, save_status);
|
||||
write_connections(connects, writer);
|
||||
writer.write_event(Event::End(BytesEnd::new("DisconnectedPart"))).unwrap();
|
||||
}
|
||||
writer.write_event(Event::End(BytesEnd::new("DisconnectedParts"))).unwrap();
|
||||
}
|
||||
|
||||
fn write_data(data: &SR1Ship, save_status: &SaveStatus) -> String {
|
||||
@ -915,41 +920,13 @@ impl SR1ShipTrait for SR1Ship {
|
||||
|
||||
#[inline]
|
||||
fn to_raw_ship(&self) -> RawShip {
|
||||
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: connections.clone(),
|
||||
},
|
||||
});
|
||||
}
|
||||
Some(RawDisconnectedParts {
|
||||
parts: Some(disconnected_vec),
|
||||
})
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
RawShip {
|
||||
parts: RawParts { parts },
|
||||
connects: connections,
|
||||
parts: RawParts::from_vec_sr1(self.parts.clone()),
|
||||
connects: RawConnections::from_vec(self.connections.clone()),
|
||||
version: Some(self.version),
|
||||
lift_off: self.lift_off as i8,
|
||||
touch_ground: Some(self.touch_ground as i8),
|
||||
disconnected,
|
||||
disconnected: DisconnectedParts::from_vec_sr1(self.disconnected.clone()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,19 +28,7 @@ pub struct RawShip {
|
||||
// SR1 says it's optional, let them happy
|
||||
// NOT always 0
|
||||
#[serde(rename = "DisconnectedParts")]
|
||||
pub disconnected: Option<DisconnectedParts>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Parts {
|
||||
#[serde(rename = "Part")]
|
||||
pub parts: Vec<Part>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Connections {
|
||||
#[serde(rename = "Connection")]
|
||||
pub connects: Option<Vec<Connection>>,
|
||||
pub disconnected: DisconnectedParts,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
@ -96,6 +84,58 @@ pub struct Part {
|
||||
pub deployed: Option<i8>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Parts {
|
||||
#[serde(rename = "Part", default)]
|
||||
pub parts: Vec<Part>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Connections {
|
||||
#[serde(rename = "$value", default)]
|
||||
pub connections: Vec<Connection>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct DisconnectedParts {
|
||||
#[serde(rename = "DisconnectedPart", default)]
|
||||
pub parts: Vec<DisconnectedPart>,
|
||||
}
|
||||
|
||||
impl Parts {
|
||||
pub fn as_sr1_vec(&self) -> Vec<SR1PartData> {
|
||||
self.parts.iter().map(|x| x.to_sr_part_data()).collect()
|
||||
}
|
||||
pub fn from_vec_sr1(parts: Vec<SR1PartData>) -> Self {
|
||||
Parts {
|
||||
parts: parts.iter().map(|x| x.to_raw_part_data()).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Connections {
|
||||
pub fn as_vec(&self) -> Vec<Connection> {
|
||||
self.connections.clone()
|
||||
}
|
||||
pub fn from_vec(connections: Vec<Connection>) -> Self {
|
||||
Connections { connections }
|
||||
}
|
||||
}
|
||||
|
||||
impl DisconnectedParts {
|
||||
pub fn as_sr1_vec(&self) -> Vec<(Vec<SR1PartData>, Vec<Connection>)> {
|
||||
self.parts.iter().map(|x| x.into_sr_part()).collect()
|
||||
}
|
||||
pub fn from_vec_sr1(parts_list: Vec<(Vec<SR1PartData>, Vec<Connection>)>) -> Self {
|
||||
DisconnectedParts {
|
||||
parts: parts_list
|
||||
.iter()
|
||||
.map(|(part, connects)| DisconnectedPart::from_sr_part(part.to_vec(), connects.to_vec()))
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Engine {
|
||||
#[serde(rename = "@fuel")]
|
||||
@ -122,14 +162,16 @@ pub struct Pod {
|
||||
pub struct Staging {
|
||||
#[serde(rename = "@currentStage")]
|
||||
pub current_stage: i32,
|
||||
#[serde(rename = "Step")]
|
||||
pub steps: Option<Vec<Step>>,
|
||||
#[serde(rename = "Step", default)]
|
||||
pub steps: Vec<Step>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Step {
|
||||
#[serde(rename = "Activate")]
|
||||
pub activates: Option<Vec<Activate>>, // Option for https://github.com/shenjackyuanjie/Difficult-Rocket/issues/21
|
||||
/// ~~Option for https://github.com/shenjackyuanjie/Difficult-Rocket/issues/21~~
|
||||
/// Now is (default)
|
||||
#[serde(rename = "Activate", default)]
|
||||
pub activates: Vec<Activate>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
@ -141,12 +183,6 @@ pub struct Activate {
|
||||
pub moved: i8, // 1 or 0
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct DisconnectedParts {
|
||||
#[serde(rename = "DisconnectedPart")]
|
||||
pub parts: Option<Vec<DisconnectedPart>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct DisconnectedPart {
|
||||
#[serde(rename = "Parts")]
|
||||
@ -155,41 +191,96 @@ pub struct DisconnectedPart {
|
||||
pub connects: Connections,
|
||||
}
|
||||
|
||||
impl DisconnectedPart {
|
||||
pub fn into_sr_part(&self) -> (Vec<SR1PartData>, Vec<Connection>) {
|
||||
(self.parts.as_sr1_vec(), self.connects.as_vec())
|
||||
}
|
||||
|
||||
pub fn from_sr_part(parts: Vec<SR1PartData>, connects: Vec<Connection>) -> Self {
|
||||
Self {
|
||||
parts: Parts::from_vec_sr1(parts),
|
||||
connects: Connections::from_vec(connects),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub type RawConnectionData = (i32, i32, IdType, IdType);
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Connection {
|
||||
#[serde(rename = "@parentAttachPoint")]
|
||||
pub parent_attach_point: i32,
|
||||
#[serde(rename = "@childAttachPoint")]
|
||||
pub child_attach_point: i32,
|
||||
#[serde(rename = "@parentPart")]
|
||||
pub parent_part: IdType,
|
||||
#[serde(rename = "@childPart")]
|
||||
pub child_part: IdType,
|
||||
pub enum Connection {
|
||||
#[serde(rename = "Connection")]
|
||||
Normal {
|
||||
#[serde(rename = "@parentAttachPoint")]
|
||||
parent_attach_point: i32,
|
||||
#[serde(rename = "@childAttachPoint")]
|
||||
child_attach_point: i32,
|
||||
#[serde(rename = "@parentPart")]
|
||||
parent_part: IdType,
|
||||
#[serde(rename = "@childPart")]
|
||||
child_part: IdType,
|
||||
},
|
||||
#[serde(rename = "DockConnection")]
|
||||
Dock {
|
||||
#[serde(rename = "@dockPart")]
|
||||
dock_part: IdType,
|
||||
#[serde(rename = "@parentPart")]
|
||||
parent_part: IdType,
|
||||
#[serde(rename = "@childPart")]
|
||||
child_part: IdType,
|
||||
},
|
||||
}
|
||||
|
||||
pub type RawDockConnectionData = (IdType, IdType, IdType);
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct DockConnection {
|
||||
#[serde(rename = "@dockPart")]
|
||||
pub dock_part: IdType,
|
||||
#[serde(rename = "@parentPart")]
|
||||
pub parent_part: IdType,
|
||||
#[serde(rename = "@childPart")]
|
||||
pub child_part: IdType,
|
||||
}
|
||||
|
||||
impl Connection {
|
||||
/// 真有地方需要
|
||||
pub fn as_raw_data(&self) -> RawConnectionData {
|
||||
(
|
||||
self.parent_attach_point,
|
||||
self.child_attach_point,
|
||||
self.parent_part,
|
||||
self.child_part,
|
||||
)
|
||||
pub fn as_normal_raw(&self) -> Option<RawConnectionData> {
|
||||
match self {
|
||||
Connection::Normal {
|
||||
parent_attach_point,
|
||||
child_attach_point,
|
||||
parent_part,
|
||||
child_part,
|
||||
} => Some((*parent_attach_point, *child_attach_point, *parent_part, *child_part)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
pub fn as_dock_raw(&self) -> Option<RawDockConnectionData> {
|
||||
match self {
|
||||
Connection::Dock {
|
||||
dock_part,
|
||||
parent_part,
|
||||
child_part,
|
||||
} => Some((*dock_part, *parent_part, *child_part)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
/// 通用的获取父节点
|
||||
pub fn get_parent(&self) -> IdType {
|
||||
match self {
|
||||
Connection::Normal { parent_part, .. } => *parent_part,
|
||||
Connection::Dock { parent_part, .. } => *parent_part,
|
||||
}
|
||||
}
|
||||
/// 通用的获取子节点
|
||||
pub fn get_child(&self) -> IdType {
|
||||
match self {
|
||||
Connection::Normal { child_part, .. } => *child_part,
|
||||
Connection::Dock { child_part, .. } => *child_part,
|
||||
}
|
||||
}
|
||||
/// 是否为 Dock 类型
|
||||
pub fn is_dock(&self) -> bool {
|
||||
match self {
|
||||
Connection::Dock { .. } => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
/// 是否为 Normal 类型
|
||||
pub fn is_normal(&self) -> bool {
|
||||
match self {
|
||||
Connection::Normal { .. } => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -221,40 +312,15 @@ impl SR1PartDataTrait for Part {
|
||||
|
||||
impl SR1ShipTrait for RawShip {
|
||||
fn to_sr_ship(&self, name: Option<String>) -> SR1Ship {
|
||||
let mut parts = Vec::new();
|
||||
for part in &self.parts.parts {
|
||||
parts.push(part.to_sr_part_data());
|
||||
}
|
||||
let disconnected = match &self.disconnected {
|
||||
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()));
|
||||
}
|
||||
Some(disconnected_parts_vec)
|
||||
}
|
||||
None => None,
|
||||
},
|
||||
_ => None,
|
||||
};
|
||||
let connections = match &self.connects.connects {
|
||||
Some(connections) => connections.clone(),
|
||||
_ => Vec::new(),
|
||||
};
|
||||
SR1Ship {
|
||||
name: name.unwrap_or("NewShip".to_string()),
|
||||
description: "".to_string(),
|
||||
version: self.version.unwrap_or(1_i32),
|
||||
parts,
|
||||
connections,
|
||||
parts: self.parts.as_sr1_vec(),
|
||||
connections: self.connects.as_vec(),
|
||||
lift_off: self.lift_off != 0,
|
||||
touch_ground: self.touch_ground.to_owned().map(|i| i != 0).unwrap_or(true),
|
||||
disconnected,
|
||||
disconnected: self.disconnected.as_sr1_vec(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -267,7 +333,7 @@ impl RawShip {
|
||||
pub fn from_file(path: String) -> Option<RawShip> {
|
||||
let ship_file = std::fs::read_to_string(path); // for encoding error
|
||||
if let Err(e) = ship_file {
|
||||
println!("ERROR!\n{}\n----------", e);
|
||||
println!("ERROR while reading file!\n{}\n----------", e);
|
||||
return None;
|
||||
}
|
||||
let ship_file = ship_file.unwrap();
|
||||
@ -275,7 +341,7 @@ impl RawShip {
|
||||
match ship {
|
||||
Ok(ship) => Some(ship),
|
||||
Err(e) => {
|
||||
println!("ERROR!\n{}", e);
|
||||
println!("ERROR in serde!\n{}", e);
|
||||
None
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
import traceback
|
||||
|
||||
from typing import Optional
|
||||
from typing import Optional, Type
|
||||
|
||||
from Difficult_Rocket import DR_status
|
||||
from Difficult_Rocket.main import Game
|
||||
@ -16,7 +16,7 @@ from Difficult_Rocket.api.types import Options, Version
|
||||
|
||||
from lib_not_dr import loggers
|
||||
|
||||
DR_rust_version = Version("0.3.7") # DR_mod 的 Rust 编写部分的兼容版本
|
||||
DR_rust_version = Version("0.4.0") # DR_mod 的 Rust 编写部分的兼容版本
|
||||
|
||||
logger = loggers.config.get_logger_from_old("client.dr_game", "client")
|
||||
|
||||
@ -41,7 +41,7 @@ class _DR_mod_runtime(Options): # NOQA
|
||||
DR_rust_version: Version = DR_rust_version
|
||||
DR_rust_get_version: Optional[Version] = None
|
||||
|
||||
def init(self) -> None:
|
||||
def init(self, **kwargs) -> bool:
|
||||
try:
|
||||
from .Difficult_Rocket_rs import get_version_str
|
||||
|
||||
@ -68,6 +68,7 @@ class _DR_mod_runtime(Options): # NOQA
|
||||
self.use_DR_rust = False
|
||||
logger.warn(f"DR_rust load faild\n{traceback.format_exc()}", tag="load_dll")
|
||||
self.flush_option()
|
||||
return True
|
||||
|
||||
|
||||
DR_mod_runtime = _DR_mod_runtime()
|
||||
|
@ -366,8 +366,9 @@ class SR1ShipRender(BaseScreen):
|
||||
count = 0
|
||||
|
||||
# 渲染未连接的部件
|
||||
for part_groups, part_connections in self.rust_ship.disconnected_parts():
|
||||
for part_type, part_data in part_groups[0]:
|
||||
for (part_groups, part_connections) in self.rust_ship.disconnected_parts():
|
||||
self.logger.info(part_groups[0], tag="sprite_batch")
|
||||
for (part_type, part_data) in part_groups[0]:
|
||||
# 未连接的需要同时把连接线也给渲染了
|
||||
# TODO: 连接线渲染
|
||||
part_sprite, part_box = self.part_render_init(
|
||||
|
Loading…
Reference in New Issue
Block a user