Compare commits

..

No commits in common. "b483e4a12bd7571536876eef1bc7b900547006f3" and "1f44748750c8732fd19df0651425e171a75d9e6c" have entirely different histories.

16 changed files with 146 additions and 1667 deletions

@ -1 +1 @@
Subproject commit 4da7e7457051870cfd4c539dfa7c0352db9aaa1c Subproject commit 0ff06e9edc2f5b5f0c9ba15d5979894447add897

View File

@ -52,11 +52,6 @@ if TYPE_CHECKING:
""" """
... ...
def render_hack() -> None:
"""
进行一些 rust 方面的 渲染接管
"""
class SR1PartType_rs: # NOQA class SR1PartType_rs: # NOQA
""" """
用于从 rust 中读取 SR1PartType 用于从 rust 中读取 SR1PartType

File diff suppressed because it is too large Load Diff

View File

@ -24,18 +24,15 @@ opt-level = 2
[dependencies] [dependencies]
anyhow = "1.0" anyhow = "1.0"
quick-xml = { version = "0.37", features = ["serialize"] } quick-xml = { version = "0.36.1", features = ["serialize"] }
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
nalgebra = "0.33" nalgebra = "0.33"
pyo3 = { version = "0.22", features = [ pyo3 = { version = "0.22.2", features = [
"extension-module", "extension-module",
"macros", "macros",
"py-clone", "py-clone",
] } ] }
# 让我们来试试黑魔法 rapier2d-f64 = { version = "0.22.0", features = ["simd-stable"] }
winit = "0.30.5"
rapier2d-f64 = { version = "0.22", features = ["simd-stable"] }
# 虽然但是, raiper在这里! # 虽然但是, raiper在这里!

View File

