commit about v 0.5.2
release comming(no DEMO)
This commit is contained in:
parent
bed01bad82
commit
5ad8a0450d
@ -16,7 +16,7 @@ from .api import *
|
||||
__all__ = [
|
||||
'new_thread',
|
||||
'Delivery',
|
||||
'config'
|
||||
'load_file'
|
||||
]
|
||||
|
||||
|
||||
|
@ -11,7 +11,7 @@ github: @shenjackyuanjie
|
||||
gitee: @shenjackyuanjie
|
||||
"""
|
||||
|
||||
from .tools import config
|
||||
from .tools import load_file
|
||||
from .translate import Lang
|
||||
from .delivery import Delivery
|
||||
from .new_thread import new_thread
|
||||
@ -21,6 +21,6 @@ __all__ = ['TexturesError',
|
||||
'LanguageError',
|
||||
'new_thread',
|
||||
'Delivery',
|
||||
'config',
|
||||
'load_file',
|
||||
'Lang']
|
||||
|
||||
|
@ -48,7 +48,7 @@ def report_file_error(filetype: str, error_type, filename: str, stack: any):
|
||||
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:] # 从最后一个.到末尾 (截取文件格式)
|
||||
try:
|
||||
if (f_type == 'json5') or (f_type == 'json'):
|
||||
@ -95,7 +95,7 @@ def config(file_name: str, stack=None) -> dict:
|
||||
|
||||
|
||||
# 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):
|
||||
|
@ -11,11 +11,16 @@ github: @shenjackyuanjie
|
||||
gitee: @shenjackyuanjie
|
||||
"""
|
||||
|
||||
from typing import List
|
||||
from typing import Union
|
||||
|
||||
from Difficult_Rocket.api import tools
|
||||
from Difficult_Rocket.api.Exp import *
|
||||
|
||||
"""
|
||||
这部分代码使用了中文编程,why?
|
||||
你觉得呢?
|
||||
"""
|
||||
|
||||
|
||||
class Lang:
|
||||
"""
|
||||
@ -30,8 +35,8 @@ class Lang:
|
||||
|
||||
def __init__(self, language: str = 'zh-CN'):
|
||||
self.language = language
|
||||
self.翻译结果 = tools.config(f'configs/lang/{language}.json5')
|
||||
self.默认翻译 = tools.config('configs/lang/zh-CN.json5')
|
||||
self.翻译结果 = tools.load_file(f'configs/lang/{language}.json5')
|
||||
self.默认翻译 = tools.load_file('configs/lang/zh-CN.json5')
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.language
|
||||
@ -40,12 +45,15 @@ class Lang:
|
||||
try:
|
||||
return self.翻译结果[item]
|
||||
except KeyError:
|
||||
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):
|
||||
if key == 'language' or key == 'lang':
|
||||
try:
|
||||
self.翻译结果 = tools.config(f'configs/lang/{value}.json5')
|
||||
self.翻译结果 = tools.load_file(f'configs/lang/{value}.json5')
|
||||
self.language = value
|
||||
except FileNotFoundError:
|
||||
raise LanguageError(f'{value}\'s language json5 file not found')
|
||||
@ -54,11 +62,26 @@ class Lang:
|
||||
|
||||
def set_language(self, language):
|
||||
try:
|
||||
self.翻译结果 = tools.config(f'configs/lang/{language}.json5')
|
||||
self.翻译结果 = tools.load_file(f'configs/lang/{language}.json5')
|
||||
self.language = language
|
||||
except FileNotFoundError:
|
||||
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:
|
||||
tr = Lang('zh-CN')
|
||||
|
@ -34,7 +34,7 @@ from Difficult_Rocket import crash
|
||||
from Difficult_Rocket.api.Exp import *
|
||||
from Difficult_Rocket.api.translate import tr
|
||||
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
|
||||
local_lib = True
|
||||
@ -51,9 +51,9 @@ class Client:
|
||||
# logging
|
||||
self.logger = logging.getLogger('client')
|
||||
# config
|
||||
self.config = tools.config('configs/main.config')
|
||||
self.config = tools.load_file('configs/main.config')
|
||||
# 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
|
||||
self.process_id = 'Client'
|
||||
self.process_name = 'Client process'
|
||||
@ -67,6 +67,7 @@ class Client:
|
||||
caption=self.caption,
|
||||
resizable=tools.format_bool(self.config['window']['resizable']),
|
||||
visible=tools.format_bool(self.config['window']['visible']))
|
||||
self.logger.info(tr['client']['setup.done'])
|
||||
|
||||
def start(self):
|
||||
self.window.start_game() # 游戏启动
|
||||
@ -92,11 +93,11 @@ class ClientWindow(pyglet.window.Window):
|
||||
# configs
|
||||
pyglet.resource.path = ['textures']
|
||||
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.SPF = Decimal('1') / self.FPS
|
||||
# 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
|
||||
self.environment = {}
|
||||
self.textures = {} # all textures
|
||||
@ -122,7 +123,7 @@ class ClientWindow(pyglet.window.Window):
|
||||
@new_thread('client_load_environment')
|
||||
def load_environment(self) -> None:
|
||||
# load parts info
|
||||
self.environment['parts'] = config('configs/sys_value/parts.json5')
|
||||
self.environment['parts'] = load_file('configs/sys_value/parts.json5')
|
||||
try:
|
||||
self.load_textures()
|
||||
except TexturesError:
|
||||
@ -136,7 +137,7 @@ class ClientWindow(pyglet.window.Window):
|
||||
pass
|
||||
|
||||
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')
|
||||
self.textures['test'] = DragSprite(10, 20, image, batch=self.label_batch, drag_by_all=False, drag_out_window=True)
|
||||
self.load_environment()
|
||||
@ -210,7 +211,7 @@ class ClientWindow(pyglet.window.Window):
|
||||
self.textures['test'].on_mouse_press(x, y, button, modifiers)
|
||||
|
||||
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)
|
||||
|
||||
def on_key_press(self, symbol, modifiers) -> None:
|
||||
|
@ -26,7 +26,6 @@ if __name__ == '__main__': # been start will not run this
|
||||
from Difficult_Rocket import client, server
|
||||
from Difficult_Rocket.api import tools, thread, translate
|
||||
from Difficult_Rocket.api.translate import tr
|
||||
from libs import pyglet
|
||||
|
||||
|
||||
class Game:
|
||||
@ -36,11 +35,11 @@ class Game:
|
||||
self.on_python_v = sys.version.split(' ')[0]
|
||||
self.start_time = time.strftime('%Y-%m-%d %H-%M-%S', time.gmtime(time.time()))
|
||||
# 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']
|
||||
tr.set_language(self.language)
|
||||
# logging config
|
||||
log_config = tools.config('configs/logger.json5')
|
||||
log_config = tools.load_file('configs/logger.json5')
|
||||
file_name = log_config['handlers']['file']['filename']
|
||||
del log_config['handlers']['file']['datefmt']
|
||||
log_config['handlers']['file']['filename'] = f'logs/{file_name.format(self.start_time)}'
|
||||
|
@ -37,11 +37,11 @@ class Server:
|
||||
self.process_id = 'Server'
|
||||
self.process_name = 'server process'
|
||||
# config
|
||||
self.config = tools.config('configs/main.config')
|
||||
self.config = tools.load_file('configs/main.config')
|
||||
self.dev = Dev
|
||||
self.net_mode = net_mode
|
||||
# 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'])
|
||||
|
||||
@new_thread('Server')
|
||||
|
@ -19,7 +19,7 @@ import json5
|
||||
|
||||
|
||||
def rewrite_config(name, save_name):
|
||||
load_xml = tools.config(name)
|
||||
load_xml = tools.load_file(name)
|
||||
load_xml = load_xml.documentElement
|
||||
sprites = load_xml.getElementsByTagName('sprite')
|
||||
pic_path = load_xml.getAttribute('imagePath')
|
||||
|
@ -16,8 +16,12 @@
|
||||
},
|
||||
'client': {
|
||||
'setup.done': '客户端载入完成',
|
||||
'setup.use_time': '客户端载入消耗时间: {} 秒',
|
||||
'os.pid_is': '客户端 PID: {} PPID: {}',
|
||||
'setup.use_time': '客户端载入花费: {} 秒'
|
||||
},
|
||||
'window': {
|
||||
'setup.done': '游戏窗口载入完成',
|
||||
'setup.use_time': '游戏窗口载入消耗时间: {} 秒',
|
||||
'os.pid_is': '游戏窗口 PID: {} PPID: {}',
|
||||
'button.been_press': '按钮被按下,目前状态为:',
|
||||
'mouse.press': '鼠标在 {} 被按下,按键为:{}',
|
||||
'mouse.release': '鼠标在 {} 释放,按键为:{}',
|
||||
|
@ -29,6 +29,7 @@
|
||||
'datefmt': '%Y-%m-%d %H-%M-%S',
|
||||
'encoding': 'utf-8',
|
||||
'formatter': 'file',
|
||||
'level': 'DEBUG',
|
||||
'mode': 'w'
|
||||
}
|
||||
},
|
||||
|
@ -23,10 +23,13 @@
|
||||
- now when pressed, the sprite will rotate randomly
|
||||
- now `pyglet.app.run()` use multiprocess
|
||||
- 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
|
||||
|
||||
- ~~`"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
|
||||
- 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`
|
||||
@ -37,6 +40,9 @@
|
||||
- `crash` now have more information about multiprocess
|
||||
- add some unused read_input in `client`
|
||||
- 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
|
||||
|
||||
@ -110,7 +116,6 @@
|
||||
### Delete
|
||||
|
||||
- all game window render has been deleted
|
||||
-
|
||||
- will be rewritten in 0.5.0
|
||||
- delete some useless code
|
||||
- delete some useless file
|
||||
|
Loading…
Reference in New Issue
Block a user