好开心~ 今天是最美好的一天!
This commit is contained in:
parent
04636e0979
commit
889c5b466e
@ -24,7 +24,7 @@ from libs.MCDR.version import Version
|
||||
|
||||
game_version = Version("0.7.2.1") # 游戏版本
|
||||
build_version = Version("1.2.1.0") # 编译文件版本(与游戏本体无关)
|
||||
DR_rust_version = Version("0.2.6.0") # DR 的 Rust 编写部分的版本
|
||||
DR_rust_version = Version("0.2.6.1") # DR 的 Rust 编写部分的版本
|
||||
Api_version = Version("0.0.1.0") # API 版本
|
||||
__version__ = game_version
|
||||
|
||||
|
@ -90,6 +90,11 @@ class Client:
|
||||
file_drops=file_drop)
|
||||
end_time = time.time_ns()
|
||||
self.use_time = end_time - start_time
|
||||
if DR_option.use_DR_rust:
|
||||
from libs.Difficult_Rocket_rs import read_ship_test, part_list_read_test
|
||||
part_list_read_test()
|
||||
read_ship_test()
|
||||
|
||||
self.logger.info(tr().client.setup.use_time().format(Decimal(self.use_time) / 1000000000))
|
||||
self.logger.debug(tr().client.setup.use_time_ns().format(self.use_time))
|
||||
|
||||
|
@ -7,8 +7,8 @@ fonts_folder = "libs/fonts"
|
||||
|
||||
[window]
|
||||
style = "None"
|
||||
width = 1912
|
||||
height = 987
|
||||
width = 1406
|
||||
height = 893
|
||||
visible = true
|
||||
gui_scale = 1
|
||||
caption = "Difficult Rocket v{DR_version}|DR_rs v{DR_Rust_get_version}"
|
||||
|
@ -27,6 +27,7 @@ if TYPE_CHECKING:
|
||||
|
||||
def part_list_read_test(file_name: Optional[str] = "./configs/PartList.xml") -> None: ...
|
||||
|
||||
def read_ship_test(path: Optional[str] = "./configs/dock1.xml") -> None: ...
|
||||
|
||||
class Camera_rs:
|
||||
""" 用于闲的没事 用 rust 写一个 camera """
|
||||
|
@ -17,7 +17,7 @@ use pyo3::prelude::*;
|
||||
|
||||
#[pyfunction]
|
||||
fn get_version_str() -> String {
|
||||
return "0.2.6.0".to_string();
|
||||
return "0.2.6.1".to_string();
|
||||
}
|
||||
|
||||
#[pyfunction]
|
||||
@ -36,6 +36,7 @@ fn module_init(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
|
||||
m.add_function(wrap_pyfunction!(test_call, m)?)?;
|
||||
m.add_function(wrap_pyfunction!(simulator::simluation, m)?)?;
|
||||
m.add_function(wrap_pyfunction!(sr1_data::part_list::read_part_list_py, m)?)?;
|
||||
m.add_function(wrap_pyfunction!(sr1_data::ship::py_raw_ship_from_file, m)?)?;
|
||||
m.add_class::<render::camera::CameraRs>()?;
|
||||
m.add_class::<render::camera::CenterCameraRs>()?;
|
||||
m.add_class::<render::screen::PartFrame>()?;
|
||||
|
@ -388,11 +388,13 @@ pub mod ship {
|
||||
use pyo3::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
// use quick_xml::de::from_str;
|
||||
use serde_xml_rs::{expect, from_str};
|
||||
use serde_xml_rs::from_str;
|
||||
|
||||
use crate::types::sr1::{SR1Ship, SR1ShipTrait};
|
||||
use crate::types::sr1::{SR1PartData, SR1PartDataAttr, SR1Ship};
|
||||
use crate::types::sr1::{SR1PartDataTrait, SR1ShipTrait};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[serde(rename = "Ship")]
|
||||
pub struct RawShip {
|
||||
#[serde(rename = "Parts")]
|
||||
pub parts: Parts,
|
||||
@ -403,8 +405,9 @@ pub mod ship {
|
||||
pub lift_off: i8,
|
||||
#[serde(rename = "touchingGround")]
|
||||
pub touch_ground: i8,
|
||||
#[serde(rename = "DisconnectedParts")]
|
||||
pub disconnected: Option<Vec<DisconnectedParts>>,
|
||||
}
|
||||
// <Ship version="1" liftedOff="0" touchingGround="0">
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Parts {
|
||||
@ -427,6 +430,8 @@ pub mod ship {
|
||||
#[serde(rename = "Pod")]
|
||||
pub pod: Option<Pod>,
|
||||
|
||||
#[serde(rename = "partType")]
|
||||
pub part_type: String,
|
||||
pub id: i64,
|
||||
pub x: f64,
|
||||
pub y: f64,
|
||||
@ -439,35 +444,27 @@ pub mod ship {
|
||||
pub flip_x: Option<i8>,
|
||||
#[serde(rename = "flippedY")]
|
||||
pub flip_y: Option<i8>,
|
||||
// 降落伞
|
||||
#[serde(rename = "chuteX")]
|
||||
pub chute_x: Option<f64>,
|
||||
#[serde(rename = "chuteY")]
|
||||
pub chute_y: Option<f64>,
|
||||
#[serde(rename = "partType")]
|
||||
pub part_type: String,
|
||||
pub extension: Option<f64>,
|
||||
pub exploded: Option<i8>,
|
||||
#[serde(rename = "chuteAngle")]
|
||||
pub chute_angle: Option<f64>,
|
||||
#[serde(rename = "chuteHeight")]
|
||||
pub chute_height: Option<f64>,
|
||||
pub deployed: Option<i8>,
|
||||
pub rope: Option<i8>,
|
||||
pub extension: Option<f64>,
|
||||
pub inflate: Option<i8>,
|
||||
pub inflation: Option<i8>,
|
||||
pub exploded: Option<i8>,
|
||||
pub rope: Option<i8>,
|
||||
// ?
|
||||
pub deployed: Option<i8>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Engine {
|
||||
pub fuel: i64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Pod {
|
||||
#[serde(rename = "Staging")]
|
||||
pub stages: Vec<Staging>,
|
||||
pub name: String,
|
||||
pub throttle: f64,
|
||||
pub fuel: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
@ -476,14 +473,29 @@ pub mod ship {
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Staging {
|
||||
#[serde(rename = "currentStage")]
|
||||
pub current_stage: u32,
|
||||
#[serde(rename = "Activate")]
|
||||
pub steps: Vec<Activate>,
|
||||
pub struct Pod {
|
||||
#[serde(rename = "Staging")]
|
||||
pub stages: Staging,
|
||||
pub name: String,
|
||||
pub throttle: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Staging {
|
||||
#[serde(rename = "currentStage")]
|
||||
pub current_stage: u32,
|
||||
#[serde(rename = "Step")]
|
||||
pub steps: Vec<Step>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Step {
|
||||
#[serde(rename = "Activate")]
|
||||
pub activates: Vec<Activate>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[serde(rename = "Activate")]
|
||||
pub struct Activate {
|
||||
#[serde(rename = "Id")]
|
||||
pub id: i64,
|
||||
@ -498,9 +510,9 @@ pub mod ship {
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct DisconnectedPart {
|
||||
#[serde(rename = "Parts")]
|
||||
pub parts: Vec<Parts>,
|
||||
pub parts: Vec<Part>,
|
||||
#[serde(rename = "Connections")]
|
||||
pub connects: Vec<Connections>,
|
||||
pub connects: Vec<Connection>,
|
||||
}
|
||||
/// <DisconnectedParts>
|
||||
/// <DisconnectedPart>
|
||||
@ -531,6 +543,15 @@ 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!()
|
||||
}
|
||||
|
||||
@ -548,4 +569,14 @@ pub mod ship {
|
||||
Some(ship)
|
||||
}
|
||||
}
|
||||
|
||||
#[pyfunction]
|
||||
#[pyo3(name = "read_ship_test")]
|
||||
#[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);
|
||||
Ok(true)
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,12 @@ pub mod sr1 {
|
||||
AttachPoint, AttachPoints, Engine, Lander, Rcs, Shape as RawShape, Solar, Tank,
|
||||
};
|
||||
use crate::sr1_data::part_list::{RawPartList, RawPartType, SR1PartTypeEnum};
|
||||
use crate::sr1_data::ship::RawShip;
|
||||
use crate::sr1_data::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,
|
||||
};
|
||||
|
||||
#[inline]
|
||||
pub fn map_ptype_textures(ptype: String) -> String {
|
||||
@ -51,34 +56,20 @@ pub mod sr1 {
|
||||
.to_string()
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SR1PartData {
|
||||
// 单独的属性
|
||||
pub attr: Option<SR1PartDataAttr>,
|
||||
// 基本状态属性
|
||||
pub x: f64,
|
||||
pub y: f64,
|
||||
pub id: i64,
|
||||
pub angle: f64, // 弧度制
|
||||
pub angle_v: f64,
|
||||
// 状态属性
|
||||
pub part_type: String,
|
||||
pub active: bool,
|
||||
pub editor_angle: i32,
|
||||
pub flip_x: bool,
|
||||
pub flip_y: bool,
|
||||
// 降落伞属性
|
||||
pub chute_x: f64,
|
||||
pub chute_y: f64,
|
||||
pub chute_angle: f64,
|
||||
pub chute_height: f64,
|
||||
pub inflate: bool,
|
||||
pub inflation: bool,
|
||||
pub deployed: bool,
|
||||
// 太阳能板属性
|
||||
pub extension: f64,
|
||||
#[inline]
|
||||
pub fn i8_to_bool(i: i8) -> bool {
|
||||
match i {
|
||||
0 => false,
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
|
||||
pub explode: bool,
|
||||
#[inline]
|
||||
pub fn bool_to_i8(b: bool) -> i8 {
|
||||
match b {
|
||||
false => 0,
|
||||
true => 1,
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
@ -118,22 +109,6 @@ pub mod sr1 {
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum SR1PartDataAttr {
|
||||
Tank {
|
||||
fuel: f64,
|
||||
},
|
||||
Engine {
|
||||
fuel: f64,
|
||||
},
|
||||
Pod {
|
||||
name: String,
|
||||
throttle: f64,
|
||||
current_stage: u32,
|
||||
steps: Vec<(i64, bool)>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Damage {
|
||||
pub disconnect: i32,
|
||||
@ -213,6 +188,7 @@ pub mod sr1 {
|
||||
}
|
||||
|
||||
impl SR1PartList {
|
||||
#[inline]
|
||||
pub fn from_file(file_name: String) -> Option<SR1PartList> {
|
||||
if let Some(raw_list) = RawPartList::from_file(file_name) {
|
||||
return Some(raw_list.to_sr_part_list(None));
|
||||
@ -239,6 +215,11 @@ pub mod sr1 {
|
||||
fn to_raw_part_type(&self) -> RawPartType;
|
||||
}
|
||||
|
||||
pub trait SR1PartDataTrait {
|
||||
fn to_sr_part_data(&self) -> SR1PartData;
|
||||
fn to_raw_part_data(&self) -> RawPartData;
|
||||
}
|
||||
|
||||
pub trait SR1PartListTrait {
|
||||
fn to_sr_part_list(&self, name: Option<String>) -> SR1PartList;
|
||||
fn to_raw_part_list(&self) -> RawPartList;
|
||||
@ -416,14 +397,179 @@ pub mod sr1 {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SR1PartData {
|
||||
// 单独的属性
|
||||
pub attr: Option<SR1PartDataAttr>,
|
||||
// 基本状态属性
|
||||
pub x: f64,
|
||||
pub y: f64,
|
||||
pub id: i64,
|
||||
pub angle: f64, // 弧度制
|
||||
pub angle_v: f64,
|
||||
// 状态属性
|
||||
pub part_type: String,
|
||||
pub active: bool,
|
||||
pub editor_angle: i32,
|
||||
pub flip_x: bool,
|
||||
pub flip_y: bool,
|
||||
|
||||
pub explode: bool,
|
||||
}
|
||||
|
||||
impl SR1PartDataTrait for SR1PartData {
|
||||
#[inline]
|
||||
fn to_sr_part_data(&self) -> SR1PartData {
|
||||
self.clone()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn to_raw_part_data(&self) -> RawPartData {
|
||||
let tank = match &self.attr {
|
||||
Some(attr) => match attr {
|
||||
SR1PartDataAttr::Tank { fuel } => Some(RawTank { fuel: *fuel }),
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
};
|
||||
let engine = match &self.attr {
|
||||
Some(attr) => match attr {
|
||||
SR1PartDataAttr::Engine { fuel } => Some(RawEngine { fuel: *fuel }),
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
};
|
||||
let pod = match &self.attr {
|
||||
Some(attr) => match attr {
|
||||
SR1PartDataAttr::Pod {
|
||||
name,
|
||||
throttle,
|
||||
current_stage,
|
||||
steps,
|
||||
} => Some({
|
||||
let mut actives = Vec::new();
|
||||
for step in steps {
|
||||
let mut steps_ = Vec::new();
|
||||
for active in step {
|
||||
steps_.push(RawActivate {
|
||||
id: active.0,
|
||||
moved: bool_to_i8(active.1),
|
||||
});
|
||||
}
|
||||
actives.push(RawStep { activates: steps_ });
|
||||
}
|
||||
let stages = RawStaging {
|
||||
current_stage: *current_stage,
|
||||
steps: actives,
|
||||
};
|
||||
RawPod {
|
||||
name: name.clone(),
|
||||
throttle: *throttle,
|
||||
stages,
|
||||
}
|
||||
}),
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
};
|
||||
let (chute_x, chute_y, chute_angle, chute_height, inflate, inflation, deployed, rope) =
|
||||
match &self.attr {
|
||||
Some(attr) => match attr {
|
||||
SR1PartDataAttr::Parachute {
|
||||
chute_x,
|
||||
chute_y,
|
||||
chute_angle,
|
||||
chute_height,
|
||||
inflate,
|
||||
inflation,
|
||||
deployed,
|
||||
rope,
|
||||
} => (
|
||||
Some(*chute_x),
|
||||
Some(*chute_y),
|
||||
Some(*chute_angle),
|
||||
Some(*chute_height),
|
||||
Some(bool_to_i8(*inflate)),
|
||||
Some(bool_to_i8(*inflation)),
|
||||
Some(bool_to_i8(*deployed)),
|
||||
Some(bool_to_i8(*rope)),
|
||||
),
|
||||
_ => (None, None, None, None, None, None, None, None),
|
||||
},
|
||||
_ => (None, None, None, None, None, None, None, None),
|
||||
};
|
||||
let extension = match &self.attr {
|
||||
Some(attr) => match attr {
|
||||
SR1PartDataAttr::Solar { extension } => Some(*extension),
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
};
|
||||
RawPartData {
|
||||
tank,
|
||||
engine,
|
||||
pod,
|
||||
part_type: self.part_type.clone(),
|
||||
id: self.id,
|
||||
x: self.x,
|
||||
y: self.y,
|
||||
editor_angle: self.editor_angle,
|
||||
angle: self.angle,
|
||||
angle_v: self.angle_v,
|
||||
flip_x: Some(bool_to_i8(self.flip_x)),
|
||||
flip_y: Some(bool_to_i8(self.flip_y)),
|
||||
chute_x,
|
||||
chute_y,
|
||||
chute_height,
|
||||
extension,
|
||||
inflate,
|
||||
inflation,
|
||||
exploded: Some(bool_to_i8(self.explode)),
|
||||
rope,
|
||||
chute_angle,
|
||||
deployed,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum SR1PartDataAttr {
|
||||
Tank {
|
||||
fuel: f64,
|
||||
},
|
||||
Engine {
|
||||
fuel: f64,
|
||||
},
|
||||
Pod {
|
||||
name: String,
|
||||
throttle: f64,
|
||||
current_stage: u32,
|
||||
steps: Vec<Vec<(i64, bool)>>,
|
||||
},
|
||||
Solar {
|
||||
extension: f64,
|
||||
},
|
||||
Parachute {
|
||||
chute_x: f64,
|
||||
chute_y: f64,
|
||||
chute_angle: f64,
|
||||
chute_height: f64,
|
||||
inflate: bool,
|
||||
inflation: bool,
|
||||
deployed: bool,
|
||||
rope: bool,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SR1Ship {
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
pub parts: Vec<SR1PartData>,
|
||||
pub connections: Vec<String>,
|
||||
pub connections: Vec<Connection>,
|
||||
pub lift_off: bool,
|
||||
pub touch_ground: bool,
|
||||
pub disconnected: Vec<(Vec<SR1PartData>, Vec<Connection>)>,
|
||||
}
|
||||
|
||||
impl SR1ShipTrait for SR1Ship {
|
||||
@ -440,7 +586,30 @@ pub mod sr1 {
|
||||
|
||||
#[inline]
|
||||
fn to_raw_ship(&self) -> RawShip {
|
||||
todo!() // 1145行的内容
|
||||
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,
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user