release about v0.5.1
happy lazy
This commit is contained in:
parent
c176b9bd9f
commit
f315d4f297
11
.gitignore
vendored
11
.gitignore
vendored
@ -3,15 +3,14 @@
|
|||||||
.vs/
|
.vs/
|
||||||
DR.code-workspace
|
DR.code-workspace
|
||||||
|
|
||||||
# local libs
|
|
||||||
pyglet/
|
|
||||||
pyglet
|
|
||||||
|
|
||||||
# PYCharm file
|
# PYCharm file
|
||||||
.idea/
|
.idea/
|
||||||
|
|
||||||
# log file
|
# log files
|
||||||
*.log
|
logs/
|
||||||
|
|
||||||
|
# crash report files
|
||||||
|
crash_report/
|
||||||
|
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
"""
|
"""
|
||||||
writen by shenjackyuanjie
|
writen by shenjackyuanjie
|
||||||
mail: 3695888@qq.com
|
mail: 3695888@qq.com
|
||||||
github: @shenjackyuanjie
|
github: @shenjackyuanjie
|
||||||
|
gitee: @shenjackyuanjie
|
||||||
"""
|
"""
|
||||||
from .new_thread import new_thread
|
|
||||||
from .tools import config
|
from .api import *
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'new_thread',
|
'new_thread',
|
||||||
|
'Delivery',
|
||||||
'config'
|
'config'
|
||||||
]
|
]
|
||||||
|
|
31
DR/api/Exp.py
Normal file
31
DR/api/Exp.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
"""
|
||||||
|
writen by shenjackyuanjie
|
||||||
|
mail: 3695888@qq.com
|
||||||
|
github: @shenjackyuanjie
|
||||||
|
gitee: @shenjackyuanjie
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class Error(Exception):
|
||||||
|
"""基础 Exception"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class TexturesError(Error):
|
||||||
|
"""材质相关error 包含info和textures"""
|
||||||
|
def __init__(self, info, textures):
|
||||||
|
self.info = info
|
||||||
|
self.textures = textures
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return '{}{}'.format(self.info, self.textures)
|
||||||
|
|
||||||
|
|
||||||
|
class LanguageError(Error):
|
||||||
|
"""lang文件相关error 包含info和language"""
|
||||||
|
def __init__(self, info, language):
|
||||||
|
self.info = info
|
||||||
|
self.lang = language
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return '{}{}'.format(self.info, self.lang)
|
14
DR/api/__init__.py
Normal file
14
DR/api/__init__.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
"""
|
||||||
|
writen by shenjackyuanjie
|
||||||
|
mail: 3695888@qq.com
|
||||||
|
github: @shenjackyuanjie
|
||||||
|
gitee: @shenjackyuanjie
|
||||||
|
"""
|
||||||
|
|
||||||
|
from .new_thread import new_thread
|
||||||
|
from .delivery import Delivery
|
||||||
|
from .tools import config
|
||||||
|
|
||||||
|
__all__ = ['new_thread',
|
||||||
|
'Delivery',
|
||||||
|
'config']
|
@ -1,6 +1,7 @@
|
|||||||
import functools
|
import functools
|
||||||
import inspect
|
import inspect
|
||||||
import threading
|
import threading
|
||||||
|
import time
|
||||||
from typing import Optional, Callable
|
from typing import Optional, Callable
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -38,3 +39,15 @@ def new_thread(thread_name: Optional[str or Callable] = None):
|
|||||||
return wrapper(this_is_a_function)
|
return wrapper(this_is_a_function)
|
||||||
# Use @on_new_thread with ending brackets case
|
# Use @on_new_thread with ending brackets case
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
@new_thread()
|
||||||
|
def a():
|
||||||
|
print('ah')
|
||||||
|
time.sleep(2)
|
||||||
|
print('done')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
b = a()
|
||||||
|
b.join()
|
@ -8,24 +8,26 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import math
|
import math
|
||||||
|
import xml.dom.minidom
|
||||||
|
|
||||||
import semver
|
import semver
|
||||||
import logging
|
import logging
|
||||||
import decimal
|
import decimal
|
||||||
import traceback
|
import traceback
|
||||||
import configparser
|
import configparser
|
||||||
from xml.dom.minidom import parse
|
from xml.dom.minidom import parse
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
if __name__ == '__main__': # been start will not run this
|
if __name__ == '__main__': # been start will not run this
|
||||||
sys.path.append('/bin/libs')
|
sys.path.append('/bin/libs')
|
||||||
sys.path.append('/bin')
|
sys.path.append('/bin')
|
||||||
|
|
||||||
import json5
|
import json5
|
||||||
|
import importlib
|
||||||
|
|
||||||
import configs
|
configs = importlib.import_module('configs')
|
||||||
|
|
||||||
# logger
|
# logger
|
||||||
tools_logger = logging.getLogger('part-tools')
|
tools_logger = logging.getLogger('part-tools')
|
||||||
|
|
||||||
"""
|
"""
|
||||||
file configs
|
file configs
|
||||||
"""
|
"""
|
||||||
@ -42,7 +44,7 @@ def report_file_error(filetype: str, error_type, filename: str, stack: any):
|
|||||||
tools_logger.exception(log)
|
tools_logger.exception(log)
|
||||||
|
|
||||||
|
|
||||||
def config(file_name: str, stack=None):
|
def config(file_name: str, stack=None) -> dict:
|
||||||
f_type = file_name[file_name.rfind('.') + 1:] # 从最后一个.到末尾 (截取文件格式)
|
f_type = file_name[file_name.rfind('.') + 1:] # 从最后一个.到末尾 (截取文件格式)
|
||||||
try:
|
try:
|
||||||
if (f_type == 'json5') or (f_type == 'json'):
|
if (f_type == 'json5') or (f_type == 'json'):
|
||||||
@ -152,16 +154,27 @@ def name_handler(name: str, formats: dict = None) -> str:
|
|||||||
some tools
|
some tools
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
yes = ['true', '1', 1, 1.0, True]
|
||||||
|
no = ['false', '0', 0, 0.0, False, None]
|
||||||
|
|
||||||
def format_bool(thing):
|
|
||||||
yes = ['True', 'TRUE', 'true', '1', 1, True]
|
def format_bool(thing) -> bool:
|
||||||
no = ['False', 'FALSE', 'false', '0', 0, False]
|
"""
|
||||||
if thing in yes:
|
:param thing 啥都行,只要是能传进来的都可以
|
||||||
|
|
||||||
|
如果看起来像"True" 比如 'true','1',1
|
||||||
|
就返回 True
|
||||||
|
如果看起来像"False" 比如 'false','0',0
|
||||||
|
就返回 False
|
||||||
|
都不像就 raise TypeError
|
||||||
|
感谢来自MCDReforged的各位同志《你能在MCDR群里聊除了MCDR的任何东西》
|
||||||
|
"""
|
||||||
|
if (thing in yes) or (isinstance(thing, str) and thing.lower() in yes):
|
||||||
return True
|
return True
|
||||||
elif thing in no:
|
elif (thing in no) or (isinstance(thing, str) and thing.lower() in no):
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
raise ValueError("Need a 'like bool' not anything else")
|
raise TypeError("Need a 'like bool' not a {}".format(thing))
|
||||||
|
|
||||||
|
|
||||||
level_ = ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL',
|
level_ = ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL',
|
26
DR/api/translate.py
Normal file
26
DR/api/translate.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
"""
|
||||||
|
writen by shenjackyuanjie
|
||||||
|
mail: 3695888@qq.com
|
||||||
|
github: @shenjackyuanjie
|
||||||
|
gitee: @shenjackyuanjie
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class Lang:
|
||||||
|
"""
|
||||||
|
用于创建一个对应语言的翻译类
|
||||||
|
感谢Fallen的MCDR提供idea
|
||||||
|
https://github.com/Fallen-Breath/MCDReforged
|
||||||
|
"""
|
||||||
|
def __init__(self, language: str):
|
||||||
|
self.语言 = language
|
||||||
|
self.翻译结果 = {}
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.语言
|
||||||
|
|
||||||
|
def __getitem__(self, item):
|
||||||
|
return self.翻译结果[item]
|
||||||
|
|
||||||
|
def __setitem__(self, key, value):
|
||||||
|
pass
|
@ -16,10 +16,13 @@ import pyglet
|
|||||||
from pyglet.window import key
|
from pyglet.window import key
|
||||||
from pyglet.window import mouse
|
from pyglet.window import mouse
|
||||||
|
|
||||||
import tools
|
|
||||||
import delivery
|
|
||||||
import drag_sprite
|
import drag_sprite
|
||||||
from new_thread import new_thread
|
from api import Exp
|
||||||
|
from api import tools
|
||||||
|
from api.tools import config
|
||||||
|
from api.delivery import Delivery
|
||||||
|
from api.new_thread import new_thread
|
||||||
|
# from mcdreforged.api.decorator import new_thread
|
||||||
|
|
||||||
|
|
||||||
class Client:
|
class Client:
|
||||||
@ -56,6 +59,7 @@ class Client:
|
|||||||
class ClientWindow(pyglet.window.Window):
|
class ClientWindow(pyglet.window.Window):
|
||||||
|
|
||||||
def __init__(self, dev_dic=None, dev_list=None, net_mode='local', *args, **kwargs):
|
def __init__(self, dev_dic=None, dev_list=None, net_mode='local', *args, **kwargs):
|
||||||
|
self.times = [time.time()]
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
"""
|
"""
|
||||||
:param dev_list: 共享内存
|
:param dev_list: 共享内存
|
||||||
@ -76,15 +80,17 @@ class ClientWindow(pyglet.window.Window):
|
|||||||
self.config_file = tools.config('configs/main.config')
|
self.config_file = tools.config('configs/main.config')
|
||||||
self.FPS = int(self.config_file['runtime']['fps'])
|
self.FPS = int(self.config_file['runtime']['fps'])
|
||||||
self.SPF = 1.0 / self.FPS
|
self.SPF = 1.0 / self.FPS
|
||||||
|
# lang
|
||||||
|
self.lang = tools.config('configs/lang/%s.json5' % self.config_file['runtime']['language'], 'client')
|
||||||
|
# dic
|
||||||
|
self.environment = {}
|
||||||
|
self.textures = {} # all textures
|
||||||
|
self.runtime = {}
|
||||||
|
# list
|
||||||
# FPS
|
# FPS
|
||||||
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
|
||||||
# lang
|
|
||||||
self.lang = tools.config('configs/lang/%s.json5' % self.config_file['runtime']['language'], 'client')
|
|
||||||
# dic
|
|
||||||
self.textures = {}
|
|
||||||
# list
|
|
||||||
# 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()
|
||||||
@ -96,25 +102,38 @@ class ClientWindow(pyglet.window.Window):
|
|||||||
self.info_label = pyglet.text.Label(x=10, y=self.height - 10,
|
self.info_label = pyglet.text.Label(x=10, y=self.height - 10,
|
||||||
anchor_x='left', anchor_y='top',
|
anchor_x='left', anchor_y='top',
|
||||||
batch=self.label_batch)
|
batch=self.label_batch)
|
||||||
|
self.fps_display = pyglet.window.FPSDisplay(self)
|
||||||
pyglet.clock.schedule_interval(self.update, self.SPF)
|
pyglet.clock.schedule_interval(self.update, self.SPF)
|
||||||
|
self.times.append(time.time())
|
||||||
|
self.times.append(self.times[1] - self.times[0])
|
||||||
|
self.logger.debug(self.times[2])
|
||||||
|
|
||||||
|
@new_thread('client_load_environment')
|
||||||
|
def load_environment(self) -> None:
|
||||||
|
# load parts info
|
||||||
|
self.environment['parts'] = config('configs/sys_value/parts.json5')
|
||||||
|
self.load_textures()
|
||||||
|
|
||||||
@new_thread('client_load_textures')
|
@new_thread('client_load_textures')
|
||||||
def load_textures(self):
|
def load_textures(self) -> None:
|
||||||
pass
|
# load parts
|
||||||
|
self.textures['parts'] = {}
|
||||||
|
for part in self.environment['parts']:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
self.logger.info(self.lang['os.pid_is'].format(os.getpid(), os.getppid()))
|
self.logger.info(self.lang['os.pid_is'].format(os.getpid(), os.getppid()))
|
||||||
image = pyglet.image.load('textures/Editor/PartButton.png')
|
image = pyglet.image.load('textures/Editor/PartButton.png')
|
||||||
self.textures['test'] = drag_sprite.DragSprite(10, 20, image, batch=self.label_batch, drag_by_all=False, drag_out_window=True)
|
self.textures['test'] = drag_sprite.DragSprite(10, 20, image, batch=self.label_batch, drag_by_all=False, drag_out_window=True)
|
||||||
pass
|
self.load_environment()
|
||||||
|
|
||||||
# draws
|
# draws
|
||||||
|
|
||||||
def update(self, tick):
|
def update(self, tick: float):
|
||||||
self.FPS_update()
|
self.FPS_update(tick)
|
||||||
self.hit_box_update()
|
|
||||||
|
|
||||||
def FPS_update(self):
|
def FPS_update(self, tick: float):
|
||||||
now_FPS = pyglet.clock.get_fps()
|
now_FPS = pyglet.clock.get_fps()
|
||||||
if now_FPS > self.max_fps[0]:
|
if now_FPS > self.max_fps[0]:
|
||||||
self.max_fps = [now_FPS, time.time()]
|
self.max_fps = [now_FPS, time.time()]
|
||||||
@ -125,21 +144,24 @@ class ClientWindow(pyglet.window.Window):
|
|||||||
self.max_fps = [self.FPS, time.time()]
|
self.max_fps = [self.FPS, time.time()]
|
||||||
elif (time.time() - self.min_fps[1]) > self.fps_wait:
|
elif (time.time() - self.min_fps[1]) > self.fps_wait:
|
||||||
self.min_fps = [self.FPS, time.time()]
|
self.min_fps = [self.FPS, time.time()]
|
||||||
self.info_label.text = 'now FPS: %06d \n max FPS: %02d \n min FPS: %02d' % (now_FPS, self.max_fps[0], self.min_fps[0])
|
self.info_label.text = 'FPS: {:.1f} {:.1f} ({:.1f}/{:.1f}) | MSPF: {:.5f} '.format(now_FPS, 1 / tick, self.max_fps[0], self.min_fps[0], tick)
|
||||||
|
|
||||||
def hit_box_update(self):
|
"""
|
||||||
pass
|
window draw and event
|
||||||
|
"""
|
||||||
|
|
||||||
def on_draw(self):
|
def on_draw(self):
|
||||||
self.clear()
|
self.clear()
|
||||||
self.draw_batch()
|
self.draw_batch()
|
||||||
|
|
||||||
|
def on_resize(self, width: int, height: int):
|
||||||
|
super().on_resize(width, height)
|
||||||
|
self.info_label.y = height - 10
|
||||||
|
|
||||||
def draw_batch(self):
|
def draw_batch(self):
|
||||||
self.part_batch.draw()
|
self.part_batch.draw()
|
||||||
self.label_batch.draw()
|
self.label_batch.draw()
|
||||||
|
self.fps_display.draw()
|
||||||
def draw_label(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
keyboard and mouse input
|
keyboard and mouse input
|
@ -12,7 +12,7 @@ if __name__ == '__main__': # been start will not run this
|
|||||||
sys.path.append('/bin/libs')
|
sys.path.append('/bin/libs')
|
||||||
sys.path.append('/bin')
|
sys.path.append('/bin')
|
||||||
|
|
||||||
import tools
|
from api import tools
|
||||||
|
|
||||||
# logger
|
# logger
|
||||||
configs_logger = logging.getLogger('configs')
|
configs_logger = logging.getLogger('configs')
|
71
DR/crash.py
Normal file
71
DR/crash.py
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
"""
|
||||||
|
writen by shenjackyuanjie
|
||||||
|
mail: 3695888@qq.com
|
||||||
|
github: @shenjackyuanjie
|
||||||
|
gitee: @shenjackyuanjie
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
import traceback
|
||||||
|
import threading
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
|
# where the crash report from
|
||||||
|
# this can't be crash , or the game will really crash!
|
||||||
|
|
||||||
|
# TODO 写完它
|
||||||
|
|
||||||
|
Head_message = """# ----- Difficult Rocket Crash Report -----
|
||||||
|
## Traceback
|
||||||
|
"""
|
||||||
|
|
||||||
|
Thread_message = """## Thread info
|
||||||
|
"""
|
||||||
|
|
||||||
|
System_message = """## System info
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def crash_info_handler(info: str = None) -> str:
|
||||||
|
if not info:
|
||||||
|
info = traceback.format_exc()
|
||||||
|
format_info = '- {}'.format(info.replace('\n', '\n- '))
|
||||||
|
if (format_info.rfind('- ') + 2) == len(format_info):
|
||||||
|
format_info = format_info[:-2]
|
||||||
|
return format_info
|
||||||
|
|
||||||
|
|
||||||
|
def markdown_line_handler(string: Optional[str or bool or int or float], code: bool = False, level: int = 1) -> str:
|
||||||
|
lvl = '- ' * level
|
||||||
|
f_string = string
|
||||||
|
if code:
|
||||||
|
f_string = '`{}`'.format(f_string)
|
||||||
|
return '{}{}\n'.format(lvl, f_string)
|
||||||
|
|
||||||
|
|
||||||
|
def create_crash_report(info: str = None) -> None:
|
||||||
|
crash_info = crash_info_handler(info)
|
||||||
|
if 'crash_report' not in os.listdir('./'):
|
||||||
|
os.mkdir('./crash_report')
|
||||||
|
date_time = time.strftime('%Y-%m-%d %H-%M-%S', time.gmtime(time.time()))
|
||||||
|
filename = 'crash-{}.md'.format(date_time)
|
||||||
|
with open('./crash_report/{}'.format(filename), 'w+') as crash_file:
|
||||||
|
crash_file.write(Head_message) # 开头信息
|
||||||
|
crash_file.write(crash_info)
|
||||||
|
crash_file.write(Thread_message)
|
||||||
|
for thread in threading.enumerate():
|
||||||
|
crash_file.write(markdown_line_handler(thread.name, code=True))
|
||||||
|
crash_file.write(markdown_line_handler(f'Ident: {thread.ident}', level=2))
|
||||||
|
crash_file.write(markdown_line_handler(f'Daemon: {thread.isDaemon()}', level=2))
|
||||||
|
crash_file.write(System_message)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
os.chdir('../')
|
||||||
|
try:
|
||||||
|
raise FileNotFoundError('abc')
|
||||||
|
except:
|
||||||
|
create_crash_report()
|
@ -65,7 +65,6 @@ class DragSprite(WidgetBase):
|
|||||||
self.dragging = False
|
self.dragging = False
|
||||||
|
|
||||||
def _check_hit(self, x, y):
|
def _check_hit(self, x, y):
|
||||||
print(self._x, self._y, x, y, self._width, self._height)
|
|
||||||
return self._x < x < self._x + self._width and self._y < y < self._y + self._height
|
return self._x < x < self._x + self._width and self._y < y < self._y + self._height
|
||||||
|
|
||||||
def on_mouse_press(self, x, y, buttons, modifiers):
|
def on_mouse_press(self, x, y, buttons, modifiers):
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user