prepare for DEMO!

This commit is contained in:
沈瑗杰 2021-02-14 19:03:36 +08:00
parent f9f9e09f17
commit 5f2962c248
5 changed files with 84 additions and 27 deletions

View File

@ -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()

View File

@ -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()

View File

@ -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

8
bin/unpack_textures.py Normal file
View File

@ -0,0 +1,8 @@
"""
writen by shenjackyuanjie
mail: 3695888@qq.com
"""
from xml.dom.minidom import parse

View File

@ -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
}
}
}
}