From 245cc09716a298afe68df4eaad8c5b1364ab3e95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E7=91=97=E6=9D=B0?= <3695888@qq.com> Date: Sun, 7 Feb 2021 13:50:19 +0800 Subject: [PATCH] reeee --- .gitignore | 2 +- SR-PY.py => Difficult_Rocket.py | 0 bin/client.py | 2 +- bin/configs.py | 40 ++++++++++++++++++++++++--------- bin/tools.py | 8 ++++--- test_tools.py | 3 +++ 6 files changed, 40 insertions(+), 15 deletions(-) rename SR-PY.py => Difficult_Rocket.py (100%) create mode 100644 test_tools.py diff --git a/.gitignore b/.gitignore index 09f9a02..e4094fe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ # VScode file .vscode/ -SR.code-workspace +DR.code-workspace # PYCharm file .idea/ diff --git a/SR-PY.py b/Difficult_Rocket.py similarity index 100% rename from SR-PY.py rename to Difficult_Rocket.py diff --git a/bin/client.py b/bin/client.py index 6c1b474..494208d 100644 --- a/bin/client.py +++ b/bin/client.py @@ -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 diff --git a/bin/configs.py b/bin/configs.py index d360c36..d845ee9 100644 --- a/bin/configs.py +++ b/bin/configs.py @@ -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 diff --git a/bin/tools.py b/bin/tools.py index 88879eb..b360109 100644 --- a/bin/tools.py +++ b/bin/tools.py @@ -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 diff --git a/test_tools.py b/test_tools.py new file mode 100644 index 0000000..57dc77c --- /dev/null +++ b/test_tools.py @@ -0,0 +1,3 @@ +from bin import tools + +tools.distance()