0.6.0 comming!

This commit is contained in:
沈瑗杰 2021-10-25 22:08:00 +08:00
parent b45b041d23
commit 82e8c4a062
8 changed files with 170 additions and 46 deletions

View File

@ -14,7 +14,7 @@ gitee: @shenjackyuanjie
import math import math
import decimal import decimal
from typing import List, Optional from typing import List, Optional, Union
from decimal import Decimal from decimal import Decimal
@ -283,18 +283,26 @@ class ScientificNumber:
""" """
def __init__(self, def __init__(self,
floats: Optional[float] = 1.0, 小数: Union[float, Decimal] = 1.0,
integer: Optional[int] = 0, 指数: int = 0,
multi_unit: list = None, 乘单位: list = list,
divide_unit: list = None): 除单位: list = list):
if divide_unit is None: if not isinstance(小数, Decimal):
self.divide_unit = [] self.小数 = Decimal(小数)
else: else:
self.divide_unit = divide_unit self.小数 = 小数
if multi_unit is None: self.指数 = 指数
self.multi_unit = [] self.乘单位 = 乘单位
else: self.除单位 = 除单位
self.multi_unit = multi_unit self.check()
self.floats = floats
self.integer = integer def check(self):
while self.小数 > 10:
self.小数 /= 10
self.指数 += 1
while self.小数 < 1:
self.小数 *= 10
self.指数 -= 1
self.除单位.sort()
self.乘单位.sort()

View File

@ -13,9 +13,12 @@ gitee: @shenjackyuanjie
import time import time
from typing import Union
from decimal import Decimal
# from DR # from DR
from Difficult_Rocket.api import translate from . import translate
from Difficult_Rocket.api.new_thread import new_thread from .new_thread import new_thread
# from libs.pyglet # from libs.pyglet
from libs import pyglet from libs import pyglet
@ -49,7 +52,7 @@ class CommandLine(widgets.WidgetBase):
# normal values # normal values
self.length = length self.length = length
self.command_list = ['' for line in range(length)] self.command_list = ['' for line in range(length)]
self.command_text = command_text self._command_text = command_text
self._text_position = 0 self._text_position = 0
self._command_view = 0 self._command_view = 0
self._value = 0 self._value = 0
@ -78,7 +81,7 @@ class CommandLine(widgets.WidgetBase):
color = (100, 100, 100, 100) color = (100, 100, 100, 100)
self._pad = p = 5 self._pad = p = 5
self._outline = pyglet.shapes.Rectangle(x=x - p, y=y - p, self._outline = pyglet.shapes.Rectangle(x=x - p, y=y - p,
width=width + p + p, height=height + p + p, width=width + p, height=height + p,
color=color[:3], color=color[:3],
batch=batch, group=fg_group) batch=batch, group=fg_group)
self._outline.opacity = color[3] self._outline.opacity = color[3]
@ -135,7 +138,7 @@ class CommandLine(widgets.WidgetBase):
pass pass
else: # move downwards else: # move downwards
pass pass
self._command_view = value # self._command_view = value
@property @property
def editing(self): def editing(self):
@ -157,16 +160,22 @@ class CommandLine(widgets.WidgetBase):
if self._label[0].visible and not self.editing: if self._label[0].visible and not self.editing:
self._label[0].visible = False self._label[0].visible = False
"""
events
"""
def on_text(self, text): def on_text(self, text):
if self.editing: if self.editing:
if text in ('\r', '\n'): # goto a new line if text in ('\r', '\n'): # goto a new line
if not self.text: if not self.text:
pass pass
elif self.text[0] == self.command_text: elif self.text[0] == self._command_text:
self.dispatch_event('on_command', self.text[1:]) self.dispatch_event('on_command', self.text[1:])
else: else:
self.dispatch_event('on_message', self.text) self.dispatch_event('on_message', self.text)
self.command_view = -1 # on_message 和 on_command 可能会覆盖 self.text 需要再次判定
if self.text:
self.command_view = -1
self.editing = False self.editing = False
self.wait(1) self.wait(1)
else: else:
@ -204,7 +213,6 @@ class CommandLine(widgets.WidgetBase):
self.command_view -= 1 self.command_view -= 1
else: else:
pass pass
print(self._text_position)
def on_text_motion_select(self, motion): def on_text_motion_select(self, motion):
if self.editing: if self.editing:
@ -218,6 +226,10 @@ class CommandLine(widgets.WidgetBase):
if self.editing: if self.editing:
pass pass
"""
custom event
"""
def on_command(self, command: text): def on_command(self, command: text):
if self.editing: if self.editing:
return return
@ -228,6 +240,13 @@ class CommandLine(widgets.WidgetBase):
return return
"""give message to it""" """give message to it"""
def push_line(self, line: Union[str, int, float, Decimal], block_line: bool = False):
_text = self.text
self.text = str(line)
self.command_view = -1
if not block_line:
self.text = _text
CommandLine.register_event_type('on_command') CommandLine.register_event_type('on_command')
CommandLine.register_event_type('on_message') CommandLine.register_event_type('on_message')