@ -8,13 +8,12 @@
mod dr_physics; mod dr_physics;
mod python; mod python;
/// 也许是一些渲染的东西
mod renders;
/// sr1 的逆天数据结构解析
mod sr1_parse; mod sr1_parse;
use pyo3::prelude::*; use pyo3::prelude::*;
pub type IdType = i64;
#[pyfunction] #[pyfunction]
fn get_version_str() -> String { fn get_version_str() -> String {
env!("CARGO_PKG_VERSION").to_string() env!("CARGO_PKG_VERSION").to_string()
@ -24,11 +23,10 @@ fn get_version_str() -> String {
#[pyo3(name = "Difficult_Rocket_rs")] #[pyo3(name = "Difficult_Rocket_rs")]
fn module_init(m: &Bound<'_, PyModule>) -> PyResult<()> { fn module_init(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(get_version_str, m)?)?; m.add_function(wrap_pyfunction!(get_version_str, m)?)?;
m.add_function(wrap_pyfunction!(sr1_parse::py::read_part_list_py, m)?)?; m.add_function(wrap_pyfunction!(sr1_parse::part_list::read_part_list_py, m)?)?;
m.add_function(wrap_pyfunction!(sr1_parse::py::py_raw_ship_from_file, m)?)?; m.add_function(wrap_pyfunction!(sr1_parse::ship::py_raw_ship_from_file, m)?)?;
m.add_function(wrap_pyfunction!(sr1_parse::py::py_assert_ship, m)?)?;
m.add_function(wrap_pyfunction!(python::data::load_and_save_test, m)?)?; m.add_function(wrap_pyfunction!(python::data::load_and_save_test, m)?)?;
m.add_function(wrap_pyfunction!(renders::render_hack, m)?)?; m.add_function(wrap_pyfunction!(sr1_parse::ship::py_assert_ship, m)?)?;
m.add_class::<python::data::PySR1Ship>()?; m.add_class::<python::data::PySR1Ship>()?;
m.add_class::<python::data::PySR1PartList>()?; m.add_class::<python::data::PySR1PartList>()?;
m.add_class::<python::data::PySR1PartType>()?; m.add_class::<python::data::PySR1PartType>()?;

View File

@ -1,4 +1,4 @@
use std::io::Write; use std::io::{self, Write};
use pyo3::prelude::*; use pyo3::prelude::*;
@ -24,7 +24,7 @@ impl PyConsole {
let (stop_sender, stop_receiver) = std::sync::mpsc::channel(); let (stop_sender, stop_receiver) = std::sync::mpsc::channel();
let (keyboard_input_sender, keyboard_input_receiver) = std::sync::mpsc::channel(); let (keyboard_input_sender, keyboard_input_receiver) = std::sync::mpsc::channel();
std::thread::spawn(move || { std::thread::spawn(move || {
let std_in = std::io::stdin(); let std_in = io::stdin();
loop { loop {
if let Ok(()) = stop_receiver.try_recv() { if let Ok(()) = stop_receiver.try_recv() {
break; break;
@ -39,7 +39,7 @@ impl PyConsole {
} }
}); });
print!("rs>"); print!("rs>");
std::io::stdout().flush().unwrap(); io::stdout().flush().unwrap();
self.stop_sender = Some(stop_sender); self.stop_sender = Some(stop_sender);
self.keyboard_input_receiver = Some(keyboard_input_receiver); self.keyboard_input_receiver = Some(keyboard_input_receiver);
} }
@ -54,7 +54,7 @@ impl PyConsole {
fn new_command(&self) -> bool { fn new_command(&self) -> bool {
print!("rs>"); print!("rs>");
std::io::stdout().flush().unwrap(); io::stdout().flush().unwrap();
true true
} }

View File

@ -6,10 +6,10 @@ use pyo3::prelude::*;
use crate::dr_physics::math::{Point2D, Rotate}; use crate::dr_physics::math::{Point2D, Rotate};
use crate::sr1_parse::part_list::RawPartList; use crate::sr1_parse::part_list::RawPartList;
use crate::sr1_parse::ship::{Connection, RawConnectionData, RawShip}; use crate::sr1_parse::ship::{Connection, RawConnectionData, RawShip};
use crate::sr1_parse::IdType;
use crate::sr1_parse::SaveStatus; use crate::sr1_parse::SaveStatus;
use crate::sr1_parse::{get_max_box, SR1PartData, SR1PartListTrait}; use crate::sr1_parse::{get_max_box, SR1PartData, SR1PartListTrait};
use crate::sr1_parse::{SR1PartList, SR1PartType, SR1Ship}; use crate::sr1_parse::{SR1PartList, SR1PartType, SR1Ship};
use crate::IdType;
use quick_xml::se::to_string; use quick_xml::se::to_string;

View File

@ -6,7 +6,7 @@
* ------------------------------- * -------------------------------
*/ */
use crate::sr1_parse::IdType; use crate::IdType;
use nalgebra::{Matrix2, Vector2}; use nalgebra::{Matrix2, Vector2};
use pyo3::prelude::*; use pyo3::prelude::*;

View File

@ -1,38 +0,0 @@
use pyo3::pyfunction;
use winit::{application::ApplicationHandler, event_loop::EventLoop, window::Window};
#[pyfunction]
pub fn render_hack() {
println!("render_hacking_start");
render_main();
println!("render_hacking_end");
}
#[derive(Default)]
struct App {
window: Option<Window>,
}
impl ApplicationHandler for App {
fn resumed(&mut self, event_loop: &winit::event_loop::ActiveEventLoop) {
// 这里需要获取现有的窗口, 毕竟是运行在一个已有窗口的 Python 程序里
// self.window = Some(event_loop.ge)
}
fn window_event(
&mut self,
event_loop: &winit::event_loop::ActiveEventLoop,
window_id: winit::window::WindowId,
event: winit::event::WindowEvent,
) {
}
}
fn render_main() -> anyhow::Result<()> {
let event_loop = EventLoop::new()?;
let mut app = App::default();
event_loop.run_app(&mut app);
Ok(())
}

View File

@ -1,9 +1,6 @@
pub mod part_list; mod data_structure;
/// 所有的 Python 相关交互都应该在这里
pub mod py;
pub mod ship;
pub type IdType = i64; pub use self::data_structure::*;
use crate::dr_physics::math::{Edge, Shape}; use crate::dr_physics::math::{Edge, Shape};
use crate::dr_physics::math::{Point2D, Rotate}; use crate::dr_physics::math::{Point2D, Rotate};
@ -15,6 +12,7 @@ use crate::sr1_parse::ship::{
Staging as RawStaging, Step as RawStep, Tank as RawTank, Staging as RawStaging, Step as RawStep, Tank as RawTank,
}; };
use crate::sr1_parse::ship::{Connections as RawConnections, DisconnectedParts, Parts as RawParts}; use crate::sr1_parse::ship::{Connections as RawConnections, DisconnectedParts, Parts as RawParts};
use crate::IdType;
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use std::collections::HashMap; use std::collections::HashMap;

View File

@ -0,0 +1,10 @@
/*
* -------------------------------
* Difficult Rocket
* Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com
* All rights reserved
* -------------------------------
*/
pub mod part_list;
pub mod ship;

View File

@ -2,6 +2,7 @@ use crate::sr1_parse::{SR1PartList, SR1PartType, SR1PartTypeAttr};
use crate::sr1_parse::{SR1PartListTrait, SR1PartTypeData}; use crate::sr1_parse::{SR1PartListTrait, SR1PartTypeData};
use anyhow::Result; use anyhow::Result;
use pyo3::prelude::*;
use quick_xml::de::from_str; use quick_xml::de::from_str;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -406,3 +407,17 @@ impl SR1PartListTrait for RawPartList {
self.clone() self.clone()
} }
} }
#[pyfunction]
#[pyo3(name = "part_list_read_test", signature = (file_name = "./assets/builtin/PartList.xml".to_string()))]
pub fn read_part_list_py(_py: Python, file_name: Option<String>) -> PyResult<()> {
let file_name = file_name.unwrap_or("./assets/builtin/PartList.xml".to_string());
// let _parts = RawPartList::from_file(file_name);
// if let Some(parts) = _parts {
// // println!("{:?}", parts)
// parts.list_print();
// let _part_list = parts.to_sr_part_list(Some("Vanilla".to_string()));
// }
println!("{:?}", RawPartList::from_file(file_name));
Ok(())
}

View File

@ -1,7 +1,9 @@
use crate::sr1_parse::IdType;
use crate::sr1_parse::{SR1PartData, SR1PartDataAttr, SR1Ship}; use crate::sr1_parse::{SR1PartData, SR1PartDataAttr, SR1Ship};
use crate::sr1_parse::{SR1PartDataTrait, SR1ShipTrait}; use crate::sr1_parse::{SR1PartDataTrait, SR1ShipTrait};
use crate::IdType;
use anyhow::Result;
use pyo3::prelude::*;
use quick_xml::de::from_str; use quick_xml::de::from_str;
use quick_xml::events::Event; use quick_xml::events::Event;
use quick_xml::reader::Reader; use quick_xml::reader::Reader;
@ -342,10 +344,87 @@ impl RawShip {
} }
#[allow(unused)] #[allow(unused)]
pub fn save(&self, file_name: String) -> anyhow::Result<()> { pub fn save(&self, file_name: String) -> Result<()> {
let part_list_file = to_string(self)?; let part_list_file = to_string(self)?;
print!("{:?}", part_list_file); print!("{:?}", part_list_file);
std::fs::write(file_name, part_list_file)?; std::fs::write(file_name, part_list_file)?;
Ok(()) Ok(())
} }
} }
#[pyfunction]
#[pyo3(name = "read_ship_test")]
#[pyo3(signature = (path = "./assets/builtin/dock1.xml".to_string()))]
pub fn py_raw_ship_from_file(path: String) -> PyResult<bool> {
let file = std::fs::read_to_string(path)?;
let raw_ship = from_str::<RawShip>(&file);
match raw_ship {
Ok(ship) => {
println!("{:?}", ship);
Ok(true)
}
Err(e) => {
println!("{:?}", e);
Ok(false)
}
}
}
#[pyfunction]
#[pyo3(name = "assert_ship")]
/// 校验这玩意是不是个船
pub fn py_assert_ship(path: String) -> bool {
let file_data = match std::fs::read_to_string(path) {
Ok(data) => data,
Err(e) => {
println!("ERROR while reading file!\n{}\n----------", e);
return false;
}
};
let mut reader = Reader::from_str(&file_data);
// 读取第一个
loop {
match reader.read_event() {
Ok(Event::Start(e)) => {
if e.name().as_ref() == b"Ship" {
// 再验证一下 version, liftedOff, touchingGround
let mut founds = (false, false, false);
for attr in e.attributes().flatten() {
match attr.key.as_ref() {
b"version" => {
founds.0 = true;
}
b"liftedOff" => {
founds.1 = true;
}
b"touchingGround" => {
founds.2 = true;
}
_ => (),
}
}
if !(founds.0 && founds.1 && founds.2) {
println!(
"warning: {}{}{} not found",
if founds.0 { "" } else { "version " },
if founds.1 { "" } else { "liftedOff " },
if founds.2 { "" } else { "touchingGround " }
);
return false;
} else {
return true;
}
}
}
Ok(Event::Eof) => {
println!("EOF");
return false;
}
Err(e) => {
println!("ERROR while using xml to parse the file!\n{:?}\n----------", e);
return false;
}
_ => (),
}
}
}

