This commit is contained in:
沈瑗杰 2021-02-07 13:50:19 +08:00
parent 23b9e29abb
commit 245cc09716
6 changed files with 40 additions and 15 deletions

2
.gitignore vendored
View File

@ -1,6 +1,6 @@
# VScode file
.vscode/
SR.code-workspace
DR.code-workspace
# PYCharm file
.idea/

View File

@ -51,7 +51,7 @@ class RenderThread(mp.Process, pyglet.window.Window):
self.part_list = tools.config('sys_value/parts.json5')
self.map_view = [configs.basic_poi(poi_type='chunk')]
# dic
self.ships = {} # all ship
self.ships = {} # all ship(part)
self.planet_system = {} # hole planet system
# list
# re stuff

View File

@ -19,7 +19,7 @@ except ModuleNotFoundError:
configs_logger = logging.getLogger('configs')
def __basic_number(int_num=0, float_num=1, unit1=None, unit2=None) -> list:
def _BasicNumber(int_num=0, float_num=1, unit1=None, unit2=None) -> list:
if unit1 is None:
unit1 = []
if unit2 is None:
@ -30,28 +30,47 @@ def __basic_number(int_num=0, float_num=1, unit1=None, unit2=None) -> list:
return [int_num, decimal.Decimal(str(float_num)), unit1, unit2] # no create a decimal class
def basic_number(int_num=0, float_num=1, unit1=None, unit2=None, num=1) -> list:
def BasicNumber(int_num=0, float_num=1, unit1=None, unit2=None, num=1) -> list:
numbers = []
if num > 1:
for x in range(0, num, 1):
numbers.append(__basic_number(int_num, float_num, unit1, unit2))
numbers.append(_BasicNumber(int_num, float_num, unit1, unit2))
elif num == 1:
return __basic_number(int_num, float_num, unit1, unit2)
return _BasicNumber(int_num, float_num, unit1, unit2)
else: # num < 1
raise TypeError('you should give me a num with >= 1!')
return numbers
class BasicNumberClass:
def __init__(self, int_num=0, float_num=1, unit1=None, unit2=None):
self.int = int_num
self.float = decimal.Decimal(str(float_num))
if unit1:
self.units1 = unit1
else:
self.units1 = []
if unit2:
self.units2 = unit2
else:
self.units2 = []
def __str__(self):
return None
def __add__(self, other):
pass
def basic_poi(poi_type=None) -> list:
if poi_type is None:
return basic_number(unit1='m', num=2)
return BasicNumber(unit1='m', num=2)
if poi_type == 'chunk':
return [basic_number(unit1='chunk', num=2), basic_number(unit1='m', num=2)]
return [BasicNumber(unit1='chunk', num=2), BasicNumber(unit1='m', num=2)]
def basic_force() -> list:
return basic_number(unit1='N', num=2)
return BasicNumber(unit1='N', num=2)
def configs(name, option=None) -> dict:
@ -61,8 +80,9 @@ def configs(name, option=None) -> dict:
try:
data = data[option]
except IndexError as exp:
logging.exception(exp)
raise exp
log = 'can\'t find stack named %s in file %s' % (option, name)
configs_logger.exception(log)
raise IndexError(log)
return data

View File

@ -157,7 +157,8 @@ def distance(A, B) -> float:
A & B format: docs.basic_config:basic_poi
"""
poi_dis = configs.basic_poi()
dis = decimal.Decimal('0.0')
for x in A, B:
x = decimal.Decimal(str(x))
xd = A[0] - B[0]
yd = A[1] - B[1]
poi_dis[0] = xd
@ -181,8 +182,9 @@ def config(file_name, stack=None):
with open(file_name, "r") as jf: # jf -> json file
rd = json5.load(jf)
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))
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

3
test_tools.py Normal file
View File

@ -0,0 +1,3 @@
from bin import tools
tools.distance()