View File

@ -16,6 +16,7 @@ import os
import sys import sys
import time import time
import logging import logging
import traceback
import configparser import configparser
from decimal import Decimal from decimal import Decimal
@ -25,10 +26,9 @@ if __name__ == '__main__': # been start will not run this
sys.path.append('/bin') sys.path.append('/bin')
# Difficult_Rocket function # Difficult_Rocket function
from . import guis
from .api import command from .api import command
from .api.Exp import *
from .api.translate import tr from .api.translate import tr
from .fps.fps_log import FpsLogger
from .api import tools, new_thread, translate from .api import tools, new_thread, translate
# libs function # libs function
@ -103,6 +103,8 @@ class ClientWindow(pyglet.window.Window):
self.max_fps = [self.FPS, time.time()] self.max_fps = [self.FPS, time.time()]
self.min_fps = [self.FPS, time.time()] self.min_fps = [self.FPS, time.time()]
self.fps_wait = 5 self.fps_wait = 5
self.fps_log = FpsLogger(stable_fps=int(self.FPS),
wait_time=5)
# batch # batch
self.part_batch = pyglet.graphics.Batch() self.part_batch = pyglet.graphics.Batch()
self.label_batch = pyglet.graphics.Batch() self.label_batch = pyglet.graphics.Batch()
@ -137,20 +139,19 @@ class ClientWindow(pyglet.window.Window):
def setup(self): def setup(self):
self.load_fonts().join() self.load_fonts().join()
# print(pyglet.font.load(translate.鸿蒙简体))
@new_thread('client load_fonts') @new_thread('window load_fonts')
def load_fonts(self): def load_fonts(self):
file_path = './libs/fonts/HarmonyOS_Sans/' file_path = './libs/fonts/HarmonyOS_Sans/'
ttf_files = os.listdir(file_path) ttf_files = os.listdir(file_path)
self.logger.info(tr.lang('window', 'fonts.found').format(ttf_files)) self.logger.info(tr.lang('window', 'fonts.found').format(ttf_files))
for ttf_folder in ttf_files: for ttf_folder in ttf_files:
for ttf_file in os.listdir(f'{file_path}{ttf_folder}'): for ttf_file in os.listdir(f'{file_path}{ttf_folder}'):
if not ttf_file[-4:] == '.ttf': continue if not ttf_file[-4:] == '.ttf':
continue
pyglet.font.add_file(f'{file_path}{ttf_folder}/{ttf_file}') pyglet.font.add_file(f'{file_path}{ttf_folder}/{ttf_file}')
# print(f'{file_path}{ttf_file}')
# @new_thread('client load_editor') # @new_thread('window load_editor')
def load_Editor(self): def load_Editor(self):
pass pass
@ -159,27 +160,37 @@ class ClientWindow(pyglet.window.Window):
self.read_input() self.read_input()
pyglet.app.run() pyglet.app.run()
@new_thread('read_input', daemon=True) @new_thread('window read_input', daemon=True)
def read_input(self): def read_input(self):
self.logger.debug('read_input start') self.logger.debug('read_input start')
while self.run_input: while self.run_input:
self.logger.info('<<<')
get = input() get = input()
if get in ('', ' ', '\n', '\r'): if get in ('', ' ', '\n', '\r'):
continue continue
self.logger.info(get)
if get == 'stop': if get == 'stop':
self.run_input = False self.run_input = False
self.dispatch_event('on_close', 'a') # source = 'command' try:
self.on_command(get)
except:
self.logger.error(traceback.format_exc())
self.logger.debug('read_input end') self.logger.debug('read_input end')
@new_thread('window save_info')
def save_info(self):
config_file = configparser.ConfigParser()
config_file.read('configs/main.config')
config_file['window']['width'] = str(self.width)
config_file['window']['height'] = str(self.height)
config_file.write(open('configs/main.config', 'w', encoding='utf-8'))
""" """
draws and some event draws and some event
""" """
def update(self, tick: float): def update(self, tick: float):
decimal_tick = Decimal(tick) decimal_tick = Decimal(str(tick)[:10])
self.FPS_update(decimal_tick) self.FPS_update(decimal_tick)
self.fps_log.update_tick(Decimal(tick))
def FPS_update(self, tick: Decimal): def FPS_update(self, tick: Decimal):
now_FPS = pyglet.clock.get_fps() now_FPS = pyglet.clock.get_fps()
@ -214,6 +225,16 @@ class ClientWindow(pyglet.window.Window):
self.logger.info(tr.lang('window', 'command.text').format(command)) self.logger.info(tr.lang('window', 'command.text').format(command))
if command == 'stop': if command == 'stop':
self.dispatch_event('on_close', 'command') # source = command self.dispatch_event('on_close', 'command') # source = command
elif command == 'log_tick':
self.logger.debug(self.fps_log.fps_list)
elif command == 'max_fps':
self.logger.info(self.fps_log.max_fps)
self.command.push_line(self.fps_log.max_fps, block_line=True)
elif command == 'min_fps':
self.logger.info(self.fps_log.min_fps)
self.command.push_line(self.fps_log.min_fps, block_line=True)
elif command == 'default':
self.set_size(int(self.config_file['window_default']['width']), int(self.config_file['window_default']['height']))
def on_message(self, message: command.CommandLine.text): def on_message(self, message: command.CommandLine.text):
self.logger.info(tr.lang('window', 'message.text').format(message)) self.logger.info(tr.lang('window', 'message.text').format(message))
@ -263,10 +284,6 @@ class ClientWindow(pyglet.window.Window):
self.logger.info(tr.lang('window', 'game.stop')) self.logger.info(tr.lang('window', 'game.stop'))
if self.run_input: if self.run_input:
self.run_input = False self.run_input = False
config_file = configparser.ConfigParser() self.save_info()
config_file.read('configs/main.config')
config_file['window']['width'] = str(self.width)
config_file['window']['height'] = str(self.height)
config_file.write(open('configs/main.config', 'w', encoding='utf-8'))
super().on_close() super().on_close()
self.logger.info(tr.lang('window', 'game.end')) self.logger.info(tr.lang('window', 'game.end'))

