reeee
This commit is contained in:
parent
23b9e29abb
commit
245cc09716
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,6 +1,6 @@
|
|||||||
# VScode file
|
# VScode file
|
||||||
.vscode/
|
.vscode/
|
||||||
SR.code-workspace
|
DR.code-workspace
|
||||||
|
|
||||||
# PYCharm file
|
# PYCharm file
|
||||||
.idea/
|
.idea/
|
||||||
|
@ -51,7 +51,7 @@ class RenderThread(mp.Process, pyglet.window.Window):
|
|||||||
self.part_list = tools.config('sys_value/parts.json5')
|
self.part_list = tools.config('sys_value/parts.json5')
|
||||||
self.map_view = [configs.basic_poi(poi_type='chunk')]
|
self.map_view = [configs.basic_poi(poi_type='chunk')]
|
||||||
# dic
|
# dic
|
||||||
self.ships = {} # all ship
|
self.ships = {} # all ship(part)
|
||||||
self.planet_system = {} # hole planet system
|
self.planet_system = {} # hole planet system
|
||||||
# list
|
# list
|
||||||
# re stuff
|
# re stuff
|
||||||
|
@ -19,7 +19,7 @@ except ModuleNotFoundError:
|
|||||||
configs_logger = logging.getLogger('configs')
|
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:
|
if unit1 is None:
|
||||||
unit1 = []
|
unit1 = []
|
||||||
if unit2 is None:
|
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
|
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 = []
|
numbers = []
|
||||||
if num > 1:
|
if num > 1:
|
||||||
for x in range(0, 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:
|
elif num == 1:
|
||||||
return __basic_number(int_num, float_num, unit1, unit2)
|
return _BasicNumber(int_num, float_num, unit1, unit2)
|
||||||
else: # num < 1
|
else: # num < 1
|
||||||
|
|
||||||
raise TypeError('you should give me a num with >= 1!')
|
raise TypeError('you should give me a num with >= 1!')
|
||||||
return numbers
|
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:
|
def basic_poi(poi_type=None) -> list:
|
||||||
if poi_type is None:
|
if poi_type is None:
|
||||||
return basic_number(unit1='m', num=2)
|
return BasicNumber(unit1='m', num=2)
|
||||||
if poi_type == 'chunk':
|
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:
|
def basic_force() -> list:
|
||||||
return basic_number(unit1='N', num=2)
|
return BasicNumber(unit1='N', num=2)
|
||||||
|
|
||||||
|
|
||||||
def configs(name, option=None) -> dict:
|
def configs(name, option=None) -> dict:
|
||||||
@ -61,8 +80,9 @@ def configs(name, option=None) -> dict:
|
|||||||
try:
|
try:
|
||||||
data = data[option]
|
data = data[option]
|
||||||
except IndexError as exp:
|
except IndexError as exp:
|
||||||
logging.exception(exp)
|
log = 'can\'t find stack named %s in file %s' % (option, name)
|
||||||
raise exp
|
configs_logger.exception(log)
|
||||||
|
raise IndexError(log)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
@ -157,7 +157,8 @@ def distance(A, B) -> float:
|
|||||||
A & B format: docs.basic_config:basic_poi
|
A & B format: docs.basic_config:basic_poi
|
||||||
"""
|
"""
|
||||||
poi_dis = configs.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]
|
xd = A[0] - B[0]
|
||||||
yd = A[1] - B[1]
|
yd = A[1] - B[1]
|
||||||
poi_dis[0] = xd
|
poi_dis[0] = xd
|
||||||
@ -181,8 +182,9 @@ def config(file_name, stack=None):
|
|||||||
with open(file_name, "r") as jf: # jf -> json file
|
with open(file_name, "r") as jf: # jf -> json file
|
||||||
rd = json5.load(jf)
|
rd = json5.load(jf)
|
||||||
except FileNotFoundError as exp:
|
except FileNotFoundError as exp:
|
||||||
tools_logger.exception("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)
|
||||||
raise FileNotFoundError("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:
|
if stack is not None:
|
||||||
rd = rd[stack]
|
rd = rd[stack]
|
||||||
return rd
|
return rd
|
||||||
|
3
test_tools.py
Normal file
3
test_tools.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
from bin import tools
|
||||||
|
|
||||||
|
tools.distance()
|
Loading…
Reference in New Issue
Block a user