update after long time

This commit is contained in:
shenjack 2024-06-19 00:58:30 +08:00
parent cdfc552c4f
commit 4f94a2c8e0
Signed by: shenjack
GPG Key ID: 7B1134A979775551
8 changed files with 105 additions and 13 deletions

View File

@ -135,7 +135,7 @@ checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80"
[[package]]
name = "difficult_rocket_rs"
version = "0.4.0"
version = "0.4.1"
dependencies = [
"anyhow",
"nalgebra",
@ -454,9 +454,9 @@ dependencies = [
[[package]]
name = "quick-xml"
version = "0.31.0"
version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1004a344b30a54e2ee58d66a71b32d2db2feb0a31f9a2d302bf0536f15de2a33"
checksum = "1d3a6e5838b60e0e8fa7a43f22ade549a37d61f8bdbe636d0d7816191de969c2"
dependencies = [
"memchr",
"serde",
@ -473,9 +473,9 @@ dependencies = [
[[package]]
name = "rapier2d-f64"
version = "0.19.0"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7445a5148251f0e1d31e5bd798b8d5aed07984beb44a89ad0af13e99a7804748"
checksum = "569c367a5f266a20e4253d798d3b9115d07c7c085b7be3258de104af3557f38f"
dependencies = [
"approx",
"arrayvec",
@ -491,6 +491,7 @@ dependencies = [
"parry2d-f64",
"rustc-hash",
"simba",
"thiserror",
"vec_map",
]
@ -624,6 +625,26 @@ version = "0.12.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1fc403891a21bcfb7c37834ba66a547a8f402146eba7265b5a6d88059c9ff2f"
[[package]]
name = "thiserror"
version = "1.0.61"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.61"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.66",
]
[[package]]
name = "typenum"
version = "1.17.0"

View File

@ -1,6 +1,6 @@
[package]
name = "difficult_rocket_rs"
version = "0.4.0"
version = "0.4.1"
edition = "2021"
license-file = '../../LICENSE'
authors = ["shenjackyuanjie <3695888@qq.com>"]
@ -24,10 +24,10 @@ opt-level = 2
[dependencies]
anyhow = "1.0"
quick-xml = { version = "0.31.0", features = ["serialize"] }
quick-xml = { version = "0.32.0", features = ["serialize"] }
serde = { version = "1.0", features = ["derive"] }
nalgebra = "0.32.5"
pyo3 = { version = "0.21.2", features = ["extension-module", "macros"] }
rapier2d-f64 = { version = "0.19.0", features = ["simd-stable"] }
rapier2d-f64 = { version = "0.20.0", features = ["simd-stable"] }
# 虽然但是, raiper在这里!

View File

@ -26,6 +26,7 @@ fn module_init(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(sr1_parse::part_list::read_part_list_py, m)?)?;
m.add_function(wrap_pyfunction!(sr1_parse::ship::py_raw_ship_from_file, m)?)?;
m.add_function(wrap_pyfunction!(python::data::load_and_save_test, m)?)?;
m.add_function(wrap_pyfunction!(sr1_parse::ship::py_assert_ship, m)?)?;
m.add_class::<python::data::PySR1Ship>()?;
m.add_class::<python::data::PySR1PartList>()?;
m.add_class::<python::data::PySR1PartType>()?;

View File

@ -365,10 +365,67 @@ pub fn py_raw_ship_from_file(path: String) -> PyResult<bool> {
match raw_ship {
Ok(ship) => {
println!("{:?}", ship);
Ok(true)
}
Err(e) => {
println!("{:?}", e);
Ok(false)
}
}
Ok(true)
}
use quick_xml::events::Event;
use quick_xml::reader::Reader;
#[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);
// 读取第一个
match reader.read_event() {
Ok(Event::Start(e)) => {
if e.name().as_ref() == b"Ship" {
// 再验证一下 version, liftedOff, touchingGround
let mut founds = (false, false, false);
let _ = e.attributes().map(|attr| match attr {
Ok(attr) => match attr.value.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;
}
}
}
x => {
println!("ERROR while using xml to parse the file!\n{:?}\n----------", x);
return false;
},
}
true
}

View File

@ -16,7 +16,7 @@ from Difficult_Rocket.api.types import Options, Version
from lib_not_dr import loggers
DR_rust_version = Version("0.4.0") # DR_mod 的 Rust 编写部分的兼容版本
DR_rust_version = Version("0.4.1") # DR_mod 的 Rust 编写部分的兼容版本
logger = loggers.config.get_logger_from_old("client.dr_game", "client")

View File

@ -9,4 +9,5 @@ xml.load_time = "XML file loading has used: {} second"
ship.load = "Loading ship: {}"
ship.load_time = "Ship loading has used: {} second"
ship.info = "Ship info:\n- Parts: {}\n- Weight: {}"
ship.render.done = "Ship render done"
ship.render.done = "Ship render done"
folder.invalid = "Invalid folder: {}"

View File

@ -11,3 +11,4 @@ ship.load_time = "飞船加载消耗时间: {} 秒"
ship.info = "飞船信息:\n- 部件数量: {}\n- 部件重量: {}"
ship.render.done = "飞船渲染完成"
save.start = "正在保存飞船: {}"
folder.invaild = "无效的文件夹: {}"

View File

@ -19,6 +19,7 @@ from pyglet.text import Label
from pyglet.sprite import Sprite
from pyglet.graphics import Batch, Group
from pyglet.shapes import Line, Box
# from pyglet.window import mouse
from . import DR_mod_runtime
@ -31,7 +32,7 @@ from Difficult_Rocket.client import ClientWindow
from Difficult_Rocket.api.types import Fonts, Options
from Difficult_Rocket.command.line import CommandText
from Difficult_Rocket.client.screen import BaseScreen
from Difficult_Rocket.api.camera import CenterGroupCamera
from Difficult_Rocket.api.camera import CenterGroupCamera, GroupCamera
from Difficult_Rocket.gui.widget.button import (
PressTextButton,
@ -88,9 +89,19 @@ class SR1ShipSelecter(BaseScreen):
def __init__(self, main_window: ClientWindow):
super().__init__(main_window)
self.main_batch = Batch()
self.main_group = Group()
self.main_group = GroupCamera(window=main_window)
self.folder_path: Path = Path("ships")
def set_folder(self, path: Path):
if not path.is_dir():
logger.warn(sr_tr().sr1.ship.folder.invalid().format(path), tag="ship explorer")
return
for file in path.iterdir():
if not file.is_file:
continue
# 尝试加载一下
class SR1ShipEditor(BaseScreen):