看起来不错哦
This commit is contained in:
parent
bd1b6d000c
commit
b481d8e012
@ -89,11 +89,11 @@ class Client:
|
|||||||
resizable=tools.format_bool(self.config['window']['resizable']),
|
resizable=tools.format_bool(self.config['window']['resizable']),
|
||||||
visible=tools.format_bool(self.config['window']['visible']),
|
visible=tools.format_bool(self.config['window']['visible']),
|
||||||
file_drops=file_drop)
|
file_drops=file_drop)
|
||||||
self.logger.info(tr.lang('client', 'setup.done'))
|
self.logger.info(tr().client.setup.done)
|
||||||
end_time = time.time_ns()
|
end_time = time.time_ns()
|
||||||
self.use_time = end_time - start_time
|
self.use_time = end_time - start_time
|
||||||
self.logger.info(tr.lang('client', 'setup.use_time').format(Decimal(self.use_time) / 1000000000))
|
self.logger.info(tr().client.setup.use_time.format(Decimal(self.use_time) / 1000000000))
|
||||||
self.logger.debug(tr.lang('client', 'setup.use_time_ns').format(self.use_time))
|
self.logger.debug(tr().client.setup.use_time_ns.format(self.use_time))
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
DR_runtime.running = True
|
DR_runtime.running = True
|
||||||
@ -188,13 +188,13 @@ class ClientWindow(Window):
|
|||||||
# 设置刷新率
|
# 设置刷新率
|
||||||
pyglet.clock.schedule_interval(self.draw_update, float(self.SPF))
|
pyglet.clock.schedule_interval(self.draw_update, float(self.SPF))
|
||||||
# 完成设置后的信息输出
|
# 完成设置后的信息输出
|
||||||
self.logger.info(tr.lang('window', 'setup.done'))
|
self.logger.info(tr().window.setup.done())
|
||||||
self.logger.info(tr.lang('window', 'os.pid_is').format(os.getpid(), os.getppid()))
|
self.logger.info(tr().window.os.pid_is().format(os.getpid(), os.getppid()))
|
||||||
end_time = time.time_ns()
|
end_time = time.time_ns()
|
||||||
self.use_time = end_time - start_time
|
self.use_time = end_time - start_time
|
||||||
DR_runtime.client_setup_cause_ns = self.use_time
|
DR_runtime.client_setup_cause_ns = self.use_time
|
||||||
self.logger.info(tr.lang('window', 'setup.use_time').format(Decimal(self.use_time) / 1000000000))
|
self.logger.info(tr().window.setup.use_time().format(Decimal(self.use_time) / 1000000000))
|
||||||
self.logger.debug(tr.lang('window', 'setup.use_time_ns').format(self.use_time))
|
self.logger.debug(tr().window.setup.use_time_ns().format(self.use_time))
|
||||||
self.count = 0
|
self.count = 0
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
@ -295,7 +295,7 @@ class ClientWindow(Window):
|
|||||||
|
|
||||||
@_call_screen_after
|
@_call_screen_after
|
||||||
def on_command(self, command: line.CommandText):
|
def on_command(self, command: line.CommandText):
|
||||||
self.logger.info(tr.lang('window', 'command.text').format(command))
|
self.logger.info(tr().window.command.text.format(command))
|
||||||
if command.re_match('stop'):
|
if command.re_match('stop'):
|
||||||
# self.dispatch_event('on_exit')
|
# self.dispatch_event('on_exit')
|
||||||
pyglet.app.platform_event_loop.stop()
|
pyglet.app.platform_event_loop.stop()
|
||||||
@ -316,7 +316,7 @@ class ClientWindow(Window):
|
|||||||
|
|
||||||
@_call_screen_after
|
@_call_screen_after
|
||||||
def on_message(self, message: line.CommandLine.text):
|
def on_message(self, message: line.CommandLine.text):
|
||||||
self.logger.info(tr.lang('window', 'message.text').format(message))
|
self.logger.info(tr().window.message.text.format(message))
|
||||||
|
|
||||||
"""
|
"""
|
||||||
keyboard and mouse input
|
keyboard and mouse input
|
||||||
@ -357,16 +357,16 @@ class ClientWindow(Window):
|
|||||||
@_call_screen_after
|
@_call_screen_after
|
||||||
def on_mouse_press(self, x, y, button, modifiers) -> None:
|
def on_mouse_press(self, x, y, button, modifiers) -> None:
|
||||||
self.logger.debug(
|
self.logger.debug(
|
||||||
tr.lang('window', 'mouse.press').format(
|
tr().window.mouse.press().format(
|
||||||
[x, y], tr.lang('window', f'mouse.{mouse.buttons_string(button)}')
|
[x, y], tr().window.mouse[mouse.buttons_string(button)]()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@_call_screen_after
|
@_call_screen_after
|
||||||
def on_mouse_release(self, x, y, button, modifiers) -> None:
|
def on_mouse_release(self, x, y, button, modifiers) -> None:
|
||||||
self.logger.debug(
|
self.logger.debug(
|
||||||
tr.lang('window', 'mouse.release').format(
|
tr().window.mouse.release().format(
|
||||||
[x, y], tr.lang('window', f'mouse.{mouse.buttons_string(button)}')
|
[x, y], tr().window.mouse[mouse.buttons_string(button)]()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -377,12 +377,12 @@ class ClientWindow(Window):
|
|||||||
key.MOD_SCROLLLOCK)):
|
key.MOD_SCROLLLOCK)):
|
||||||
self.dispatch_event('on_close')
|
self.dispatch_event('on_close')
|
||||||
self.logger.debug(
|
self.logger.debug(
|
||||||
tr.lang('window', 'key.press').format(key.symbol_string(symbol), key.modifiers_string(modifiers)))
|
tr().window.key.press().format(key.symbol_string(symbol), key.modifiers_string(modifiers)))
|
||||||
|
|
||||||
@_call_screen_after
|
@_call_screen_after
|
||||||
def on_key_release(self, symbol, modifiers) -> None:
|
def on_key_release(self, symbol, modifiers) -> None:
|
||||||
self.logger.debug(
|
self.logger.debug(
|
||||||
tr.lang('window', 'key.release').format(key.symbol_string(symbol), key.modifiers_string(modifiers)))
|
tr().window.key.release().format(key.symbol_string(symbol), key.modifiers_string(modifiers)))
|
||||||
|
|
||||||
@_call_screen_after
|
@_call_screen_after
|
||||||
def on_file_drop(self, x, y, paths):
|
def on_file_drop(self, x, y, paths):
|
||||||
@ -391,30 +391,30 @@ class ClientWindow(Window):
|
|||||||
@_call_screen_after
|
@_call_screen_after
|
||||||
def on_text(self, text):
|
def on_text(self, text):
|
||||||
if text == '\r':
|
if text == '\r':
|
||||||
self.logger.debug(tr.lang('window', 'text.new_line'))
|
self.logger.debug(tr().window.text.new_line())
|
||||||
else:
|
else:
|
||||||
self.logger.debug(tr.lang('window', 'text.input').format(text))
|
self.logger.debug(tr().window.text.input().format(text))
|
||||||
if text == 't':
|
if text == 't':
|
||||||
self.input_box.enabled = True
|
self.input_box.enabled = True
|
||||||
|
|
||||||
@_call_screen_after
|
@_call_screen_after
|
||||||
def on_text_motion(self, motion):
|
def on_text_motion(self, motion):
|
||||||
motion_string = key.motion_string(motion)
|
motion_string = key.motion_string(motion)
|
||||||
self.logger.debug(tr.lang('window', 'text.motion').format(motion_string))
|
self.logger.debug(tr().window.text.motion.format(motion_string)())
|
||||||
|
|
||||||
@_call_screen_after
|
@_call_screen_after
|
||||||
def on_text_motion_select(self, motion):
|
def on_text_motion_select(self, motion):
|
||||||
motion_string = key.motion_string(motion)
|
motion_string = key.motion_string(motion)
|
||||||
self.logger.debug(tr.lang('window', 'text.motion_select').format(motion_string))
|
self.logger.debug(tr().window.text.motion_select.format(motion_string)())
|
||||||
|
|
||||||
@_call_screen_before
|
@_call_screen_before
|
||||||
def on_close(self, source: str = 'window') -> None:
|
def on_close(self, source: str = 'window') -> None:
|
||||||
self.logger.info(tr.lang('window', 'game.stop_get').format(tr.lang('window', f'game.{source}_stop')))
|
self.logger.info(tr().window.game.stop_get().format(tr().game[source]))
|
||||||
self.logger.info(tr.lang('window', 'game.stop'))
|
self.logger.info(tr().window.game.stop())
|
||||||
self.fps_log.check_list = False
|
self.fps_log.check_list = False
|
||||||
DR_runtime.running = False
|
DR_runtime.running = False
|
||||||
if self.run_input:
|
if self.run_input:
|
||||||
self.run_input = False
|
self.run_input = False
|
||||||
self.save_info()
|
self.save_info()
|
||||||
super().on_close()
|
super().on_close()
|
||||||
self.logger.info(tr.lang('window', 'game.end'))
|
self.logger.info(tr().window.game.end())
|
||||||
|
@ -49,8 +49,8 @@ class Game:
|
|||||||
os.mkdir('logs')
|
os.mkdir('logs')
|
||||||
logging.config.dictConfig(log_config)
|
logging.config.dictConfig(log_config)
|
||||||
self.logger = logging.getLogger('main')
|
self.logger = logging.getLogger('main')
|
||||||
self.logger.info(tr['main']['logger.mkdir'])
|
self.logger.info(tr().main.logger.mkdir())
|
||||||
self.logger.info(tr['main']['logger.created'])
|
self.logger.info(tr().main.logger.created())
|
||||||
# version check
|
# version check
|
||||||
self.python_version_check()
|
self.python_version_check()
|
||||||
self.setup()
|
self.setup()
|
||||||
@ -60,12 +60,12 @@ class Game:
|
|||||||
self.server = server.Server(net_mode='local')
|
self.server = server.Server(net_mode='local')
|
||||||
|
|
||||||
def python_version_check(self) -> None: # best 3.8+ and write at 3.8.10
|
def python_version_check(self) -> None: # best 3.8+ and write at 3.8.10
|
||||||
self.logger.info(f"{tr().main['version.now_on']} {self.on_python_v}")
|
self.logger.info(f"{tr().main.version.now_on()} {self.on_python_v}")
|
||||||
if self.on_python_v_info[0] == 2:
|
if self.on_python_v_info[0] == 2:
|
||||||
self.logger.critical(f"{tr['main']['version.need3+']}")
|
self.logger.critical(tr().main.version.need3p())
|
||||||
raise SystemError(f"{tr['main']['version.need3+']}")
|
raise SystemError(tr().main.version.need3p())
|
||||||
elif self.on_python_v_info[1] < 8:
|
elif self.on_python_v_info[1] < 8:
|
||||||
warning = tools.name_handler(tr['main']['version.best3.8+'])
|
warning = tools.name_handler(tr.main.version.best38p())
|
||||||
self.logger.warning(warning)
|
self.logger.warning(warning)
|
||||||
|
|
||||||
# @new_thread('main')
|
# @new_thread('main')
|
||||||
|
@ -37,7 +37,7 @@ class Server:
|
|||||||
self.config = tools.load_file('configs/main.toml')
|
self.config = tools.load_file('configs/main.toml')
|
||||||
# self.dev = Dev
|
# self.dev = Dev
|
||||||
# self.net_mode = net_mode
|
# self.net_mode = net_mode
|
||||||
self.logger.info(tr.lang('server', 'setup.done'))
|
self.logger.info(tr().server.setup.done())
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.logger.info(tr.lang('server', 'os.pid_is').format(os.getpid(), os.getppid()))
|
self.logger.info(tr().server.os.pid_is().format(os.getpid(), os.getppid()))
|
||||||
|
@ -24,7 +24,7 @@ from Difficult_Rocket.exception.language import *
|
|||||||
@dataclass
|
@dataclass
|
||||||
class TranslateConfig:
|
class TranslateConfig:
|
||||||
raise_error: bool = False # 引用错误时抛出错误
|
raise_error: bool = False # 引用错误时抛出错误
|
||||||
crack_normal: bool = False # 出现错误引用后 将引用到的正确内容替换为引用路径
|
crack_normal: bool = True # 出现错误引用后 将引用到的正确内容替换为引用路径
|
||||||
insert_crack: bool = True # 加入引用的错误内容
|
insert_crack: bool = True # 加入引用的错误内容
|
||||||
is_final: bool = False # 是否为最终内容
|
is_final: bool = False # 是否为最终内容
|
||||||
keep_get: bool = True # 引用错误后是否继续引用
|
keep_get: bool = True # 引用错误后是否继续引用
|
||||||
@ -112,18 +112,18 @@ class Translates:
|
|||||||
if self.config.always_copy:
|
if self.config.always_copy:
|
||||||
return Translates(value=cache_value, config=self.config, get_list=self.get_list)
|
return Translates(value=cache_value, config=self.config, get_list=self.get_list)
|
||||||
self.value = cache_value
|
self.value = cache_value
|
||||||
return self
|
|
||||||
except (KeyError, TypeError, AttributeError) as e:
|
except (KeyError, TypeError, AttributeError) as e:
|
||||||
self.get_list.append((False, item))
|
self.get_list.append((False, item))
|
||||||
self._raise_no_value(e, item)
|
self._raise_no_value(e, item)
|
||||||
if not self.config.keep_get:
|
if not self.config.keep_get:
|
||||||
self.config.is_final = True
|
self.config.is_final = True
|
||||||
|
return self
|
||||||
|
|
||||||
def __call__(self, *args, **kwargs):
|
def __call__(self, *args, **kwargs) -> Union[dict, list, int, str]:
|
||||||
if len(self.get_list) == 0:
|
if len(self.get_list) == 0:
|
||||||
return self
|
return self.__str__()
|
||||||
if any([x[0] for x in self.get_list]):
|
if any([x[0] for x in self.get_list]):
|
||||||
return
|
return self.__str__()
|
||||||
|
|
||||||
def copy(self):
|
def copy(self):
|
||||||
return self.__copy__()
|
return self.__copy__()
|
||||||
@ -132,12 +132,14 @@ class Translates:
|
|||||||
return Translates(value=self.value, config=self.config, get_list=self.get_list)
|
return Translates(value=self.value, config=self.config, get_list=self.get_list)
|
||||||
|
|
||||||
def __getattr__(self, item: key_type) -> "Translates":
|
def __getattr__(self, item: key_type) -> "Translates":
|
||||||
if self.config.is_final and hasattr(self.value, item):
|
if (self.config.is_final or any(x[0] for x in self.get_list)) and hasattr(self.value, item):
|
||||||
return getattr(self.value, item)
|
return getattr(self.value, item)
|
||||||
# 实际上我这里完全不需要处理正常需求,因为 __getattribute__ 已经帮我处理过了
|
# 实际上我这里完全不需要处理正常需求,因为 __getattribute__ 已经帮我处理过了
|
||||||
return self.__getitem__(item)
|
return self.__getitem__(item)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
if not any(not x[0] for x in self.get_list):
|
||||||
|
return self.value
|
||||||
if self.config.crack_normal:
|
if self.config.crack_normal:
|
||||||
return f'{".".join(f"{gets[1]}({gets[0]})" for gets in self.get_list)}'
|
return f'{".".join(f"{gets[1]}({gets[0]})" for gets in self.get_list)}'
|
||||||
elif self.config.insert_crack:
|
elif self.config.insert_crack:
|
||||||
@ -172,7 +174,7 @@ class Tr:
|
|||||||
else:
|
else:
|
||||||
return self.default_translate[items]
|
return self.default_translate[items]
|
||||||
|
|
||||||
def lang(self, *items):
|
def lang(self, *items) -> Translates:
|
||||||
cache = self.translates_cache.copy()
|
cache = self.translates_cache.copy()
|
||||||
for item in items:
|
for item in items:
|
||||||
cache = cache[item]
|
cache = cache[item]
|
||||||
|
@ -43,9 +43,6 @@ libs.local = "using local pyglet, version: {}"
|
|||||||
libs.outer = "using global pyglet, version: {}\n(may cause bug)"
|
libs.outer = "using global pyglet, version: {}\n(may cause bug)"
|
||||||
fonts.found = "found fonts in font lib: {}"
|
fonts.found = "found fonts in font lib: {}"
|
||||||
fonts.load = "loading fonts: {}"
|
fonts.load = "loading fonts: {}"
|
||||||
game.input_stop = "console"
|
|
||||||
game.command_stop = "in game commands"
|
|
||||||
game.window_stop = "window"
|
|
||||||
game.stop_get = "Received closing commands from {}, game closing"
|
game.stop_get = "Received closing commands from {}, game closing"
|
||||||
game.stop = "game closing, saving data……"
|
game.stop = "game closing, saving data……"
|
||||||
game.end = "game closed"
|
game.end = "game closed"
|
||||||
@ -55,4 +52,6 @@ setup.done = "Server loaded "
|
|||||||
os.pid_is = "Server PID: {} PPID: {}"
|
os.pid_is = "Server PID: {} PPID: {}"
|
||||||
|
|
||||||
[game]
|
[game]
|
||||||
|
input = "console"
|
||||||
|
command = "in game commands"
|
||||||
|
window = "window"
|
||||||
|
@ -43,9 +43,6 @@ libs.local = "正在使用本地 pyglet 库 版本为: {}"
|
|||||||
libs.outer = "正在使用全局 pyglet 库 版本为: {}\n(可能会造成bug,因为本地库版本为2.0dev9)"
|
libs.outer = "正在使用全局 pyglet 库 版本为: {}\n(可能会造成bug,因为本地库版本为2.0dev9)"
|
||||||
fonts.found = "在字体列表中找到以下字体库: {}"
|
fonts.found = "在字体列表中找到以下字体库: {}"
|
||||||
fonts.load = "正在加载字体: {}"
|
fonts.load = "正在加载字体: {}"
|
||||||
game.input_stop = "控制台"
|
|
||||||
game.command_stop = "游戏内命令行"
|
|
||||||
game.window_stop = "窗口"
|
|
||||||
game.stop_get = "从{}传入关闭指令,关闭游戏中"
|
game.stop_get = "从{}传入关闭指令,关闭游戏中"
|
||||||
game.stop = "游戏正在关闭,保存数据中···"
|
game.stop = "游戏正在关闭,保存数据中···"
|
||||||
game.end = "游戏已经关闭"
|
game.end = "游戏已经关闭"
|
||||||
@ -55,4 +52,6 @@ setup.done = "服务端载入完成"
|
|||||||
os.pid_is = "服务端 PID: {} PPID: {}"
|
os.pid_is = "服务端 PID: {} PPID: {}"
|
||||||
|
|
||||||
[game]
|
[game]
|
||||||
|
input = "控制台"
|
||||||
|
command = "游戏内命令行"
|
||||||
|
window = "窗口"
|
||||||
|
Loading…
Reference in New Issue
Block a user