cargo fmt 的另一部分
This commit is contained in:
parent
ba9750e265
commit
6b0da4b205
@ -32,9 +32,25 @@ pub mod camera {
|
||||
impl CenterCameraRs {
|
||||
#[new]
|
||||
#[pyo3(signature = (window, zoom=1.0, dx=1.0, dy=1.0, min_zoom=1.0, max_zoom=1.0))]
|
||||
pub fn py_new(window: &PyAny, zoom: f64, dx: f64, dy: f64,min_zoom: f64, max_zoom: f64) -> PyResult<(Self, CameraRs)> {
|
||||
return Ok((CenterCameraRs {}, CameraRs {dx, dy, zoom, min_zoom, max_zoom,
|
||||
window: window.into()}))
|
||||
pub fn py_new(
|
||||
window: &PyAny,
|
||||
zoom: f64,
|
||||
dx: f64,
|
||||
dy: f64,
|
||||
min_zoom: f64,
|
||||
max_zoom: f64,
|
||||
) -> PyResult<(Self, CameraRs)> {
|
||||
return Ok((
|
||||
CenterCameraRs {},
|
||||
CameraRs {
|
||||
dx,
|
||||
dy,
|
||||
zoom,
|
||||
min_zoom,
|
||||
max_zoom,
|
||||
window: window.into(),
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
// pub fn __enter__(py_self: PyRef<Self>) -> PyResult<PyRef<Self>> {
|
||||
@ -50,8 +66,14 @@ pub mod camera {
|
||||
Python::with_gil(|py| -> PyResult<()> {
|
||||
let view = super_.window.getattr(py, intern!(py, "view"))?;
|
||||
// 获取存储的 view
|
||||
let x: f64 = super_.window.getattr(py, intern!(py, "width"))?.extract(py)?;
|
||||
let y: f64 = super_.window.getattr(py, intern!(py, "height"))?.extract(py)?;
|
||||
let x: f64 = super_
|
||||
.window
|
||||
.getattr(py, intern!(py, "width"))?
|
||||
.extract(py)?;
|
||||
let y: f64 = super_
|
||||
.window
|
||||
.getattr(py, intern!(py, "height"))?
|
||||
.extract(py)?;
|
||||
let x: f64 = x / 2.0 / super_.zoom + (super_.dx / super_.zoom);
|
||||
let y: f64 = y / 2.0 / super_.zoom + (super_.dy / super_.zoom);
|
||||
// 计算中心点
|
||||
@ -59,15 +81,17 @@ pub mod camera {
|
||||
// view.call_method1(py, "translate", (x, y))?;
|
||||
// view.call_method1(py, "scale", (super_.zoom, super_.zoom))?;
|
||||
|
||||
let args = ((x * super_.zoom, y * super_.zoom, 0), );
|
||||
let args = ((x * super_.zoom, y * super_.zoom, 0),);
|
||||
let view_matrix = view.call_method1(py, intern!(py, "translate"), args)?;
|
||||
// view_matrix = self.view.translate((x * zoom, y * zoom, 0))
|
||||
|
||||
let args = ((super_.zoom, super_.zoom, 1), );
|
||||
let args = ((super_.zoom, super_.zoom, 1),);
|
||||
let view_matrix = view_matrix.call_method1(py, intern!(py, "scale"), args)?;
|
||||
// view_matrix = view_matrix.scale((zoom, zoom, 1))
|
||||
|
||||
super_.window.setattr(py, intern!(py, "view"), view_matrix)?;
|
||||
super_
|
||||
.window
|
||||
.setattr(py, intern!(py, "view"), view_matrix)?;
|
||||
// self.view = view_matrix
|
||||
Ok(())
|
||||
})?;
|
||||
@ -79,9 +103,22 @@ pub mod camera {
|
||||
impl CameraRs {
|
||||
#[new]
|
||||
#[pyo3(signature = (window, zoom=1.0, dx=1.0, dy=1.0, min_zoom=1.0, max_zoom=1.0))]
|
||||
pub fn py_new(window: &PyAny, zoom: f64, dx: f64, dy: f64,min_zoom: f64, max_zoom: f64) -> PyResult<Self> {
|
||||
return Ok(CameraRs {dx, dy, zoom, min_zoom, max_zoom,
|
||||
window: window.into()})
|
||||
pub fn py_new(
|
||||
window: &PyAny,
|
||||
zoom: f64,
|
||||
dx: f64,
|
||||
dy: f64,
|
||||
min_zoom: f64,
|
||||
max_zoom: f64,
|
||||
) -> PyResult<Self> {
|
||||
return Ok(CameraRs {
|
||||
dx,
|
||||
dy,
|
||||
zoom,
|
||||
min_zoom,
|
||||
max_zoom,
|
||||
window: window.into(),
|
||||
});
|
||||
}
|
||||
|
||||
pub fn get_view(&self) -> PyResult<PyObject> {
|
||||
@ -92,7 +129,7 @@ pub mod camera {
|
||||
|
||||
#[getter]
|
||||
pub fn get_position(&self) -> (f64, f64) {
|
||||
return (self.dx, self.dy)
|
||||
return (self.dx, self.dy);
|
||||
}
|
||||
|
||||
#[setter]
|
||||
@ -117,16 +154,19 @@ pub mod camera {
|
||||
let view = self.window.getattr(py, intern!(py, "view"))?;
|
||||
|
||||
let x: f64 = self.window.getattr(py, intern!(py, "width"))?.extract(py)?;
|
||||
let y: f64 = self.window.getattr(py, intern!(py, "height"))?.extract(py)?;
|
||||
let y: f64 = self
|
||||
.window
|
||||
.getattr(py, intern!(py, "height"))?
|
||||
.extract(py)?;
|
||||
let x: f64 = x / 2.0 / self.zoom + (self.dx / self.zoom);
|
||||
let y: f64 = y / 2.0 / self.zoom + (self.dy / self.zoom);
|
||||
// use to get center of the screen
|
||||
|
||||
let args = ((x * self.zoom, y * self.zoom, 0), );
|
||||
let args = ((x * self.zoom, y * self.zoom, 0),);
|
||||
let view_matrix = view.call_method1(py, intern!(py, "translate"), args)?;
|
||||
// view_matrix = self.view.translate((x * zoom, y * zoom, 0))
|
||||
|
||||
let args = ((self.zoom, self.zoom, 1), );
|
||||
let args = ((self.zoom, self.zoom, 1),);
|
||||
let view_matrix = view_matrix.call_method1(py, intern!(py, "scale"), args)?;
|
||||
// view_matrix = view_matrix.scale((zoom, zoom, 1))
|
||||
|
||||
@ -134,7 +174,7 @@ pub mod camera {
|
||||
// self.view = view_matrix
|
||||
Ok(())
|
||||
})?;
|
||||
return Ok(())
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
pub fn end(&self) -> PyResult<()> {
|
||||
@ -142,20 +182,23 @@ pub mod camera {
|
||||
let view = self.window.getattr(py, intern!(py, "view"))?;
|
||||
|
||||
let x: f64 = self.window.getattr(py, intern!(py, "width"))?.extract(py)?;
|
||||
let y: f64 = self.window.getattr(py, intern!(py, "height"))?.extract(py)?;
|
||||
let y: f64 = self
|
||||
.window
|
||||
.getattr(py, intern!(py, "height"))?
|
||||
.extract(py)?;
|
||||
let x: f64 = x / 2.0 / self.zoom + (self.dx / self.zoom);
|
||||
let y: f64 = y / 2.0 / self.zoom + (self.dy / self.zoom);
|
||||
|
||||
let args = ((1.0 / self.zoom, 1.0 / self.zoom, 1), );
|
||||
let args = ((1.0 / self.zoom, 1.0 / self.zoom, 1),);
|
||||
let view_matrix = view.call_method1(py, intern!(py, "scale"), args)?;
|
||||
|
||||
let args = ((-x * self.zoom, -y * self.zoom, 0), );
|
||||
let args = ((-x * self.zoom, -y * self.zoom, 0),);
|
||||
let view_matrix = view_matrix.call_method1(py, intern!(py, "translate"), args)?;
|
||||
|
||||
self.window.setattr(py, intern!(py, "view"), view_matrix)?;
|
||||
Ok(())
|
||||
})?;
|
||||
return Ok(())
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
/// https://github.com/PyO3/pyo3/discussions/2931#discussioncomment-4820729 for finding this
|
||||
@ -166,10 +209,15 @@ pub mod camera {
|
||||
Ok(py_self)
|
||||
}
|
||||
|
||||
pub fn __exit__(&self, _exc_type: PyObject, _exc_value: PyObject, _traceback: PyObject) -> PyResult<()>{
|
||||
pub fn __exit__(
|
||||
&self,
|
||||
_exc_type: PyObject,
|
||||
_exc_value: PyObject,
|
||||
_traceback: PyObject,
|
||||
) -> PyResult<()> {
|
||||
// println!("exit!");
|
||||
self.end()?;
|
||||
return Ok(())
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -194,7 +242,7 @@ pub mod screen {
|
||||
Ok(PartFrame {
|
||||
box_size: 111,
|
||||
width: 111,
|
||||
height: 111
|
||||
height: 111,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -10,11 +10,11 @@ pub mod part_list {
|
||||
use std::fs;
|
||||
|
||||
use pyo3::prelude::*;
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
// use quick_xml::de::from_str;
|
||||
use serde_xml_rs::{from_str};
|
||||
use serde_xml_rs::from_str;
|
||||
|
||||
use crate::types::sr1::{SR1PartTypeData, SR1PartType, SR1PartAttr, SR1PartList};
|
||||
use crate::types::sr1::{SR1PartAttr, SR1PartList, SR1PartType, SR1PartTypeData};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct RawPartList {
|
||||
@ -238,37 +238,62 @@ pub mod part_list {
|
||||
let part_attr: Option<SR1PartAttr> = match self.r#type {
|
||||
SR1PartTypeEnum::tank => {
|
||||
let tank = self.tank.unwrap();
|
||||
Some(SR1PartAttr::Tank {fuel: tank.fuel, dry_mass: tank.dry_mass,
|
||||
fuel_type: tank.fuel_type.unwrap_or(0)})
|
||||
},
|
||||
Some(SR1PartAttr::Tank {
|
||||
fuel: tank.fuel,
|
||||
dry_mass: tank.dry_mass,
|
||||
fuel_type: tank.fuel_type.unwrap_or(0),
|
||||
})
|
||||
}
|
||||
SR1PartTypeEnum::engine => {
|
||||
let engine = self.engine.unwrap();
|
||||
Some(SR1PartAttr::Engine {power: engine.power,
|
||||
consumption: engine.consumption, size: engine.size,
|
||||
turn: engine.turn, fuel_type: engine.fuel_type.unwrap_or(0),
|
||||
throttle_exponential: engine.throttle_exponential.unwrap_or(false)})
|
||||
},
|
||||
Some(SR1PartAttr::Engine {
|
||||
power: engine.power,
|
||||
consumption: engine.consumption,
|
||||
size: engine.size,
|
||||
turn: engine.turn,
|
||||
fuel_type: engine.fuel_type.unwrap_or(0),
|
||||
throttle_exponential: engine.throttle_exponential.unwrap_or(false),
|
||||
})
|
||||
}
|
||||
SR1PartTypeEnum::rcs => {
|
||||
let rcs = self.rcs.unwrap();
|
||||
Some(SR1PartAttr::Rcs {power: rcs.power, consumption: rcs.consumption,
|
||||
size: rcs.size})
|
||||
},
|
||||
Some(SR1PartAttr::Rcs {
|
||||
power: rcs.power,
|
||||
consumption: rcs.consumption,
|
||||
size: rcs.size,
|
||||
})
|
||||
}
|
||||
SR1PartTypeEnum::solar => {
|
||||
let solar = self.solar.unwrap();
|
||||
Some(SR1PartAttr::Solar {charge_rate: solar.charge_rate})
|
||||
},
|
||||
Some(SR1PartAttr::Solar {
|
||||
charge_rate: solar.charge_rate,
|
||||
})
|
||||
}
|
||||
SR1PartTypeEnum::lander => {
|
||||
let lander = self.lander.unwrap();
|
||||
Some(SR1PartAttr::Lander {max_angle: lander.max_angle, min_length: lander.min_length,
|
||||
max_length: lander.max_length, angle_speed: lander.angle_speed.unwrap_or(0.0),
|
||||
length_speed: lander.length_speed.unwrap_or(0.0), width: lander.width})
|
||||
},
|
||||
_ => None
|
||||
Some(SR1PartAttr::Lander {
|
||||
max_angle: lander.max_angle,
|
||||
min_length: lander.min_length,
|
||||
max_length: lander.max_length,
|
||||
angle_speed: lander.angle_speed.unwrap_or(0.0),
|
||||
length_speed: lander.length_speed.unwrap_or(0.0),
|
||||
width: lander.width,
|
||||
})
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
let damage = self.damage.unwrap_or(Damage {
|
||||
disconnect: 0,
|
||||
explode: 0,
|
||||
explosion_power: Some(0u32),
|
||||
explosion_size: Some(0u32),
|
||||
});
|
||||
let attach_points: Option<Vec<AttachPoint>> =
|
||||
if let Some(attach_points) = &self.attach_points {
|
||||
Some(attach_points.unzip())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let damage = self.damage.unwrap_or(Damage {disconnect: 0, explode: 0,
|
||||
explosion_power: Some(0u32), explosion_size: Some(0u32) });
|
||||
let attach_points: Option<Vec<AttachPoint>> = if let Some(attach_points) = &self.attach_points {
|
||||
Some(attach_points.unzip()) } else { None };
|
||||
SR1PartType {
|
||||
id: self.id.clone(),
|
||||
name: self.name.clone(),
|
||||
@ -312,7 +337,10 @@ pub mod part_list {
|
||||
println!("{}", part_data.id.to_string());
|
||||
part_list.push(part_data.to_sr_part_type());
|
||||
}
|
||||
SR1PartList { types: part_list, name: name.unwrap_or("".to_string()) }
|
||||
SR1PartList {
|
||||
types: part_list,
|
||||
name: name.unwrap_or("".to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -350,9 +378,9 @@ pub mod part_list {
|
||||
pub mod ship {
|
||||
|
||||
use pyo3::prelude::*;
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
// use quick_xml::de::from_str;
|
||||
use serde_xml_rs::{from_str};
|
||||
use serde_xml_rs::from_str;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Ship {
|
||||
@ -364,20 +392,20 @@ pub mod ship {
|
||||
#[serde(rename = "liftedOff")]
|
||||
pub lift_off: i8,
|
||||
#[serde(rename = "touchingGround")]
|
||||
pub touch_ground: i8
|
||||
pub touch_ground: i8,
|
||||
}
|
||||
// <Ship version="1" liftedOff="0" touchingGround="0">
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Parts {
|
||||
#[serde(rename = "Part")]
|
||||
pub parts: Vec<Part>
|
||||
pub parts: Vec<Part>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Connections {
|
||||
#[serde(rename = "Connection")]
|
||||
pub connects: Vec<Connection>
|
||||
pub connects: Vec<Connection>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
@ -421,7 +449,7 @@ pub mod ship {
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Engine {
|
||||
pub fuel: i64
|
||||
pub fuel: i64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
@ -429,12 +457,12 @@ pub mod ship {
|
||||
#[serde(rename = "Staging")]
|
||||
pub stages: Vec<Staging>,
|
||||
pub name: String,
|
||||
pub throttle: i8
|
||||
pub throttle: i8,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Tank {
|
||||
pub fuel: i64
|
||||
pub fuel: i64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
@ -449,12 +477,12 @@ pub mod ship {
|
||||
pub struct Activate {
|
||||
#[serde(rename = "Id")]
|
||||
pub id: i64,
|
||||
pub moved: i8 // 1 or 0
|
||||
pub moved: i8, // 1 or 0
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct DisconnectedParts {
|
||||
pub parts: Vec<DisconnectedPart>
|
||||
pub parts: Vec<DisconnectedPart>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
|
@ -6,18 +6,18 @@
|
||||
* -------------------------------
|
||||
*/
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::time;
|
||||
use crate::types::sr1::SR1PartData;
|
||||
use pyo3::intern;
|
||||
use pyo3::prelude::*;
|
||||
use crate::types::sr1::SR1PartData;
|
||||
use std::collections::HashMap;
|
||||
use std::time;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub mod types {
|
||||
use std::collections::HashMap;
|
||||
use pyo3::intern;
|
||||
use pyo3::prelude::*;
|
||||
use pyo3::types::{PyDict};
|
||||
use pyo3::types::PyDict;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::types::sr1::SR1PartData;
|
||||
|
||||
@ -25,7 +25,7 @@ pub mod types {
|
||||
pub x: f64,
|
||||
pub y: f64,
|
||||
pub id: usize,
|
||||
pub type_: String
|
||||
pub type_: String,
|
||||
}
|
||||
|
||||
#[pyclass(name = "PartDatas")]
|
||||
@ -44,21 +44,20 @@ pub mod types {
|
||||
#[new]
|
||||
fn py_new(py_part_data: &PyDict) -> PyResult<Self> {
|
||||
let datas: HashMap<i64, SR1PartData> = part_data_tp_SR1PartDatas(py_part_data)?;
|
||||
return Ok(PartDatas { part_structs: datas })
|
||||
return Ok(PartDatas {
|
||||
part_structs: datas,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub fn part_data_to_SR1PartData(input: &PyAny) -> PyResult<SR1PartData> {
|
||||
let connections = match input.getattr(intern!(input.py(), "connections")) {
|
||||
Ok(ok) => {
|
||||
ok.extract()?
|
||||
}
|
||||
_ => None
|
||||
Ok(ok) => ok.extract()?,
|
||||
_ => None,
|
||||
};
|
||||
|
||||
return Ok(SR1PartData{
|
||||
return Ok(SR1PartData {
|
||||
x: input.getattr(intern!(input.py(), "x"))?.extract()?,
|
||||
y: input.getattr(intern!(input.py(), "y"))?.extract()?,
|
||||
id: input.getattr(intern!(input.py(), "id"))?.extract()?,
|
||||
@ -66,14 +65,15 @@ pub mod types {
|
||||
active: input.getattr(intern!(input.py(), "active"))?.extract()?,
|
||||
angle: input.getattr(intern!(input.py(), "angle"))?.extract()?,
|
||||
angle_v: input.getattr(intern!(input.py(), "angle_v"))?.extract()?,
|
||||
editor_angle: input.getattr(intern!(input.py(), "editor_angle"))?.extract()?,
|
||||
editor_angle: input
|
||||
.getattr(intern!(input.py(), "editor_angle"))?
|
||||
.extract()?,
|
||||
flip_x: input.getattr(intern!(input.py(), "flip_x"))?.extract()?,
|
||||
flip_y: input.getattr(intern!(input.py(), "flip_y"))?.extract()?,
|
||||
explode: input.getattr(intern!(input.py(), "explode"))?.extract()?,
|
||||
textures: input.getattr(intern!(input.py(), "textures"))?.extract()?,
|
||||
connections
|
||||
// connections: input.getattr(intern!(input.py(), "connections"))?.extract()?,
|
||||
})
|
||||
connections, // connections: input.getattr(intern!(input.py(), "connections"))?.extract()?,
|
||||
});
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
@ -82,18 +82,23 @@ pub mod types {
|
||||
for key in input.iter() {
|
||||
result.insert(key.0.extract()?, part_data_to_SR1PartData(key.1)?);
|
||||
}
|
||||
return Ok(result)
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[pyfunction]
|
||||
#[allow(unused_variables)]
|
||||
pub fn better_update_parts(render: &PyAny, option: &PyAny, window: &PyAny,
|
||||
parts: &types::PartDatas, sr1_xml_scale: i32) -> PyResult<bool> {
|
||||
if !render.getattr(intern!(render.py(), "rendered"))?.is_true()? {
|
||||
pub fn better_update_parts(
|
||||
render: &PyAny,
|
||||
option: &PyAny,
|
||||
window: &PyAny,
|
||||
parts: &types::PartDatas,
|
||||
sr1_xml_scale: i32,
|
||||
) -> PyResult<bool> {
|
||||
if !render
|
||||
.getattr(intern!(render.py(), "rendered"))?
|
||||
.is_true()?
|
||||
{
|
||||
return Ok(false);
|
||||
}
|
||||
let start_time = time::Instant::now();
|
||||
|
@ -6,12 +6,13 @@
|
||||
* -------------------------------
|
||||
*/
|
||||
|
||||
|
||||
pub mod sr1 {
|
||||
// use super::math::{Shape, Point2D};
|
||||
use crate::sr1_data::part_list::{RawPartList, RawPartType, SR1PartTypeEnum};
|
||||
use crate::sr1_data::part_list::Damage as RawDamage;
|
||||
use crate::sr1_data::part_list::{Tank, Engine, Solar, Rcs, Lander, AttachPoint, AttachPoints, Shape as RawShape};
|
||||
use crate::sr1_data::part_list::{
|
||||
AttachPoint, AttachPoints, Engine, Lander, Rcs, Shape as RawShape, Solar, Tank,
|
||||
};
|
||||
use crate::sr1_data::part_list::{RawPartList, RawPartType, SR1PartTypeEnum};
|
||||
|
||||
#[inline]
|
||||
pub fn map_ptype_textures(ptype: String) -> String {
|
||||
@ -44,7 +45,8 @@ pub mod sr1 {
|
||||
"port-1" => "DockingPort",
|
||||
"lander-1" => "LanderLegPreview",
|
||||
_ => "Pod",
|
||||
}.to_string()
|
||||
}
|
||||
.to_string()
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@ -61,7 +63,7 @@ pub mod sr1 {
|
||||
pub flip_y: bool,
|
||||
pub explode: bool,
|
||||
pub textures: String,
|
||||
pub connections: Option<Vec<((usize, usize), (isize, isize))>>
|
||||
pub connections: Option<Vec<((usize, usize), (isize, isize))>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
@ -88,7 +90,9 @@ pub mod sr1 {
|
||||
consumption: f64,
|
||||
size: f64,
|
||||
},
|
||||
Solar { charge_rate: f64 },
|
||||
Solar {
|
||||
charge_rate: f64,
|
||||
},
|
||||
Lander {
|
||||
max_angle: f64,
|
||||
min_length: f64,
|
||||
@ -96,7 +100,7 @@ pub mod sr1 {
|
||||
angle_speed: f64,
|
||||
length_speed: f64,
|
||||
width: f64,
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
@ -117,7 +121,7 @@ pub mod sr1 {
|
||||
disconnect: self.disconnect,
|
||||
explode: self.explode,
|
||||
explosion_power: Some(self.explosion_power),
|
||||
explosion_size: Some(self.explosion_size)
|
||||
explosion_size: Some(self.explosion_size),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -167,8 +171,7 @@ pub mod sr1 {
|
||||
// 部件碰撞箱
|
||||
pub attach_points: Option<Vec<AttachPoint>>,
|
||||
// 部件连接点
|
||||
pub attr: Option<SR1PartAttr>
|
||||
// 部件特殊属性
|
||||
pub attr: Option<SR1PartAttr>, // 部件特殊属性
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@ -183,7 +186,7 @@ pub mod sr1 {
|
||||
for part_type in &self.types {
|
||||
types.insert(0, part_type.to_raw_part_type());
|
||||
}
|
||||
RawPartList{part_types: types}
|
||||
RawPartList { part_types: types }
|
||||
}
|
||||
}
|
||||
|
||||
@ -202,7 +205,7 @@ pub mod sr1 {
|
||||
let mut types: Vec<SR1PartType> = Vec::new();
|
||||
let name = match name {
|
||||
Some(name) => name,
|
||||
None => "NewPartList".to_string()
|
||||
None => "NewPartList".to_string(),
|
||||
};
|
||||
for part_type in part_types {
|
||||
types.insert(0, part_type);
|
||||
@ -222,42 +225,96 @@ pub mod sr1 {
|
||||
|
||||
fn to_raw_part_type(&self) -> RawPartType {
|
||||
let tank: Option<Tank> = match &self.attr {
|
||||
Some(attr) => {
|
||||
match attr {
|
||||
SR1PartAttr::Tank {fuel, dry_mass, fuel_type} => {
|
||||
Some(Tank {fuel: *fuel, dry_mass: *dry_mass, fuel_type: Some(*fuel_type)})
|
||||
} _ => None } } _ => None };
|
||||
Some(attr) => match attr {
|
||||
SR1PartAttr::Tank {
|
||||
fuel,
|
||||
dry_mass,
|
||||
fuel_type,
|
||||
} => Some(Tank {
|
||||
fuel: *fuel,
|
||||
dry_mass: *dry_mass,
|
||||
fuel_type: Some(*fuel_type),
|
||||
}),
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
};
|
||||
let engine: Option<Engine> = match &self.attr {
|
||||
Some(attr) => {
|
||||
match attr {
|
||||
SR1PartAttr::Engine {power, consumption, size, turn, fuel_type, throttle_exponential } => {
|
||||
Some(Engine {power: *power, consumption: *consumption, throttle_exponential: Some(*throttle_exponential),
|
||||
size: *size, turn: *turn, fuel_type: Some(*fuel_type)})
|
||||
} _ => None } } _ => None };
|
||||
Some(attr) => match attr {
|
||||
SR1PartAttr::Engine {
|
||||
power,
|
||||
consumption,
|
||||
size,
|
||||
turn,
|
||||
fuel_type,
|
||||
throttle_exponential,
|
||||
} => Some(Engine {
|
||||
power: *power,
|
||||
consumption: *consumption,
|
||||
throttle_exponential: Some(*throttle_exponential),
|
||||
size: *size,
|
||||
turn: *turn,
|
||||
fuel_type: Some(*fuel_type),
|
||||
}),
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
};
|
||||
let rcs: Option<Rcs> = match &self.attr {
|
||||
Some(attr) => {
|
||||
match attr {
|
||||
SR1PartAttr::Rcs {power, consumption, size } => {
|
||||
Some(Rcs {power: *power, consumption: *consumption, size: *size })
|
||||
} _ => None } } _ => None };
|
||||
Some(attr) => match attr {
|
||||
SR1PartAttr::Rcs {
|
||||
power,
|
||||
consumption,
|
||||
size,
|
||||
} => Some(Rcs {
|
||||
power: *power,
|
||||
consumption: *consumption,
|
||||
size: *size,
|
||||
}),
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
};
|
||||
let solar: Option<Solar> = match &self.attr {
|
||||
Some(attr) => {
|
||||
match attr {
|
||||
SR1PartAttr::Solar {charge_rate } => {
|
||||
Some(Solar {charge_rate: *charge_rate })
|
||||
} _ => None } } _ => None };
|
||||
Some(attr) => match attr {
|
||||
SR1PartAttr::Solar { charge_rate } => Some(Solar {
|
||||
charge_rate: *charge_rate,
|
||||
}),
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
};
|
||||
let lander: Option<Lander> = match &self.attr {
|
||||
Some(attr) => {
|
||||
match attr {
|
||||
SR1PartAttr::Lander {max_angle, min_length, max_length, angle_speed, length_speed, width } => {
|
||||
Some(Lander {max_angle: *max_angle, min_length: *min_length, max_length: *max_length,
|
||||
angle_speed: Some(*angle_speed), length_speed: Some(*length_speed), width: *width })
|
||||
} _ => None } } _ => None };
|
||||
Some(attr) => match attr {
|
||||
SR1PartAttr::Lander {
|
||||
max_angle,
|
||||
min_length,
|
||||
max_length,
|
||||
angle_speed,
|
||||
length_speed,
|
||||
width,
|
||||
} => Some(Lander {
|
||||
max_angle: *max_angle,
|
||||
min_length: *min_length,
|
||||
max_length: *max_length,
|
||||
angle_speed: Some(*angle_speed),
|
||||
length_speed: Some(*length_speed),
|
||||
width: *width,
|
||||
}),
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
};
|
||||
let attach_point: Option<AttachPoints> = match &self.attach_points {
|
||||
Some(attach_points) => {
|
||||
if attach_points.len() > 0 {
|
||||
Some(AttachPoints::new(attach_points.clone()))
|
||||
} else { None } } _ => None };
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
RawPartType {
|
||||
id: self.id.clone(),
|
||||
name: self.name.clone(),
|
||||
@ -288,7 +345,6 @@ pub mod sr1 {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
@ -305,7 +361,7 @@ pub mod math {
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct Point2D {
|
||||
pub x: f64,
|
||||
pub y: f64
|
||||
pub y: f64,
|
||||
}
|
||||
|
||||
impl Point2D {
|
||||
@ -314,7 +370,9 @@ pub mod math {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn new_00() -> Self { Point2D { x: 0.0, y: 0.0 } }
|
||||
pub fn new_00() -> Self {
|
||||
Point2D { x: 0.0, y: 0.0 }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn distance(&self, other: &Point2D) -> f64 {
|
||||
@ -341,11 +399,10 @@ pub mod math {
|
||||
let cos = radius.cos();
|
||||
let x = self.x * cos - self.y * sin;
|
||||
let y = self.x * sin + self.y * cos;
|
||||
Point2D{ x, y }
|
||||
Point2D { x, y }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct CircularArc {
|
||||
pub r: f64,
|
||||
@ -376,7 +433,10 @@ pub mod math {
|
||||
}
|
||||
|
||||
fn rotate_radius(&self, radius: f64) -> Self {
|
||||
OneTimeLine::point_new(&self.start.rotate_radius(radius), &self.end.rotate_radius(radius))
|
||||
OneTimeLine::point_new(
|
||||
&self.start.rotate_radius(radius),
|
||||
&self.end.rotate_radius(radius),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -399,37 +459,58 @@ pub mod math {
|
||||
let x = x.unwrap_or(0.0);
|
||||
let y = y.unwrap_or(0.0);
|
||||
let angle = angle.unwrap_or(0.0);
|
||||
Shape { pos: Point2D::new(x, y), angle, bounds }
|
||||
Shape {
|
||||
pos: Point2D::new(x, y),
|
||||
angle,
|
||||
bounds,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_width_height(width: f64, height: f64, angle: Option<f64>) -> Self {
|
||||
let d_width = width / 2.0;
|
||||
let d_height = height / 2.0;
|
||||
let mut edges: Vec<Edge> = vec![
|
||||
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)}
|
||||
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 {
|
||||
edges = edges.iter().map(|edge| {
|
||||
match edge {
|
||||
edges = edges
|
||||
.iter()
|
||||
.map(|edge| match edge {
|
||||
Edge::OneTimeLine(line) => {
|
||||
let start = line.start.rotate(angle);
|
||||
let end = line.end.rotate(angle);
|
||||
Edge::OneTimeLine(OneTimeLine::point_new(&start, &end))
|
||||
},
|
||||
}
|
||||
Edge::CircularArc(arc) => {
|
||||
let pos = arc.pos.rotate(angle);
|
||||
Edge::CircularArc(CircularArc{ r: arc.r, pos, start_angle: arc.start_angle, end_angle: arc.end_angle })
|
||||
Edge::CircularArc(CircularArc {
|
||||
r: arc.r,
|
||||
pos,
|
||||
start_angle: arc.start_angle,
|
||||
end_angle: arc.end_angle,
|
||||
})
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
}
|
||||
Shape {
|
||||
pos: Point2D::new_00(),
|
||||
angle: 0.0,
|
||||
bounds: edges,
|
||||
}
|
||||
}
|
||||
}).collect();
|
||||
}
|
||||
Shape { pos: Point2D::new_00(), angle: 0.0, bounds: edges}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl OneTimeLine {
|
||||
#[inline]
|
||||
@ -453,23 +534,23 @@ pub mod math {
|
||||
(Some(k), None) => {
|
||||
k_ = k;
|
||||
b_ = point.y - (k * point.x)
|
||||
},
|
||||
}
|
||||
(None, Some(b)) => {
|
||||
b_ = b;
|
||||
k_ = (point.y - b) / point.x;
|
||||
},
|
||||
}
|
||||
(Some(k), Some(b)) => {
|
||||
k_ = k;
|
||||
b_ = b;
|
||||
},
|
||||
}
|
||||
_ => {
|
||||
k_ = point.y / point.x;
|
||||
b_ = 0.0;
|
||||
}
|
||||
}
|
||||
OneTimeLine{
|
||||
OneTimeLine {
|
||||
start: *point,
|
||||
end: Point2D::new(0.0, b_)
|
||||
end: Point2D::new(0.0, b_),
|
||||
}
|
||||
}
|
||||
|
||||
@ -494,10 +575,8 @@ pub mod dr {
|
||||
pub c_type: ConnectType,
|
||||
pub d_pos: f64,
|
||||
pub angel: f64,
|
||||
|
||||
}
|
||||
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum PartType {
|
||||
Pod,
|
||||
@ -513,7 +592,7 @@ pub mod dr {
|
||||
Battery,
|
||||
Dock,
|
||||
Port,
|
||||
Lander
|
||||
Lander,
|
||||
}
|
||||
|
||||
pub struct DRPartData {
|
||||
@ -528,7 +607,7 @@ pub mod dr {
|
||||
pub angle_v: f64,
|
||||
pub flip_x: bool,
|
||||
pub flip_y: bool,
|
||||
pub connections: Option<Vec<usize>>
|
||||
pub connections: Option<Vec<usize>>,
|
||||
}
|
||||
|
||||
impl DRPartData {
|
||||
|
Loading…
Reference in New Issue
Block a user