commit about v 0.5.2

release comming(no DEMO)
This commit is contained in:
沈瑗杰 2021-09-28 22:47:19 +08:00
parent bed01bad82
commit 5ad8a0450d
11 changed files with 62 additions and 29 deletions

View File

@ -16,7 +16,7 @@ from .api import *
__all__ = [ __all__ = [
'new_thread', 'new_thread',
'Delivery', 'Delivery',
'config' 'load_file'
] ]

View File

@ -11,7 +11,7 @@ github: @shenjackyuanjie
gitee: @shenjackyuanjie gitee: @shenjackyuanjie
""" """
from .tools import config from .tools import load_file
from .translate import Lang from .translate import Lang
from .delivery import Delivery from .delivery import Delivery
from .new_thread import new_thread from .new_thread import new_thread
@ -21,6 +21,6 @@ __all__ = ['TexturesError',
'LanguageError', 'LanguageError',
'new_thread', 'new_thread',
'Delivery', 'Delivery',
'config', 'load_file',
'Lang'] 'Lang']

View File

@ -48,7 +48,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) -> dict: def load_file(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'):
@ -95,7 +95,7 @@ def config(file_name: str, stack=None) -> dict:
# main config # main config
main_config_file = config('./configs/main.config') main_config_file = load_file('./configs/main.config')
def get_At(name, in_xml, need_type=str): def get_At(name, in_xml, need_type=str):

View File

@ -11,11 +11,16 @@ github: @shenjackyuanjie
gitee: @shenjackyuanjie gitee: @shenjackyuanjie
""" """
from typing import List from typing import Union
from Difficult_Rocket.api import tools from Difficult_Rocket.api import tools
from Difficult_Rocket.api.Exp import * from Difficult_Rocket.api.Exp import *
"""
这部分代码使用了中文编程why
你觉得呢
"""
class Lang: class Lang:
""" """
@ -30,8 +35,8 @@ class Lang:
def __init__(self, language: str = 'zh-CN'): def __init__(self, language: str = 'zh-CN'):
self.language = language self.language = language
self.翻译结果 = tools.config(f'configs/lang/{language}.json5') self.翻译结果 = tools.load_file(f'configs/lang/{language}.json5')
self.默认翻译 = tools.config('configs/lang/zh-CN.json5') self.默认翻译 = tools.load_file('configs/lang/zh-CN.json5')
def __str__(self) -> str: def __str__(self) -> str:
return self.language return self.language
@ -40,12 +45,15 @@ class Lang:
try: try:
return self.翻译结果[item] return self.翻译结果[item]
except KeyError: except KeyError:
return self.默认翻译[item] try:
return self.默认翻译[item]
except KeyError:
raise LanguageError(f'there\'s no key {item} in both {self.language} and zh-CN')
def __setitem__(self, key, value): def __setitem__(self, key, value):
if key == 'language' or key == 'lang': if key == 'language' or key == 'lang':
try: try:
self.翻译结果 = tools.config(f'configs/lang/{value}.json5') self.翻译结果 = tools.load_file(f'configs/lang/{value}.json5')
self.language = value self.language = value
except FileNotFoundError: except FileNotFoundError:
raise LanguageError(f'{value}\'s language json5 file not found') raise LanguageError(f'{value}\'s language json5 file not found')
@ -54,11 +62,26 @@ class Lang:
def set_language(self, language): def set_language(self, language):
try: try:
self.翻译结果 = tools.config(f'configs/lang/{language}.json5') self.翻译结果 = tools.load_file(f'configs/lang/{language}.json5')
self.language = language self.language = language
except FileNotFoundError: except FileNotFoundError:
raise LanguageError(f'{language}\'s language json5 file not found') raise LanguageError(f'{language}\'s language json5 file not found')
def lang(self, *args) -> Union[int, str, list]:
try:
结果 = self.翻译结果
for 选项 in args:
结果 = 结果[选项]
return 结果
except KeyError:
try:
结果 = self.默认翻译
for 选项 in args:
结果 = 结果[选项]
return 结果
except KeyError:
raise LanguageError(f'there\'s no key {args} in both {self.language} and zh-CN')
try: try:
tr = Lang('zh-CN') tr = Lang('zh-CN')

View File

@ -34,7 +34,7 @@ from Difficult_Rocket import crash
from Difficult_Rocket.api.Exp import * from Difficult_Rocket.api.Exp import *
from Difficult_Rocket.api.translate import tr from Difficult_Rocket.api.translate import tr
from Difficult_Rocket.drag_sprite import DragSprite from Difficult_Rocket.drag_sprite import DragSprite
from Difficult_Rocket.api import tools, config, new_thread, thread from Difficult_Rocket.api import tools, load_file, new_thread, thread
# libs function # libs function
local_lib = True local_lib = True
@ -51,9 +51,9 @@ class Client:
# logging # logging
self.logger = logging.getLogger('client') self.logger = logging.getLogger('client')
# config # config
self.config = tools.config('configs/main.config') self.config = tools.load_file('configs/main.config')
# lang # lang
self.lang = tools.config('configs/lang/%s.json5' % self.config['runtime']['language'], 'client') self.lang = tools.load_file('configs/lang/%s.json5' % self.config['runtime']['language'], 'client')
# value # value
self.process_id = 'Client' self.process_id = 'Client'
self.process_name = 'Client process' self.process_name = 'Client process'
@ -67,6 +67,7 @@ class Client:
caption=self.caption, caption=self.caption,
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']))
self.logger.info(tr['client']['setup.done'])
def start(self): def start(self):
self.window.start_game() # 游戏启动 self.window.start_game() # 游戏启动
@ -92,11 +93,11 @@ class ClientWindow(pyglet.window.Window):
# configs # configs
pyglet.resource.path = ['textures'] pyglet.resource.path = ['textures']
pyglet.resource.reindex() pyglet.resource.reindex()
self.config_file = tools.config('configs/main.config') self.config_file = tools.load_file('configs/main.config')
self.FPS = Decimal(int(self.config_file['runtime']['fps'])) self.FPS = Decimal(int(self.config_file['runtime']['fps']))
self.SPF = Decimal('1') / self.FPS self.SPF = Decimal('1') / self.FPS
# lang # lang
self.lang = tools.config('configs/lang/%s.json5' % self.config_file['runtime']['language'], 'client') self.lang = tools.load_file('configs/lang/%s.json5' % self.config_file['runtime']['language'], 'client')
# dic # dic
self.environment = {} self.environment = {}
self.textures = {} # all textures self.textures = {} # all textures
@ -122,7 +123,7 @@ class ClientWindow(pyglet.window.Window):
@new_thread('client_load_environment') @new_thread('client_load_environment')
def load_environment(self) -> None: def load_environment(self) -> None:
# load parts info # load parts info
self.environment['parts'] = config('configs/sys_value/parts.json5') self.environment['parts'] = load_file('configs/sys_value/parts.json5')
try: try:
self.load_textures() self.load_textures()
except TexturesError: except TexturesError:
@ -136,7 +137,7 @@ class ClientWindow(pyglet.window.Window):
pass pass
def setup(self): def setup(self):
self.logger.info(self.lang['os.pid_is'].format(os.getpid(), os.getppid())) self.logger.info(tr.lang('window', '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'] = DragSprite(10, 20, image, batch=self.label_batch, drag_by_all=False, drag_out_window=True) self.textures['test'] = DragSprite(10, 20, image, batch=self.label_batch, drag_by_all=False, drag_out_window=True)
self.load_environment() self.load_environment()
@ -210,7 +211,7 @@ class ClientWindow(pyglet.window.Window):
self.textures['test'].on_mouse_press(x, y, button, modifiers) self.textures['test'].on_mouse_press(x, y, button, modifiers)
def on_mouse_release(self, x, y, button, modifiers) -> None: def on_mouse_release(self, x, y, button, modifiers) -> None:
self.logger.debug(self.lang['mouse.release'].format([x, y], self.lang['mouse.right'])) self.logger.debug(tr.lang('window', 'mouse.release').format([x, y], tr.lang('window', 'mouse.right')))
self.textures['test'].on_mouse_release(x, y, button, modifiers) self.textures['test'].on_mouse_release(x, y, button, modifiers)
def on_key_press(self, symbol, modifiers) -> None: def on_key_press(self, symbol, modifiers) -> None:

View File

@ -26,7 +26,6 @@ if __name__ == '__main__': # been start will not run this
from Difficult_Rocket import client, server from Difficult_Rocket import client, server
from Difficult_Rocket.api import tools, thread, translate from Difficult_Rocket.api import tools, thread, translate
from Difficult_Rocket.api.translate import tr from Difficult_Rocket.api.translate import tr
from libs import pyglet
class Game: class Game:
@ -36,11 +35,11 @@ class Game:
self.on_python_v = sys.version.split(' ')[0] self.on_python_v = sys.version.split(' ')[0]
self.start_time = time.strftime('%Y-%m-%d %H-%M-%S', time.gmtime(time.time())) self.start_time = time.strftime('%Y-%m-%d %H-%M-%S', time.gmtime(time.time()))
# lang_config # lang_config
self.language = tools.config('configs/sys_value/basic_config.json5') self.language = tools.load_file('configs/sys_value/basic_config.json5')
self.language = self.language['language'] self.language = self.language['language']
tr.set_language(self.language) tr.set_language(self.language)
# logging config # logging config
log_config = tools.config('configs/logger.json5') log_config = tools.load_file('configs/logger.json5')
file_name = log_config['handlers']['file']['filename'] file_name = log_config['handlers']['file']['filename']
del log_config['handlers']['file']['datefmt'] del log_config['handlers']['file']['datefmt']
log_config['handlers']['file']['filename'] = f'logs/{file_name.format(self.start_time)}' log_config['handlers']['file']['filename'] = f'logs/{file_name.format(self.start_time)}'

View File

@ -37,11 +37,11 @@ class Server:
self.process_id = 'Server' self.process_id = 'Server'
self.process_name = 'server process' self.process_name = 'server process'
# config # config
self.config = tools.config('configs/main.config') self.config = tools.load_file('configs/main.config')
self.dev = Dev self.dev = Dev
self.net_mode = net_mode self.net_mode = net_mode
# lang # lang
self.lang = tools.config('configs/lang/%s.json5' % self.config['runtime']['language'], 'server') self.lang = tools.load_file('configs/lang/%s.json5' % self.config['runtime']['language'], 'server')
self.logger.info('%s' % self.lang['setup.done']) self.logger.info('%s' % self.lang['setup.done'])
@new_thread('Server') @new_thread('Server')

View File

@ -19,7 +19,7 @@ import json5
def rewrite_config(name, save_name): def rewrite_config(name, save_name):
load_xml = tools.config(name) load_xml = tools.load_file(name)
load_xml = load_xml.documentElement load_xml = load_xml.documentElement
sprites = load_xml.getElementsByTagName('sprite') sprites = load_xml.getElementsByTagName('sprite')
pic_path = load_xml.getAttribute('imagePath') pic_path = load_xml.getAttribute('imagePath')

View File

@ -16,8 +16,12 @@
}, },
'client': { 'client': {
'setup.done': '客户端载入完成', 'setup.done': '客户端载入完成',
'setup.use_time': '客户端载入消耗时间: {} 秒', 'setup.use_time': '客户端载入花费: {} 秒'
'os.pid_is': '客户端 PID: {} PPID: {}', },
'window': {
'setup.done': '游戏窗口载入完成',
'setup.use_time': '游戏窗口载入消耗时间: {} 秒',
'os.pid_is': '游戏窗口 PID: {} PPID: {}',
'button.been_press': '按钮被按下,目前状态为:', 'button.been_press': '按钮被按下,目前状态为:',
'mouse.press': '鼠标在 {} 被按下,按键为:{}', 'mouse.press': '鼠标在 {} 被按下,按键为:{}',
'mouse.release': '鼠标在 {} 释放,按键为:{}', 'mouse.release': '鼠标在 {} 释放,按键为:{}',

View File

@ -29,6 +29,7 @@
'datefmt': '%Y-%m-%d %H-%M-%S', 'datefmt': '%Y-%m-%d %H-%M-%S',
'encoding': 'utf-8', 'encoding': 'utf-8',
'formatter': 'file', 'formatter': 'file',
'level': 'DEBUG',
'mode': 'w' 'mode': 'w'
} }
}, },

