Merge pull request #3 from shenjackyuanjie/main

Update fork
This commit is contained in:
Ray Chen 2022-06-06 12:18:10 +08:00 committed by GitHub
commit 8b0988fb6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 45 additions and 172 deletions

1
.gitignore vendored
View File

@ -146,3 +146,4 @@ dmypy.json
# some other thing
other things/
.git-/

View File

@ -35,6 +35,13 @@ class CommandQMarkMissing(CommandParseError):
例如: /command "aawwdawda awdaw """
class CommandQMarkConflict(CommandParseError):
"""命令中引号位置冲突
例如: /command "aaaa "aaaa aaaa"""
first_qmark_pos = None
conflict_qmark_pos = None
class CommandQMarkPreMissing(CommandQMarkMissing):
"""命令中 前面的引号缺失
例如: /command aaaa" aaaaaa"""

View File

@ -23,7 +23,7 @@ from decimal import Decimal
# Difficult_Rocket function
from Difficult_Rocket.command import line, tree
from Difficult_Rocket.api import new_thread
from Difficult_Rocket.utils import new_thread
from Difficult_Rocket.utils.translate import tr
from Difficult_Rocket.guis.widgets import InputBox
# from Difficult_Rocket.client.screen import DRScreen

View File

@ -19,6 +19,7 @@ from decimal import Decimal
from libs.pyglet.clock import get_frequency
class FpsLogger:
def __init__(self,
stable_fps: int = 60,
@ -32,7 +33,6 @@ class FpsLogger:
self._max_fps = stable_fps
self._min_fps = stable_fps
def update_tick(self,
tick: Decimal):
now_fps = get_frequency()

View File

@ -14,7 +14,7 @@ gitee: @shenjackyuanjie
# system function
import re
from typing import Union, Optional, Type, Tuple
from typing import Union, Optional, Type, Tuple, List
# DR
from Difficult_Rocket.api.Exp.command import *
@ -39,22 +39,16 @@ class CommandText:
self.tree_node = tree_list
@staticmethod
def parse_command(raw_command: Union[str, "CommandText"]) -> Tuple[list, Union[Type[CommandParseError], type(True)]]:
spilt_list = str(raw_command).split(" ")
spilts = [None, None]
for spited in spilt_list:
if len(spited) > 1:
if spited[0] == "\"": # 开头有一个 "
if spilts[0] is None: # 如果没有标记一个字符串开头
pass
else: # 已经标记了一个字符串开头
return spilt_list, CommandQMarkPosError
if spited[-1] == "\"" and spited[-2] != "\\": # 末尾有一个没有被转义的 "
def parse_text(raw_text: str) -> str:
q_mark_iter = re.finditer('\\"', raw_text)
for q_mark in q_mark_iter:
...
return spilt_list, True
@staticmethod
def parse_command(raw_command: Union[str, "CommandText"]) -> Tuple[List[str], Union[CommandParseError, type(True)]]:
spilt_list = re.split(r'', raw_command)
done_list = [re.sub(r'\\"', '"', raw_text) for raw_text in spilt_list]
return done_list, True # 完事了
def find(self, text: str) -> Union[str, bool]:
finding = re.match(text, self.text)

View File

@ -19,7 +19,7 @@ from decimal import Decimal
# from DR
from utils import translate
from Difficult_Rocket.api import new_thread
from Difficult_Rocket.utils import new_thread
from Difficult_Rocket.command.api import CommandText
# from libs.pyglet

View File

@ -10,3 +10,7 @@ mail: 3695888@qq.com
github: @shenjackyuanjie
gitee: @shenjackyuanjie
"""
from .new_thread import new_thread
__all__ = ['new_thread']

View File

@ -19,11 +19,6 @@ GNU Lesser General Public License v3.0GNU LGPL v3)
(have some changes)
"""
__all__ = [
'new_thread',
'FunctionThread'
]
def copy_signature(target: Callable, origin: Callable) -> Callable:
"""

View File

@ -194,142 +194,3 @@ def C_R_P(position, degrees): # stand for calculation
sin = math.sin(radians)
rotated_pos = (position[0] * cos - position[1] * sin, position[0] * sin + position[1] * cos)
return rotated_pos
"""
Physics calculation
"""
def is_decimal(A: any) -> bool:
if isinstance(A, decimal.Decimal):
return False
else:
return True
def F_D(A: decimal, B: decimal) -> decimal:
if is_decimal(A) and is_decimal(B):
return A / B
def F_Mu(A: decimal, B: decimal) -> decimal:
if is_decimal(A) and is_decimal(B):
return A * B
def F_Mi(A: decimal, B: decimal) -> decimal:
if is_decimal(A) and is_decimal(B):
return A - B
def F_A(A: decimal, B: decimal) -> decimal:
if is_decimal(A) and is_decimal(B):
return A + B
def D_C(listA: list, listB: list): # stand for Duplicate check
"""
usage:\n
input two list\n
the fun will do duplicate check and sort then\n
the fun won't return any thing just change the list now
"""
for unit in listB:
if unit in listA:
listA.remove(unit)
listB.remove(unit)
else:
continue
listA.sort()
listB.sort()
def S_C_float_check(SC): # stand for Scientific notation's float check
"""
formats:
SC list format:docs.basic_config.json:basic_number"""
while SC[0] >= 10:
SC[0] = F_D(SC[0], 10)
SC[1] += 1
while SC[0] < 1:
SC[0] = F_Mu(SC[0], 10)
SC[1] -= 1
def S_N_M(*SN): # stand for Scientific notation multiple
"""
formats:
A & B & C list format:docs.basic_config.json:basic_number"""
if len(SN) < 2:
raise TypeError('it need more than 1!')
elif len(SN) == 2:
return __S_N_M(SN[0], SN[1])
else:
R = __S_N_M(SN[0], SN[1])
for A in SN[2:]:
R = __S_N_M(R, A)
return R
def __S_N_M(A, B):
"""
formats:
A & B list format:docs.basic_config.json:basic_number"""
R = [F_Mu(A[0], B[0]), A[1] + B[1]]
S_C_float_check(R)
Unit1, Unit2 = A[2] + B[2], A[3] + B[3]
if Unit1 is None:
Unit1 = []
D_C(Unit1, Unit2)
R += [Unit1, Unit2]
return R
def S_N_D(A, B): # stand for Scientific notation divided
"""
formats:
A & B list format:docs.basic_config:basic_number"""
R = [F_D(A[0], B[0]), A[1] - B[1]]
S_C_float_check(R)
Unit1, Unit2 = A[2] + B[3], A[3] + B[2]
if Unit1 is None:
Unit1 = []
D_C(Unit1, Unit2)
R += [Unit1, Unit2]
return R
def G_C(M, m, R, G): # stand for gravity calculation
"""
formats:
M : ship's mass
m : planet's mass
R : distance to the planet
G : Gravitational constant
M & m & R format: docs.basic_config:basic_number
"""
g = configs.basic_force()
A = S_N_M(M, m, G)
g = S_N_D(A, S_N_M(R, R))
return g
def distance(A, B):
"""
formats:
A & B format: docs.basic_config:basic_poi
"""
poi_dis = configs.basic_poi()
for x in A, B:
x = decimal.Decimal(str(x))
xd = A[0] - B[0]
yd = A[1] - B[1]
poi_dis[0] = xd
poi_dis[1] = yd
# 勾股定理
poi_dis[0] **= 2
poi_dis[1] **= 2
poi_dis.append(poi_dis[0] + poi_dis[1])
poi_dis[2] **= 0.5
return poi_dis[2]

View File

@ -35,10 +35,10 @@ class Lang:
lang.lang(xxx, xxx)来获取翻译过的值
"""
def __init__(self, language: str = 'zh-CN'):
def __init__(self, language: str = 'zh-CN') -> None:
self.语言 = language
self.翻译结果 = tools.load_file(f'configs/lang/{language}.json5')
self.默认翻译 = tools.load_file('configs/lang/zh-CN.json5')
self.翻译结果 = tools.load_file(f'configs/lang/{language}.toml')
self.默认翻译 = tools.load_file('configs/lang/zh-CN.toml')
def __str__(self) -> str:
return self.语言
@ -52,22 +52,22 @@ class Lang:
except KeyError:
raise LanguageError(f'there\'s no key {item} in both {self.语言} and zh-CN')
def __setitem__(self, key, value):
def __setitem__(self, key, value) -> None:
if key == 'language' or key == 'lang':
try:
self.翻译结果 = tools.load_file(f'configs/lang/{value}.json5')
self.翻译结果 = tools.load_file(f'configs/lang/{value}.toml')
self.语言 = value
except FileNotFoundError:
raise LanguageError(f'{value}\'s language json5 file not found')
raise LanguageError(f'{value}\'s language toml file not found')
else:
raise NotImplementedError
def set_language(self, language) -> None:
try:
self.翻译结果 = tools.load_file(f'configs/lang/{language}.json5')
self.翻译结果 = tools.load_file(f'configs/lang/{language}.toml')
self.语言 = language
except FileNotFoundError:
raise LanguageError(f'{language}\'s language json5 file not found')
raise LanguageError(f'{language}\'s language toml file not found')
def lang(self, *args) -> Union[int, str, list, dict]:
try:

11
try/mcdr/command_tree.py Normal file
View File

@ -0,0 +1,11 @@
# -------------------------------
# Difficult Rocket
# Copyright © 2021-2022 by shenjackyuanjie
# All rights reserved
# -------------------------------
from mcdreforged.api.command import *
test_command_tree = Literal('!!test')
test_command_tree.parse('aaaaa')