add api dr rs 0.2.15.0

This commit is contained in:
shenjack 2023-06-26 01:28:53 +08:00
parent bad02add7c
commit c4a1807033
7 changed files with 33 additions and 14 deletions

View File

@ -91,6 +91,9 @@ if TYPE_CHECKING:
@property
def img_pos(self) -> Tuple[int, int, int, int]: ...
""" -x -y +x +y 左下右上 """
@property
def connection(self) -> List[Tuple[int, int, int, int]]: ...
"""获取所有连接信息"""
def get_part_box(self, part_id: int) -> Optional[Tuple[Tuple[int, int], Tuple[int, int]]]: ...
def as_dict(self) -> Dict[int, List[Tuple[SR1PartType_rs, SR1PartData]]]:
"""用于返回一个包含所有已连接零件的字典"""

View File

@ -12,7 +12,7 @@ package_path = 'Difficult_Rocket_rs'
setup(
name='Difficult_Rocket_rs',
version="0.2.14.0",
version="0.2.15.0",
author='shenjackyuanjie',
author_email='3695888@qq.com',
rust_extensions=[RustExtension(target="Difficult_Rocket_rs.Difficult_Rocket_rs",

View File

@ -25,7 +25,7 @@ enum LoadState {
}
#[pyfunction]
fn get_version_str() -> String { "0.2.14.0".to_string() }
fn get_version_str() -> String { "0.2.15.0".to_string() }
#[pyfunction]
fn test_call(py_obj: &PyAny) -> PyResult<bool> {

View File

@ -13,8 +13,8 @@ pub mod data {
use crate::sr1_data::part_list::RawPartList;
use crate::types::math::{Point2D, Rotatable};
use crate::types::sr1::SaveStatus;
use crate::types::sr1::{get_max_box, SR1PartData, SR1PartListTrait};
use crate::types::sr1::{IdType, SaveStatus};
use crate::types::sr1::{SR1PartList, SR1PartType, SR1Ship};
#[pyclass]
@ -187,6 +187,20 @@ pub mod data {
mass
}
#[getter]
fn get_connection(&self) -> Vec<(i32, i32, IdType, IdType)> {
let mut connections = Vec::new();
for connect in self.ship.connections.iter() {
connections.push((
connect.parent_attach_point,
connect.child_attach_point,
connect.parent_part,
connect.child_part,
));
}
connections
}
fn as_dict(&self) -> HashMap<i64, Vec<(PySR1PartType, PySR1PartData)>> {
let mut parts: HashMap<i64, Vec<(PySR1PartType, PySR1PartData)>> = HashMap::new();
for part_data in self.ship.parts.iter() {

View File

@ -378,7 +378,7 @@ pub mod ship {
use super::part_list::SR1PartTypeEnum;
use crate::types::sr1::{i8_to_bool, SR1PartDataTrait, SR1PartTypeAttr, SR1ShipTrait};
use crate::types::sr1::{SR1PartData, SR1PartDataAttr, SR1Ship};
use crate::types::sr1::{IdType, SR1PartData, SR1PartDataAttr, SR1Ship};
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename = "Ship")]
@ -506,13 +506,13 @@ pub mod ship {
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Connection {
#[serde(rename = "parentAttachPoint")]
pub parent_attach_point: i64,
pub parent_attach_point: i32,
#[serde(rename = "childAttachPoint")]
pub child_attach_point: i64,
pub child_attach_point: i32,
#[serde(rename = "parentPart")]
pub parent_part: i64,
pub parent_part: IdType,
#[serde(rename = "childPart")]
pub child_part: i64,
pub child_part: IdType,
}
impl Part {

View File

@ -20,6 +20,8 @@ pub mod sr1 {
};
use crate::types::math::{Point2D, Rotatable};
pub type IdType = i64;
#[allow(unused)]
#[inline]
pub fn map_ptype_textures(ptype: String) -> String {
@ -488,7 +490,7 @@ pub mod sr1 {
// 基本状态属性
pub x: f64,
pub y: f64,
pub id: i64,
pub id: IdType,
pub angle: f64, // 弧度制
pub angle_v: f64,
// 状态属性
@ -536,7 +538,7 @@ pub mod sr1 {
pub name: Option<String>,
pub throttle: Option<f64>,
pub current_stage: Option<i32>,
pub steps: Option<Vec<Vec<(i64, bool)>>>,
pub steps: Option<Vec<Vec<(IdType, bool)>>>,
// Solar
pub extension: Option<f64>,
// Parachute
@ -587,7 +589,7 @@ pub mod sr1 {
name: Option<String>,
throttle: Option<f64>,
current_stage: Option<i32>,
steps: Option<Vec<Vec<(i64, bool)>>>,
steps: Option<Vec<Vec<(IdType, bool)>>>,
extension: Option<f64>,
chute_x: Option<f64>,
chute_y: Option<f64>,
@ -731,11 +733,11 @@ pub mod sr1 {
}
}
pub fn part_as_hashmap(&self) -> HashMap<i64, Vec<SR1PartData>> {
pub fn part_as_hashmap(&self) -> HashMap<IdType, Vec<SR1PartData>> {
// 返回一个 HashMap 用于快速查找
// 同时为了 防止出现多个相同的 PartID 造成的数据丢失
// 采用 Vec 存储
let mut result: HashMap<i64, Vec<SR1PartData>> = HashMap::new();
let mut result: HashMap<IdType, Vec<SR1PartData>> = HashMap::new();
for part_data in self.parts.iter() {
if let Some(part_vec) = result.get_mut(&part_data.id) {
part_vec.push(part_data.clone());

View File

@ -17,7 +17,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.14.0") # DR_mod 的 Rust 编写部分的兼容版本
DR_rust_version = Version("0.2.15.0") # DR_mod 的 Rust 编写部分的兼容版本
logger = logging.getLogger('client.dr_game')