Changes to be committed:
modified: Difficult_Rocket/api/Exp/command.py modified: Difficult_Rocket/client/__init__.py modified: Difficult_Rocket/client/fps/fps_log.py modified: Difficult_Rocket/command/api.py modified: Difficult_Rocket/command/line.py modified: Difficult_Rocket/utils/__init__.py modified: Difficult_Rocket/utils/new_thread.py modified: Difficult_Rocket/utils/tools.py modified: Difficult_Rocket/utils/translate.py new file: try/mcdr/command_tree.py
This commit is contained in:
parent
a0deee3488
commit
369b675963
@ -35,6 +35,13 @@ class CommandQMarkMissing(CommandParseError):
|
|||||||
例如: /command "aawwdawda awdaw """
|
例如: /command "aawwdawda awdaw """
|
||||||
|
|
||||||
|
|
||||||
|
class CommandQMarkConflict(CommandParseError):
|
||||||
|
"""命令中引号位置冲突
|
||||||
|
例如: /command "aaaa "aaaa aaaa"""
|
||||||
|
first_qmark_pos = None
|
||||||
|
conflict_qmark_pos = None
|
||||||
|
|
||||||
|
|
||||||
class CommandQMarkPreMissing(CommandQMarkMissing):
|
class CommandQMarkPreMissing(CommandQMarkMissing):
|
||||||
"""命令中 前面的引号缺失
|
"""命令中 前面的引号缺失
|
||||||
例如: /command aaaa" aaaaaa"""
|
例如: /command aaaa" aaaaaa"""
|
||||||
|
@ -23,7 +23,7 @@ from decimal import Decimal
|
|||||||
|
|
||||||
# Difficult_Rocket function
|
# Difficult_Rocket function
|
||||||
from Difficult_Rocket.command import line, tree
|
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.utils.translate import tr
|
||||||
from Difficult_Rocket.guis.widgets import InputBox
|
from Difficult_Rocket.guis.widgets import InputBox
|
||||||
# from Difficult_Rocket.client.screen import DRScreen
|
# from Difficult_Rocket.client.screen import DRScreen
|
||||||
|
@ -19,6 +19,7 @@ from decimal import Decimal
|
|||||||
|
|
||||||
from libs.pyglet.clock import get_frequency
|
from libs.pyglet.clock import get_frequency
|
||||||
|
|
||||||
|
|
||||||
class FpsLogger:
|
class FpsLogger:
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
stable_fps: int = 60,
|
stable_fps: int = 60,
|
||||||
@ -32,7 +33,6 @@ class FpsLogger:
|
|||||||
self._max_fps = stable_fps
|
self._max_fps = stable_fps
|
||||||
self._min_fps = stable_fps
|
self._min_fps = stable_fps
|
||||||
|
|
||||||
|
|
||||||
def update_tick(self,
|
def update_tick(self,
|
||||||
tick: Decimal):
|
tick: Decimal):
|
||||||
now_fps = get_frequency()
|
now_fps = get_frequency()
|
||||||
|
@ -14,7 +14,7 @@ gitee: @shenjackyuanjie
|
|||||||
# system function
|
# system function
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from typing import Union, Optional, Type, Tuple
|
from typing import Union, Optional, Type, Tuple, List
|
||||||
|
|
||||||
# DR
|
# DR
|
||||||
from Difficult_Rocket.api.Exp.command import *
|
from Difficult_Rocket.api.Exp.command import *
|
||||||
@ -39,22 +39,16 @@ class CommandText:
|
|||||||
self.tree_node = tree_list
|
self.tree_node = tree_list
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_command(raw_command: Union[str, "CommandText"]) -> Tuple[list, Union[Type[CommandParseError], type(True)]]:
|
def parse_text(raw_text: str) -> str:
|
||||||
spilt_list = str(raw_command).split(" ")
|
q_mark_iter = re.finditer('\\"', raw_text)
|
||||||
|
for q_mark in q_mark_iter:
|
||||||
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] != "\\": # 末尾有一个没有被转义的 "
|
|
||||||
|
|
||||||
...
|
...
|
||||||
|
|
||||||
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]:
|
def find(self, text: str) -> Union[str, bool]:
|
||||||
finding = re.match(text, self.text)
|
finding = re.match(text, self.text)
|
||||||
|
@ -19,7 +19,7 @@ from decimal import Decimal
|
|||||||
|
|
||||||
# from DR
|
# from DR
|
||||||
from utils import translate
|
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 Difficult_Rocket.command.api import CommandText
|
||||||
|
|
||||||
# from libs.pyglet
|
# from libs.pyglet
|
||||||
|
@ -10,3 +10,7 @@ mail: 3695888@qq.com
|
|||||||
github: @shenjackyuanjie
|
github: @shenjackyuanjie
|
||||||
gitee: @shenjackyuanjie
|
gitee: @shenjackyuanjie
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from .new_thread import new_thread
|
||||||
|
|
||||||
|
__all__ = ['new_thread']
|
||||||
|
@ -19,11 +19,6 @@ GNU Lesser General Public License v3.0(GNU LGPL v3)
|
|||||||
(have some changes)
|
(have some changes)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__all__ = [
|
|
||||||
'new_thread',
|
|
||||||
'FunctionThread'
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def copy_signature(target: Callable, origin: Callable) -> Callable:
|
def copy_signature(target: Callable, origin: Callable) -> Callable:
|
||||||
"""
|
"""
|
||||||
|
@ -194,142 +194,3 @@ def C_R_P(position, degrees): # stand for calculation
|
|||||||
sin = math.sin(radians)
|
sin = math.sin(radians)
|
||||||
rotated_pos = (position[0] * cos - position[1] * sin, position[0] * sin + position[1] * cos)
|
rotated_pos = (position[0] * cos - position[1] * sin, position[0] * sin + position[1] * cos)
|
||||||
return rotated_pos
|
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]
|
|
||||||
|
@ -35,10 +35,10 @@ class Lang:
|
|||||||
lang.lang(xxx, xxx)来获取翻译过的值
|
lang.lang(xxx, xxx)来获取翻译过的值
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, language: str = 'zh-CN'):
|
def __init__(self, language: str = 'zh-CN') -> None:
|
||||||
self.语言 = language
|
self.语言 = language
|
||||||
self.翻译结果 = tools.load_file(f'configs/lang/{language}.json5')
|
self.翻译结果 = tools.load_file(f'configs/lang/{language}.toml')
|
||||||
self.默认翻译 = tools.load_file('configs/lang/zh-CN.json5')
|
self.默认翻译 = tools.load_file('configs/lang/zh-CN.toml')
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return self.语言
|
return self.语言
|
||||||
@ -52,22 +52,22 @@ class Lang:
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
raise LanguageError(f'there\'s no key {item} in both {self.语言} and zh-CN')
|
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':
|
if key == 'language' or key == 'lang':
|
||||||
try:
|
try:
|
||||||
self.翻译结果 = tools.load_file(f'configs/lang/{value}.json5')
|
self.翻译结果 = tools.load_file(f'configs/lang/{value}.toml')
|
||||||
self.语言 = value
|
self.语言 = value
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
raise LanguageError(f'{value}\'s language json5 file not found')
|
raise LanguageError(f'{value}\'s language toml file not found')
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def set_language(self, language) -> None:
|
def set_language(self, language) -> None:
|
||||||
try:
|
try:
|
||||||
self.翻译结果 = tools.load_file(f'configs/lang/{language}.json5')
|
self.翻译结果 = tools.load_file(f'configs/lang/{language}.toml')
|
||||||
self.语言 = language
|
self.语言 = language
|
||||||
except FileNotFoundError:
|
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]:
|
def lang(self, *args) -> Union[int, str, list, dict]:
|
||||||
try:
|
try:
|
||||||
|
11
try/mcdr/command_tree.py
Normal file
11
try/mcdr/command_tree.py
Normal 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')
|
Loading…
Reference in New Issue
Block a user