View 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
"""

View File

@ -0,0 +1,55 @@
# -------------------------------
# Difficult Rocket
# Copyright © 2021 by shenjackyuanjie
# All rights reserved
# -------------------------------
"""
writen by shenjackyuanjie
mail: 3695888@qq.com
github: @shenjackyuanjie
gitee: @shenjackyuanjie
"""
import time
import decimal
from decimal import Decimal
from libs import pyglet
"""
fps_list ->
[
[fps, time_ns, tick time_ns, pyglet tick]
]
"""
class FpsLogger:
def __init__(self,
stable_fps: int = 60,
wait_time: int = 5):
self.stable_fps = stable_fps
self.wait_time = wait_time
self.fps_list = [[stable_fps, time.time_ns()]]
def update_tick(self,
tick: Decimal):
now_time = time.time_ns()
now_fps = pyglet.clock.get_fps()
tick_time = now_time - self.fps_list[-1][1]
self.fps_list.append([now_fps, now_time, tick_time, tick])
if now_time - self.fps_list[0][1] >= self.wait_time * (10 ** 9):
self.fps_list.pop(0)
@property
def max_fps(self):
fps_list = [fpss[0] for fpss in self.fps_list]
return max(fps_list)
@property
def min_fps(self):
fps_list = [fpss[0] for fpss in self.fps_list]
return min(fps_list)

View File

@ -35,7 +35,7 @@
}, },
'loggers': { 'loggers': {
'client': { 'client': {
'level': 'DEBUG', 'level': 'INFO',
'handlers': [] 'handlers': []
}, },
'server': { 'server': {

View File

@ -1,14 +1,14 @@
[runtime] [runtime]
fps = 60 fps = 60
version = 0.5.2 version = 0.6.0
language = zh-CN language = zh-CN
date_fmt = %%Y-%%m-%%d %%H-%%M-%%S date_fmt = %%Y-%%m-%%d %%H-%%M-%%S
write_py_v = 3.8.10 write_py_v = 3.8.10
[window] [window]
style = None style = None
width = 1217 width = 1024
height = 896 height = 768
visible = true visible = true
caption = Difficult Rocket {version} caption = Difficult Rocket {version}
resizable = true resizable = true

View File

@ -3,20 +3,23 @@
## Readme ## Readme
##### most badge can be clicked and jump ##### most badge can be clicked and jump
[![Generic badge](https://img.shields.io/badge/SemVer-2.0.0-blue.svg)](https://Semver.org/) [![Generic badge](https://img.shields.io/badge/SemVer-2.0.0-blue.svg)](https://Semver.org/)
![Generic badge](https://img.shields.io/badge/Version-0.5.3-yellow.svg) ![Generic badge](https://img.shields.io/badge/Version-0.6.0-yellow.svg)
- [![Readme-github](https://img.shields.io/badge/Readme-Github-blue.svg?style=flat-square&logo=Github)](https://github.com/shenjackyuanjie/Difficult-Rocket) - [![Readme-github](https://img.shields.io/badge/Readme-Github-blue.svg?style=flat-square&logo=Github)](https://github.com/shenjackyuanjie/Difficult-Rocket)
- [![Readme-gitee](https://img.shields.io/badge/Readme-Gitee-blue.svg?style=flat-square&logo=Gitee)](https://gitee.com/shenjackyuanjie/Difficult-Rocket) - [![Readme-gitee](https://img.shields.io/badge/Readme-Gitee-blue.svg?style=flat-square&logo=Gitee)](https://gitee.com/shenjackyuanjie/Difficult-Rocket)
- [![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
## 202110 V 0.5.3 ## 20211025 V 0.6.0
#### Command Line Update!
### Change ### Change
- now `Difficult Rocket` will only fit python3.8+ - now `Difficult Rocket` will only fit python3.8+
- because `:=` - because `:=`
- now main crash report handler have new way to handler crash - now main crash report handler have new way to handler crash
- now fonts' folder's name is `HarmonyOS_Sans`
### Add ### Add
@ -29,6 +32,7 @@
- `translate/Lang.翻译` same as `Lang.lang` - `translate/Lang.翻译` same as `Lang.lang`
- `command/CommandLine` to render command line - `command/CommandLine` to render command line
- `@new_thread` now can option if log this thread to `crash` or not - `@new_thread` now can option if log this thread to `crash` or not
- `start.cmd` witch could debug easier
### Translate ### Translate
@ -54,7 +58,16 @@
- now you can press `t` to call out a message window - now you can press `t` to call out a message window
- or press `/` to open command line - or press `/` to open command line
- not done - not done
- useless until now - ~~useless until now~~
- new command
- `/min_fps`
- get min fps in 5 second
- `/max_fps`
- get max fps in 5 second
- `/stop`
- stop the game
- `/default`
- switch window size to default size
## 20210928 V 0.5.2 ## 20210928 V 0.5.2