pyscreeps-arena 0.5.6.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyscreeps_arena/__init__.py +51 -0
- pyscreeps_arena/build.py +7 -0
- pyscreeps_arena/compiler.py +1221 -0
- pyscreeps_arena/core/__init__.py +1 -0
- pyscreeps_arena/core/basic.py +72 -0
- pyscreeps_arena/core/config.py +19 -0
- pyscreeps_arena/core/const.py +28 -0
- pyscreeps_arena/core/core.py +132 -0
- pyscreeps_arena/core/main.py +9 -0
- pyscreeps_arena/core/utils.py +11 -0
- pyscreeps_arena/localization.py +146 -0
- pyscreeps_arena/project.7z +0 -0
- pyscreeps_arena/ui/P2PY.py +108 -0
- pyscreeps_arena/ui/__init__.py +10 -0
- pyscreeps_arena/ui/project_ui.py +214 -0
- pyscreeps_arena/ui/rs_icon.py +43 -0
- pyscreeps_arena-0.5.6.6.dist-info/METADATA +50 -0
- pyscreeps_arena-0.5.6.6.dist-info/RECORD +21 -0
- pyscreeps_arena-0.5.6.6.dist-info/WHEEL +5 -0
- pyscreeps_arena-0.5.6.6.dist-info/entry_points.txt +4 -0
- pyscreeps_arena-0.5.6.6.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from pyscreeps_arena.core.core import *
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
#
|
|
3
|
+
# pyscreeps_arena - basic.py
|
|
4
|
+
# Author: 我阅读理解一直可以的
|
|
5
|
+
# Template: V0.1
|
|
6
|
+
# Versions:
|
|
7
|
+
# .2025 01 01 - v0.1:
|
|
8
|
+
# Created.
|
|
9
|
+
#
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
import os
|
|
13
|
+
import sys
|
|
14
|
+
import shutil
|
|
15
|
+
import inspect
|
|
16
|
+
from colorama import Fore, Back
|
|
17
|
+
from pyscreeps_arena.core import const
|
|
18
|
+
from pyscreeps_arena.core import config
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class __pyscreeps_arena_themeException(Exception):
|
|
22
|
+
"""
|
|
23
|
+
具有__pyscreeps_arena_themeException主题的异常类 | Exception class with __pyscreeps_arena_themeException theme
|
|
24
|
+
:param *args: str 异常信息 | Exception message
|
|
25
|
+
:param indent=1: int 在每一行的开头和其中所有超过一行的部分替换为\n + \t * indent | Replace at the beginning of each line and all parts that exceed one line with \n + \t * indent
|
|
26
|
+
"""
|
|
27
|
+
try:
|
|
28
|
+
# 尝试获取终端的宽度 | Try to get the width of the terminal
|
|
29
|
+
__TERMINAL_COLUMNS = shutil.get_terminal_size().columns
|
|
30
|
+
except AttributeError:
|
|
31
|
+
# 如果无法获取终端宽度,设置一个默认值 | If the terminal width cannot be obtained, set a default value
|
|
32
|
+
__TERMINAL_COLUMNS = 80 # 通常终端的默认宽度是80个字符 | The default width of the terminal is usually 80 characters
|
|
33
|
+
|
|
34
|
+
__SEPARATOR = "-" * __TERMINAL_COLUMNS
|
|
35
|
+
|
|
36
|
+
def __init__(self, *args: str, indent: int = 1):
|
|
37
|
+
txts = ["\n", self.__SEPARATOR, "\n"]
|
|
38
|
+
# 现在我需要遍历每一个元素:
|
|
39
|
+
# 首先,移除开头的所有\n,并确保在开头有且只有一个\n
|
|
40
|
+
# 然后,将其中\n替换为\n + \t * indent
|
|
41
|
+
## Now I need to iterate every element:
|
|
42
|
+
## First, remove all \n at the beginning, and make sure there is only one \n at the beginning
|
|
43
|
+
## Then, replace the \n in it with \n + \t * indent
|
|
44
|
+
for arg in args:
|
|
45
|
+
tmp = arg.strip("\n\t\r ")
|
|
46
|
+
if not tmp: continue
|
|
47
|
+
replaced = "\n" + "\t" * indent
|
|
48
|
+
tmp = replaced + tmp.replace("\n", replaced)
|
|
49
|
+
txts.append(tmp)
|
|
50
|
+
super().__init__("".join(txts))
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
# 不可实例化异常 | Cannot instantiate exception
|
|
54
|
+
class CannotInstantiate(__pyscreeps_arena_themeException):
|
|
55
|
+
pass
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
# 静态类(不可实例化) | Static class
|
|
59
|
+
class StaticClass:
|
|
60
|
+
def __new__(cls, *args, **kwargs):
|
|
61
|
+
raise CannotInstantiate(
|
|
62
|
+
f"Class:'{cls.__name__}' can not be instantiate, because it's marked as a static class."
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
# 静态类Meta(不可实例化) | Static metaclass
|
|
66
|
+
class StaticMeta(type):
|
|
67
|
+
def __call__(cls, *args, **kwargs):
|
|
68
|
+
raise CannotInstantiate(
|
|
69
|
+
f"Class:'{cls.__name__}' can not be instantiate, because it's marked as a static class."
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
PROJECT_EXCEPTION = __pyscreeps_arena_themeException
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
#
|
|
3
|
+
# pyscreeps_arena - config.py
|
|
4
|
+
# Author: 我阅读理解一直可以的
|
|
5
|
+
# Template: V0.1
|
|
6
|
+
# Versions:
|
|
7
|
+
# .2025 01 01 - v0.1:
|
|
8
|
+
# Created.
|
|
9
|
+
#
|
|
10
|
+
import os
|
|
11
|
+
from pyscreeps_arena.core import const
|
|
12
|
+
arena = "green"
|
|
13
|
+
level = "basic"
|
|
14
|
+
season = "beta"
|
|
15
|
+
language = 'cn'
|
|
16
|
+
# 默认路径: 用户 + ScreepsArena + beta-spawn_and_swamp + main.mjs
|
|
17
|
+
target = None
|
|
18
|
+
TARGET_GETTER = lambda: os.path.join(os.path.expanduser('~'), 'ScreepsArena', f'{("season" + season) if season.isdigit() else season}-{const.ARENA_NAMES.get(arena, "spawn_and_swamp")}{"-advanced" if level in ["advance", "advanced"] else ""}', 'main.mjs')
|
|
19
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
#
|
|
3
|
+
# pyscreeps_arena - const.py
|
|
4
|
+
# Author: 我阅读理解一直可以的
|
|
5
|
+
# Template: V0.1
|
|
6
|
+
# Versions:
|
|
7
|
+
# .2025 01 01 - v0.1:
|
|
8
|
+
# Created.
|
|
9
|
+
#
|
|
10
|
+
import re
|
|
11
|
+
|
|
12
|
+
VERSION = "0.5.6.6"
|
|
13
|
+
AUTHOR = "●ω<🤍♪"
|
|
14
|
+
STEAM_ID = "1029562896"
|
|
15
|
+
GITHUB_NAME = "EagleBaby"
|
|
16
|
+
BILIBILI_NAME = "我阅读理解一直可以的"
|
|
17
|
+
|
|
18
|
+
ARENA_GREEN = "portal_exploration"
|
|
19
|
+
ARENA_BLUE = "spawn_strike"
|
|
20
|
+
ARENA_RED = "construct_and_control"
|
|
21
|
+
ARENA_GRAY = "tutorial"
|
|
22
|
+
|
|
23
|
+
ARENA_NAMES = {
|
|
24
|
+
"green": ARENA_GREEN,
|
|
25
|
+
"blue" : ARENA_BLUE,
|
|
26
|
+
"red" : ARENA_RED,
|
|
27
|
+
"gray" : ARENA_GRAY,
|
|
28
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
#
|
|
3
|
+
# pyscreeps_arena - core.py
|
|
4
|
+
# Author: 我阅读理解一直可以的
|
|
5
|
+
# Template: V0.1
|
|
6
|
+
# Versions:
|
|
7
|
+
# .2025 01 01 - v0.1:
|
|
8
|
+
# Created.
|
|
9
|
+
#
|
|
10
|
+
|
|
11
|
+
from pyscreeps_arena.core.utils import *
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class __core__(PROJECT_EXCEPTION, metaclass=StaticMeta):
|
|
15
|
+
@staticmethod
|
|
16
|
+
def lprint(*args, sep=' ', end='\n', head="", ln='en') -> None:
|
|
17
|
+
new_args = []
|
|
18
|
+
for arg in args:
|
|
19
|
+
if isinstance(arg, dict) and "en" in arg:
|
|
20
|
+
new_args.append(str(arg.get(ln, arg)))
|
|
21
|
+
else:
|
|
22
|
+
new_args.append(arg)
|
|
23
|
+
print(head, end="", sep="")
|
|
24
|
+
print(*new_args, sep=sep, end=end)
|
|
25
|
+
|
|
26
|
+
@staticmethod
|
|
27
|
+
def ltrans(*args, auto:bool=True, ln='en') -> list:
|
|
28
|
+
new_args = []
|
|
29
|
+
if not args: return new_args
|
|
30
|
+
for arg in args:
|
|
31
|
+
if isinstance(arg, dict) and ln in arg:
|
|
32
|
+
new_args.append(str(arg.get(ln, arg)))
|
|
33
|
+
else:
|
|
34
|
+
new_args.append(arg)
|
|
35
|
+
return new_args[0] if auto and len(new_args) == 1 else new_args
|
|
36
|
+
|
|
37
|
+
@staticmethod
|
|
38
|
+
def lformat(element, formats:list) -> dict:
|
|
39
|
+
new_element = {}
|
|
40
|
+
if not element: return element
|
|
41
|
+
if not isinstance(element, dict): return element
|
|
42
|
+
if not formats: return element
|
|
43
|
+
if 'en' not in element: return element
|
|
44
|
+
for key, value in element.items():
|
|
45
|
+
element[key] = value.format(*formats)
|
|
46
|
+
return element
|
|
47
|
+
|
|
48
|
+
@classmethod
|
|
49
|
+
def log(cls, caller: str, *args, sep:str=" ", head:str="", end:str="\n", ln:str='en') -> None:
|
|
50
|
+
"""
|
|
51
|
+
输出一条日志 | Output a log
|
|
52
|
+
Args:
|
|
53
|
+
caller: str 调用者 | Caller
|
|
54
|
+
*args: str 日志信息 | Log message
|
|
55
|
+
sep=" ": str 分隔符 | Separator
|
|
56
|
+
head="" : str 头部插入 | Head insert
|
|
57
|
+
end='\n': str 结尾符 | End
|
|
58
|
+
ln='en' : str 语言 | Language
|
|
59
|
+
|
|
60
|
+
Returns:
|
|
61
|
+
None
|
|
62
|
+
"""
|
|
63
|
+
print(f"{head}{Fore.BLACK}[{cls.ltrans(caller, ln=ln)} {Fore.YELLOW}Log{Fore.BLACK}]:", *cls.ltrans(*args, auto=False, ln=ln), Fore.RESET, sep=sep, end=end)
|
|
64
|
+
|
|
65
|
+
@classmethod
|
|
66
|
+
def info(cls, caller: str, *args, sep:str=" ", head:str="", end:str="\n", ln:str='en') -> None:
|
|
67
|
+
"""
|
|
68
|
+
输出一条信息 | Output an information
|
|
69
|
+
Args:
|
|
70
|
+
caller: str 调用者 | Caller
|
|
71
|
+
*args: str 信息 | Information
|
|
72
|
+
sep=" ": str 分隔符 | Separator
|
|
73
|
+
head="" : str 头部插入 | Head insert
|
|
74
|
+
end='\n': str 结尾符 | End
|
|
75
|
+
ln='en' : str 语言 | Language
|
|
76
|
+
|
|
77
|
+
Returns:
|
|
78
|
+
None
|
|
79
|
+
"""
|
|
80
|
+
print(f"{head}{Fore.BLACK}[{cls.ltrans(caller, ln=ln)} {Fore.GREEN}Info{Fore.BLACK}]:", *cls.ltrans(*args, auto=False, ln=ln), Fore.RESET, sep=sep, end=end)
|
|
81
|
+
|
|
82
|
+
@classmethod
|
|
83
|
+
def warn(cls, caller: str, *args, sep:str=" ", head:str="", end:str="\n", ln:str='en') -> None:
|
|
84
|
+
"""
|
|
85
|
+
输出一条警告 | Output a warning
|
|
86
|
+
Args:
|
|
87
|
+
caller: str 调用者 | Caller
|
|
88
|
+
*args: str 警告信息 | Warning message
|
|
89
|
+
sep=" ": str 分隔符 | Separator
|
|
90
|
+
head="" : str 头部插入 | Head insert
|
|
91
|
+
end='\n': str 结尾符 | End
|
|
92
|
+
ln='en' : str 语言 | Language
|
|
93
|
+
|
|
94
|
+
Returns:
|
|
95
|
+
None
|
|
96
|
+
"""
|
|
97
|
+
print(f"{head}{Fore.BLACK}[{cls.ltrans(caller, ln=ln)} {Fore.YELLOW}Warn{Fore.BLACK}]:", *cls.ltrans(*args, auto=False, ln=ln), Fore.RESET, sep=sep, end=end)
|
|
98
|
+
|
|
99
|
+
@classmethod
|
|
100
|
+
def error(cls, caller: str, *args, sep:str=" ", head:str="", end:str="\n", ln:str='en', indent:int=1, error:bool=False, ecode:int=1) -> None:
|
|
101
|
+
"""
|
|
102
|
+
生成一个异常并抛出 | Generate an exception and throw it
|
|
103
|
+
Args:
|
|
104
|
+
caller: str 调用者 | Caller
|
|
105
|
+
*args: str 异常信息 | Exception message
|
|
106
|
+
sep=" " : str 分隔符 | Separator
|
|
107
|
+
head="" : str 头部插入 | Head insert
|
|
108
|
+
end='\n' : str 结尾符 | End
|
|
109
|
+
ln='en' : str 语言 | Language
|
|
110
|
+
indent=1 : int 在每一行的开头和其中所有超过一行的部分替换为\n + \t * indent |
|
|
111
|
+
Replace at the beginning of each line and all parts that exceed one line with \n + \t * indent
|
|
112
|
+
error=False : bool 是否抛出异常(False仅退出, True抛出异常) | Whether to throw an exception (False only exit, True throw an exception)
|
|
113
|
+
ecode=1 : int 退出码(仅在error=False时有效) | Exit code (only valid when error=False)
|
|
114
|
+
|
|
115
|
+
Returns:
|
|
116
|
+
None
|
|
117
|
+
"""
|
|
118
|
+
txts = [f"{head}{Fore.BLACK}[{cls.ltrans(caller, ln=ln)} {Fore.RED}Error{Fore.BLACK}]:"]
|
|
119
|
+
txts.extend(cls.ltrans(*args, auto=False, ln=ln))
|
|
120
|
+
txts.append(Fore.RESET)
|
|
121
|
+
txt = sep.join(txts) + end
|
|
122
|
+
if error:
|
|
123
|
+
raise PROJECT_EXCEPTION(txt, indent=indent)
|
|
124
|
+
else:
|
|
125
|
+
print(txt, sep="", end="")
|
|
126
|
+
sys.exit(ecode)
|
|
127
|
+
|
|
128
|
+
class core(__core__):
|
|
129
|
+
pass
|
|
130
|
+
|
|
131
|
+
if __name__ == '__main__':
|
|
132
|
+
core()
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
from pyscreeps_arena.core import *
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
TEMPLATE = {
|
|
5
|
+
'en': "English",
|
|
6
|
+
'cn': "中文",
|
|
7
|
+
}
|
|
8
|
+
LOC_DONE = {
|
|
9
|
+
"en": Fore.GREEN + "[DONE]" + Fore.RESET,
|
|
10
|
+
"cn": Fore.GREEN + "[完成]" + Fore.RESET,
|
|
11
|
+
}
|
|
12
|
+
LOC_DIR_NOT_EXISTS = {
|
|
13
|
+
'en': "{} dir not exists. got: {}",
|
|
14
|
+
'cn': "{} 目录不存在。传入: {}",
|
|
15
|
+
}
|
|
16
|
+
LOC_FILE_NOT_EXISTS = {
|
|
17
|
+
'en': "{} File not exists: {}. You can ignore if it's a not used file.",
|
|
18
|
+
'cn': "{} 文件不存在: {}. 如果它是一个未使用的文件,您可以忽略它。",
|
|
19
|
+
}
|
|
20
|
+
LOC_PREPROCESSING = {
|
|
21
|
+
'en': "Preprocessing ...",
|
|
22
|
+
'cn': "预处理中 ...",
|
|
23
|
+
}
|
|
24
|
+
LOC_PREPROCESSING_FINISH = {
|
|
25
|
+
'en': "Preprocessing finished.",
|
|
26
|
+
'cn': "预处理完成。",
|
|
27
|
+
}
|
|
28
|
+
LOC_IMPORT_STAR_ERROR = {
|
|
29
|
+
'en': "Only 'from xxx import *' is allowed, but found 'import {}'." + Fore.LIGHTBLUE_EX + "Maybe you can use 'from {} import *' instead." + Fore.RESET,
|
|
30
|
+
'cn': "只允许'from xxx import *',但是发现了'import {}'。" + Fore.LIGHTBLUE_EX + "也许你可以使用'from {} import *'代替之。" + Fore.RESET,
|
|
31
|
+
}
|
|
32
|
+
LOC_IMPORT_STAR2_ERROR = {
|
|
33
|
+
'en': "Only 'from xxx import *' is allowed, but found 'from {} import {}'." + Fore.LIGHTBLUE_EX + "Maybe you can use 'from {} import *' instead." + Fore.RESET,
|
|
34
|
+
'cn': "只允许'from xxx import *',但是发现了'from {} import {}'。 " + Fore.LIGHTBLUE_EX + "也许你可以使用'from {} import *'代替之。" + Fore.RESET,
|
|
35
|
+
}
|
|
36
|
+
LOC_CHAIN_FILE_NOT_EXISTS = {
|
|
37
|
+
'en': "During search chain-import at {}, lineno {}:\n\tfile not exists: {}",
|
|
38
|
+
'cn': "在搜索链式导入时,位于 {},行号 {}:\n\t文件不存在: {}",
|
|
39
|
+
}
|
|
40
|
+
LOC_TRANSCRYPTING = {
|
|
41
|
+
'en': "Transcrypting ... # cmd:{}",
|
|
42
|
+
'cn': "转译中 ... # cmd命令:{}",
|
|
43
|
+
}
|
|
44
|
+
LOC_TRANSCRYPTING_FINISH = {
|
|
45
|
+
'en': "Transcrypting finished.",
|
|
46
|
+
'cn': "转译完成。",
|
|
47
|
+
}
|
|
48
|
+
LOC_TRANSCRYPTING_ERROR = {
|
|
49
|
+
'en': "Transcrypting error: see details above.",
|
|
50
|
+
'cn': "转译出错: 请查看上面的详细信息。",
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
LOC_ANALYZING_AND_REBUILDING_MAIN_JS = {
|
|
54
|
+
'en': "analyzing and rebuilding js files ...",
|
|
55
|
+
'cn': "正在分析和重建js文件 ...",
|
|
56
|
+
}
|
|
57
|
+
LOC_ANALYZING_AND_REBUILDING_MAIN_JS_FINISH = {
|
|
58
|
+
'en': "analyzing and rebuilding js files finished.",
|
|
59
|
+
'cn': "分析和重建js文件完成。",
|
|
60
|
+
}
|
|
61
|
+
LOC_GENERATING_TOTAL_MAIN_JS = {
|
|
62
|
+
'en': "generating total main.js ...",
|
|
63
|
+
'cn': "正在生成总的 main.js ...",
|
|
64
|
+
}
|
|
65
|
+
LOC_GENERATING_TOTAL_MAIN_JS_FINISH = {
|
|
66
|
+
'en': "generating total main.js finished.",
|
|
67
|
+
'cn': "生成总的 main.js 完成。",
|
|
68
|
+
}
|
|
69
|
+
LOC_EXPORTING_TOTAL_MAIN_JS = {
|
|
70
|
+
'en': "exporting total main.js ...",
|
|
71
|
+
'cn': "正在导出总的 main.js ...",
|
|
72
|
+
}
|
|
73
|
+
LOC_USR_EXPORT_INFO = {
|
|
74
|
+
'en': "usr export to {}",
|
|
75
|
+
'cn': "用户指定导出到 {}",
|
|
76
|
+
}
|
|
77
|
+
LOC_COPY_TO_CLIPBOARD = {
|
|
78
|
+
'en': "copy code to clipboard.",
|
|
79
|
+
'cn': "已复制代码内容到剪贴板。",
|
|
80
|
+
}
|
|
81
|
+
LOC_EXPORT_DIR_PATH_NOT_EXISTS = {
|
|
82
|
+
'en': "export dir path not exists: {}",
|
|
83
|
+
'cn': "目标导出目录不存在: {}",
|
|
84
|
+
}
|
|
85
|
+
LOC_EXPORTING_TOTAL_MAIN_JS_FINISH = {
|
|
86
|
+
'en': "exporting main.js to target finished.",
|
|
87
|
+
'cn': "已将main.js导出到指定目标。",
|
|
88
|
+
}
|
|
89
|
+
LOC_CLEAN_BUILD_DIR = {
|
|
90
|
+
'en': "clean build dir ...",
|
|
91
|
+
'cn': "正在清理build目录 ...",
|
|
92
|
+
}
|
|
93
|
+
LOC_BUILD_DIR_NOT_EXISTS = {
|
|
94
|
+
'en': "build dir not exists",
|
|
95
|
+
'cn': "build目录不存在",
|
|
96
|
+
}
|
|
97
|
+
LOC_MAIN_MJS_NOT_EXISTS = {
|
|
98
|
+
'en': "main.mjs not exists",
|
|
99
|
+
'cn': "main.mjs 不存在",
|
|
100
|
+
}
|
|
101
|
+
LOC_CLEAN_BUILD_DIR_FINISH = {
|
|
102
|
+
'en': "clean build dir finished.",
|
|
103
|
+
'cn': "清理build目录完成。",
|
|
104
|
+
}
|
|
105
|
+
LOC_COPYING_TO_BUILD_DIR = {
|
|
106
|
+
'en': "copying to build dir: {}...",
|
|
107
|
+
'cn': "正在复制到build目录: {}...",
|
|
108
|
+
}
|
|
109
|
+
LOC_COPYING_TO_BUILD_DIR_FINISH = {
|
|
110
|
+
'en': "copying to build dir finished.",
|
|
111
|
+
'cn': "复制到build目录完成。",
|
|
112
|
+
}
|
|
113
|
+
LOC_SORT_NUMBER_ERROR = {
|
|
114
|
+
'en': "sort number error: {}, use 65535 instead.",
|
|
115
|
+
'cn': "sort的值错误: {}, 使用 65535 代替。",
|
|
116
|
+
}
|
|
117
|
+
LOC_PYFILE_WORD_WARNING_CHECK_GET = {
|
|
118
|
+
'en': "Please use 'dict.py_get' instead of general 'dict.get'. (add '# > ignore' same line to ignore it if you sure right).",
|
|
119
|
+
'cn': "请使用 'dict.py_get' 而不是通用的 'dict.get'。 (如果确定你是对的,请在同一行添加 '# > ignore' 来忽略它。)",
|
|
120
|
+
}
|
|
121
|
+
LOC_PYFILE_WORD_WARNING_CHECK_MATH = {
|
|
122
|
+
'en': "Please remove 'import math' and use 'math' in 'builtin'. (add '# > ignore' same line to ignore it if you sure right).",
|
|
123
|
+
'cn': "请删除 'import math' 并使用 'builtin' 中的 'math'。 (如果确定你是对的,请在同一行添加 '# > ignore' 来忽略它。)",
|
|
124
|
+
}
|
|
125
|
+
LOC_PYFILE_WORD_WARNING_CHECK_CLEAR = {
|
|
126
|
+
'en': "Please use 'container.py_clear' instead of general 'container.clear'. (add '# > ignore' same line to ignore it if you sure right).",
|
|
127
|
+
'cn': "请使用 'container.py_clear' 而不是通用的 'container.clear'。 (如果确定你是对的,请在同一行添加 '# > ignore' 来忽略它。)",
|
|
128
|
+
}
|
|
129
|
+
LOC_PYFILE_WORD_WARNING_INDEX_MINUS_ONE = {
|
|
130
|
+
'en': "Index by '[-1]' may not work in js. (add '# > ignore' same line to ignore it if you sure right).",
|
|
131
|
+
'cn': "在 js 中,通过 '[-1]' 索引可能不起作用。 (如果确定你是对的,请在同一行添加 '# > ignore' 来忽略它。)",
|
|
132
|
+
}
|
|
133
|
+
LOC_NOT_SUPPORT_PYFILE_INIT = {
|
|
134
|
+
'en': 'Not support __init__.py! Please remove it(the init file) and use from directory.xxx import xxxx instead.',
|
|
135
|
+
'cn': '不支持 __init__.py!请删除它(初始化文件)并使用 from directory.xxx import xxxx 代替之。',
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
# V0.5.4
|
|
139
|
+
LOC_DIR_UNDER_NONINIT_DIR = {
|
|
140
|
+
'en': "Directory [{}] is located under [{}] without __init__.py, therefore it is ignored.",
|
|
141
|
+
'cn': "目录 [{}] 位于 `无__init__.py`的目录[{}]下,因此被忽略。",
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if __name__ == '__main__':
|
|
145
|
+
lprint(TEMPLATE)
|
|
146
|
+
|
|
Binary file
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# png_to_py.py - 将PNG图片转换为Python模块(最终验证版)
|
|
2
|
+
import base64
|
|
3
|
+
import sys
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
import re
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def png_to_py(png_path, py_path=None, var_name=None):
|
|
9
|
+
"""
|
|
10
|
+
将PNG图片转换为Python模块文件
|
|
11
|
+
|
|
12
|
+
:param png_path: PNG图片路径
|
|
13
|
+
:param py_path: 输出的.py文件路径(默认为图片同名.py)
|
|
14
|
+
:param var_name: 变量名(默认为文件名的大写形式)
|
|
15
|
+
"""
|
|
16
|
+
png_file = Path(png_path)
|
|
17
|
+
|
|
18
|
+
if not png_file.exists():
|
|
19
|
+
raise FileNotFoundError(f"文件 '{png_path}' 不存在")
|
|
20
|
+
|
|
21
|
+
if png_file.suffix.lower() != '.png':
|
|
22
|
+
print(f"[警告] 文件 '{png_path}' 不是PNG格式")
|
|
23
|
+
return False
|
|
24
|
+
|
|
25
|
+
# 自动生成输出路径
|
|
26
|
+
if py_path is None:
|
|
27
|
+
py_path = png_file.with_suffix('.py')
|
|
28
|
+
else:
|
|
29
|
+
py_path = Path(py_path)
|
|
30
|
+
|
|
31
|
+
# 自动生成变量名
|
|
32
|
+
if var_name is None:
|
|
33
|
+
base_name = png_file.stem.replace('-', '_').replace(' ', '_')
|
|
34
|
+
base_name = re.sub(r'[^0-9a-zA-Z_]', '', base_name)
|
|
35
|
+
if base_name and base_name[0].isdigit():
|
|
36
|
+
base_name = f'ICON_{base_name}'
|
|
37
|
+
var_name = base_name.upper()
|
|
38
|
+
|
|
39
|
+
try:
|
|
40
|
+
# 读取PNG文件并转换为base64
|
|
41
|
+
with open(png_file, 'rb') as f:
|
|
42
|
+
png_data = f.read()
|
|
43
|
+
base64_data = base64.b64encode(png_data).decode('utf-8')
|
|
44
|
+
|
|
45
|
+
print(f"[DEBUG] 读取PNG文件: {len(png_data)} 字节")
|
|
46
|
+
print(f"[DEBUG] Base64编码长度: {len(base64_data)} 字符")
|
|
47
|
+
|
|
48
|
+
# 生成Python代码(关键修复:使用 len({var_name}))
|
|
49
|
+
py_content = f'''# -*- coding: utf-8 -*-
|
|
50
|
+
"""
|
|
51
|
+
PyQt6资源模块: {png_file.name}
|
|
52
|
+
由 png_to_py.py 自动生成
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
# Base64编码的PNG数据(单行,无换行符)
|
|
56
|
+
{var_name} = b"{base64_data}"
|
|
57
|
+
|
|
58
|
+
def get_pixmap():
|
|
59
|
+
\"\"\"返回QPixmap对象\"\"\"
|
|
60
|
+
from PyQt6.QtGui import QPixmap
|
|
61
|
+
from PyQt6.QtCore import QByteArray
|
|
62
|
+
|
|
63
|
+
byte_array = QByteArray.fromBase64({var_name})
|
|
64
|
+
pixmap = QPixmap()
|
|
65
|
+
pixmap.loadFromData(byte_array)
|
|
66
|
+
return pixmap
|
|
67
|
+
|
|
68
|
+
def get_icon():
|
|
69
|
+
\"\"\"返回QIcon对象\"\"\"
|
|
70
|
+
from PyQt6.QtGui import QIcon
|
|
71
|
+
return QIcon(get_pixmap())
|
|
72
|
+
|
|
73
|
+
if __name__ == '__main__':
|
|
74
|
+
import sys
|
|
75
|
+
from PyQt6.QtWidgets import QApplication
|
|
76
|
+
|
|
77
|
+
app = QApplication.instance() or QApplication(sys.argv)
|
|
78
|
+
|
|
79
|
+
print(f"资源模块 {var_name} 已加载")
|
|
80
|
+
print(f"字节数据长度: {{len({var_name})}} 字节") # ✅ 修复:使用 {var_name}
|
|
81
|
+
|
|
82
|
+
# 验证能否正确加载
|
|
83
|
+
pixmap = get_pixmap()
|
|
84
|
+
print(f"QPixmap加载成功: 尺寸 {{pixmap.width()}}x{{pixmap.height()}}")
|
|
85
|
+
'''
|
|
86
|
+
|
|
87
|
+
# 写入Python文件
|
|
88
|
+
with open(py_path, 'w', encoding='utf-8') as f:
|
|
89
|
+
f.write(py_content)
|
|
90
|
+
|
|
91
|
+
print(f"✓ 成功: {png_path} -> {py_path}")
|
|
92
|
+
print(f" 变量名: {var_name}")
|
|
93
|
+
return True
|
|
94
|
+
|
|
95
|
+
except Exception as e:
|
|
96
|
+
print(f"错误: 转换失败 - {e}")
|
|
97
|
+
import traceback
|
|
98
|
+
traceback.print_exc()
|
|
99
|
+
return False
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
if __name__ == '__main__':
|
|
103
|
+
if len(sys.argv) > 1:
|
|
104
|
+
target = sys.argv[1]
|
|
105
|
+
else:
|
|
106
|
+
target = "icon.png"
|
|
107
|
+
|
|
108
|
+
png_to_py(target, "rs_icon.py")
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
PyScreeps Arena UI模块
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from .rs_icon import get_icon, get_pixmap
|
|
7
|
+
from .project_ui import ProjectCreatorUI, run_project_creator
|
|
8
|
+
from .P2PY import png_to_py
|
|
9
|
+
|
|
10
|
+
__all__ = ['get_icon', 'get_pixmap', 'ProjectCreatorUI', 'run_project_creator', 'png_to_py']
|