update DR rs 0.2.22.0

This commit is contained in:
shenjack 2023-08-26 02:19:48 +08:00
parent 78e98978de
commit d5b20a8d03
Signed by: shenjack
GPG Key ID: 7B1134A979775551
8 changed files with 235 additions and 137 deletions

View File

@ -3,7 +3,25 @@
- 最新版本号
- DR game: 0.3.3.0
- DR rs: 0.2.21.0
- DR rs: 0.2.22.0
## 20230825 DR rs 0.2.22.0
### Remove
- 删除了 `map_ptype_textures` 函数
- 直接通过 `SR1PartType_rs` 实例获取贴图路径
- Delete `map_ptype_textures`
- Get the texture path directly through the `SR1PartType_rs` instance
### Changes
- 为 `types.rs` 添加了一些注释
- 感谢 `sssssssboom` 的帮助
- Add some comments to `types.rs`
- Thanks to `sssssssboom` for the help
- 正在设计 DR 的数据结构
- Designing DR's data structure
## 20230812 DR game 0.3.3.0

View File

@ -116,7 +116,7 @@ dependencies = [
[[package]]
name = "difficult_rocket_rs"
version = "0.2.20"
version = "0.2.22"
dependencies = [
"pyo3",
"quick-xml",
@ -408,9 +408,9 @@ dependencies = [
[[package]]
name = "quick-xml"
version = "0.29.0"
version = "0.30.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81b9228215d82c7b61490fec1de287136b5de6f5700f6e58ea9ad61a7964ca51"
checksum = "eff6510e86862b57b210fd8cbe8ed3f0d7d600b9c2863cd4549a2e033c66e956"
dependencies = [
"memchr",
"serde",
@ -490,9 +490,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "serde"
version = "1.0.173"
version = "1.0.186"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e91f70896d6720bc714a4a57d22fc91f1db634680e65c8efe13323f1fa38d53f"
checksum = "9f5db24220c009de9bd45e69fb2938f4b6d2df856aa9304ce377b3180f83b7c1"
dependencies = [
"serde_derive",
]
@ -511,13 +511,13 @@ dependencies = [
[[package]]
name = "serde_derive"
version = "1.0.173"
version = "1.0.186"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6250dde8342e0232232be9ca3db7aa40aceb5a3e5dd9bddbc00d99a007cde49"
checksum = "5ad697f7e0b65af4983a4ce8f56ed5b357e8d3c36651bf6a7e13639c17b8e670"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.26",
"syn 2.0.29",
]
[[package]]
@ -573,9 +573,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.26"
version = "2.0.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45c3457aacde3c65315de5031ec191ce46604304d2446e803d71ade03308d970"
checksum = "c324c494eba9d92503e6f1ef2e6df781e78f6a7705a0202d9801b198807d518a"
dependencies = [
"proc-macro2",
"quote",
@ -605,7 +605,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.26",
"syn 2.0.29",
]
[[package]]

View File

@ -1,6 +1,6 @@
[package]
name = "difficult_rocket_rs"
version = "0.2.20"
version = "0.2.22"
edition = "2021"
license-file = '../../LICENSE'
authors = [
@ -22,11 +22,11 @@ opt-level = "s"
# codegen-units = 1
[dependencies.quick-xml]
version = "0.29.0"
version = "0.30.0"
features = ["serialize"]
[dependencies.serde]
version = "1.0.173"
version = "1.0.186"
features = ["derive"]
[dependencies.xml-rs]

View File

@ -24,7 +24,7 @@ enum LoadState {
}
#[pyfunction]
fn get_version_str() -> String { "0.2.21.0".to_string() }
fn get_version_str() -> String { "0.2.22.0".to_string() }
#[pyfunction]
fn test_call(py_obj: &PyAny) -> PyResult<bool> {
@ -43,7 +43,6 @@ fn module_init(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
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_function(wrap_pyfunction!(python::data::load_and_save_test, m)?)?;
m.add_function(wrap_pyfunction!(python::data::py_map_ptype_textures, m)?)?;
m.add_class::<python::data::PySR1Ship>()?;
m.add_class::<python::data::PySR1PartList>()?;
m.add_class::<python::data::PySR1PartType>()?;

View File

@ -14,15 +14,10 @@ pub mod data {
use crate::sr1_data::part_list::RawPartList;
use crate::types::math::{Point2D, Rotatable};
use crate::types::sr1::{get_max_box, map_ptype_textures, SR1PartData, SR1PartListTrait};
use crate::types::sr1::{get_max_box, SR1PartData, SR1PartListTrait};
use crate::types::sr1::{IdType, SaveStatus};
use crate::types::sr1::{SR1PartList, SR1PartType, SR1Ship};
#[pyfunction]
#[pyo3(signature = (part_type))]
#[pyo3(name = "map_ptype_textures")]
pub fn py_map_ptype_textures(part_type: String) -> String { map_ptype_textures(part_type) }
#[pyclass]
#[pyo3(name = "SaveStatus_rs")]
#[derive(Clone, Debug)]

View File

@ -129,22 +129,22 @@ pub mod part_list {
#[derive(Debug, Serialize, Deserialize, Copy, Clone)]
pub struct Damage {
pub disconnect: i32,
pub explode: i32,
pub disconnect: f64,
pub explode: f64,
#[serde(rename = "explosionPower")]
pub explosion_power: Option<u32>,
pub explosion_power: Option<f64>,
#[serde(rename = "explosionSize")]
pub explosion_size: Option<u32>,
pub explosion_size: Option<f64>,
}
impl Damage {
#[inline]
pub fn to_damage(&self) -> crate::types::sr1::Damage {
crate::types::sr1::Damage {
disconnect: self.disconnect.to_owned(),
explode: self.explode.to_owned(),
explosion_power: self.explosion_power.unwrap_or(100),
explosion_size: self.explosion_size.unwrap_or(100),
disconnect: self.disconnect,
explode: self.explode,
explosion_power: self.explosion_power.unwrap_or(100_f64),
explosion_size: self.explosion_size.unwrap_or(100_f64),
}
}
}
@ -300,10 +300,10 @@ pub mod part_list {
_ => None,
};
let damage = self.damage.unwrap_or(Damage {
disconnect: 0,
explode: 0,
explosion_power: Some(0u32),
explosion_size: Some(0u32),
disconnect: 0_f64,
explode: 0_f64,
explosion_power: Some(0_f64),
explosion_size: Some(0_f64),
});
let attach_points: Option<Vec<AttachPoint>> = self.attach_points.as_ref().map(|attach_points| attach_points.unzip());
SR1PartType {

View File

@ -26,15 +26,6 @@ pub mod sr1 {
#[inline]
pub fn radians_map_to_degrees(angle: f64) -> f64 {
// match angle {
// 0.0 => 0.,
// 1.570796 => 270.,
// 3.141593 => 180.,
// 4.712389 => 90.,
// _ => {
// angle.to_degrees()
// }
// }
#[allow(clippy::approx_constant)]
if angle == 1.570796 {
270.
@ -47,42 +38,6 @@ pub mod sr1 {
}
}
#[allow(unused)]
#[inline]
pub fn map_ptype_textures(ptype: String) -> String {
match ptype.as_str() {
"pod-1" => "Pod",
"detacher-1" => "DetacherVertical",
"detacher-2" => "DetacherRadial",
"wheel-1" => "Wheel",
"wheel-2" => "Wheel",
"fuselage-1" => "Fuselage",
"strut-1" => "Beam",
"fueltank-0" => "TankTiny",
"fueltank-1" => "TankSmall",
"fueltank-2" => "TankMedium",
"fueltank-3" => "TankLarge",
"fueltank-4" => "Puffy750",
"fueltank-5" => "SideTank",
"engine-0" => "EngineTiny",
"engine-1" => "EngineSmall",
"engine-2" => "EngineMedium",
"engine-3" => "EngineLarge",
"engine-4" => "SolidRocketBooster",
"ion-0" => "EngineIon",
"parachute-1" => "ParachuteCanister",
"nosecone-1" => "NoseCone",
"rcs-1" => "RcsBlock",
"solar-1" => "SolarPanelBase",
"battery-0" => "Battery",
"dock-1" => "DockingConnector",
"port-1" => "DockingPort",
"lander-1" => "LanderLegPreview",
_ => "Pod",
}
.to_string()
}
#[inline]
pub fn i8_to_bool(i: i8) -> bool { !matches!(i, 0) }
@ -113,10 +68,10 @@ pub mod sr1 {
size: f64,
turn: f64,
fuel_type: i32,
// 0 -> 普通燃料
// 1 -> Rcs
// 2 -> 电量
// 3 -> 固推
/// 0 -> 普通燃料
/// 1 -> Rcs
/// 2 -> 电量
/// 3 -> 固推
throttle_exponential: bool,
},
Rcs {
@ -139,14 +94,14 @@ pub mod sr1 {
#[derive(Debug, Copy, Clone)]
pub struct Damage {
pub disconnect: i32,
// 断裂受力大小
pub explode: i32,
// 爆炸受力大小
pub explosion_power: u32,
// 爆炸力量
pub explosion_size: u32,
// 爆炸大小
/// 导致断裂的受力大小
pub disconnect: f64,
/// 导致爆炸的受力大小
pub explode: f64,
/// 爆炸威力(虽然在 sr1 里不是 0 就没用)
pub explosion_power: f64,
/// 爆炸影响范围(虽然在 sr1 里不是 0 就没用)
pub explosion_size: f64,
}
impl Damage {
@ -162,50 +117,51 @@ pub mod sr1 {
#[derive(Debug, Clone)]
pub struct SR1PartType {
/// 部件 ID
pub id: String,
// 部件 ID
/// 部件名称
pub name: String,
// 部件名称
/// 部件描述
pub description: String,
// 部件描述
/// 部件材质
pub sprite: String,
// 部件材质
/// 部件类型
pub p_type: SR1PartTypeEnum,
// 部件类型
/// 部件质量
pub mass: f64,
// 部件质量
/// 部件宽度
pub width: u32,
// 部件宽
/// 部件高
pub height: u32,
// 部件高度
/// 摩擦力
pub friction: f64,
// 摩擦力
/// 部件类别 (原版仅有 "Satellite" 可自定义)
pub category: String,
// 部件类别 (原版仅有 "Satellite" 可自定义)
/// 是否忽略编辑器碰撞
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: Option<Vec<RawShape>>,
// 部件碰撞箱
/// 部件连接点
pub attach_points: Option<Vec<AttachPoint>>,
// 部件连接点
pub attr: Option<SR1PartTypeAttr>, // 部件特殊属性
/// 部件特殊属性
pub attr: Option<SR1PartTypeAttr>,
}
impl SR1PartType {
@ -492,22 +448,34 @@ pub mod sr1 {
#[derive(Debug, Clone)]
pub struct SR1PartData {
// 单独的属性
/// 单独的属性
pub attr: SR1PartDataAttr,
// 基本状态属性
/// x 坐标
pub x: f64,
/// y 坐标
pub y: f64,
/// 零件 id
pub id: IdType,
pub angle: f64, // 弧度制
/// 旋转角度 弧度
pub angle: f64,
/// 旋转角速度 弧度/秒
pub angle_v: f64,
// 状态属性
/// 零件类型
pub part_type: SR1PartTypeEnum,
/// 零件类型 id
pub part_type_id: String,
/// 零件被顺时针转了几个90度影响连接点的位置不影响碰撞箱
/// 在游戏里计算飞船朝向也会参考
pub editor_angle: i32,
/// 是否水平翻转
pub flip_x: bool,
/// 是否垂直翻转
pub flip_y: bool,
/// 是否启用
pub active: bool,
/// 是否爆炸
pub explode: bool,
}
@ -1239,6 +1207,12 @@ pub mod math {
#[allow(dead_code)]
pub mod dr {
use std::collections::HashMap;
use rapier2d_f64::geometry::{SharedShape, TriMeshFlags};
use rapier2d_f64::math::{Isometry, Point, Real};
use rapier2d_f64::parry::transformation::vhacd::VHACDParameters;
#[derive(Clone, Copy)]
pub enum ConnectType {
Stick,
@ -1253,36 +1227,148 @@ pub mod dr {
pub angel: f64,
}
#[derive(Clone, Copy)]
pub enum PartType {
Pod,
Separator,
Wheel,
Fuselage,
Beam,
Engine,
FuelTank,
Parachute,
Nosecone,
SolarPanel,
Battery,
Dock,
Port,
Lander,
}
pub struct DRPartData {
pub x: f64,
pub y: f64,
pub dx: f64,
pub dy: f64,
pub id: i64,
pub p_type: PartType,
pub p_type: String,
pub active: bool,
pub angle: f64, // 角度制
pub angle_v: f64,
pub flip_x: bool,
pub flip_y: bool,
pub connections: Option<Vec<usize>>,
pub shape_type: bool,
pub shape_data: ShapeData,
}
pub enum ShapeData {
// rapier2d_f64::geometry::ColliderBuilder
/// 球
/// 半径
Ball(Real),
/// 矩形
/// 宽 高
Cuboid(Real, Real),
/// 圆角矩形
/// 宽 高 圆角半径
RoundCuboid(Real, Real, Real),
/// 三角形
/// 三个点坐标
Triangle(Point<Real>, Point<Real>, Point<Real>),
/// 圆角三角形
/// 三个点坐标 圆角半径
RoundTriangle(Point<Real>, Point<Real>, Point<Real>, Real),
/// 圆柱体 ( 横向 )
/// 半径 高
CapsuleX(Real, Real),
/// 圆柱体 ( 纵向 )
/// 半径 高
CapsuleY(Real, Real),
/// 复合形状
/// 给一堆坐标
Segment(Point<Real>, Point<Real>),
/// 三角形面定义的几何体(有限元?)
/// 使用由顶点和索引缓冲区定义的三角形网格形状
TriMesh(Vec<Point<Real>>, Vec<[u32; 3]>),
/// 三角形面定义的几何体有限元带一系列可定义的Flags
/// 三角形网格形状由其顶点和索引缓冲区以及控制其预处理的标志定义。
TriMeshWithFlags(Vec<Point<Real>>, Vec<[u32; 3]>, TriMeshFlags),
/// 给定一个多边形几何体,此方法将其分解为一系列凸多边形
ConvexDecomposition(Vec<Point<Real>>, Vec<[u32; 2]>),
/// 给定一个圆角的多边形几何体,此方法将其分解为一系列圆角的凸多边形,虽然不知道怎么分
RoundConvexDecomposition(Vec<Point<Real>>, Vec<[u32; 2]>, Real),
/// 给定一个多边形几何体,此方法将其分解为一系列凸多边形
/// 由VHACDParameters指定算法的参数这将影响分解的结果或质量
ConvexDecompositionWithParams(Vec<Point<Real>>, Vec<[u32; 2]>, VHACDParameters),
/// 给定一个圆角的多边形几何体,此方法将其分解为一系列圆角的凸多边形,虽然不知道怎么分
/// 由VHACDParameters指定算法的参数这将影响分解的结果或质量
RoundConvexDecompositionWithParams(Vec<Point<Real>>, Vec<[u32; 2]>, VHACDParameters, Real),
/// 给定一系列点,计算出对应的凸包络的多边形
ConvexHull(Vec<Point<Real>>),
/// 给定一系列点,计算出对应的凸包络的多边形,然后加上圆角
RoundConvexHull(Vec<Point<Real>>, Real),
/// 给定一系列点,按照凸多边形来计算碰撞箱,但不会算出这个凸多边形
/// 如果实际上这些点并没有定义一个凸多边形在计算过程可能导致bug
ConvexPolyline(Vec<Point<Real>>),
/// 给定一系列点,按照凸多边形加上圆角来计算碰撞箱,但不会算出这个凸多边形
/// 如果实际上这些点并没有定义一个凸多边形在计算过程可能导致bug
RoundConvexPolyline(Vec<Point<Real>>, Real),
/// 由顶点定义的多边形
Polyline(Vec<(Real, Real)>),
/// 由一系列高度定义的某种东西,大概是地面之类的
Heightfield(Vec<(Real, Real)>),
/// 凸分解的复合形状
Compound(Vec<(Isometry<Real>, SharedShape)>), //凸分解,好像可以略微提升复杂刚体碰撞的性能
}
pub struct TankData {
/// 油量if p_type==tank
pub fuel: f64,
/// 空油罐的质量if p_type==tank
pub dry_mass: f64,
/// 燃油种类if p_type==tank
pub fuel_type: i32,
}
pub struct EngineData {
pub power: f64,
pub consumption: f64,
pub size: f64,
pub turn: f64,
pub fuel_type: f64,
pub throttle_exponential: f64,
}
pub trait DRPartTypeAttrTrait {
fn name() -> String;
}
pub struct DRPartType<T>
where
T: DRPartTypeAttrTrait,
{
/// 部件 ID
pub id: String,
/// 是否支持自定义形状
/// shenjack: 折磨我的时候到了
pub shape_type: bool,
/// 所有 raiper2d 支持的碰撞箱类型
pub shape_data: ShapeData,
// 基本属性
/// 名称
pub name: String,
/// 描述
pub description: String,
/// 贴图
pub sprite: String,
///pub r#type: SR1PartTypeEnum,
/// 质量单位500kg
pub mass: f64,
/// 宽度,用于判断放置时是否回合其他零件重叠
pub width: f64,
/// 高度,用于判断放置时是否回合其他零件重叠
pub height: f64,
// 可选属性
/// 摩擦力
pub friction: f64,
/// 分类
pub category: String,
/// 是否可以爆炸
pub can_explode: bool,
/// 好像是影响引擎下方连接点被连接时外面那层贴图的高度,装饰作用
pub cover_height: Option<u32>,
/// 是否只有沙盒可用
pub sandbox_only: Option<bool>,
/// 减阻效果
pub drag: Option<f64>,
/// 是否隐藏
pub hidden: Option<bool>,
/// 浮力
pub buoyancy: Option<f64>,
// 附加属性
pub attr: HashMap<String, T>,
}
}

View File

@ -16,7 +16,7 @@ from Difficult_Rocket.api.mod import ModInfo
from Difficult_Rocket.client import ClientWindow
from Difficult_Rocket.api.types import Options, Version
DR_rust_version = Version("0.2.21.0") # DR_mod 的 Rust 编写部分的兼容版本
DR_rust_version = Version("0.2.22.0") # DR_mod 的 Rust 编写部分的兼容版本
logger = logging.getLogger('client.dr_game')