first part for phy simluation #34
@ -16,20 +16,19 @@ import sys
|
|||||||
import time
|
import time
|
||||||
import math
|
import math
|
||||||
import json
|
import json
|
||||||
|
import rtoml
|
||||||
import logging
|
import logging
|
||||||
import configparser
|
import configparser
|
||||||
|
|
||||||
from typing import Union
|
from pathlib import Path
|
||||||
|
from typing import Union, Optional
|
||||||
from xml.etree import ElementTree
|
from xml.etree import ElementTree
|
||||||
|
|
||||||
import rtoml
|
|
||||||
|
|
||||||
from defusedxml.ElementTree import parse
|
from defusedxml.ElementTree import parse
|
||||||
|
|
||||||
from Difficult_Rocket.exception.unsupport import NoMoreJson5
|
from Difficult_Rocket.exception.unsupport import NoMoreJson5
|
||||||
|
|
||||||
# logger
|
# logger
|
||||||
tools_logger = logging.getLogger('part-tools')
|
tools_logger = logging.getLogger('tools')
|
||||||
"""
|
"""
|
||||||
file configs
|
file configs
|
||||||
"""
|
"""
|
||||||
@ -39,10 +38,12 @@ file_error = {FileNotFoundError: 'no {filetype} file was founded!:\n file name:
|
|||||||
Exception: 'get some {error_type} when read {filetype} file {filename}! \n file type: {} \n file name: {} \n stack: {stack}'}
|
Exception: 'get some {error_type} when read {filetype} file {filename}! \n file type: {} \n file name: {} \n stack: {stack}'}
|
||||||
|
|
||||||
|
|
||||||
def load_file(file_name: str,
|
def load_file(file_name: Union[str, Path],
|
||||||
stack: Union[str, list, dict, None] = None,
|
stack: Optional[Union[str, list, dict]] = None,
|
||||||
raise_error: bool = True,
|
raise_error: Optional[bool] = True,
|
||||||
encoding: str = 'utf-8') -> Union[dict, ElementTree.ElementTree]:
|
encoding: Optional[str] = 'utf-8') -> Union[dict, ElementTree.ElementTree]:
|
||||||
|
if isinstance(file_name, Path):
|
||||||
|
file_name = str(file_name)
|
||||||
f_type = file_name[file_name.rfind('.') + 1:] # 从最后一个.到末尾 (截取文件格式)
|
f_type = file_name[file_name.rfind('.') + 1:] # 从最后一个.到末尾 (截取文件格式)
|
||||||
get_file = NotImplementedError('解析失败,请检查文件类型/文件内容/文件是否存在!')
|
get_file = NotImplementedError('解析失败,请检查文件类型/文件内容/文件是否存在!')
|
||||||
try:
|
try:
|
||||||
|
@ -14,6 +14,7 @@ gitee: @shenjackyuanjie
|
|||||||
import os
|
import os
|
||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Union, Tuple, Any, List, Dict, Hashable, Optional
|
from typing import Union, Tuple, Any, List, Dict, Hashable, Optional
|
||||||
|
|
||||||
@ -153,15 +154,16 @@ class Tr:
|
|||||||
GOOD
|
GOOD
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, language: str = None, config: Optional[TranslateConfig] = None):
|
def __init__(self, language: str = None, config: Optional[TranslateConfig] = None, lang_path: Optional[Path] = None):
|
||||||
"""
|
"""
|
||||||
诶嘿,我抄的MCDR
|
诶嘿,我抄的MCDR
|
||||||
:param language: Tr 所使用的的语言
|
:param language: Tr 所使用的的语言
|
||||||
:param config: 配置
|
:param config: 配置
|
||||||
"""
|
"""
|
||||||
self.language_name = language if language is not None else DR_runtime.language
|
self.language_name = language if language is not None else DR_runtime.language
|
||||||
self.translates: Dict[str, Union[str, Dict]] = tools.load_file(f'configs/lang/{self.language_name}.toml')
|
self.language_path = lang_path if lang_path is not None else Path('configs/lang')
|
||||||
self.default_translate: Dict = tools.load_file(f'configs/lang/{DR_status.default_language}.toml')
|
self.translates: Dict[str, Union[str, Dict]] = tools.load_file(self.language_path / f'{self.language_name}.toml')
|
||||||
|
self.default_translate: Dict = tools.load_file(f'{self.language_path}/{DR_status.default_language}.toml')
|
||||||
self.default_config = config.set('source', self) if config is not None else TranslateConfig(source=self)
|
self.default_config = config.set('source', self) if config is not None else TranslateConfig(source=self)
|
||||||
self.translates_cache = Translates(value=self.translates, config=self.default_config.copy())
|
self.translates_cache = Translates(value=self.translates, config=self.default_config.copy())
|
||||||
|
|
||||||
@ -185,11 +187,11 @@ class Tr:
|
|||||||
if lang == ' ' or lang == '':
|
if lang == ' ' or lang == '':
|
||||||
raise LanguageNotFound('Can not be empty')
|
raise LanguageNotFound('Can not be empty')
|
||||||
lang = lang or self.language_name
|
lang = lang or self.language_name
|
||||||
if not os.path.exists(f'./configs/lang/{lang}.toml'):
|
if not os.path.exists(f'{self.language_path}/{lang}.toml'):
|
||||||
print(f"lang: {os.path.exists(f'./configs/lang/{lang}.toml')} language = {lang} {self.language_name=}")
|
print(f"lang: {os.path.exists(f'{self.language_path}/{lang}.toml')} language = {lang} {self.language_name=}")
|
||||||
raise LanguageNotFound(lang)
|
raise LanguageNotFound(lang)
|
||||||
self.translates: Dict[str, Union[str, Dict]] = tools.load_file(f'configs/lang/{lang}.toml')
|
self.translates: Dict[str, Union[str, Dict]] = tools.load_file(f'{self.language_path}/{lang}.toml')
|
||||||
self.default_translate: Dict = tools.load_file(f'configs/lang/{DR_runtime.default_language}.toml')
|
self.default_translate: Dict = tools.load_file(f'{self.language_path}/{DR_runtime.default_language}.toml')
|
||||||
self.translates_cache = Translates(value=self.translates, config=self.default_config.copy())
|
self.translates_cache = Translates(value=self.translates, config=self.default_config.copy())
|
||||||
self.language_name = lang
|
self.language_name = lang
|
||||||
DR_runtime.language = self.language_name
|
DR_runtime.language = self.language_name
|
||||||
|
@ -75,14 +75,3 @@ input = "console"
|
|||||||
window = "window"
|
window = "window"
|
||||||
command = "in game commands"
|
command = "in game commands"
|
||||||
require_DR_rs = "require DR_rs module"
|
require_DR_rs = "require DR_rs module"
|
||||||
|
|
||||||
[client.sr1_render]
|
|
||||||
setup.start = "SR1 Renderer start loading"
|
|
||||||
setup.use_time = "SR1 Renderer loading has used: {} second"
|
|
||||||
xml.loading = "Loading XML file: {}"
|
|
||||||
xml.load_done = "XML file loaded"
|
|
||||||
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"
|
|
||||||
|
@ -75,15 +75,3 @@ input = "控制台"
|
|||||||
window = "窗口"
|
window = "窗口"
|
||||||
command = "游戏内命令行"
|
command = "游戏内命令行"
|
||||||
require_DR_rs = "需要 DR_rs 模块"
|
require_DR_rs = "需要 DR_rs 模块"
|
||||||
|
|
||||||
[client.sr1_render]
|
|
||||||
setup.start = "SR1 渲染器开始载入"
|
|
||||||
setup.use_time = "SR1 渲染器载入消耗时间: {} 秒"
|
|
||||||
xml.loading = "正在加载XML文件: {}"
|
|
||||||
xml.load_done = "XML 文件加载完成"
|
|
||||||
xml.load_time = "XML 文件加载消耗时间: {} 秒"
|
|
||||||
ship.load = "正在加载飞船: {}"
|
|
||||||
ship.load_time = "飞船加载消耗时间: {} 秒"
|
|
||||||
#ship.info = "飞船信息:\n- 部件数量: {}\n- 部件重量: {}\n- 文件大小: {}"
|
|
||||||
ship.info = "飞船信息:\n- 部件数量: {}\n- 部件重量: {}"
|
|
||||||
ship.render.done = "飞船渲染完成"
|
|
||||||
|
12
mods/dr_game/lang/en-us.toml
Normal file
12
mods/dr_game/lang/en-us.toml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
[mod.info]
|
||||||
|
setup.start = "SR1 Renderer start loading"
|
||||||
|
setup.use_time = "SR1 Renderer loading has used: {} second"
|
||||||
|
|
||||||
|
[sr1.ship]
|
||||||
|
xml.loading = "Loading XML file: {}"
|
||||||
|
xml.load_done = "XML file loaded"
|
||||||
|
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"
|
@ -0,0 +1,13 @@
|
|||||||
|
[mod.info]
|
||||||
|
setup.start = "SR1 渲染器开始载入"
|
||||||
|
setup.use_time = "SR1 渲染器载入消耗时间: {} 秒"
|
||||||
|
|
||||||
|
[sr1.ship]
|
||||||
|
xml.loading = "正在加载XML文件: {}"
|
||||||
|
xml.load_done = "XML 文件加载完成"
|
||||||
|
xml.load_time = "XML 文件加载消耗时间: {} 秒"
|
||||||
|
ship.load = "正在加载飞船: {}"
|
||||||
|
ship.load_time = "飞船加载消耗时间: {} 秒"
|
||||||
|
#ship.info = "飞船信息:\n- 部件数量: {}\n- 部件重量: {}\n- 文件大小: {}"
|
||||||
|
ship.info = "飞船信息:\n- 部件数量: {}\n- 部件重量: {}"
|
||||||
|
ship.render.done = "飞船渲染完成"
|
@ -9,14 +9,12 @@ import time
|
|||||||
import random
|
import random
|
||||||
import logging
|
import logging
|
||||||
import traceback
|
import traceback
|
||||||
# from xml.etree import ElementTree
|
|
||||||
|
from pathlib import Path
|
||||||
from xml.etree.ElementTree import Element
|
from xml.etree.ElementTree import Element
|
||||||
from typing import List, TYPE_CHECKING, Union, Dict, Optional, Generator
|
from typing import List, TYPE_CHECKING, Union, Dict, Optional, Generator
|
||||||
|
|
||||||
# third party package
|
|
||||||
from defusedxml.ElementTree import parse
|
from defusedxml.ElementTree import parse
|
||||||
|
|
||||||
# pyglet
|
|
||||||
from pyglet.math import Vec4
|
from pyglet.math import Vec4
|
||||||
from pyglet.text import Label
|
from pyglet.text import Label
|
||||||
from pyglet.sprite import Sprite
|
from pyglet.sprite import Sprite
|
||||||
@ -28,7 +26,7 @@ from . import DR_mod_runtime
|
|||||||
|
|
||||||
# Difficult Rocket
|
# Difficult Rocket
|
||||||
from Difficult_Rocket import DR_status
|
from Difficult_Rocket import DR_status
|
||||||
from Difficult_Rocket.utils.translate import tr
|
from Difficult_Rocket.utils.translate import Tr
|
||||||
from Difficult_Rocket.api.types import Fonts, Options
|
from Difficult_Rocket.api.types import Fonts, Options
|
||||||
from Difficult_Rocket.command.line import CommandText
|
from Difficult_Rocket.command.line import CommandText
|
||||||
from Difficult_Rocket.client.screen import BaseScreen
|
from Difficult_Rocket.client.screen import BaseScreen
|
||||||
@ -41,6 +39,7 @@ if DR_mod_runtime.use_DR_rust:
|
|||||||
from .Difficult_Rocket_rs import CenterCamera_rs, SR1PartList_rs, SR1Ship_rs
|
from .Difficult_Rocket_rs import CenterCamera_rs, SR1PartList_rs, SR1Ship_rs
|
||||||
|
|
||||||
logger = logging.getLogger('client.dr_game_sr1_ship')
|
logger = logging.getLogger('client.dr_game_sr1_ship')
|
||||||
|
sr_tr = Tr(lang_path=Path('./mods/dr_game/lang'))
|
||||||
|
|
||||||
|
|
||||||
def get_sr1_part(part_xml: Element) -> Optional[SR1PartData]:
|
def get_sr1_part(part_xml: Element) -> Optional[SR1PartData]:
|
||||||
@ -88,7 +87,7 @@ class SR1ShipRender(BaseScreen):
|
|||||||
def __init__(self,
|
def __init__(self,
|
||||||
main_window: "ClientWindow"):
|
main_window: "ClientWindow"):
|
||||||
super().__init__(main_window)
|
super().__init__(main_window)
|
||||||
logger.info(tr().client.sr1_render.setup.start())
|
logger.info(sr_tr().mod.info.setup.start())
|
||||||
load_start_time = time.time_ns()
|
load_start_time = time.time_ns()
|
||||||
self.rendered = False
|
self.rendered = False
|
||||||
self.focus = True
|
self.focus = True
|
||||||
@ -133,7 +132,7 @@ class SR1ShipRender(BaseScreen):
|
|||||||
self.part_box_dict: Dict[int, Rectangle] = {}
|
self.part_box_dict: Dict[int, Rectangle] = {}
|
||||||
self.part_line_box: Dict[int, List[Line]] = {}
|
self.part_line_box: Dict[int, List[Line]] = {}
|
||||||
load_end_time = time.time_ns()
|
load_end_time = time.time_ns()
|
||||||
logger.info(tr().client.sr1_render.setup.use_time().format(
|
logger.info(sr_tr().mod.info.setup.use_time().format(
|
||||||
(load_end_time - load_start_time) / 1000000000))
|
(load_end_time - load_start_time) / 1000000000))
|
||||||
if DR_mod_runtime.use_DR_rust:
|
if DR_mod_runtime.use_DR_rust:
|
||||||
self.camera_rs = CenterCamera_rs(main_window,
|
self.camera_rs = CenterCamera_rs(main_window,
|
||||||
@ -144,7 +143,7 @@ class SR1ShipRender(BaseScreen):
|
|||||||
def load_xml(self, file_path: str) -> bool:
|
def load_xml(self, file_path: str) -> bool:
|
||||||
try:
|
try:
|
||||||
start_time = time.time_ns()
|
start_time = time.time_ns()
|
||||||
logger.info(tr().client.sr1_render.xml.loading().format(file_path))
|
logger.info(sr_tr().sr1.ship.xml.loading().format(file_path))
|
||||||
cache_doc = parse(file_path)
|
cache_doc = parse(file_path)
|
||||||
self.xml_doc = cache_doc
|
self.xml_doc = cache_doc
|
||||||
self.xml_root = self.xml_doc.getroot()
|
self.xml_root = self.xml_doc.getroot()
|
||||||
@ -156,8 +155,8 @@ class SR1ShipRender(BaseScreen):
|
|||||||
print(self.rust_ship.img_pos)
|
print(self.rust_ship.img_pos)
|
||||||
except Exception:
|
except Exception:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
logger.info(tr().client.sr1_render.xml.load_done())
|
logger.info(sr_tr().sr1.ship.xml.load_done())
|
||||||
logger.info(tr().client.sr1_render.xml.load_time().format(
|
logger.info(sr_tr().sr1.ship.xml.load_time().format(
|
||||||
(time.time_ns() - start_time) / 1000000000))
|
(time.time_ns() - start_time) / 1000000000))
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -224,7 +223,7 @@ class SR1ShipRender(BaseScreen):
|
|||||||
def render_ship(self):
|
def render_ship(self):
|
||||||
if self.textures is None:
|
if self.textures is None:
|
||||||
self.load_textures()
|
self.load_textures()
|
||||||
logger.info(tr().client.sr1_render.ship.load().format(self.xml_name))
|
logger.info(sr_tr().sr1.ship.ship.load().format(self.xml_name))
|
||||||
start_time = time.perf_counter_ns()
|
start_time = time.perf_counter_ns()
|
||||||
self.part_data: Dict[int, SR1PartData] = {}
|
self.part_data: Dict[int, SR1PartData] = {}
|
||||||
self.parts_sprite: Dict[int, Sprite] = {}
|
self.parts_sprite: Dict[int, Sprite] = {}
|
||||||
@ -252,10 +251,10 @@ class SR1ShipRender(BaseScreen):
|
|||||||
if DR_mod_runtime.use_DR_rust:
|
if DR_mod_runtime.use_DR_rust:
|
||||||
for part in self.part_data:
|
for part in self.part_data:
|
||||||
full_mass += self.part_list_rs.get_part_type(self.part_data[part].p_type).mass * 500
|
full_mass += self.part_list_rs.get_part_type(self.part_data[part].p_type).mass * 500
|
||||||
logger.info(tr().client.sr1_render.ship.load_time().format(
|
logger.info(sr_tr().sr1.ship.ship.load_time().format(
|
||||||
(time.perf_counter_ns() - start_time) / 1000000000))
|
(time.perf_counter_ns() - start_time) / 1000000000))
|
||||||
logger.info(tr().client.sr1_render.ship.info().format(
|
logger.info(sr_tr().sr1.ship.ship.info().format(
|
||||||
len(self.part_data), f'{full_mass}kg' if DR_mod_runtime.use_DR_rust else tr().game.require_DR_rs()))
|
len(self.part_data), f'{full_mass}kg' if DR_mod_runtime.use_DR_rust else sr_tr().game.require_DR_rs()))
|
||||||
self.rendered = True
|
self.rendered = True
|
||||||
|
|
||||||
def update_parts(self) -> bool:
|
def update_parts(self) -> bool:
|
||||||
@ -278,7 +277,7 @@ class SR1ShipRender(BaseScreen):
|
|||||||
next(self.gen_draw)
|
next(self.gen_draw)
|
||||||
except GeneratorExit:
|
except GeneratorExit:
|
||||||
self.drawing = False
|
self.drawing = False
|
||||||
logger.info(tr().client.sr1_render.ship.render.done())
|
logger.info(sr_tr().sr1.ship.ship.render.done())
|
||||||
|
|
||||||
if self.need_update_parts:
|
if self.need_update_parts:
|
||||||
self.update_parts()
|
self.update_parts()
|
||||||
|
Loading…
Reference in New Issue
Block a user