V 0.4.4
update(not done)
This commit is contained in:
parent
b76e8a492a
commit
22f448ec28
@ -7,6 +7,7 @@ import multiprocessing as mp
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
sys.path.append('./bin/libs/')
|
||||
sys.path.append('./')
|
||||
import pyglet
|
||||
@ -47,10 +48,10 @@ class client(mp.Process):
|
||||
net_mode=net_mode,
|
||||
width=int(self.window_config['width']),
|
||||
height=int(self.window_config['height']),
|
||||
fullscreen=tools.c_b(self.window_config['full_screen']),
|
||||
fullscreen=tools.format_bool(self.window_config['full_screen']),
|
||||
caption=self.caption,
|
||||
resizable=tools.c_b(self.window_config['resizable']),
|
||||
visible=tools.c_b(self.window_config['visible']))
|
||||
resizable=tools.format_bool(self.window_config['resizable']),
|
||||
visible=tools.format_bool(self.window_config['visible']))
|
||||
self.log_config()
|
||||
|
||||
def log_config(self):
|
||||
|
@ -3,18 +3,14 @@ writen by shenjackyuanjie
|
||||
mail: 3695888@qq.com
|
||||
"""
|
||||
|
||||
# import re
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import decimal
|
||||
import logging
|
||||
# import re
|
||||
import sys
|
||||
|
||||
sys.path.append('./bin/libs/')
|
||||
sys.path.append('./')
|
||||
|
||||
import json5
|
||||
|
||||
try:
|
||||
from bin import tools
|
||||
except (ModuleNotFoundError, ImportError, ImportWarning):
|
||||
|
@ -3,10 +3,10 @@ writen by shenjackyuanjie
|
||||
mail: 3695888@qq.com
|
||||
"""
|
||||
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import logging
|
||||
# share memory
|
||||
from multiprocessing import Manager as share
|
||||
|
||||
@ -42,10 +42,9 @@ class Game:
|
||||
# logger
|
||||
self.log_config = tools.config('configs/logging.json5', 'file')
|
||||
self.log_filename = tools.name_handler(self.log_config['filename']['main'],
|
||||
{'date': self.log_config['date_fmt']})
|
||||
{'date': self.log_config['date_fmt']})
|
||||
self.root_logger_fmt = logging.Formatter(self.log_config['fmt'], self.log_config['date_fmt'])
|
||||
self.root_logger_stream_handler = logging.StreamHandler()
|
||||
self.root_logger_stream_handler.setLevel(self.log_config['level'])
|
||||
self.root_logger_stream_handler.setFormatter(self.root_logger_fmt)
|
||||
self.root_logger_stream_handler.setLevel(tools.log_level(self.log_config['level']))
|
||||
try:
|
||||
|
226
bin/tools.py
226
bin/tools.py
@ -1,21 +1,22 @@
|
||||
"""
|
||||
writen by shenjackyuanjie
|
||||
mail: 3695888@qq.com
|
||||
github: @shenjackyuanjie
|
||||
"""
|
||||
|
||||
import sys
|
||||
|
||||
sys.path.append('./bin/libs/')
|
||||
sys.path.append('./')
|
||||
import json5
|
||||
import configparser
|
||||
import decimal
|
||||
import logging
|
||||
import math
|
||||
import time
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
from xml.dom.minidom import parse
|
||||
|
||||
sys.path.append('./bin/libs/')
|
||||
sys.path.append('./')
|
||||
import json5
|
||||
|
||||
try:
|
||||
import configs
|
||||
except ModuleNotFoundError:
|
||||
@ -24,12 +25,119 @@ except ModuleNotFoundError:
|
||||
# logger
|
||||
tools_logger = logging.getLogger('part-tools')
|
||||
|
||||
"""
|
||||
file configs
|
||||
"""
|
||||
|
||||
|
||||
def report_file_error(filetype: str, error_type, filename: str, stack: any):
|
||||
if error_type == FileNotFoundError:
|
||||
log = 'no config %s file \n file name: %s \n file type: %s \n stack: %s' % (filetype, filename, filetype, stack)
|
||||
elif error_type == KeyError:
|
||||
log = 'no stack in %s file: %s \n file type: %s \n stack: %s' % (filetype, filename, filetype, stack)
|
||||
else:
|
||||
log = 'some error has been found! \n error type: %s \n file name: %s \n file type: %s \n stack: %s' % (error_type, filename, filetype, stack)
|
||||
tools_logger.exception(log)
|
||||
raise error_type(log)
|
||||
|
||||
|
||||
def config(file_name: str, stack=None):
|
||||
f_type = file_name[file_name.rfind('.') + 1:] # 从最后一个.到末尾 (截取文件格式)
|
||||
try:
|
||||
if (f_type == 'json5') or (f_type == 'json'):
|
||||
try:
|
||||
with open(file_name, 'r', encoding='utf-8') as jf: # jf -> json file
|
||||
rd = json5.load(jf)
|
||||
except UnicodeDecodeError:
|
||||
with open(file_name, 'r', encoding='gbk') as jf:
|
||||
rd = json5.load(jf)
|
||||
tools_logger.info('文件 %s 解码错误,已重新使用gbk编码打开' % file_name)
|
||||
if stack is not None:
|
||||
rd = rd[stack]
|
||||
return rd
|
||||
elif f_type == 'xml':
|
||||
xml_load = parse(file_name)
|
||||
if stack is not None:
|
||||
xml_get = xml_load.getElementsByTagName(stack)
|
||||
return xml_get
|
||||
else:
|
||||
return xml_load
|
||||
elif (f_type == 'config') or (f_type == 'conf'):
|
||||
cp = configparser.ConfigParser() # cp -> config parser
|
||||
cp.read(file_name) # config parser -> reader
|
||||
rd = {}
|
||||
for section in cp.sections():
|
||||
rd[section] = {}
|
||||
for data in cp[section]:
|
||||
rd[section][data] = cp[section][data]
|
||||
if stack:
|
||||
rd = rd[stack]
|
||||
return rd
|
||||
except Exception as exp:
|
||||
report_file_error(f_type, exp, file_name, stack)
|
||||
|
||||
|
||||
# main config
|
||||
main_config_file = config('./configs/main.config')
|
||||
|
||||
|
||||
def get_At(name, in_xml, need_type=str):
|
||||
"""
|
||||
get Attribute from a XML tree
|
||||
will raise TypeError if input is not str or list
|
||||
XML no! Json5 yes!
|
||||
"""
|
||||
name_type = type(name)
|
||||
if name_type == list:
|
||||
At_list = []
|
||||
for need_name in name:
|
||||
if in_xml.hasAttribute(need_name):
|
||||
get = in_xml.getAttribute(need_name)
|
||||
At_list.append(need_type(get))
|
||||
else:
|
||||
continue
|
||||
return At_list
|
||||
elif name_type == str:
|
||||
if in_xml.hasAttribute(name):
|
||||
At = in_xml.getAttribute(name)
|
||||
else:
|
||||
return None
|
||||
else:
|
||||
raise TypeError('only str and list type is ok but you give me a' + name_type + 'type')
|
||||
return need_type(At)
|
||||
|
||||
|
||||
def default_name_handler(name_: str) -> str:
|
||||
"""
|
||||
won't change the string
|
||||
just return one
|
||||
"""
|
||||
name = name_
|
||||
name = name.replace('{time.time}', str(time.time()))
|
||||
name = name.replace('{dir}', str(os.getcwd()))
|
||||
name = name.replace('{py_v}', str(sys.version.split(' ')[0]))
|
||||
name = name.replace('{version}', str(main_config_file['runtime']['version']))
|
||||
return name
|
||||
|
||||
|
||||
def name_handler(name: str, formats=None) -> str:
|
||||
if formats is None:
|
||||
return default_name_handler(name)
|
||||
name = default_name_handler(name)
|
||||
for need_replace in formats:
|
||||
replace = formats[need_replace]
|
||||
if need_replace == '{date}':
|
||||
replace = time.strftime(formats['{date}'], time.gmtime(time.time()))
|
||||
name = name.replace(need_replace, replace)
|
||||
return name
|
||||
|
||||
|
||||
"""
|
||||
some tools
|
||||
"""
|
||||
|
||||
|
||||
def c_b(thing): # stand for my bool
|
||||
def format_bool(thing):
|
||||
yes = ['True', 'TRUE', 'true', '1', 1, True]
|
||||
no = ['False', 'FALSE', 'false', '0', 0, False]
|
||||
if thing in yes:
|
||||
@ -57,14 +165,14 @@ def log_level(level):
|
||||
if (level == 'CRITICAL') or (level == logging.CRITICAL):
|
||||
return logging.CRITICAL
|
||||
else:
|
||||
raise ValueError('Need a like level thing not anything else')
|
||||
raise ValueError('Need a like logging.level thing not anything else')
|
||||
|
||||
|
||||
# linear_algebra
|
||||
|
||||
def C_R_P(position, degrees): # stand for calculation
|
||||
"""
|
||||
very thanks for lenny from pyglet delvoper
|
||||
very thanks for lenny from pyglet developer
|
||||
https://github.com/LennyPhoenix
|
||||
this part of code is write by him
|
||||
"""
|
||||
@ -107,7 +215,7 @@ def F_A(A: decimal, B: decimal) -> decimal:
|
||||
return A + B
|
||||
|
||||
|
||||
def D_C(listA: list, listB: list) -> '1': # stand for Duplicate check
|
||||
def D_C(listA: list, listB: list): # stand for Duplicate check
|
||||
"""
|
||||
usage:\n
|
||||
input two list\n
|
||||
@ -122,7 +230,6 @@ def D_C(listA: list, listB: list) -> '1': # stand for Duplicate check
|
||||
continue
|
||||
listA.sort()
|
||||
listB.sort()
|
||||
return 1
|
||||
|
||||
|
||||
def S_C_float_check(SC): # stand for Scientific notation's float check
|
||||
@ -142,7 +249,7 @@ def S_N_M(*SN): # stand for Scientific notation multiple
|
||||
formats:
|
||||
A & B & C list format:docs.basic_config.json:basic_number"""
|
||||
if len(SN) < 2:
|
||||
raise TypeError('it need more than 2!')
|
||||
raise TypeError('it need more than 1!')
|
||||
elif len(SN) == 2:
|
||||
return __S_N_M(SN[0], SN[1])
|
||||
else:
|
||||
@ -213,98 +320,3 @@ def distance(A, B):
|
||||
poi_dis.append(poi_dis[0] + poi_dis[1])
|
||||
poi_dis[2] **= 0.5
|
||||
return poi_dis[2]
|
||||
|
||||
|
||||
# loads
|
||||
|
||||
|
||||
def config(file_name, stack=None): # // TODO 加上.config的读取+解析
|
||||
f_type = file_name[file_name.rfind('.') + 1:] # 从最后一个.到末尾 (截取文件格式)
|
||||
if (f_type == 'json5') or (f_type == 'json'):
|
||||
try:
|
||||
try:
|
||||
with open(file_name, 'r', encoding='utf-8') as jf: # jf -> json file
|
||||
rd = json5.load(jf)
|
||||
except UnicodeDecodeError:
|
||||
with open(file_name, 'r', encoding='gbk') as jf:
|
||||
rd = json5.load(jf)
|
||||
tools_logger.info('文件 %s 解码错误,已重新使用gbk编码打开' % file_name)
|
||||
except FileNotFoundError as exp:
|
||||
log = 'no config json(5) file \n file name : %s \n stack : %s' % (
|
||||
file_name, stack)
|
||||
tools_logger.exception(log)
|
||||
raise FileNotFoundError(log)
|
||||
if stack is not None:
|
||||
rd = rd[stack]
|
||||
return rd
|
||||
elif f_type == 'xml':
|
||||
try:
|
||||
xml_load = parse(file_name)
|
||||
except FileNotFoundError as exp:
|
||||
log = 'no config xml file \n file name : %s \n stack : %s' % (
|
||||
file_name, stack)
|
||||
tools_logger.exception(log)
|
||||
raise FileNotFoundError(log)
|
||||
if stack is not None:
|
||||
xml_get = xml_load.getElementsByTagName(stack)
|
||||
return xml_get
|
||||
else:
|
||||
return xml_load
|
||||
elif (f_type == 'config') or (f_type == 'conf'):
|
||||
cp = configparser.ConfigParser() # cp -> config parser
|
||||
cp.read(file_name) # config parser -> reader
|
||||
|
||||
|
||||
def get_At(name, in_xml, need_type=str):
|
||||
"""
|
||||
get Attribute from a XML tree
|
||||
will raise TypeError if input is not str or list
|
||||
XML no! Json5 yes!
|
||||
"""
|
||||
name_type = type(name)
|
||||
if name_type == list:
|
||||
At_list = []
|
||||
for need_name in name:
|
||||
if in_xml.hasAttribute(need_name):
|
||||
get = in_xml.getAttribute(need_name)
|
||||
At_list.append(need_type(get))
|
||||
else:
|
||||
continue
|
||||
return At_list
|
||||
elif name_type == str:
|
||||
if in_xml.hasAttribute(name):
|
||||
At = in_xml.getAttribute(name)
|
||||
else:
|
||||
return None
|
||||
else:
|
||||
raise TypeError('only str and list type is ok but you give me a' + name_type + 'type')
|
||||
return need_type(At)
|
||||
|
||||
|
||||
names = {'{time.time}': str(time.time()),
|
||||
'{dir}': str(os.getcwd()),
|
||||
'{py_v}': str(sys.version.split(' ')[0])}
|
||||
|
||||
|
||||
def default_name_handler(name: str) -> str:
|
||||
"""
|
||||
won't change the string
|
||||
just return one
|
||||
"""
|
||||
name = name
|
||||
name = name.replace('{time.time}', str(time.time()))
|
||||
name = name.replace('{dir}', str(os.getcwd()))
|
||||
name = name.replace('{py_v}', str(sys.version.split(' ')[0]))
|
||||
return name
|
||||
|
||||
|
||||
def name_handler(name: str, formats=None) -> str:
|
||||
if formats is None:
|
||||
return default_name_handler(name)
|
||||
name = default_name_handler(name)
|
||||
for need_replace in formats:
|
||||
replace = formats[need_replace]
|
||||
if need_replace == '{date}':
|
||||
replace = time.strftime(formats['{date}'], time.gmtime(time.time()))
|
||||
name = name.replace(need_replace, replace)
|
||||
return name
|
||||
|
12
configs/main.config
Normal file
12
configs/main.config
Normal file
@ -0,0 +1,12 @@
|
||||
[runtime]
|
||||
version = 0.4.4
|
||||
fps = 60
|
||||
|
||||
[window]
|
||||
style = None
|
||||
width = 1024
|
||||
height = 768
|
||||
visible = true
|
||||
resizable = true
|
||||
full_screen = false
|
||||
caption = Difficult Rocket {version}
|
@ -6,7 +6,7 @@
|
||||
'caption': 'Simple Rocket {version}',
|
||||
// {version} -> version of SR
|
||||
'caption_option': {
|
||||
'version': '0.4.3'
|
||||
'version': '0.4.4'
|
||||
},
|
||||
'resizable': 'true',
|
||||
// bool
|
||||
|
@ -7,7 +7,9 @@
|
||||
## 描述
|
||||
|
||||
### 底层机制
|
||||
|
||||
单个部件可以同时连接到2个或两个以上部件
|
||||
|
||||
### 效果
|
||||
|
||||
可以搞点 环世界 之类的巨构
|
@ -3,7 +3,30 @@
|
||||
## Readme
|
||||
|
||||
- [README](https://github.com/shenjackyuanjie/Difficult-Rocket)
|
||||
- [中文README](https://github.com/shenjackyuanjie/Difficult-Rocket/blob/main/docs/README-cn.md)
|
||||
- [中文README](README-cn.md)
|
||||
- Using [SemVer 2.0.0](https://semver.org/) to manage version
|
||||
|
||||
## 20210708 V 0.4.4
|
||||
|
||||
### PS
|
||||
|
||||
- Nice day everyone!
|
||||
- I have finish my final exam on grade 8.
|
||||
- Will soon reach grade 9, so update will be late very much.
|
||||
|
||||
### Change
|
||||
|
||||
- function tools.config()'s way of raise error change tools.report_file_error()
|
||||
- function tools.cb() change name to tools.format_bool()
|
||||
- config.py clear some useless import class
|
||||
- changing configfile to main.config *doing
|
||||
|
||||
### Test change
|
||||
|
||||
- test_config_file.py
|
||||
- test_for_speed.py
|
||||
- test_logging_conf.py
|
||||
- test_speed_of_sprite.py
|
||||
|
||||
## 2021/06/26 V 0.4.3
|
||||
|
||||
@ -38,8 +61,8 @@
|
||||
- debug name_format
|
||||
|
||||
## 2021/04/17 V 0.4.1
|
||||
|
||||
PS:
|
||||
|
||||
PS:
|
||||
|
||||
- `Va.b.c`
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
import random
|
||||
import time
|
||||
from pprint import pprint
|
||||
|
||||
TPS = 60
|
||||
SPT = 1 / TPS
|
||||
|
||||
@ -26,8 +27,8 @@ while t < times:
|
||||
pass
|
||||
print(t, end='\n')
|
||||
e_t = time.time()
|
||||
time_list[t] = [s_t, e_t, e_t-s_t]
|
||||
time_list[t] = [s_t, e_t, e_t - s_t]
|
||||
end_time = time.time()
|
||||
pprint(time_list)
|
||||
pprint(test_list)
|
||||
print(start_t, end_time, end_time-start_t)
|
||||
print(start_t, end_time, end_time - start_t)
|
||||
|
@ -4,28 +4,36 @@ import pyglet
|
||||
|
||||
window = pyglet.window.Window(resizable=True)
|
||||
|
||||
ball_image = pyglet.image.load('/DR/textures/Atmospheres.png') # 可自定义材质
|
||||
ball_image = pyglet.image.load('D:/github/DR/textures/Atmospheres.png') # 可自定义材质
|
||||
batch = pyglet.graphics.Batch()
|
||||
|
||||
ball_sprites = []
|
||||
start_t = time.time()
|
||||
for i in range(1500): # 可自定义数量
|
||||
x, y = i * 10, 50
|
||||
for i in range(10000): # 可自定义数量
|
||||
x, y = i * 30, 50
|
||||
ball_sprites.append(pyglet.sprite.Sprite(ball_image, x, y, batch=batch))
|
||||
ball_sprites[i - 1].visible = False
|
||||
end_t = time.time()
|
||||
print(start_t, end_t, end_t-start_t)
|
||||
print(start_t, end_t, end_t - start_t)
|
||||
|
||||
a = 1
|
||||
|
||||
|
||||
a = 0
|
||||
@window.event
|
||||
def on_draw():
|
||||
start_t = time.time()
|
||||
if a:
|
||||
if a == 0:
|
||||
for x in ball_sprites:
|
||||
if x.visible:
|
||||
x.draw()
|
||||
elif a == 1:
|
||||
for x in ball_sprites:
|
||||
x.draw()
|
||||
else:
|
||||
batch.draw()
|
||||
end_t = time.time()
|
||||
print(start_t, end_t-start_t)
|
||||
print(start_t, end_t - start_t)
|
||||
print(end_t, pyglet.clock.get_fps(), 'fps')
|
||||
|
||||
|
||||
pyglet.app.run()
|
||||
|
38
tests/logging.config
Normal file
38
tests/logging.config
Normal file
@ -0,0 +1,38 @@
|
||||
[loggers]
|
||||
keys=root, client, server
|
||||
|
||||
[handlers]
|
||||
keys=consoleHandler, fileHandler
|
||||
|
||||
[formatters]
|
||||
keys=consoleFormatter, fileFormatter
|
||||
|
||||
[logger_root]
|
||||
level=DEBUG
|
||||
handlers=consoleHandler
|
||||
|
||||
[logger_client]
|
||||
level=DEBUG
|
||||
handlers=consoleHandler, fileHandler
|
||||
qualname=simpleExample
|
||||
propagate=0
|
||||
|
||||
[handler_fileHandler]
|
||||
class=FileHandler
|
||||
level=DEBUG
|
||||
formatter=clientFormatter
|
||||
args=('latest.log', 'w')
|
||||
|
||||
[formatter_fileFormatter]
|
||||
format=[%(asctime)s][%(name)s]:[%(levelname)s] %(message)s
|
||||
datefmt=%Y-%m-%d %H-%M-%S
|
||||
|
||||
[handler_consoleHandler]
|
||||
class=StreamHandler
|
||||
level=DEBUG
|
||||
formatter=clientFormatter
|
||||
args=(sys.stdout,)
|
||||
|
||||
[formatter_consoleFormatter]
|
||||
format=[%(asctime)s][%(name)s]:[%(levelname)s] %(message)s
|
||||
datefmt=%Y-%m-%d %H-%M-%S
|
@ -4,12 +4,23 @@ configs = configparser.ConfigParser()
|
||||
|
||||
configs.read('test_config.config')
|
||||
|
||||
print(configs.sections())
|
||||
# print(configs.sections())
|
||||
back = {}
|
||||
for c in configs.sections():
|
||||
back[c] = {}
|
||||
for con in configs[c]:
|
||||
name = configs[c][con]
|
||||
print(c, con, name)
|
||||
|
||||
back[c][con] = configs[c][c]
|
||||
# name = configs[c][con]
|
||||
# print(c, con, name)
|
||||
print('ree')
|
||||
b = {}
|
||||
for c in configs:
|
||||
print(c)
|
||||
b[c] = configs[c]
|
||||
# print(configs['a'])
|
||||
print('ree')
|
||||
conf = configparser.ConfigParser()
|
||||
conf.read('test_config.config')
|
||||
print(type(conf))
|
||||
# conf.read('test_config.config')
|
||||
# print(type(conf))
|
||||
print(back)
|
||||
print(b)
|
||||
|
23
tests/test_logging_conf.py
Normal file
23
tests/test_logging_conf.py
Normal file
@ -0,0 +1,23 @@
|
||||
"""
|
||||
writen by shenjackyuanjie
|
||||
mail: 3695888@qq.com
|
||||
github: @shenjackyuanjie
|
||||
"""
|
||||
import logging
|
||||
import logging.config
|
||||
import configparser
|
||||
|
||||
configs = configparser.ConfigParser()
|
||||
configs.read('logging.config')
|
||||
# configs['version'] = 1
|
||||
|
||||
# logging.config.dictConfig(configs)
|
||||
logging.config.fileConfig('logging.config')
|
||||
logger = logging.getLogger('simpleExample')
|
||||
|
||||
|
||||
logger.debug('debug message')
|
||||
logger.info('info message')
|
||||
logger.warning('warn message')
|
||||
logger.error('error message')
|
||||
logger.critical('critical message')
|
Loading…
Reference in New Issue
Block a user