commiting 0.6.1
This commit is contained in:
parent
08117406c0
commit
65a0260d91
@ -54,7 +54,8 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
print(error_format['error.happen'])
|
print(error_format['error.happen'])
|
||||||
error = traceback.format_exc()
|
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])
|
print(error_format[name])
|
||||||
else:
|
else:
|
||||||
print(error_format['error.unknown'])
|
print(error_format['error.unknown'])
|
||||||
@ -64,4 +65,3 @@ if __name__ == '__main__':
|
|||||||
crash.record_thread = False
|
crash.record_thread = False
|
||||||
print(crash.all_thread)
|
print(crash.all_thread)
|
||||||
print(crash.all_process)
|
print(crash.all_process)
|
||||||
sys.exit(1)
|
|
||||||
|
@ -19,7 +19,6 @@ from .new_thread import new_thread
|
|||||||
# lazy之后之前全部导入的(太多了写不动__all__了)
|
# lazy之后之前全部导入的(太多了写不动__all__了)
|
||||||
from .Exp import *
|
from .Exp import *
|
||||||
from .tools import *
|
from .tools import *
|
||||||
from .command import *
|
|
||||||
from .calculation import *
|
from .calculation import *
|
||||||
from .scientific_unit import *
|
from .scientific_unit import *
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ if __name__ == '__main__': # been start will not run this
|
|||||||
sys.path.append('/bin')
|
sys.path.append('/bin')
|
||||||
|
|
||||||
# Difficult_Rocket function
|
# Difficult_Rocket function
|
||||||
from .api import command
|
from .command import command
|
||||||
from .api.translate import tr
|
from .api.translate import tr
|
||||||
from .fps.fps_log import FpsLogger
|
from .fps.fps_log import FpsLogger
|
||||||
from .api import tools, new_thread, translate
|
from .api import tools, new_thread, translate
|
||||||
@ -93,16 +93,13 @@ class ClientWindow(pyglet.window.Window):
|
|||||||
pyglet.resource.reindex()
|
pyglet.resource.reindex()
|
||||||
self.config_file = tools.load_file('configs/main.config')
|
self.config_file = tools.load_file('configs/main.config')
|
||||||
self.game_config = tools.load_file('configs/game.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
|
# dic
|
||||||
self.environment = {}
|
self.environment = {}
|
||||||
self.textures = {} # all textures
|
self.textures = {} # all textures
|
||||||
self.runtime = {}
|
self.runtime = {}
|
||||||
# FPS
|
# FPS
|
||||||
self.max_fps = [self.FPS, time.time()]
|
self.FPS = Decimal(int(self.config_file['runtime']['fps']))
|
||||||
self.min_fps = [self.FPS, time.time()]
|
self.SPF = Decimal('1') / self.FPS
|
||||||
self.fps_wait = 5
|
|
||||||
self.fps_log = FpsLogger(stable_fps=int(self.FPS),
|
self.fps_log = FpsLogger(stable_fps=int(self.FPS),
|
||||||
wait_time=5)
|
wait_time=5)
|
||||||
# batch
|
# batch
|
||||||
@ -194,16 +191,9 @@ class ClientWindow(pyglet.window.Window):
|
|||||||
|
|
||||||
def FPS_update(self, tick: Decimal):
|
def FPS_update(self, tick: Decimal):
|
||||||
now_FPS = pyglet.clock.get_fps()
|
now_FPS = pyglet.clock.get_fps()
|
||||||
if now_FPS > self.max_fps[0]:
|
self.fps_log.update_tick(tick)
|
||||||
self.max_fps = [now_FPS, time.time()]
|
# 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)
|
||||||
elif now_FPS < self.min_fps[0]:
|
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}'
|
||||||
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)
|
|
||||||
|
|
||||||
def on_draw(self):
|
def on_draw(self):
|
||||||
self.clear()
|
self.clear()
|
||||||
|
12
Difficult_Rocket/command/__init__.py
Normal file
12
Difficult_Rocket/command/__init__.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# -------------------------------
|
||||||
|
# Difficult Rocket
|
||||||
|
# Copyright © 2021 by shenjackyuanjie
|
||||||
|
# All rights reserved
|
||||||
|
# -------------------------------
|
||||||
|
|
||||||
|
"""
|
||||||
|
writen by shenjackyuanjie
|
||||||
|
mail: 3695888@qq.com
|
||||||
|
github: @shenjackyuanjie
|
||||||
|
gitee: @shenjackyuanjie
|
||||||
|
"""
|
@ -17,8 +17,8 @@ from typing import Union
|
|||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
# from DR
|
# from DR
|
||||||
from . import translate
|
from ..api import translate
|
||||||
from .new_thread import new_thread
|
from ..api.new_thread import new_thread
|
||||||
|
|
||||||
# from libs.pyglet
|
# from libs.pyglet
|
||||||
from libs import pyglet
|
from libs import pyglet
|
||||||
@ -26,10 +26,7 @@ from libs.pyglet import font
|
|||||||
from libs.pyglet.text import Label
|
from libs.pyglet.text import Label
|
||||||
from libs.pyglet.window import key
|
from libs.pyglet.window import key
|
||||||
from libs.pyglet.gui import widgets
|
from libs.pyglet.gui import widgets
|
||||||
from libs.pyglet.text.caret import Caret
|
|
||||||
from libs.pyglet.graphics import Batch, Group
|
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):
|
class CommandLine(widgets.WidgetBase):
|
||||||
@ -97,6 +94,14 @@ class CommandLine(widgets.WidgetBase):
|
|||||||
label.group = Group(order=order + 1, parent=self._user_group)
|
label.group = Group(order=order + 1, parent=self._user_group)
|
||||||
self._outline.group = Group(order=order + 2, parent=self._user_group)
|
self._outline.group = Group(order=order + 2, parent=self._user_group)
|
||||||
|
|
||||||
|
"""
|
||||||
|
values
|
||||||
|
"""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def value(self):
|
||||||
|
return self.text
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def text(self):
|
def text(self):
|
||||||
return self._text
|
return self._text
|
||||||
@ -122,7 +127,7 @@ class CommandLine(widgets.WidgetBase):
|
|||||||
实际上还有一个限制
|
实际上还有一个限制
|
||||||
"""
|
"""
|
||||||
assert type(value) is int, 'Command View must be integer'
|
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
|
if value == -1: # flush command list
|
||||||
self._label.insert(0, self._label[-1])
|
self._label.insert(0, self._label[-1])
|
||||||
self._label.pop(-1)
|
self._label.pop(-1)
|
||||||
@ -153,12 +158,24 @@ class CommandLine(widgets.WidgetBase):
|
|||||||
for label in self._label:
|
for label in self._label:
|
||||||
label.visible = value
|
label.visible = value
|
||||||
|
|
||||||
@new_thread('command wait', log_thread=False)
|
@new_thread('command wait', daemon=True, log_thread=False)
|
||||||
def wait(self, wait):
|
def wait(self, wait: Union[float, int] = 0):
|
||||||
|
this = self._label[0]
|
||||||
self._label[0].visible = True
|
self._label[0].visible = True
|
||||||
time.sleep(wait)
|
time.sleep(wait)
|
||||||
if self._label[0].visible and not self.editing:
|
if self._label[0].visible and not self.editing:
|
||||||
|
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
|
self._label[0].visible = False
|
||||||
|
print(self._label[0].opacity)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
events
|
events
|
||||||
@ -177,7 +194,7 @@ class CommandLine(widgets.WidgetBase):
|
|||||||
if self.text:
|
if self.text:
|
||||||
self.command_view = -1
|
self.command_view = -1
|
||||||
self.editing = False
|
self.editing = False
|
||||||
self.wait(1)
|
self.wait()
|
||||||
else:
|
else:
|
||||||
self.text = f'{self.text[:self._text_position]}{text}{self.text[self._text_position:]}' # 插入字符(简单粗暴)
|
self.text = f'{self.text[:self._text_position]}{text}{self.text[self._text_position:]}' # 插入字符(简单粗暴)
|
||||||
self._text_position += 1
|
self._text_position += 1
|
@ -16,6 +16,8 @@ import decimal
|
|||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
|
from ..api.new_thread import new_thread
|
||||||
|
|
||||||
from libs import pyglet
|
from libs import pyglet
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -34,6 +36,7 @@ class FpsLogger:
|
|||||||
self.wait_time = wait_time
|
self.wait_time = wait_time
|
||||||
self.fps_list = [[stable_fps, time.time_ns()]]
|
self.fps_list = [[stable_fps, time.time_ns()]]
|
||||||
|
|
||||||
|
# @new_thread('fps_logger update', daemon=False, log_thread=False)
|
||||||
def update_tick(self,
|
def update_tick(self,
|
||||||
tick: Decimal):
|
tick: Decimal):
|
||||||
now_time = time.time_ns()
|
now_time = time.time_ns()
|
||||||
@ -43,6 +46,12 @@ class FpsLogger:
|
|||||||
if now_time - self.fps_list[0][1] >= self.wait_time * (10 ** 9):
|
if now_time - self.fps_list[0][1] >= self.wait_time * (10 ** 9):
|
||||||
self.fps_list.pop(0)
|
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
|
@property
|
||||||
def max_fps(self):
|
def max_fps(self):
|
||||||
fps_list = [fpss[0] for fpss in self.fps_list]
|
fps_list = [fpss[0] for fpss in self.fps_list]
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
},
|
},
|
||||||
'loggers': {
|
'loggers': {
|
||||||
'client': {
|
'client': {
|
||||||
'level': 'INFO',
|
'level': 'DEBUG',
|
||||||
'handlers': []
|
'handlers': []
|
||||||
},
|
},
|
||||||
'server': {
|
'server': {
|
||||||
|
@ -10,6 +10,12 @@
|
|||||||
- [![Readme-gitee](https://img.shields.io/badge/Readme-中文(点我!)-blue.svg?style=flat-square)](README-cn.md)
|
- [![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
|
- 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
|
## 20211025 V 0.6.0
|
||||||
|
|
||||||
#### Command Line Update!
|
#### Command Line Update!
|
||||||
|
@ -315,11 +315,11 @@ class DocumentLabel(layout.TextLayout):
|
|||||||
|
|
||||||
:type: int
|
:type: int
|
||||||
"""
|
"""
|
||||||
return self.color[4]
|
return self.color[3]
|
||||||
|
|
||||||
@opacity.setter
|
@opacity.setter
|
||||||
def opacity(self, alpha):
|
def opacity(self, alpha):
|
||||||
if alpha != self.color[4]:
|
if alpha != self.color[3]:
|
||||||
self.color = list(map(int, (*self.color[:3], alpha)))
|
self.color = list(map(int, (*self.color[:3], alpha)))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
Loading…
Reference in New Issue
Block a user