diff --git a/DR-start.py b/DR-start.py index 2c19e57..7842a8c 100644 --- a/DR-start.py +++ b/DR-start.py @@ -20,7 +20,31 @@ errors = { 'error.happen': '游戏出现了一个报错!正在处理' } +def print_path() -> None: + print(f'{__file__=}') + print(f'{sys.path=}') + print(f'{sys.path[0]=}') + print(f'{sys.argv[0]=}') + print(f'{os.getcwd()=}') + print(f'{os.path.abspath(__file__)=}') + print(f'{os.path.realpath(__file__)=}') + print(f'{os.path.split(os.path.split(os.path.realpath(__file__))[0])=}') + # 输出一遍大部分文件位置相关信息 以后可能会加到logs里 + + +def modify_path() -> None: + file_path = os.path.split(os.path.realpath(__file__))[0] + os.chdir(file_path) # 将运行路径切换到文件位置 防止bug + sys.path.append(f'{file_path}/Difficult_Rocket') # 添加local path + sys.path.append(f'{file_path}/libs') # 添加 libs path + + if __name__ == '__main__': + print(hi) # hi! # 记录启动信息 start_time_ns = time.time_ns() start_time_perf_ns = time.perf_counter_ns() + print_path() + modify_path() + + diff --git a/DR.py b/DR.py index 5fdeaee..454086b 100644 --- a/DR.py +++ b/DR.py @@ -23,10 +23,9 @@ error_format = { } -def main() -> None: - start_time_ns = time.time_ns() - start_time_perf_ns = time.perf_counter_ns() +def print_path() -> None: print(f'{__file__=}') + print(f'{sys.path=}') print(f'{sys.path[0]=}') print(f'{sys.argv[0]=}') print(f'{os.getcwd()=}') @@ -34,12 +33,17 @@ def main() -> None: print(f'{os.path.realpath(__file__)=}') print(f'{os.path.split(os.path.split(os.path.realpath(__file__))[0])=}') # 输出一遍大部分文件位置相关信息 以后可能会加到logs里 + + +def main() -> None: + print(hi) # hi! + start_time_ns = time.time_ns() + start_time_perf_ns = time.perf_counter_ns() + print_path() file_path = os.path.split(os.path.realpath(__file__))[0] os.chdir(file_path) # 将运行路径切换到文件位置 防止bug sys.path.append(f'{file_path}/Difficult_Rocket') # 添加local path sys.path.append(f'{file_path}/libs') # 添加 libs path - print(sys.path) # 输出路径 - print(hi) # hi! from Difficult_Rocket.exception import TestError from Difficult_Rocket import crash diff --git a/README.md b/README.md index 7a9edd6..3798b79 100644 --- a/README.md +++ b/README.md @@ -70,12 +70,13 @@ - `xmltodict`: xml 与 dict 转换器 - `pyperclip`: 剪贴板! - `rapier2d`: 物理模拟引擎 + - `pyo3`: Rust Python 扩展 - 主要贡献者 - [@Rayawa](https://github.com/Rayawa) : 文档矫正 & 翻译部分 lang - [@rouxiao-you](https://github.com/ruoxiao-you) : 翻译 lang - [@Billchyi](https://github.com/Billchyi) : 文档矫正 - - [@MSDNicrosoft]() + - [@MSDNicrosoft](https://github.com/MSDNicrosoft) : 优化代码 ## 相关链接 diff --git a/build_rs.ps1 b/build_rs.ps1 index 6aab144..f93dc1b 100644 --- a/build_rs.ps1 +++ b/build_rs.ps1 @@ -21,6 +21,6 @@ if ($do -or "311" -in $args) { python3.11 setup.py build } -python3.10 post_build.py +python3 post_build.py Set-Location ..\..\..\ diff --git a/docs/README-en.md b/docs/README-en.md index 06f4c2f..b9abc86 100644 --- a/docs/README-en.md +++ b/docs/README-en.md @@ -70,11 +70,13 @@ - `xmltodict`: translate data between xml and dict - `pyperclip`: paste board! - `rapier2d`: Phy simulate engine + - `pyo3`: Rust Python Binding - Main contributors - - [@Rayawa](https://github.com/Rayawa) : check mistake in docs & some translates - - [@rouxiao-you](https://github.com/ruoxiao-you) : translate chinese to English - - [@Billchyi](https://github.com/Billchyi) : check mistake in docs + - [@Rayawa](https://github.com/Rayawa) : Check mistake in docs & some translates + - [@rouxiao-you](https://github.com/ruoxiao-you) : Translate chinese to English + - [@Billchyi](https://github.com/Billchyi) : Check mistake in docs + - [@MSDNicrosoft](https://github.com/MSDNicrosoft) : Optimize code ## Other links diff --git a/docs/book.toml b/docs/book.toml index add0e9e..5350e52 100644 --- a/docs/book.toml +++ b/docs/book.toml @@ -28,6 +28,8 @@ open-on-text = "Found a bug? [Edit this page on GitHub.]" # Should we check links on the internet? Enabling this option adds a # non-negligible performance impact follow-web-links = false +warning-policy = "ignore" +exclude = [ "requirement-dev.txt" ] # Are we allowed to link to files outside of the book's root directory? This # may help prevent linking to sensitive files (e.g. "../../../../etc/shadow") diff --git a/docs/src/contributors.md b/docs/src/contributors.md index 9e3e009..1882b29 100644 --- a/docs/src/contributors.md +++ b/docs/src/contributors.md @@ -5,4 +5,16 @@ 1. Powershell 7+ 2. Python3.8 + 3. gcc / clang 编译器 -4. git +4. rust 工具链 +5. git + +## 安装依赖 + +1. 确保 Path 下有以下内容 + - `python` + - `python3.8` + - 可供 `setuptools-rust` 调用的 rust 工具链 +2. 为 Python 安装 [requrements-dev.txt](../requirement-dev.txt) 的依赖 + - `python -m pip install -r requre` +3. 使用 `build_rs.ps1` 尝试编译一次 `DR_rs` + - `./build_rs.ps1` 38/39/310/311 diff --git a/docs/src/update_logs.md b/docs/src/update_logs.md index b4520be..ef656e5 100644 --- a/docs/src/update_logs.md +++ b/docs/src/update_logs.md @@ -20,6 +20,24 @@ - [![Readme-gitee](https://img.shields.io/badge/Readme-中文(点我!)-blue.svg?style=flat-square)](../../README.md) - Using [SemVer 2.0.0](https://semver.org/) to manage version +## 202303 V 0.7.1.2 + +### `DR_rs` V 0.2.5.2 + +- `0.2.5.0` -> `0.2.5.2` + +- `sr1_data.rs` + - 现在可以完整解析 SR1 的 `PartList.xml` 了 + - 解析后会生成一个 `PartList` 对象 + - Now can parse `PartList.xml` completely + - Will generate a `PartList` object after parsing + + +### 重命名 + +- `.github/workflows/after_compile.py` -> `.github/workflows/post_compile.py` +- `libs/Difficult_Rocket_rs/src/after_build.py` -> `libs/Difficult_Rocket_rs/src/post_build.py` + ## 20230219 V 0.7.1.1 ### 删除了多余的 print diff --git a/libs/Difficult_Rocket_rs/src/src/sr1_data.rs b/libs/Difficult_Rocket_rs/src/src/sr1_data.rs index 2d10be8..8635150 100644 --- a/libs/Difficult_Rocket_rs/src/src/sr1_data.rs +++ b/libs/Difficult_Rocket_rs/src/src/sr1_data.rs @@ -19,7 +19,7 @@ pub mod part_list { #[derive(Debug, Serialize, Deserialize, Clone)] pub struct PartList { #[serde(rename = "PartType")] - part_types: Vec + part_types: Vec, } #[allow(non_camel_case_types)] @@ -38,13 +38,7 @@ pub mod part_list { solar, dockconnector, dockport, - lander - } - - #[derive(Debug, Serialize, Deserialize, Copy, Clone)] - pub enum Category { - Satellite, - None + lander, } #[derive(Debug, Serialize, Deserialize, Copy, Clone)] @@ -62,14 +56,12 @@ pub mod part_list { TopSide, BottomSide, LeftSide, - RightSide + RightSide, } #[derive(Debug, Serialize, Deserialize, Copy, Clone)] pub struct Vertex { - #[serde(rename = "@x")] pub x: Option, - #[serde(rename = "@y")] pub y: Option, } @@ -78,54 +70,93 @@ pub mod part_list { #[serde(rename = "Vertex")] pub vertex: Vec, #[serde(rename = "sensor")] - pub sensor: Option + pub sensor: Option, } #[derive(Debug, Serialize, Deserialize, Copy, Clone)] pub struct AttachPoint { pub location: Option, - #[serde(rename = "@x")] pub x: Option, - #[serde(rename = "@y")] pub y: Option, - #[serde(rename = "@breakAngle")] + #[serde(rename = "flipX")] + pub flip_x: Option, + #[serde(rename = "flipY")] + pub flip_y: Option, + #[serde(rename = "breakAngle")] pub break_angle: Option, - #[serde(rename = "@breakForce")] + #[serde(rename = "breakForce")] pub break_force: Option, - #[serde(rename = "@fuelLine")] + #[serde(rename = "fuelLine")] pub fuel_line: Option, - #[serde(rename = "@group")] pub group: Option, - #[serde(rename = "@order")] pub order: Option, } #[derive(Debug, Serialize, Deserialize, Clone)] pub struct AttachPoints { #[serde(rename = "AttachPoint")] - pub points: Vec + pub points: Vec, } - #[derive(Debug, Serialize, Deserialize, Clone)] - pub enum PartAttr { - Damage, - Tank, - Engine, - Rcs, - Solar, - Lander + #[derive(Debug, Serialize, Deserialize, Copy, Clone)] + pub struct Damage { + disconnect: u32, + explode: u32, + #[serde(rename = "explosionPower")] + explosion_power: u32, + #[serde(rename = "explosionSize")] + explosion_size: u32, } - // #[derive(Debug, Serialize, Deserialize, Clone)] - // pub struct PartAttr { - // // 单独类型节点 - // // pub part_attr: Option>, - // } + #[derive(Debug, Serialize, Deserialize, Copy, Clone)] + pub struct Tank { + fuel: f64, + #[serde(rename = "dryMass")] + dry_mass: f64, + } + #[derive(Debug, Serialize, Deserialize, Copy, Clone)] + pub struct Engine { + power: f64, + consumption: f64, + size: f64, + turn: f64, + #[serde(rename = "fuelType")] + fuel_type: Option, + #[serde(rename = "throttleExponential")] + throttle_exponential: Option, + } + + #[derive(Debug, Serialize, Deserialize, Copy, Clone)] + pub struct Rcs { + power: f64, + consumption: f64, + size: f64, + } + + #[derive(Debug, Serialize, Deserialize, Copy, Clone)] + pub struct Solar { + #[serde(rename = "chargeRate")] + charge_rate: f64, + } + + #[derive(Debug, Serialize, Deserialize, Copy, Clone)] + pub struct Lander { + #[serde(rename = "maxAngle")] + max_angle: i32, + #[serde(rename = "minLength")] + min_length: f64, + #[serde(rename = "maxLength")] + max_length: f64, + #[serde(rename = "angleSpeed")] + angle_speed: Option, + #[serde(rename = "lengthSpeed")] + length_speed: Option, + width: f64, + } #[derive(Debug, Serialize, Deserialize, Clone)] pub struct PartType { - // https://docs.rs/quick-xml/latest/quick_xml/de/index.html // 基本属性 pub id: String, pub name: String, @@ -137,16 +168,16 @@ pub mod part_list { pub height: u32, // 可选属性 pub friction: Option, - pub category: Option, - #[serde(rename = "@ignoreEditorIntersections")] + pub category: Option, + #[serde(rename = "ignoreEditorIntersections")] pub ignore_editor_intersections: Option, - #[serde(rename = "@disableEditorRotation")] + #[serde(rename = "disableEditorRotation")] pub disable_editor_rotation: Option, - #[serde(rename = "@canExplode")] + #[serde(rename = "canExplode")] pub can_explode: Option, - #[serde(rename = "@coverHeight")] + #[serde(rename = "coverHeight")] pub cover_height: Option, - #[serde(rename = "@sandboxOnly")] + #[serde(rename = "sandboxOnly")] pub sandbox_only: Option, pub drag: Option, pub hidden: Option, @@ -156,9 +187,27 @@ pub mod part_list { pub shape: Option>, #[serde(rename = "AttachPoints")] pub attach_points: Option, + #[serde(rename = "Damage")] + pub damage: Option, // 特殊属性子节点 + #[serde(rename = "Tank")] + pub tank: Option, + #[serde(rename = "Engine")] + pub engine: Option, + #[serde(rename = "Tank")] + pub rcs: Option, + #[serde(rename = "Solar")] + pub solar: Option, + #[serde(rename = "Lander")] + pub lander: Option, + } - + impl PartList { + pub fn list_print(&self) -> () { + for part_data in self.part_types.iter() { + println!("{:?}\n", part_data); + } + } } #[inline] @@ -169,7 +218,7 @@ pub mod part_list { Ok(part_list_file) => { let part_list: PartList = from_str(part_list_file.as_str()).unwrap(); Some(part_list) - }, + } Err(_) => { println!("Error while reading File {}", file_name); None @@ -183,10 +232,10 @@ pub mod part_list { let file_name = file_name.unwrap_or("./configs/PartList.xml".to_string()); let _parts = read_part_list(file_name); if let Some(parts) = _parts { - println!("{:?}", parts) + // println!("{:?}", parts) + parts.list_print() } // read_part_list(file_name); Ok(()) } - } \ No newline at end of file diff --git a/libs/Difficult_Rocket_rs/src/src/types.rs b/libs/Difficult_Rocket_rs/src/src/types.rs index 715b88d..9f4687e 100644 --- a/libs/Difficult_Rocket_rs/src/src/types.rs +++ b/libs/Difficult_Rocket_rs/src/src/types.rs @@ -8,7 +8,9 @@ pub mod sr1 { + use super::math::{Shape, Point2D}; + #[inline] pub fn map_ptype_textures(ptype: String) -> String { match ptype.as_str() { "pod-1" => "Pod", @@ -42,6 +44,7 @@ pub mod sr1 { }.to_string() } + #[derive(Clone)] pub struct SR1PartData { pub x: f64, pub y: f64, @@ -57,6 +60,62 @@ pub mod sr1 { pub textures: String, pub connections: Option> } + + #[allow(non_camel_case_types)] + #[derive(Copy, Clone)] + pub enum PartTypes { + pod, + detacher, + wheel, + fuselage, + strut, + tank, + engine, + parachute, + nosecone, + rcs, + solar, + dockconnector, + dockport, + lander, + } + + #[derive(Copy, Clone)] + pub struct Damage { + disconnect: i32, + // 断裂受力大小 + explode: i32, + // 爆炸受力大小 + explosion_power: i32, + // 爆炸力量 + explosion_size: i32, + // 爆炸大小 + } + + #[derive(Clone)] + pub struct SR1PartType { + pub id: String, + pub name: String, + pub description: String, + pub sprite: String, + pub r#type: PartTypes, + pub mass: f64, + pub width: u32, + pub height: u32, + pub friction: f64, + pub category: String, + pub ignore_editor_intersections: bool, + pub disable_editor_rotation: bool, + pub can_explode: bool, + pub cover_height: u32, + pub sandbox_only: bool, + pub drag: f64, + pub hidden: bool, + pub buoyancy: f64, + pub damage: Damage, + pub shape: Shape, + } + } #[allow(unused)] @@ -113,8 +172,8 @@ pub mod math { #[derive(Clone, Copy)] pub struct OneTimeLine { - pub k: f64, - pub b: f64, + // pub k: f64, + // pub b: f64, // y = kx + b // kx + b - y = 0 pub start: Point2D, @@ -125,8 +184,8 @@ pub mod math { #[derive(Clone, Copy)] pub enum Edge { - OneTimeLine{data: OneTimeLine}, - CircularArc{data: CircularArc}, + OneTimeLine(OneTimeLine), + CircularArc(CircularArc), } #[derive(Clone)] @@ -149,10 +208,10 @@ pub mod math { let d_width = width / 2.0; let d_height = height / 2.0; let mut edges: Vec = vec![ - Edge::OneTimeLine{data: OneTimeLine::pos_new(-d_width, -d_height, d_width, -d_height)}, - Edge::OneTimeLine{data: OneTimeLine::pos_new(d_width, -d_height, d_width, d_height)}, - Edge::OneTimeLine{data: OneTimeLine::pos_new(d_width, d_height, -d_width, d_height)}, - Edge::OneTimeLine{data: OneTimeLine::pos_new(-d_width, d_height, -d_width, -d_height)} + Edge::OneTimeLine{0: OneTimeLine::pos_new(-d_width, -d_height, d_width, -d_height)}, + Edge::OneTimeLine{0: OneTimeLine::pos_new(d_width, -d_height, d_width, d_height)}, + Edge::OneTimeLine{0: OneTimeLine::pos_new(d_width, d_height, -d_width, d_height)}, + Edge::OneTimeLine{0: OneTimeLine::pos_new(-d_width, d_height, -d_width, -d_height)} ]; if let Some(angle) = angle { @@ -165,11 +224,11 @@ pub mod math { impl OneTimeLine { #[inline] pub fn pos_new(x1: f64, y1: f64, x2: f64, y2: f64) -> Self { - let k = (x2 - x1) / (y2 - y1); - let b = y1 - (x1 * k); + // let k = (x2 - x1) / (y2 - y1); + // let b = y1 - (x1 * k); let start = Point2D::new(x1, y1); let end = Point2D::new(x2, y2); - OneTimeLine { k, b, start, end } + OneTimeLine { start, end } } #[inline] @@ -199,8 +258,6 @@ pub mod math { } } OneTimeLine{ - k: k_, - b: b_, start: *point, end: Point2D::new(0.0, b_) } diff --git a/nuitka-mac.ps1 b/nuitka-mac.ps1 index 20ef6d4..d109e82 100644 --- a/nuitka-mac.ps1 +++ b/nuitka-mac.ps1 @@ -1,7 +1,7 @@ $start_time = Get-Uptime Write-Output $start_time -python3.9 .github/workflows/get_info.py -env +python3 .github/workflows/get_info.py -env if (-Not (Test-Path -Path "./.github/workflows/env.ps1")) {