DR -> DR SDK #16
@ -4,20 +4,14 @@
|
|||||||
# All rights reserved
|
# All rights reserved
|
||||||
# -------------------------------
|
# -------------------------------
|
||||||
|
|
||||||
"""
|
|
||||||
writen by shenjackyuanjie
|
|
||||||
mail: 3695888@qq.com
|
|
||||||
github: @shenjackyuanjie
|
|
||||||
gitee: @shenjackyuanjie
|
|
||||||
"""
|
|
||||||
|
|
||||||
# import ctypes
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import warnings
|
import warnings
|
||||||
import importlib
|
import importlib
|
||||||
import traceback
|
import traceback
|
||||||
import contextlib
|
import contextlib
|
||||||
|
import importlib.util
|
||||||
|
from pathlib import Path
|
||||||
from typing import Optional, List, Tuple
|
from typing import Optional, List, Tuple
|
||||||
|
|
||||||
from Difficult_Rocket.api.types import Options
|
from Difficult_Rocket.api.types import Options
|
||||||
@ -78,14 +72,11 @@ class _DR_option(Options):
|
|||||||
playing: bool = False
|
playing: bool = False
|
||||||
debugging: bool = False
|
debugging: bool = False
|
||||||
crash_report_test: bool = True
|
crash_report_test: bool = True
|
||||||
pyglet_macosx_dev_test: bool = True
|
|
||||||
|
|
||||||
# window option
|
# window option
|
||||||
gui_scale: float = 1.0 # default 1.0 2.0 -> 2x 3 -> 3x
|
gui_scale: float = 1.0 # default 1.0 2.0 -> 2x 3 -> 3x
|
||||||
|
|
||||||
def init(self, **kwargs):
|
def init(self, **kwargs):
|
||||||
if sys.platform != 'darwin': # MacOS 的测试只能在 Macos 上跑
|
|
||||||
self.pyglet_macosx_dev_test = False
|
|
||||||
try:
|
try:
|
||||||
from libs.Difficult_Rocket_rs import test_call, get_version_str
|
from libs.Difficult_Rocket_rs import test_call, get_version_str
|
||||||
test_call(self)
|
test_call(self)
|
||||||
@ -149,7 +140,6 @@ class _DR_runtime(Options):
|
|||||||
relationship = 'larger' if self.DR_Rust_version > self.DR_Rust_get_version else 'smaller'
|
relationship = 'larger' if self.DR_Rust_version > self.DR_Rust_get_version else 'smaller'
|
||||||
warnings.warn(f'DR_rust builtin version is {self.DR_Rust_version} but true version is {get_version_str()}.\n'
|
warnings.warn(f'DR_rust builtin version is {self.DR_Rust_version} but true version is {get_version_str()}.\n'
|
||||||
f'Builtin version {relationship} than true version')
|
f'Builtin version {relationship} than true version')
|
||||||
self.find_mods()
|
|
||||||
|
|
||||||
def load_file(self) -> bool:
|
def load_file(self) -> bool:
|
||||||
with contextlib.suppress(FileNotFoundError):
|
with contextlib.suppress(FileNotFoundError):
|
||||||
@ -165,13 +155,28 @@ class _DR_runtime(Options):
|
|||||||
mod_list = self.find_mods()
|
mod_list = self.find_mods()
|
||||||
|
|
||||||
def find_mods(self) -> List[str]:
|
def find_mods(self) -> List[str]:
|
||||||
objects = os.listdir(self.mod_path)
|
mods = []
|
||||||
for obj in objects:
|
paths = Path(self.mod_path).iterdir()
|
||||||
if os.path.isdir(os.path.join(self.mod_path, obj)):
|
sys.path.append(self.mod_path)
|
||||||
...
|
for mod_path in paths:
|
||||||
|
try:
|
||||||
|
if mod_path.is_dir: # 文件夹格式的 mod
|
||||||
|
if not (mod_path / '__init__.py').exists(): # 不符合格式要求
|
||||||
|
continue
|
||||||
|
if importlib.util.find_spec(mod_path.name) is not None:
|
||||||
|
module = importlib.import_module(mod_path.name)
|
||||||
|
info: Options = module.INFO
|
||||||
|
mods.append(mod_path.name)
|
||||||
|
print(f'find mod in {mod_path} ID: {info.mod_id} name: {info.name} version: {info.version}')
|
||||||
|
print(f'import mod {mod_path}')
|
||||||
|
else:
|
||||||
|
print(f'can not import mod {mod_path} because importlib can not find spec')
|
||||||
else:
|
else:
|
||||||
...
|
...
|
||||||
...
|
except ImportError:
|
||||||
|
print(f'ImportError when loading mod {mod_path}')
|
||||||
|
traceback.print_exc()
|
||||||
|
return mods
|
||||||
|
|
||||||
|
|
||||||
DR_option = _DR_option()
|
DR_option = _DR_option()
|
||||||
|
@ -31,6 +31,7 @@ class MODInfo(Options):
|
|||||||
加载mod时候的参数
|
加载mod时候的参数
|
||||||
"""
|
"""
|
||||||
"""基本信息"""
|
"""基本信息"""
|
||||||
|
mod_id: str # mod id
|
||||||
name: str # mod 名称
|
name: str # mod 名称
|
||||||
version: Version # mod 版本
|
version: Version # mod 版本
|
||||||
|
|
||||||
|
@ -5,17 +5,10 @@
|
|||||||
# All rights reserved
|
# All rights reserved
|
||||||
# -------------------------------
|
# -------------------------------
|
||||||
|
|
||||||
"""
|
|
||||||
writen by shenjackyuanjie
|
|
||||||
mail: 3695888@qq.com
|
|
||||||
github: @shenjackyuanjie
|
|
||||||
gitee: @shenjackyuanjie
|
|
||||||
"""
|
|
||||||
import inspect
|
|
||||||
# system function
|
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import logging
|
import logging
|
||||||
|
import inspect
|
||||||
import functools
|
import functools
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
@ -59,7 +52,7 @@ class ClientOption(Options):
|
|||||||
caption: str = "Difficult Rocket v{DR_version}|DR_rs v{DR_Rust_get_version}"
|
caption: str = "Difficult Rocket v{DR_version}|DR_rs v{DR_Rust_get_version}"
|
||||||
|
|
||||||
def load_file(self) -> None:
|
def load_file(self) -> None:
|
||||||
file = tools.load_file('./configs/main.toml')
|
file: dict = tools.load_file('./configs/main.toml')
|
||||||
self.fps = int(file['runtime']['fps'])
|
self.fps = int(file['runtime']['fps'])
|
||||||
self.width = int(file['window']['width'])
|
self.width = int(file['window']['width'])
|
||||||
self.height = int(file['window']['height'])
|
self.height = int(file['window']['height'])
|
||||||
@ -82,13 +75,10 @@ class Client:
|
|||||||
self.process_name = 'Client process'
|
self.process_name = 'Client process'
|
||||||
self.process_pid = os.getpid()
|
self.process_pid = os.getpid()
|
||||||
self.net_mode = net_mode
|
self.net_mode = net_mode
|
||||||
file_drop = bool(
|
|
||||||
pyglet.compat_platform != 'darwin' or DR_option.pyglet_macosx_dev_test
|
|
||||||
)
|
|
||||||
self.window = ClientWindow(net_mode=self.net_mode, width=self.config.width, height=self.config.height,
|
self.window = ClientWindow(net_mode=self.net_mode, width=self.config.width, height=self.config.height,
|
||||||
fullscreen=self.config.fullscreen, caption=self.config.caption,
|
fullscreen=self.config.fullscreen, caption=self.config.caption,
|
||||||
resizable=self.config.resizeable, visible=self.config.visible,
|
resizable=self.config.resizeable, visible=self.config.visible,
|
||||||
file_drops=file_drop)
|
file_drops=True)
|
||||||
end_time = time.time_ns()
|
end_time = time.time_ns()
|
||||||
self.use_time = end_time - start_time
|
self.use_time = end_time - start_time
|
||||||
if DR_option.use_DR_rust:
|
if DR_option.use_DR_rust:
|
||||||
@ -206,6 +196,8 @@ class ClientWindow(Window):
|
|||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
self.set_icon(pyglet.image.load('./textures/icon.png'))
|
self.set_icon(pyglet.image.load('./textures/icon.png'))
|
||||||
|
self.logger.info(f"=== finding mods from {DR_runtime.mod_path} ===")
|
||||||
|
self.logger.info(f'find mods: {DR_runtime.find_mods()}')
|
||||||
self.load_fonts()
|
self.load_fonts()
|
||||||
# TODO 读取配置文件,加载不同的屏幕,解耦
|
# TODO 读取配置文件,加载不同的屏幕,解耦
|
||||||
self.screen_list.append(DRDEBUGScreen(self))
|
self.screen_list.append(DRDEBUGScreen(self))
|
||||||
@ -242,7 +234,7 @@ class ClientWindow(Window):
|
|||||||
@new_thread('window save_info')
|
@new_thread('window save_info')
|
||||||
def save_info(self):
|
def save_info(self):
|
||||||
self.logger.info(tr().client.config.save.start())
|
self.logger.info(tr().client.config.save.start())
|
||||||
config_file = tools.load_file('./configs/main.toml')
|
config_file: dict = tools.load_file('./configs/main.toml')
|
||||||
config_file['window']['width'] = self.width
|
config_file['window']['width'] = self.width
|
||||||
config_file['window']['height'] = self.height
|
config_file['window']['height'] = self.height
|
||||||
config_file['runtime']['language'] = DR_runtime.language
|
config_file['runtime']['language'] = DR_runtime.language
|
||||||
@ -253,7 +245,7 @@ class ClientWindow(Window):
|
|||||||
client api
|
client api
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def add_sub_screen(self, sub_screen: BaseScreen.__class__):
|
def add_sub_screen(self, sub_screen: type(BaseScreen)):
|
||||||
self.screen_list.append(sub_screen(self))
|
self.screen_list.append(sub_screen(self))
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -121,7 +121,7 @@ class Translates:
|
|||||||
self._config.is_final = True
|
self._config.is_final = True
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __call__(self, *args, **kwargs) -> Union[dict, list, int, str]:
|
def __call__(self, *args, **kwargs) -> str:
|
||||||
return self.__str__()
|
return self.__str__()
|
||||||
|
|
||||||
def copy(self):
|
def copy(self):
|
||||||
|
@ -15,11 +15,10 @@
|
|||||||
pub mod plugin_trait {
|
pub mod plugin_trait {
|
||||||
pub struct ModInfo {
|
pub struct ModInfo {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub version: String
|
pub version: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ModInfoTrait {
|
pub trait ModInfoTrait {
|
||||||
fn info() -> ModInfo;
|
fn info() -> ModInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use rapier2d_f64::prelude::*;
|
use rapier2d_f64::prelude::*;
|
||||||
|
|
||||||
|
|
||||||
#[pyfunction]
|
#[pyfunction]
|
||||||
#[pyo3(name = "simluation")]
|
#[pyo3(name = "simluation")]
|
||||||
pub fn simluation() -> PyResult<()> {
|
pub fn simluation() -> PyResult<()> {
|
||||||
@ -64,4 +63,3 @@ pub fn simluation() -> PyResult<()> {
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ from MCDR.version import Version
|
|||||||
from Difficult_Rocket.mod import MODInfo
|
from Difficult_Rocket.mod import MODInfo
|
||||||
|
|
||||||
INFO = MODInfo(
|
INFO = MODInfo(
|
||||||
|
mod_id="Difficult_Rocket_mod",
|
||||||
name="Difficult_Rocket_mod",
|
name="Difficult_Rocket_mod",
|
||||||
version=Version("0.7.2.0")
|
version=Version("0.7.2.0")
|
||||||
)
|
)
|
14
test/data.jl
14
test/data.jl
@ -1,14 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct a_part
|
|
||||||
part_type :: String
|
|
||||||
part_id :: UInt64
|
|
||||||
enable :: Bool
|
|
||||||
x :: Float64
|
|
||||||
y :: Float64
|
|
||||||
x_v :: Float64
|
|
||||||
y_v :: Float64
|
|
||||||
angle :: Float16
|
|
||||||
angle_v :: Float64
|
|
||||||
end
|
|
Loading…
Reference in New Issue
Block a user