From 65a0260d917abac7311471f45ec37260b8edba72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E7=91=97=E6=9D=B0?= <3695888@qq.com> Date: Thu, 28 Oct 2021 06:43:35 +0800 Subject: [PATCH] commiting 0.6.1 --- Difficult_Rocket.py | 4 +-- Difficult_Rocket/api/__init__.py | 1 - Difficult_Rocket/client.py | 22 ++++-------- Difficult_Rocket/command/__init__.py | 12 +++++++ Difficult_Rocket/{api => command}/command.py | 37 ++++++++++++++------ Difficult_Rocket/fps/fps_log.py | 9 +++++ configs/logger.json5 | 2 +- docs/update_logs.md | 6 ++++ libs/pyglet/text/__init__.py | 4 +-- 9 files changed, 65 insertions(+), 32 deletions(-) create mode 100644 Difficult_Rocket/command/__init__.py rename Difficult_Rocket/{api => command}/command.py (86%) diff --git a/Difficult_Rocket.py b/Difficult_Rocket.py index bb4f8fb..881f08d 100644 --- a/Difficult_Rocket.py +++ b/Difficult_Rocket.py @@ -54,7 +54,8 @@ if __name__ == '__main__': print(error_format['error.happen']) error = traceback.format_exc() - if (name := type(exp).__name__) in error_format: + name = type(exp).__name__ + if name in error_format: print(error_format[name]) else: print(error_format['error.unknown']) @@ -64,4 +65,3 @@ if __name__ == '__main__': crash.record_thread = False print(crash.all_thread) print(crash.all_process) - sys.exit(1) diff --git a/Difficult_Rocket/api/__init__.py b/Difficult_Rocket/api/__init__.py index 6dceff4..9773e98 100644 --- a/Difficult_Rocket/api/__init__.py +++ b/Difficult_Rocket/api/__init__.py @@ -19,7 +19,6 @@ from .new_thread import new_thread # lazy之后之前全部导入的(太多了写不动__all__了) from .Exp import * from .tools import * -from .command import * from .calculation import * from .scientific_unit import * diff --git a/Difficult_Rocket/client.py b/Difficult_Rocket/client.py index 990e769..cf5c188 100644 --- a/Difficult_Rocket/client.py +++ b/Difficult_Rocket/client.py @@ -26,7 +26,7 @@ if __name__ == '__main__': # been start will not run this sys.path.append('/bin') # Difficult_Rocket function -from .api import command +from .command import command from .api.translate import tr from .fps.fps_log import FpsLogger from .api import tools, new_thread, translate @@ -93,16 +93,13 @@ class ClientWindow(pyglet.window.Window): pyglet.resource.reindex() self.config_file = tools.load_file('configs/main.config') self.game_config = tools.load_file('configs/game.config') - self.FPS = Decimal(int(self.config_file['runtime']['fps'])) - self.SPF = Decimal('1') / self.FPS # dic self.environment = {} self.textures = {} # all textures self.runtime = {} # FPS - self.max_fps = [self.FPS, time.time()] - self.min_fps = [self.FPS, time.time()] - self.fps_wait = 5 + self.FPS = Decimal(int(self.config_file['runtime']['fps'])) + self.SPF = Decimal('1') / self.FPS self.fps_log = FpsLogger(stable_fps=int(self.FPS), wait_time=5) # batch @@ -194,16 +191,9 @@ class ClientWindow(pyglet.window.Window): def FPS_update(self, tick: Decimal): now_FPS = pyglet.clock.get_fps() - if now_FPS > self.max_fps[0]: - self.max_fps = [now_FPS, time.time()] - elif now_FPS < self.min_fps[0]: - self.min_fps = [now_FPS, time.time()] - else: - if (time.time() - self.max_fps[1]) > self.fps_wait: - self.max_fps = [self.FPS, time.time()] - elif (time.time() - self.min_fps[1]) > self.fps_wait: - self.min_fps = [self.FPS, time.time()] - self.fps_label.text = 'FPS: {:.1f} {:.1f} ({:.1f}/{:.1f}) | MSPF: {:.5f} '.format(now_FPS, 1 / tick, self.max_fps[0], self.min_fps[0], tick) + self.fps_log.update_tick(tick) + # self.fps_label.text = 'FPS: {:5.1f} {:.1f} ({:.1f}/{:.1f}) | MSPF: {:.5f} '.format(now_FPS, 1 / tick, self.fps_log.max_fps, self.fps_log.min_fps, tick) + self.fps_label.text = f'FPS: {now_FPS:>10.1f} {now_FPS:.1f} {self.fps_log.max_fps:>5.1f} {self.fps_log.min_fps:>5.1f}' def on_draw(self): self.clear() diff --git a/Difficult_Rocket/command/__init__.py b/Difficult_Rocket/command/__init__.py new file mode 100644 index 0000000..0b6df53 --- /dev/null +++ b/Difficult_Rocket/command/__init__.py @@ -0,0 +1,12 @@ +# ------------------------------- +# Difficult Rocket +# Copyright © 2021 by shenjackyuanjie +# All rights reserved +# ------------------------------- + +""" +writen by shenjackyuanjie +mail: 3695888@qq.com +github: @shenjackyuanjie +gitee: @shenjackyuanjie +""" diff --git a/Difficult_Rocket/api/command.py b/Difficult_Rocket/command/command.py similarity index 86% rename from Difficult_Rocket/api/command.py rename to Difficult_Rocket/command/command.py index 8eeb1dd..90a2eec 100644 --- a/Difficult_Rocket/api/command.py +++ b/Difficult_Rocket/command/command.py @@ -17,8 +17,8 @@ from typing import Union from decimal import Decimal # from DR -from . import translate -from .new_thread import new_thread +from ..api import translate +from ..api.new_thread import new_thread # from libs.pyglet from libs import pyglet @@ -26,10 +26,7 @@ from libs.pyglet import font from libs.pyglet.text import Label from libs.pyglet.window import key from libs.pyglet.gui import widgets -from libs.pyglet.text.caret import Caret from libs.pyglet.graphics import Batch, Group -from libs.pyglet.text.layout import IncrementalTextLayout -from libs.pyglet.text.document import UnformattedDocument class CommandLine(widgets.WidgetBase): @@ -97,6 +94,14 @@ class CommandLine(widgets.WidgetBase): label.group = Group(order=order + 1, parent=self._user_group) self._outline.group = Group(order=order + 2, parent=self._user_group) + """ + values + """ + + @property + def value(self): + return self.text + @property def text(self): return self._text @@ -122,7 +127,7 @@ class CommandLine(widgets.WidgetBase): 实际上还有一个限制 """ assert type(value) is int, 'Command View must be integer' - assert -2 < value < self.length, f'Command View must be bigger than -1 and smaller than {self.length}' + assert -self.length < value < self.length, f'Command View must be bigger than {-self.length} and smaller than {self.length}' if value == -1: # flush command list self._label.insert(0, self._label[-1]) self._label.pop(-1) @@ -153,12 +158,24 @@ class CommandLine(widgets.WidgetBase): for label in self._label: label.visible = value - @new_thread('command wait', log_thread=False) - def wait(self, wait): + @new_thread('command wait', daemon=True, log_thread=False) + def wait(self, wait: Union[float, int] = 0): + this = self._label[0] self._label[0].visible = True time.sleep(wait) if self._label[0].visible and not self.editing: - self._label[0].visible = False + while (self._label[0].opacity >= 30) and self._label[0].visible and (self._label[0] is this) and not self.editing: + # (label 的透明度不是 0) and (label 还在显示) and (label 还是载入线程时候的那个label) and (现在不在输入新行) + self._label[0].opacity -= 2 + time.sleep(0.01) + if self._label[0] is this: # 如果结束的时候label还是这个label + self._label[0].opacity = 255 + else: # 如果不是就赶快找回来! + now = self._label.index(this) + self._label[now].opacity = 255 + if not self.editing: # 如果不在编辑再隐藏 + self._label[0].visible = False + print(self._label[0].opacity) """ events @@ -177,7 +194,7 @@ class CommandLine(widgets.WidgetBase): if self.text: self.command_view = -1 self.editing = False - self.wait(1) + self.wait() else: self.text = f'{self.text[:self._text_position]}{text}{self.text[self._text_position:]}' # 插入字符(简单粗暴) self._text_position += 1 diff --git a/Difficult_Rocket/fps/fps_log.py b/Difficult_Rocket/fps/fps_log.py index 7f905f7..94dfd0f 100644 --- a/Difficult_Rocket/fps/fps_log.py +++ b/Difficult_Rocket/fps/fps_log.py @@ -16,6 +16,8 @@ import decimal from decimal import Decimal +from ..api.new_thread import new_thread + from libs import pyglet """ @@ -34,6 +36,7 @@ class FpsLogger: self.wait_time = wait_time self.fps_list = [[stable_fps, time.time_ns()]] + # @new_thread('fps_logger update', daemon=False, log_thread=False) def update_tick(self, tick: Decimal): now_time = time.time_ns() @@ -43,6 +46,12 @@ class FpsLogger: if now_time - self.fps_list[0][1] >= self.wait_time * (10 ** 9): self.fps_list.pop(0) + def update_list(self): + now_time = time.time_ns() + for fps_time in self.fps_list: + if now_time - fps_time[1] >= self.wait_time * (10 ** 9): + del fps_time + @property def max_fps(self): fps_list = [fpss[0] for fpss in self.fps_list] diff --git a/configs/logger.json5 b/configs/logger.json5 index a602693..6fd3f07 100644 --- a/configs/logger.json5 +++ b/configs/logger.json5 @@ -35,7 +35,7 @@ }, 'loggers': { 'client': { - 'level': 'INFO', + 'level': 'DEBUG', 'handlers': [] }, 'server': { diff --git a/docs/update_logs.md b/docs/update_logs.md index 13fd5e0..c06f870 100644 --- a/docs/update_logs.md +++ b/docs/update_logs.md @@ -10,6 +10,12 @@ - [![Readme-gitee](https://img.shields.io/badge/Readme-中文(点我!)-blue.svg?style=flat-square)](README-cn.md) - Using [SemVer 2.0.0](https://semver.org/) to manage version +## 202111 V 0.6.1 + +### Change + +- now command will fade away but not suddenly disappear + ## 20211025 V 0.6.0 #### Command Line Update! diff --git a/libs/pyglet/text/__init__.py b/libs/pyglet/text/__init__.py index 33c4b30..aaa98a0 100644 --- a/libs/pyglet/text/__init__.py +++ b/libs/pyglet/text/__init__.py @@ -315,11 +315,11 @@ class DocumentLabel(layout.TextLayout): :type: int """ - return self.color[4] + return self.color[3] @opacity.setter def opacity(self, alpha): - if alpha != self.color[4]: + if alpha != self.color[3]: self.color = list(map(int, (*self.color[:3], alpha))) @property