diff --git a/Difficult_Rocket/__init__.py b/Difficult_Rocket/__init__.py index 8159541..d276276 100644 --- a/Difficult_Rocket/__init__.py +++ b/Difficult_Rocket/__init__.py @@ -11,7 +11,7 @@ github: @shenjackyuanjie gitee: @shenjackyuanjie """ -version = '0.6.1' +version = '0.6.2' __version__ = version diff --git a/Difficult_Rocket/api/tools.py b/Difficult_Rocket/api/tools.py index 71c4ac5..4977646 100644 --- a/Difficult_Rocket/api/tools.py +++ b/Difficult_Rocket/api/tools.py @@ -17,14 +17,10 @@ import time import math import decimal import logging -import traceback import configparser -from typing import List from xml.dom.minidom import parse -import Difficult_Rocket - if __name__ == '__main__': # been start will not run this sys.path.append('/bin/libs') sys.path.append('/bin') diff --git a/Difficult_Rocket/client.py b/Difficult_Rocket/client.py index 0717da6..ba325f1 100644 --- a/Difficult_Rocket/client.py +++ b/Difficult_Rocket/client.py @@ -94,8 +94,9 @@ class ClientWindow(Window): self.net_mode = net_mode self.run_input = False # configs - pyglet.resource.path = ['textures'] + pyglet.resource.path = ['/textures/'] pyglet.resource.reindex() + self.set_icon(pyglet.image.load('textures/icon.png')) self.main_config = tools.load_file('configs/main.config') self.game_config = tools.load_file('configs/game.config') # dic diff --git a/Difficult_Rocket/command/api.py b/Difficult_Rocket/command/api.py new file mode 100644 index 0000000..cf7ea1c --- /dev/null +++ b/Difficult_Rocket/command/api.py @@ -0,0 +1,70 @@ +# ------------------------------- +# Difficult Rocket +# Copyright © 2021-2022 by shenjackyuanjie +# All rights reserved +# ------------------------------- + +""" +writen by shenjackyuanjie +mail: 3695888@qq.com +github: @shenjackyuanjie +gitee: @shenjackyuanjie +""" + +# system function +import re + +from typing import Union + + +class CommandText: + """ + CommandLine返回的字符,可以用来搜索 + """ + + def __init__(self, text: str): + self.text = text + self.value_dict = {} + self.value_list = [] + + def find(self, text: str) -> Union[str, False]: + finding = re.match(text, self.text) + if finding: + return finding.group() + else: + return False + + def match(self, text: str) -> bool: + finding = re.match(text, self.text) + if finding: # 如果找到了 + try: + next_find = self.text[finding.span()[1]] + # 这里try因为可能匹配到的是字符串末尾 + except IndexError: + next_find = ' ' + # 直接过滤掉 + if next_find == ' ': + self.text = self.text[finding.span()[1] + 1:] + return True + # 将匹配到的字符串,和最后一个匹配字符后面的字符删除(相当暴力的操作) + return False + else: + return False + + def greedy(self, name: str = None) -> str: + if name: + self.value_dict[name] = self.text + self.value_list.append(self.text) + return self.text + + def value(self, + name: str = None, + split: str = ' ', + middle: list = ('\'', '\"')): + pass + + def __str__(self): + return str(self.text) + + def __int__(self): + return int(self.text) diff --git a/Difficult_Rocket/command/line.py b/Difficult_Rocket/command/line.py index 8778b04..7f2cb95 100644 --- a/Difficult_Rocket/command/line.py +++ b/Difficult_Rocket/command/line.py @@ -11,8 +11,8 @@ github: @shenjackyuanjie gitee: @shenjackyuanjie """ +# system function import time -import re from typing import Union from decimal import Decimal @@ -20,6 +20,7 @@ from decimal import Decimal # from DR from Difficult_Rocket import translate from Difficult_Rocket.api import new_thread +from Difficult_Rocket.command.api import CommandText # from libs.pyglet from libs import pyglet @@ -29,59 +30,6 @@ from libs.pyglet.gui import widgets from libs.pyglet.graphics import Batch, Group -class CommandText: - """ - CommandLine返回的字符,可以用来搜索 - """ - - def __init__(self, text: str): - self.text = text - self.value_dict = {} - self.value_list = [] - - def find(self, text: str) -> bool: - finding = re.match(text, self.text) - if finding: - return True - else: - return False - - def match(self, text: str) -> bool: - finding = re.match(text, self.text) - if finding: # 如果找到了 - try: - next_find = self.text[finding.span()[1]] - # 这里try因为可能匹配到的是字符串末尾 - except IndexError: - next_find = ' ' - # 直接过滤掉 - if next_find == ' ': - self.text = self.text[finding.span()[1] + 1:] - return True - # 将匹配到的字符串,和最后一个匹配字符后面的字符删除(相当暴力的操作) - return False - else: - return False - - def greedy(self, name: str = None) -> str: - if name: - self.value_dict[name] = self.text - self.value_list.append(self.text) - return self.text - - def value(self, - name: str = None, - split: str = ' ', - middle: list = ('\'', '\"')): - pass - - def __str__(self): - return str(self.text) - - def __int__(self): - return int(self.text) - - class CommandLine(widgets.WidgetBase): """ command line show diff --git a/Difficult_Rocket/command/tree.py b/Difficult_Rocket/command/tree.py index ccc5391..0a52068 100644 --- a/Difficult_Rocket/command/tree.py +++ b/Difficult_Rocket/command/tree.py @@ -11,7 +11,52 @@ github: @shenjackyuanjie gitee: @shenjackyuanjie """ -import line +from Difficult_Rocket import version +from Difficult_Rocket.command import line + + + +command_tree = { + 'name': 'DR-root', + 'version': version, + 'information': 'DR这一部分的代码还TM是复制我之前写的屑Census', + 'commands': { + 'info': '啊啊啊啊', + 'hint': '然而并没有什么隐藏信息(确信)', + 'run': '{app_name} help', + 'sub_command': { + 'stop': { + 'info': '停止游戏', + 'hint': 'g 你就在看着我呢~', + 'run': '{command}', + }, + 'default': { + 'info': '重置游戏', + 'hint': 'g 获得成就:我重置我自己', + 'run': '{command}', + }, + 'fps': { + 'sub_command': { + 'log': { + 'info': '输出FPS日志', + 'hint': 'rub 本操作会覆盖现有数据,所以请自行输入命令', + 'run': '{command}', + }, + 'max': { + 'info': '输出最大FPS', + 'hint': 'ub 提醒:这个操作会覆盖文件数据(虽说其实没啥事)', + 'run': '{command}', + }, + 'mix': { + 'info': '输出最小FPS', + 'hint': '获得成就:我打印了分数', + 'run': '{command}', + } + } + } + } + } +} class CommandTree: diff --git a/Difficult_Rocket/guis/format/html.py b/Difficult_Rocket/guis/format/html.py index 3820457..f25596d 100644 --- a/Difficult_Rocket/guis/format/html.py +++ b/Difficult_Rocket/guis/format/html.py @@ -262,7 +262,8 @@ italic_HTML_end = '' def decode_text2HTML(text: str, - configs=None) -> str: + configs=None, + show_style: bool = False) -> str: if text == '': return '' if configs is None: @@ -272,12 +273,11 @@ def decode_text2HTML(text: str, # 根据输入的配置对每一个字符进行样式设定 for config in configs: # 根据 配置"文件" - match_texts = config['match'].finditer(text) # 使用config.match匹配 + match_texts = config['match'].finditer(text) # 使用 config.match 匹配 for match_text in match_texts: # 每一个匹配到的匹配项 text_match = match_text.group() # 缓存一下匹配到的字符,用于匹配显示的字符 - shown_texts = config['shown'].finditer(text_match) # 使用config.shown匹配 + shown_texts = config['shown'].finditer(text_match) # 使用 config.shown 匹配 match_start, match_end = match_text.span() - if 'ignore' in config: # 如果样式选项包含忽略某些字符的tag ignore_texts = config['ignore']['match'].finditer(text_match) # 根据选项匹配可能忽略的字符 ignore = False # 忽略先为False @@ -290,25 +290,21 @@ def decode_text2HTML(text: str, break if ignore: continue # 跳过本次匹配 - if 'tag' in config: # 如果样式选项包含对部分字符添加tag tag_texts = config['tag']['match'].finditer(text_match) # 根据配置的正则表达式匹配要添加tag的字符 for tag_text in tag_texts: # 对每一个匹配到的~~~~~~ for tag_index in range(match_start + tag_text.span()[0], match_start + tag_text.span()[1]): # 用于遍历匹配到的字符 style_list[tag_index] += config['tag']['style'] - # 为匹配到的字符添加样式 for match_index in range(match_start, match_end): # 用于遍历匹配到的字符 - # 这里用match index来精确读写列表里的元素,毕竟re.Match返回的span是两个标点,得遍历 - style_list[match_index] += config['style'] # 字体样式列表的[match_index] += config['style']的样式 - style_list[match_index].show = False # 设置显示属性变为False - + # 这里用 match index 来精确读写列表里的元素,毕竟 re.Match 返回的 span 是两个标点,得遍历 + style_list[match_index] += config['style'] # 字体样式列表的 [match_index] += config['style'] 的样式 + style_list[match_index].show = show_style # 设置显示属性变为 False # 为每一个显示的字符设置显示属性 for shown_text in shown_texts: # 每一个显示的匹配项 for shown_index in range(match_start + shown_text.span()[0], match_start + shown_text.span()[1]): style_list[shown_index].show = True - # 字体样式列表的[shown_index]设置显示属性变为True - + # 字体样式列表的 [shown_index] 设置显示属性变为 True # 开始根据配置好的样式输出HTML文本 style_list[0].prefix += style_list[0].HTML() # 不管怎么说都要在最前面加一个字符标识 for style_index in range(1, len(style_list)): @@ -328,15 +324,15 @@ def decode_text2HTML(text: str, else: # 如果这个字符不显示 if style_list[style_index - 1].show: # 如果前面一个字符显示(且这个字符不显示) style_list[style_index - 1].suffix += style_list[style_index - 1].HTML(suffix=True) - # 如果前面一个字符也不显示那就直接pass + # 如果前面一个字符也不显示那就直接 pass if style_list[-1].show: style_list[-1].suffix += style_list[-1].HTML(suffix=True) - # 输出最终的HTML文本 + # 输出最终的 HTML 文本 formatted_HTML_text = '' # 初始化一下 for style in style_list: # 每一个样式 if style.show: # 如果这个字符显示 formatted_HTML_text += style.prefix + style.text + style.suffix # 文本的后面附加一下 - del style_list # 主动删掉style_list 释放内存 + del style_list # 主动删掉 style_list 释放内存 print(formatted_HTML_text) return formatted_HTML_text # 返回,DONE! diff --git a/Difficult_Rocket/guis/widgets.py b/Difficult_Rocket/guis/widgets.py index 8df32d6..b10bd03 100644 --- a/Difficult_Rocket/guis/widgets.py +++ b/Difficult_Rocket/guis/widgets.py @@ -125,7 +125,7 @@ class InputBox(widgets.WidgetBase): assert type(value) is str, 'Input Box\'s text must be string!' self._text = value self._input_box.text = value - self._HTML_box.text = html.decode_text2HTML(value) + self._HTML_box.text = html.decode_text2HTML(value, show_style=True) @property def cursor_poi(self) -> int: # 光标位置 diff --git a/start.cmd b/start.cmd index cbf93ec..9765693 100644 --- a/start.cmd +++ b/start.cmd @@ -1,2 +1,2 @@ -python Difficult_Rocket.py +python DR.py pause \ No newline at end of file diff --git a/try/julia/decodeHTML.jl b/try/julia/decodeHTML.jl new file mode 100644 index 0000000..72886c6 --- /dev/null +++ b/try/julia/decodeHTML.jl @@ -0,0 +1,15 @@ +#= +decodeHTML: +- Julia version: 1.7.1 +- Author: shenjack +- Date: 2022-01-29 +=# + + +decode_Config = [ + Dict("match" => "aaaaaaa") + ] + +function translatetext2HTML(text::String, configs::Dict{Symbol, Any}, show_code::Bool = false) + +end