View File

@ -1,96 +0,0 @@
use pyo3::{pyfunction, PyResult, Python};
use quick_xml::{de::from_str, events::Event, Reader};
use super::part_list::RawPartList;
use super::ship::RawShip;
#[pyfunction]
#[pyo3(name = "part_list_read_test", signature = (file_name = "./assets/builtin/PartList.xml".to_string()))]
pub fn read_part_list_py(_py: Python, file_name: Option<String>) -> PyResult<()> {
let file_name = file_name.unwrap_or("./assets/builtin/PartList.xml".to_string());
// let _parts = RawPartList::from_file(file_name);
// if let Some(parts) = _parts {
// // println!("{:?}", parts)
// parts.list_print();
// let _part_list = parts.to_sr_part_list(Some("Vanilla".to_string()));
// }
println!("{:?}", RawPartList::from_file(file_name));
Ok(())
}
#[pyfunction]
#[pyo3(name = "read_ship_test")]
#[pyo3(signature = (path = "./assets/builtin/dock1.xml".to_string()))]
pub fn py_raw_ship_from_file(path: String) -> PyResult<bool> {
let file = std::fs::read_to_string(path)?;
let raw_ship = from_str::<RawShip>(&file);
match raw_ship {
Ok(ship) => {
println!("{:?}", ship);
Ok(true)
}
Err(e) => {
println!("{:?}", e);
Ok(false)
}
}
}
#[pyfunction]
#[pyo3(name = "assert_ship")]
/// 校验这玩意是不是个船
pub fn py_assert_ship(path: String) -> bool {
let file_data = match std::fs::read_to_string(path) {
Ok(data) => data,
Err(e) => {
println!("ERROR while reading file!\n{}\n----------", e);
return false;
}
};
let mut reader = Reader::from_str(&file_data);
// 读取第一个
loop {
match reader.read_event() {
Ok(Event::Start(e)) => {
if e.name().as_ref() == b"Ship" {
// 再验证一下 version, liftedOff, touchingGround
let mut founds = (false, false, false);
for attr in e.attributes().flatten() {
match attr.key.as_ref() {
b"version" => {
founds.0 = true;
}
b"liftedOff" => {
founds.1 = true;
}
b"touchingGround" => {
founds.2 = true;
}
_ => (),
}
}
if !(founds.0 && founds.1 && founds.2) {
println!(
"warning: {}{}{} not found",
if founds.0 { "" } else { "version " },
if founds.1 { "" } else { "liftedOff " },
if founds.2 { "" } else { "touchingGround " }
);
return false;
} else {
return true;
}
}
}
Ok(Event::Eof) => {
println!("EOF");
return false;
}
Err(e) => {
println!("ERROR while using xml to parse the file!\n{:?}\n----------", e);
return false;
}
_ => (),
}
}
}