View File

@ -23,10 +23,13 @@
- now when pressed, the sprite will rotate randomly - now when pressed, the sprite will rotate randomly
- now `pyglet.app.run()` use multiprocess - now `pyglet.app.run()` use multiprocess
- now will allways use `libs/` lib when using `pyglet` or `json5` - now will allways use `libs/` lib when using `pyglet` or `json5`
- now `tools.config()` is `tools.load_file()`
- now `lang` file have `server``client` and `window`
### Add ### Add
- ~~`"mods support"` will done in 1.0.0~~(maybe. just maybe) - ~~mods support will done in 1.0.0~~
- just maybe
- now you can use `DEBUGGING` to test or check game run stats - now you can use `DEBUGGING` to test or check game run stats
- when `True` it will always make a crash report - when `True` it will always make a crash report
- now `Difficult_Rocket.api.translate.Lang` can be used to auto translate text in `configs/lang/xxx.json5` - now `Difficult_Rocket.api.translate.Lang` can be used to auto translate text in `configs/lang/xxx.json5`
@ -37,6 +40,9 @@
- `crash` now have more information about multiprocess - `crash` now have more information about multiprocess
- add some unused read_input in `client` - add some unused read_input in `client`
- now when `logs/` is not found logger will info `logger.mkdir` - now when `logs/` is not found logger will info `logger.mkdir`
- add `tr.lang(xx, xx)` that can solve error on getting item from lang file
- `tr[xxx]` can also use but won't solve error when item not found
- so best use `tr.lang(xx, xx)`
### DEBUG ### DEBUG
@ -110,7 +116,6 @@
### Delete ### Delete
- all game window render has been deleted - all game window render has been deleted
-
- will be rewritten in 0.5.0 - will be rewritten in 0.5.0
- delete some useless code - delete some useless code
- delete some useless file - delete some useless file