diff --git a/Difficult_Rocket.py b/Difficult_Rocket.py index 5ab2279..d5181ce 100644 --- a/Difficult_Rocket.py +++ b/Difficult_Rocket.py @@ -6,9 +6,10 @@ mail: 3695888@qq.com import os import bin import sys +from bin import main -def main(): +def game(): # Python vision check py_v_info = sys.version_info py_v = str("%d.%d.%d" % (py_v_info[0], py_v_info[1], py_v_info[2])) @@ -16,8 +17,8 @@ def main(): if py_v_info[0] == 2: raise Exception("Simple Rocket need python vision 3+") # start games - game = bin.bin.main.Game() + game = main.Game() if __name__ == "__main__": - main() + game() diff --git a/bin/main.py b/bin/main.py index 43cde24..8c30b14 100644 --- a/bin/main.py +++ b/bin/main.py @@ -14,31 +14,61 @@ try: from bin import tools from bin import client from bin import server + from bin import configs except (ModuleNotFoundError, ImportError, ImportWarning): import tools import client import server + import configs class Game: def __init__(self): # basic config - 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())) self.configs = '' # share memory self.dicts = share().dict() self.lists = share().list() # logger + # log config + self.log_config = tools.configs('configs/logging.json5') + self.log_file_config = self.log_config['file'] + self.log_file_handler = logging.FileHandler(configs.name_handler( + self.log_file_config['filename']['main'], self.log_file_config['filename']['formats'])) + # logger + # all logger + # client logger + self.client_log_config = self.log_config['client'] self.client_logger = logging.getLogger('client') + self.client_fmt = logging.Formatter( + fmt="[%(asctime)s][%(name)s]:[%(levelname)s] %(message)s", + datefmt=self.client_log_config['date_fmt']) self.client_stream_handler = logging.StreamHandler() + self.client_stream_handler.setLevel(self.client_log_config['level']) + self.client_stream_handler.setFormatter(self.client_fmt) + self.client_logger.addHandler(self.client_stream_handler) + # server logger + self.server_log_config = self.log_config['server'] self.server_logger = logging.getLogger('server') + self.server_fmt = logging.Formatter( + fmt="[%(asctime)s][%(name)s]:[%(levelname)s] %(message)s", + datefmt=self.server_log_config['date_fmt']) self.server_stream_handler = logging.StreamHandler() - self.log_file_handler = logging.FileHandler('') - self.log_formatter = logging.Formatter("[%(asctime)s][%(name)s]:[%(levelname)s] %(message)s") + self.server_stream_handler.setLevel(self.server_log_config['level']) + self.server_stream_handler.setFormatter(self.server_fmt) + self.server_logger.addHandler(self.server_stream_handler) + # file logger + self.log_formatter = logging.Formatter( + fmt="[%(asctime)s][%(name)s]:[%(levelname)s] %(message)s", + datefmt=self.log_config['date_fmt']) # client and server - self.client = client.RenderThread(self.client_logger, self.dicts, self.lists, net_mode='local') - self.server = server.server(self.lists, self.dicts, self.server_logger, net_mode='local') + self.client = client.RenderThread( + self.client_logger, self.dicts, self.lists, net_mode='local') + self.server = server.server( + self.lists, self.dicts, self.server_logger, net_mode='local') # start self.client.startGame() diff --git a/bin/tools.py b/bin/tools.py index b360109..95e5bcc 100644 --- a/bin/tools.py +++ b/bin/tools.py @@ -6,6 +6,7 @@ mail: 3695888@qq.com import json5 import decimal import logging +from xml.dom.minidom import parse try: import configs @@ -81,7 +82,7 @@ def D_C(listA: list, listB: list) -> '1': # stand for Duplicate check return 1 -def S_C_float_check(SC) -> None: # stand for Scientific notation's float check +def S_C_float_check(SC): # stand for Scientific notation's float check """ formats: SC list format:docs.basic_config.json:basic_number""" @@ -151,7 +152,7 @@ def G_C(M, m, R, G): # stand for gravity calculation return g -def distance(A, B) -> float: +def distance(A, B): """ formats: A & B format: docs.basic_config:basic_poi @@ -171,20 +172,31 @@ def distance(A, B) -> float: return poi_dis[2] -""" -loads -""" +# loads def config(file_name, stack=None): - # rd = {} # rd -> return data - try: - with open(file_name, "r") as jf: # jf -> json file - rd = json5.load(jf) - except FileNotFoundError as exp: - log = "no config 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 + type = file_name[file_name.rfind('.') + 1:] # 从最后一次.到末尾(截取文件格式) + if (type == 'json5') or (type == 'json'): + try: + with open(file_name, "r") as jf: # jf -> json file + rd = json5.load(jf) + 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 type == 'xml': + try: + xml_load = parse(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: + xml_get = xml_load.getElementsByTagName(stack) + return xml_get + else: + return xml_load diff --git a/bin/unpack_textures.py b/bin/unpack_textures.py new file mode 100644 index 0000000..de6aafc --- /dev/null +++ b/bin/unpack_textures.py @@ -0,0 +1,8 @@ +""" +writen by shenjackyuanjie +mail: 3695888@qq.com +""" + +from xml.dom.minidom import parse + + diff --git a/configs/logging.json5 b/configs/logging.json5 index 68edf5c..7d3881c 100644 --- a/configs/logging.json5 +++ b/configs/logging.json5 @@ -2,24 +2,30 @@ 'server': { 'level': 'DEBUG', // option: CRITICAL ERROR WARNING INFO DEBUG - 'date_fmt': '%Y-%m-%d %H-%M-%S' + 'fmt': '', + // format + 'date_fmt': '%Y-%m-%d %H-%M-%S', // format at https://docs.python.org/zh-cn/3.8/library/time.html#time.strftime }, 'client': { 'level': 'DEBUG', // option: CRITICAL ERROR WARNING INFO DEBUG - 'date_fmt': '%Y-%m-%d %H-%M-%S' + 'date_fmt': '%Y-%m-%d %H-%M-%S', // format at https://docs.python.org/zh-cn/3.8/library/time.html#time.strftime }, 'file': { 'level': 'DEBUG', // option: CRITICAL ERROR WARNING INFO DEBUG + 'date_fmt': '%Y-%m-%d %H-%M-%S', + // format at https://docs.python.org/zh-cn/3.8/library/time.html#time.strftime 'filename': { 'main': '{date} SR.log', // {date} -> date - '{date}': '%Y-%m-%d %H-%M-%S' + 'formats': { + '{date}': '%Y-%m-%d %H-%M-%S', // format at https://docs.python.org/zh-cn/3.8/library/time.html#time.strftime // can and more {xx} by adding more obj EZ + } } } } \ No newline at end of file