Compare commits
3 Commits
9bbece1da4
...
f5abf92cff
Author | SHA1 | Date | |
---|---|---|---|
f5abf92cff | |||
c945f33074 | |||
82edb560ba |
@ -1 +1 @@
|
||||
Subproject commit ea875640db0e529769fcfe597faa3c3267c2b1e3
|
||||
Subproject commit 55b02b16d01bd0cafa5b0db3cd2e574299db9d34
|
@ -9,6 +9,9 @@ from .lib import * # noqa: F403
|
||||
from typing import TYPE_CHECKING, Dict, Tuple, Optional, List
|
||||
|
||||
if TYPE_CHECKING:
|
||||
IdType = int
|
||||
RawConnectionData = Tuple[int, int, IdType, IdType]
|
||||
|
||||
def get_version_str() -> str:
|
||||
"""
|
||||
获取版本号
|
||||
@ -163,6 +166,42 @@ if TYPE_CHECKING:
|
||||
def __init__(self, save_default: Optional[bool] = False) -> None:
|
||||
...
|
||||
|
||||
class SR1Connection_rs: # NOQA
|
||||
"""用于存储一堆连接的信息
|
||||
同时提供了一些好用的 API
|
||||
至少总比你在那里吭哧吭哧在 Python 里搜快
|
||||
pub datas: Vec<Connection>"""
|
||||
|
||||
def search_connection_by_parent(
|
||||
self, parent_id: IdType
|
||||
) -> List[RawConnectionData]:
|
||||
"""通过父节点搜索连接"""
|
||||
...
|
||||
|
||||
def search_connection_by_child(self, child_id: IdType) -> List[RawConnectionData]:
|
||||
"""通过子节点搜索连接"""
|
||||
...
|
||||
|
||||
def search_connection_by_id(self, any_id: IdType) -> List[RawConnectionData]:
|
||||
"""通过父子中任意一个 id 搜索连接"""
|
||||
...
|
||||
|
||||
def search_by_both_id(
|
||||
self, parent_id: IdType, child_id: IdType
|
||||
) -> List[RawConnectionData]:
|
||||
"""通过父子双方 id 获取连接
|
||||
|
||||
保险起见, 我还是返回一个 Vec
|
||||
|
||||
万一真有 双/多 连接呢"""
|
||||
...
|
||||
|
||||
def get_raw_data(self) -> List[RawConnectionData]:
|
||||
"""获取原始数据
|
||||
|
||||
万一你确实需要吭哧吭哧去处理原始数据呢"""
|
||||
...
|
||||
|
||||
class SR1Ship_rs: # NOQA
|
||||
"""用于高效且省内存的读取 SR1Ship"""
|
||||
|
||||
@ -206,11 +245,6 @@ if TYPE_CHECKING:
|
||||
"""-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]]]:
|
||||
@ -229,6 +263,16 @@ if TYPE_CHECKING:
|
||||
) -> None:
|
||||
...
|
||||
|
||||
def connections(self) -> SR1Connection_rs:
|
||||
"""获取所有连接"""
|
||||
...
|
||||
|
||||
def disconnected_parts(
|
||||
self
|
||||
) -> List[Tuple[List[Tuple[SR1PartType_rs, SR1PartData_rs]], SR1Connection_rs]]:
|
||||
"""获取所有未连接的零件"""
|
||||
...
|
||||
|
||||
class Console_rs: # NOQA
|
||||
def __init__(self) -> None:
|
||||
...
|
||||
|
2
mods/dr_game/Difficult_Rocket_rs/src/Cargo.lock
generated
2
mods/dr_game/Difficult_Rocket_rs/src/Cargo.lock
generated
@ -146,7 +146,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "difficult_rocket_rs"
|
||||
version = "0.3.3"
|
||||
version = "0.3.4"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"dict_derive",
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "difficult_rocket_rs"
|
||||
version = "0.3.3"
|
||||
version = "0.3.4"
|
||||
edition = "2021"
|
||||
license-file = '../../LICENSE'
|
||||
authors = ["shenjackyuanjie <3695888@qq.com>"]
|
||||
|
@ -31,6 +31,7 @@ fn module_init(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
|
||||
m.add_class::<python::data::PySR1PartType>()?;
|
||||
m.add_class::<python::data::PySR1PartData>()?;
|
||||
m.add_class::<python::data::PySaveStatus>()?;
|
||||
m.add_class::<python::data::PySR1Connections>()?;
|
||||
m.add_class::<python::console::PyConsole>()?;
|
||||
// m.add_class::<python::editor::EditorArea>()?;
|
||||
Ok(())
|
||||
|
@ -5,7 +5,7 @@ use pyo3::prelude::*;
|
||||
|
||||
use crate::dr_physics::math::{Point2D, Rotate};
|
||||
use crate::sr1_parse::part_list::RawPartList;
|
||||
use crate::sr1_parse::ship::RawShip;
|
||||
use crate::sr1_parse::ship::{Connection, Connections, RawConnectionData, RawShip};
|
||||
use crate::sr1_parse::SaveStatus;
|
||||
use crate::sr1_parse::{get_max_box, SR1PartData, SR1PartListTrait};
|
||||
use crate::sr1_parse::{SR1PartList, SR1PartType, SR1Ship};
|
||||
@ -207,41 +207,47 @@ impl PySR1PartData {
|
||||
}
|
||||
|
||||
#[pyclass]
|
||||
#[derive(Clone, Debug)]
|
||||
#[pyo3(name = "SR1PartTypeArrayIterator_rs")]
|
||||
pub struct PySR1PartDataIterator {
|
||||
pub datas: Vec<(PySR1PartType, PySR1PartData)>,
|
||||
pub index: usize,
|
||||
#[derive(Debug, Clone)]
|
||||
#[pyo3(name = "SR1Connection_rs")]
|
||||
pub struct PySR1Connections {
|
||||
pub datas: Vec<Connection>,
|
||||
}
|
||||
|
||||
#[pymethods]
|
||||
impl PySR1PartDataIterator {
|
||||
fn __next__(mut slf: PyRefMut<'_, Self>) -> Option<(PySR1PartType, PySR1PartData)> {
|
||||
if slf.index < slf.datas.len() {
|
||||
slf.index += 1;
|
||||
Some(slf.datas[slf.index - 1].clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
impl PySR1Connections {
|
||||
/// 通过父节点获取连接
|
||||
fn search_connection_by_parent(&self, parent_id: IdType) -> Vec<RawConnectionData> {
|
||||
self.datas.iter().filter(|x| x.parent_part == parent_id).map(|x| x.as_raw_data()).collect()
|
||||
}
|
||||
}
|
||||
|
||||
/// 用来存一堆 PartData 的数组
|
||||
#[pyclass]
|
||||
#[derive(Clone, Debug)]
|
||||
#[pyo3(name = "SR1PartArray_rs")]
|
||||
pub struct PySR1PartArray {
|
||||
pub datas: Vec<(PySR1PartType, PySR1PartData)>,
|
||||
pub part_list: SR1PartList,
|
||||
}
|
||||
|
||||
#[pymethods]
|
||||
impl PySR1PartArray {
|
||||
fn __iter__(&self) -> PySR1PartDataIterator {
|
||||
PySR1PartDataIterator {
|
||||
datas: self.datas.clone(),
|
||||
index: 0,
|
||||
}
|
||||
/// 通过子节点获取连接
|
||||
fn search_by_child(&self, child_id: IdType) -> Vec<RawConnectionData> {
|
||||
self.datas.iter().filter(|x| x.child_part == child_id).map(|x| x.as_raw_data()).collect()
|
||||
}
|
||||
/// 通过父子中任意一个 id 搜索连接
|
||||
fn search_by_id(&self, any_id: IdType) -> Vec<RawConnectionData> {
|
||||
self.datas
|
||||
.iter()
|
||||
.filter(|x| x.parent_part == any_id || x.child_part == any_id)
|
||||
.map(|x| x.as_raw_data())
|
||||
.collect()
|
||||
}
|
||||
/// 通过父子双方 id 获取连接
|
||||
///
|
||||
/// 保险期间, 我还是返回一个 Vec
|
||||
///
|
||||
/// 万一真有 双/多 连接呢
|
||||
fn search_by_both_id(&self, parent_id: IdType, child_id: IdType) -> Vec<RawConnectionData> {
|
||||
self.datas
|
||||
.iter()
|
||||
.filter(|x| x.parent_part == parent_id && x.child_part == child_id)
|
||||
.map(|x| x.as_raw_data())
|
||||
.collect()
|
||||
}
|
||||
/// 获取所有连接的原始数据
|
||||
///
|
||||
/// 万一你确实需要吭哧吭哧去处理原始数据呢
|
||||
fn get_raw_data(&self) -> Vec<RawConnectionData> {
|
||||
self.datas.iter().map(|x| x.as_raw_data()).collect()
|
||||
}
|
||||
}
|
||||
|
||||
@ -272,41 +278,28 @@ impl PySR1Ship {
|
||||
}
|
||||
}
|
||||
|
||||
fn parts(&self) -> PySR1PartArray {
|
||||
let mut parts: Vec<(PySR1PartType, PySR1PartData)> = Vec::new();
|
||||
for part_data in self.ship.parts.iter() {
|
||||
if let Some(part_type) = self.part_list.get_part_type(&part_data.part_type_id) {
|
||||
let part_type = PySR1PartType::new(part_type.clone());
|
||||
let py_part_data = PySR1PartData::new(part_data.clone());
|
||||
parts.push((part_type, py_part_data));
|
||||
}
|
||||
}
|
||||
PySR1PartArray {
|
||||
datas: parts,
|
||||
part_list: self.part_list.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
fn disconnected_parts(&self) -> Vec<PySR1PartArray> {
|
||||
fn disconnected_parts(&self) -> Vec<(Vec<(PySR1PartType, PySR1PartData)>, PySR1Connections)> {
|
||||
match self.ship.disconnected.as_ref() {
|
||||
Some(parts) => {
|
||||
if parts.is_empty() {
|
||||
return Vec::new();
|
||||
}
|
||||
let mut result = Vec::with_capacity(parts.len());
|
||||
for (part_group, _) in parts.iter() {
|
||||
let mut part_list = Vec::with_capacity(part_group.len());
|
||||
for (part_group, connections) in parts.iter() {
|
||||
let mut group_parts = Vec::with_capacity(part_group.len());
|
||||
for part_data in part_group.iter() {
|
||||
if let Some(part_type) = self.part_list.get_part_type(&part_data.part_type_id) {
|
||||
let part_type = PySR1PartType::new(part_type.clone());
|
||||
let py_part_data = PySR1PartData::new(part_data.clone());
|
||||
part_list.push((part_type, py_part_data));
|
||||
group_parts.push((part_type, py_part_data));
|
||||
}
|
||||
}
|
||||
result.push(PySR1PartArray {
|
||||
datas: part_list,
|
||||
part_list: self.part_list.clone(),
|
||||
});
|
||||
result.push((
|
||||
group_parts,
|
||||
PySR1Connections {
|
||||
datas: connections.clone().unwrap_or_default(),
|
||||
},
|
||||
));
|
||||
}
|
||||
result
|
||||
}
|
||||
@ -339,12 +332,12 @@ impl PySR1Ship {
|
||||
|
||||
#[getter]
|
||||
fn get_lift_off(&self) -> bool {
|
||||
self.ship.lift_off.to_owned()
|
||||
self.ship.lift_off
|
||||
}
|
||||
|
||||
#[getter]
|
||||
fn get_touch_ground(&self) -> bool {
|
||||
self.ship.touch_ground.to_owned()
|
||||
self.ship.touch_ground
|
||||
}
|
||||
|
||||
#[getter]
|
||||
@ -357,18 +350,10 @@ impl PySR1Ship {
|
||||
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,
|
||||
));
|
||||
fn connections(&self) -> PySR1Connections {
|
||||
PySR1Connections {
|
||||
datas: self.ship.connections.clone(),
|
||||
}
|
||||
connections
|
||||
}
|
||||
|
||||
fn as_list(&self) -> Vec<(PySR1PartType, PySR1PartData)> {
|
||||
|
@ -155,6 +155,8 @@ pub struct DisconnectedPart {
|
||||
pub connects: Connections,
|
||||
}
|
||||
|
||||
pub type RawConnectionData = (i32, i32, IdType, IdType);
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Connection {
|
||||
#[serde(rename = "@parentAttachPoint")]
|
||||
@ -167,6 +169,18 @@ pub struct Connection {
|
||||
pub child_part: IdType,
|
||||
}
|
||||
|
||||
impl Connection {
|
||||
/// 真有地方需要
|
||||
pub fn as_raw_data(&self) -> RawConnectionData {
|
||||
(
|
||||
self.parent_attach_point,
|
||||
self.child_attach_point,
|
||||
self.parent_part,
|
||||
self.child_part,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl SR1PartDataTrait for Part {
|
||||
fn to_sr_part_data(&self) -> SR1PartData {
|
||||
let attr = SR1PartDataAttr::from_raw(self, None, true);
|
||||
|
@ -16,7 +16,7 @@ from Difficult_Rocket.api.types import Options, Version
|
||||
|
||||
from lib_not_dr import loggers
|
||||
|
||||
DR_rust_version = Version("0.3.3") # DR_mod 的 Rust 编写部分的兼容版本
|
||||
DR_rust_version = Version("0.3.4") # DR_mod 的 Rust 编写部分的兼容版本
|
||||
|
||||
logger = loggers.config.get_logger_from_old("client.dr_game", "client")
|
||||
|
||||
|
@ -10,10 +10,18 @@ from pyglet.graphics import Batch, Group
|
||||
from Difficult_Rocket.client import ClientWindow
|
||||
from Difficult_Rocket.api.screen import BaseScreen
|
||||
from Difficult_Rocket.main import Game
|
||||
from Difficult_Rocket.gui.widget.button import PressTextButton, MinecraftWikiButtonTheme, ButtonThemeOptions, BaseButtonTheme
|
||||
from Difficult_Rocket.gui.widget.button import (
|
||||
PressTextButton,
|
||||
MinecraftWikiButtonTheme,
|
||||
ButtonThemeOptions,
|
||||
BaseButtonTheme,
|
||||
)
|
||||
|
||||
from lib_not_dr import loggers
|
||||
|
||||
# from . import DR_mod_runtime
|
||||
|
||||
logger = loggers.config.get_logger_from_old("client.dr_game_menu", "client")
|
||||
|
||||
class Menu(BaseScreen):
|
||||
"""
|
||||
@ -31,59 +39,59 @@ class Menu(BaseScreen):
|
||||
# 欸呀, 正好是 911 纪念日哦
|
||||
# 好, 高二 第一学期 期末都考完了, 我过来做测试了 (20240119)
|
||||
|
||||
self.wiki_button1 = PressTextButton(
|
||||
x=200,
|
||||
y=300,
|
||||
width=150,
|
||||
height=30,
|
||||
text="wiki button1",
|
||||
batch=self.main_batch,
|
||||
group=self.main_group,
|
||||
draw_theme=MinecraftWikiButtonTheme,
|
||||
dict_theme={"pop_out": True},
|
||||
)
|
||||
self.wiki_button2 = PressTextButton(
|
||||
x=400,
|
||||
y=300,
|
||||
width=150,
|
||||
height=30,
|
||||
text="wiki button2",
|
||||
batch=self.main_batch,
|
||||
group=self.main_group,
|
||||
draw_theme=MinecraftWikiButtonTheme,
|
||||
dict_theme={"pop_out": False},
|
||||
)
|
||||
self.wiki_button3 = PressTextButton(
|
||||
x=200,
|
||||
y=250,
|
||||
width=150,
|
||||
height=30,
|
||||
text="wiki button3",
|
||||
batch=self.main_batch,
|
||||
group=self.main_group,
|
||||
draw_theme=MinecraftWikiButtonTheme,
|
||||
dict_theme={"pop_out": True, "drag_list": True},
|
||||
)
|
||||
self.wiki_button4 = PressTextButton(
|
||||
x=400,
|
||||
y=250,
|
||||
width=150,
|
||||
height=30,
|
||||
text="wiki button4",
|
||||
batch=self.main_batch,
|
||||
group=self.main_group,
|
||||
draw_theme=MinecraftWikiButtonTheme,
|
||||
dict_theme={"pop_out": False, "drag_list": True},
|
||||
)
|
||||
self.button3 = PressTextButton(
|
||||
x=200,
|
||||
y=200,
|
||||
width=150,
|
||||
height=30,
|
||||
text="imgui button",
|
||||
batch=self.main_batch,
|
||||
group=self.main_group,
|
||||
)
|
||||
# self.wiki_button1 = PressTextButton(
|
||||
# x=200,
|
||||
# y=300,
|
||||
# width=150,
|
||||
# height=30,
|
||||
# text="wiki button1",
|
||||
# batch=self.main_batch,
|
||||
# group=self.main_group,
|
||||
# draw_theme=MinecraftWikiButtonTheme,
|
||||
# dict_theme={"pop_out": True},
|
||||
# )
|
||||
# self.wiki_button2 = PressTextButton(
|
||||
# x=400,
|
||||
# y=300,
|
||||
# width=150,
|
||||
# height=30,
|
||||
# text="wiki button2",
|
||||
# batch=self.main_batch,
|
||||
# group=self.main_group,
|
||||
# draw_theme=MinecraftWikiButtonTheme,
|
||||
# dict_theme={"pop_out": False},
|
||||
# )
|
||||
# self.wiki_button3 = PressTextButton(
|
||||
# x=200,
|
||||
# y=250,
|
||||
# width=150,
|
||||
# height=30,
|
||||
# text="wiki button3",
|
||||
# batch=self.main_batch,
|
||||
# group=self.main_group,
|
||||
# draw_theme=MinecraftWikiButtonTheme,
|
||||
# dict_theme={"pop_out": True, "drag_list": True},
|
||||
# )
|
||||
# self.wiki_button4 = PressTextButton(
|
||||
# x=400,
|
||||
# y=250,
|
||||
# width=150,
|
||||
# height=30,
|
||||
# text="wiki button4",
|
||||
# batch=self.main_batch,
|
||||
# group=self.main_group,
|
||||
# draw_theme=MinecraftWikiButtonTheme,
|
||||
# dict_theme={"pop_out": False, "drag_list": True},
|
||||
# )
|
||||
# self.button3 = PressTextButton(
|
||||
# x=200,
|
||||
# y=200,
|
||||
# width=150,
|
||||
# height=30,
|
||||
# text="imgui button",
|
||||
# batch=self.main_batch,
|
||||
# group=self.main_group,
|
||||
# )
|
||||
self.enter_ship_editor_button = PressEnterShipEditorButton(
|
||||
window=main_window,
|
||||
x=100,
|
||||
@ -93,17 +101,19 @@ class Menu(BaseScreen):
|
||||
text="进入编辑器",
|
||||
batch=self.main_batch,
|
||||
group=self.main_group,
|
||||
draw_theme=MinecraftWikiButtonTheme
|
||||
)
|
||||
main_window.push_handlers(self.wiki_button1)
|
||||
main_window.push_handlers(self.wiki_button2)
|
||||
main_window.push_handlers(self.wiki_button3)
|
||||
main_window.push_handlers(self.wiki_button4)
|
||||
main_window.push_handlers(self.button3)
|
||||
# main_window.push_handlers(self.wiki_button1)
|
||||
# main_window.push_handlers(self.wiki_button2)
|
||||
# main_window.push_handlers(self.wiki_button3)
|
||||
# main_window.push_handlers(self.wiki_button4)
|
||||
# main_window.push_handlers(self.button3)
|
||||
main_window.push_handlers(self.enter_ship_editor_button)
|
||||
|
||||
def on_draw(self, dt: float, window: ClientWindow):
|
||||
self.main_batch.draw()
|
||||
|
||||
|
||||
class PressEnterShipEditorButton(PressTextButton):
|
||||
def __init__(
|
||||
self,
|
||||
@ -117,11 +127,14 @@ class PressEnterShipEditorButton(PressTextButton):
|
||||
group: Optional[Group] = None,
|
||||
theme: Optional[ButtonThemeOptions] = None,
|
||||
draw_theme: Optional[type(BaseButtonTheme)] = None,
|
||||
dict_theme: Optional[dict] = None,):
|
||||
super().__init__(x,y,width,height,text,batch,group,theme,draw_theme,dict_theme)
|
||||
self.window=window
|
||||
|
||||
#from lib_not_dr import loggers
|
||||
dict_theme: Optional[dict] = None,
|
||||
):
|
||||
super().__init__(
|
||||
x, y, width, height, text, batch, group, theme, draw_theme, dict_theme
|
||||
)
|
||||
self.window = window
|
||||
|
||||
|
||||
def on_mouse_release(self, x, y, buttons, modifiers):
|
||||
if self.pressed and (x, y) in self:
|
||||
if self.draw_theme:
|
||||
@ -129,10 +142,9 @@ class PressEnterShipEditorButton(PressTextButton):
|
||||
else:
|
||||
self.back_rec.color = self.touched_color
|
||||
self.pressed = False
|
||||
|
||||
|
||||
from .sr1_ship import SR1ShipRender
|
||||
|
||||
self.window.remove_sub_screen("DR_game_menu")
|
||||
self.window.add_sub_screen("SR1_ship", SR1ShipRender)
|
||||
#logger.info("added SR1_ship screen", tag="dr_game")
|
||||
|
||||
|
||||
logger.info("added SR1_ship screen", tag="dr_game")
|
||||
|
@ -38,6 +38,7 @@ if DR_mod_runtime.use_DR_rust:
|
||||
SR1Ship_rs,
|
||||
SR1PartData_rs,
|
||||
SR1PartType_rs,
|
||||
# SR1Connection_rs
|
||||
)
|
||||
|
||||
|
||||
@ -291,7 +292,7 @@ class SR1ShipRender(BaseScreen):
|
||||
count = 0
|
||||
yield
|
||||
connect_line_group = Group(7, parent=self.part_group)
|
||||
for connect in self.rust_ship.connection:
|
||||
for connect in self.rust_ship.connections().get_raw_data:
|
||||
# 连接线
|
||||
parent_part_data = cache[connect[2]][0][1]
|
||||
child_part_data = cache[connect[3]][0][1]
|
||||
@ -371,7 +372,7 @@ class SR1ShipRender(BaseScreen):
|
||||
sr_tr()
|
||||
.sr1.ship.ship.load_time()
|
||||
.format((time.perf_counter_ns() - start_time) / 1000000000),
|
||||
tag="ship"
|
||||
tag="ship",
|
||||
)
|
||||
logger.info(
|
||||
sr_tr()
|
||||
@ -538,7 +539,8 @@ class SR1ShipRender(BaseScreen):
|
||||
for index, sprite in enumerate(sprites):
|
||||
sprite_img = sprite.image
|
||||
print(
|
||||
f"sprite_img: {sprite_img} {part_data[part][index][1].x * 60} {part_data[part][index][1].y * 60}"
|
||||
f"sprite_img: {sprite_img} {part_data[part][index][1].x * 60} "
|
||||
f"{part_data[part][index][1].y * 60}"
|
||||
)
|
||||
img_data = sprite_img.get_image_data()
|
||||
fmt = img_data.format
|
||||
|
Loading…
Reference in New Issue
Block a user