View File

@ -16,7 +16,6 @@ from lib_not_dr import loggers
# from pyglet.text import Label # from pyglet.text import Label
# from . import DR_mod_runtime # from . import DR_mod_runtime
from .render import render_hack_init
logger = loggers.config.get_logger_from_old("client.dr_game_menu", "client") logger = loggers.config.get_logger_from_old("client.dr_game_menu", "client")
@ -51,18 +50,6 @@ class Menu(BaseScreen):
group=self.main_group, group=self.main_group,
) )
self.magic_rust_test_button = OreuiButton(
x=100,
y=150,
width=150,
height=30,
text="一些魔法 rust 测试",
toggle_mode=False,
auto_release=True,
batch=self.main_batch,
group=self.main_group,
)
def on_release(x, y): def on_release(x, y):
from .sr1_ship import SR1ShipEditor, SR1ShipSelecter from .sr1_ship import SR1ShipEditor, SR1ShipSelecter
@ -73,9 +60,7 @@ class Menu(BaseScreen):
logger.info("added SR1_ship screen", tag="dr_game") logger.info("added SR1_ship screen", tag="dr_game")
self.enter_ship_editor_button.set_handler("on_release", on_release) self.enter_ship_editor_button.set_handler("on_release", on_release)
self.magic_rust_test_button.set_handler("on_release", render_hack_init)
main_window.push_handlers(self.enter_ship_editor_button) main_window.push_handlers(self.enter_ship_editor_button)
main_window.push_handlers(self.magic_rust_test_button)
def on_draw(self, window: ClientWindow): def on_draw(self, window: ClientWindow):
self.main_batch.draw() self.main_batch.draw()

View File

@ -1,9 +0,0 @@
"""
温馨提示: 这里都是用来让 rust 接管的, 所以不用想别的了
"""
from .Difficult_Rocket_rs import render_hack
def render_hack_init(x, y):
render_hack()