logger and logging!
This commit is contained in:
parent
5cc9c8c042
commit
710436c35e
@ -23,8 +23,9 @@ except ModuleNotFoundError:
|
||||
|
||||
class RenderThread(mp.Process, pyglet.window.Window):
|
||||
|
||||
def __init__(self, dev_list, dev_dic, logger, net_mode='local'):
|
||||
def __init__(self, logger, dev_dic=None, dev_list=None, path=None, net_mode='local'):
|
||||
"""
|
||||
:param path: 运行路径
|
||||
:param dev_list: 共享内存
|
||||
:param dev_dic: 共享内存
|
||||
:param logger: logger
|
||||
@ -48,7 +49,7 @@ class RenderThread(mp.Process, pyglet.window.Window):
|
||||
# configs
|
||||
self.window_config = tools.config('sys_value/window.json5')
|
||||
self.part_list = tools.config('sys_value/parts.json5')
|
||||
self.map_view = [configs.basic_poi(poi_type='view')]
|
||||
self.map_view = [configs.basic_poi(poi_type='chunk')]
|
||||
# dic
|
||||
self.ships = {} # all ship
|
||||
self.planet_system = {} # hole planet system
|
||||
@ -58,13 +59,13 @@ class RenderThread(mp.Process, pyglet.window.Window):
|
||||
# window
|
||||
self.window = Window(width=int(self.window_config['width']),
|
||||
height=int(self.window_config['height']),
|
||||
fullscreen=tools.mbool(self.window_config['full_screen']),
|
||||
fullscreen=tools.c_b(self.window_config['full_screen']),
|
||||
caption=str(self.window_config['caption']),
|
||||
visible=tools.mbool(self.window_config['visible']))
|
||||
visible=tools.c_b(self.window_config['visible']))
|
||||
# setup
|
||||
self.setup()
|
||||
|
||||
def start_game(self):
|
||||
def startGame(self):
|
||||
pyglet.app.run()
|
||||
return
|
||||
|
||||
|
@ -4,15 +4,21 @@ mail: 3695888@qq.com
|
||||
"""
|
||||
|
||||
# import re
|
||||
import os
|
||||
import time
|
||||
import json5
|
||||
import decimal
|
||||
import logging
|
||||
|
||||
try:
|
||||
import tools
|
||||
except ModuleNotFoundError:
|
||||
from bin import tools
|
||||
|
||||
# logger
|
||||
configs_logger = logging.getLogger('configs')
|
||||
|
||||
|
||||
def __basic_number(int_num=0, float_num=1, unit1=None, unit2=None) -> list:
|
||||
if unit1 is None:
|
||||
unit1 = []
|
||||
@ -32,6 +38,7 @@ def basic_number(int_num=0, float_num=1, unit1=None, unit2=None, num=1) -> list:
|
||||
elif num == 1:
|
||||
return __basic_number(int_num, float_num, unit1, unit2)
|
||||
else: # num < 1
|
||||
|
||||
raise TypeError('you should give me a num with >= 1!')
|
||||
return numbers
|
||||
|
||||
@ -39,7 +46,7 @@ def basic_number(int_num=0, float_num=1, unit1=None, unit2=None, num=1) -> list:
|
||||
def basic_poi(poi_type=None) -> list:
|
||||
if poi_type is None:
|
||||
return basic_number(unit1='m', num=2)
|
||||
if poi_type == 'view':
|
||||
if poi_type == 'chunk':
|
||||
return [basic_number(unit1='chunk', num=2), basic_number(unit1='m', num=2)]
|
||||
|
||||
|
||||
@ -53,17 +60,21 @@ def configs(name, option=None) -> dict:
|
||||
if option:
|
||||
try:
|
||||
data = data[option]
|
||||
except:
|
||||
print(Exception)
|
||||
raise Exception
|
||||
except IndexError as exp:
|
||||
logging.exception(exp)
|
||||
raise exp
|
||||
return data
|
||||
|
||||
|
||||
def name_handler(name: str, configs: dict = None) -> str:
|
||||
def name_handler(name: str, configs=None) -> str:
|
||||
if configs is None:
|
||||
return name
|
||||
for need_replace in configs:
|
||||
if need_replace == '{date}': # special replace
|
||||
replace = configs[need_replace]
|
||||
if need_replace == '{date}': # special replaces
|
||||
replace = time.strftime(configs[need_replace], time.gmtime(time.time()))
|
||||
name.replace(need_replace, replace)
|
||||
name.replace(need_replace, configs[need_replace])
|
||||
elif need_replace == '{time.time}':
|
||||
replace = time.time()
|
||||
elif need_replace == '{dir}':
|
||||
replace = os.getcwd()
|
||||
name.replace(need_replace, replace)
|
||||
|
25
bin/main.py
25
bin/main.py
@ -6,16 +6,21 @@ mail: 3695888@qq.com
|
||||
# share memory
|
||||
from multiprocessing import Manager as share
|
||||
|
||||
import bin
|
||||
# import bin
|
||||
import time
|
||||
import logging
|
||||
|
||||
# 直接导入
|
||||
import bin.server as server
|
||||
import bin.client as client
|
||||
try:
|
||||
import tools
|
||||
import client
|
||||
import server
|
||||
except ModuleNotFoundError:
|
||||
from bin import tools
|
||||
from bin import client
|
||||
from bin import server
|
||||
|
||||
|
||||
class Game():
|
||||
class Game:
|
||||
|
||||
def __init__(self):
|
||||
# basic config
|
||||
@ -25,9 +30,15 @@ class Game():
|
||||
self.dicts = share().dict()
|
||||
self.lists = share().list()
|
||||
# logger
|
||||
self.server_logger = logging.getLogger('server')
|
||||
self.client_logger = logging.getLogger('client')
|
||||
self.client_stream_handler = logging.StreamHandler()
|
||||
self.server_logger = logging.getLogger('server')
|
||||
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")
|
||||
# client and server
|
||||
self.client = client.RenderThread(self.lists, self.dicts, self.client_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()
|
||||
|
@ -5,18 +5,22 @@ mail: 3695888@qq.com
|
||||
|
||||
import json5
|
||||
import decimal
|
||||
import logging
|
||||
|
||||
try:
|
||||
import configs
|
||||
except ModuleNotFoundError:
|
||||
from bin import configs
|
||||
|
||||
# logger
|
||||
tools_logger = logging.getLogger('tools')
|
||||
|
||||
"""
|
||||
some tools
|
||||
"""
|
||||
|
||||
|
||||
def mbool(thing): # stand for my bool
|
||||
def c_b(thing): # stand for my bool
|
||||
yes = ['True', 'TRUE', '1', 1]
|
||||
no = ['False', 'FALSE', '0', 0]
|
||||
if thing in yes:
|
||||
@ -176,7 +180,8 @@ def config(file_name, stack=None):
|
||||
try:
|
||||
with open(file_name, "r") as jf: # jf -> json file
|
||||
rd = json5.load(jf)
|
||||
except FileNotFoundError:
|
||||
except FileNotFoundError as exp:
|
||||
tools_logger.exception("no config file \n file name : %s \n stack : %s" % (file_name, stack))
|
||||
raise FileNotFoundError("no config file \n file name : %s \n stack : %s" % (file_name, stack))
|
||||
if stack is not None:
|
||||
rd = rd[stack]
|
||||
|
@ -1,6 +1,12 @@
|
||||
a = {'a': 'b', 're': '2'}
|
||||
|
||||
import pprint
|
||||
|
||||
a = {'a': 'b', 're': '2'}
|
||||
|
||||
for x in a:
|
||||
print(x)
|
||||
pprint.pprint(x)
|
||||
|
||||
b = [1, 'a', 5]
|
||||
|
||||
pprint.pprint(b)
|
||||
|
||||
print(b[3])
|
||||
|
Loading…
Reference in New Issue
Block a user