pyscreeps-arena 0.5.7.7__py3-none-any.whl → 0.5.8a0__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/compiler.py +60 -26
- pyscreeps_arena/core/const.py +1 -1
- pyscreeps_arena/project.7z +0 -0
- {pyscreeps_arena-0.5.7.7.dist-info → pyscreeps_arena-0.5.8a0.dist-info}/METADATA +1 -1
- {pyscreeps_arena-0.5.7.7.dist-info → pyscreeps_arena-0.5.8a0.dist-info}/RECORD +8 -8
- {pyscreeps_arena-0.5.7.7.dist-info → pyscreeps_arena-0.5.8a0.dist-info}/WHEEL +0 -0
- {pyscreeps_arena-0.5.7.7.dist-info → pyscreeps_arena-0.5.8a0.dist-info}/entry_points.txt +0 -0
- {pyscreeps_arena-0.5.7.7.dist-info → pyscreeps_arena-0.5.8a0.dist-info}/top_level.txt +0 -0
pyscreeps_arena/compiler.py
CHANGED
|
@@ -17,6 +17,10 @@ python_version_info = sys.version_info
|
|
|
17
17
|
python_version_info = f"{python_version_info.major}.{python_version_info.minor}.{python_version_info.micro}"
|
|
18
18
|
|
|
19
19
|
|
|
20
|
+
class MatchCaseError(Exception):
|
|
21
|
+
pass
|
|
22
|
+
|
|
23
|
+
|
|
20
24
|
def replace_src_prefix(file_list):
|
|
21
25
|
"""
|
|
22
26
|
将列表中以'./src.'开头的字符串替换为'./'
|
|
@@ -28,16 +32,17 @@ def replace_src_prefix(file_list):
|
|
|
28
32
|
替换后的新列表
|
|
29
33
|
"""
|
|
30
34
|
_ = []
|
|
31
|
-
|
|
35
|
+
|
|
32
36
|
for item in file_list:
|
|
33
37
|
if isinstance(item, str) and item.startswith('./src.'):
|
|
34
38
|
_new = item.replace('./src.', './', 1)
|
|
35
39
|
if _new in file_list:
|
|
36
40
|
continue
|
|
37
41
|
_.append(item)
|
|
38
|
-
|
|
42
|
+
|
|
39
43
|
return _
|
|
40
44
|
|
|
45
|
+
|
|
41
46
|
# def InsertPragmaBefore(content:str) -> str:
|
|
42
47
|
# """
|
|
43
48
|
# 在content的开头插入__pragma__('noalias', 'undefined')等内容 |
|
|
@@ -160,8 +165,8 @@ class GameConstructionBoost{{
|
|
|
160
165
|
}};
|
|
161
166
|
import {{ Portal as GamePortal}} from 'arena/season_{config.season}/{const.ARENA_GREEN}/{"advanced" if config.level in ["advance", "advanced"] else "basic"}/prototypes';
|
|
162
167
|
""",
|
|
163
|
-
# import {Portal} from 'arena/season_1/portal_exploration/basic/prototypes';
|
|
164
|
-
|
|
168
|
+
# import {Portal} from 'arena/season_1/portal_exploration/basic/prototypes';
|
|
169
|
+
|
|
165
170
|
const.ARENA_BLUE: lambda: f"""
|
|
166
171
|
const ARENA_COLOR_TYPE = "BLUE";
|
|
167
172
|
const GameScoreCollector = GameStructureSpawn;
|
|
@@ -415,8 +420,7 @@ class Compiler_Utils(Compiler_Const):
|
|
|
415
420
|
py_files.append(item)
|
|
416
421
|
elif os.path.isdir(_path):
|
|
417
422
|
rel = os.path.relpath(final_dir_path, project_path)
|
|
418
|
-
core.warn(f'Compiler.expand_folder_imports', core.lformat(LOC_DIR_UNDER_NONINIT_DIR, [item, rel]), end='', head='\n', ln=config.language
|
|
419
|
-
|
|
423
|
+
core.warn(f'Compiler.expand_folder_imports', core.lformat(LOC_DIR_UNDER_NONINIT_DIR, [item, rel]), end='', head='\n', ln=config.language)
|
|
420
424
|
|
|
421
425
|
# 为每个 .py 文件生成导入语句
|
|
422
426
|
if py_files:
|
|
@@ -436,7 +440,6 @@ class Compiler_Utils(Compiler_Const):
|
|
|
436
440
|
with open(fpath, 'w', encoding='utf-8') as f:
|
|
437
441
|
f.write(new_content)
|
|
438
442
|
|
|
439
|
-
|
|
440
443
|
def find_chain_import(self, fpath: str, search_dirs: list[str], project_path: str = None, records: dict[str, None] = None) -> list[str]:
|
|
441
444
|
r"""
|
|
442
445
|
查找文件中的所有import语句,并返回所有import的文件路径 | find all import statements in a file and return the paths of all imported files
|
|
@@ -572,13 +575,13 @@ class Compiler_Utils(Compiler_Const):
|
|
|
572
575
|
return imps
|
|
573
576
|
|
|
574
577
|
@staticmethod
|
|
575
|
-
def relist_pyimports_to_jsimports(base_dir:str, pyimps:list[str]) -> list[str]:
|
|
578
|
+
def relist_pyimports_to_jsimports(base_dir: str, pyimps: list[str]) -> list[str]:
|
|
576
579
|
"""
|
|
577
580
|
将python的imports路径列表转换为js的imports路径列表 | convert a list of python imports paths to a list of js imports paths
|
|
578
581
|
"""
|
|
579
582
|
jsimps = []
|
|
580
583
|
for pyimp in pyimps:
|
|
581
|
-
rel_path_nodes:list[str] = os.path.relpath(pyimp, base_dir).replace('\\', '/').split('/')
|
|
584
|
+
rel_path_nodes: list[str] = os.path.relpath(pyimp, base_dir).replace('\\', '/').split('/')
|
|
582
585
|
if rel_path_nodes[-1] == '__init__.py':
|
|
583
586
|
rel_path_nodes.pop()
|
|
584
587
|
else:
|
|
@@ -644,7 +647,7 @@ class Compiler_Utils(Compiler_Const):
|
|
|
644
647
|
result = '\n'.join(calls_to_add) + '\n' + result
|
|
645
648
|
|
|
646
649
|
return result
|
|
647
|
-
|
|
650
|
+
|
|
648
651
|
@staticmethod
|
|
649
652
|
def process_mate_code(code):
|
|
650
653
|
# 用于存储匹配到的信息
|
|
@@ -678,12 +681,11 @@ class Compiler_Utils(Compiler_Const):
|
|
|
678
681
|
for variable_name, class_name in mate_assignments:
|
|
679
682
|
output_string = f"# > insert Object.defineProperty ({class_name}, '{variable_name}', property.call ({class_name}, {class_name}.{variable_name}._MateGet_, {class_name}.{variable_name}._MateSet_));"
|
|
680
683
|
output_strings.append(output_string)
|
|
681
|
-
|
|
682
|
-
return code + '\n'.join(output_strings)
|
|
683
684
|
|
|
685
|
+
return code + '\n'.join(output_strings)
|
|
684
686
|
|
|
685
687
|
@staticmethod
|
|
686
|
-
def remove_long_docstring(content:str) -> str:
|
|
688
|
+
def remove_long_docstring(content: str) -> str:
|
|
687
689
|
"""
|
|
688
690
|
移除长注释 | remove long docstring
|
|
689
691
|
"""
|
|
@@ -1082,7 +1084,6 @@ class Compiler(CompilerBase):
|
|
|
1082
1084
|
with open(fpath, 'w', encoding='utf-8') as f:
|
|
1083
1085
|
f.write(content)
|
|
1084
1086
|
|
|
1085
|
-
|
|
1086
1087
|
core.lprint(GREEN.format('[2/6]'), LOC_DONE, " ", LOC_PREPROCESSING_FINISH, sep="", head="\r", ln=config.language)
|
|
1087
1088
|
return _imports, _js_imports, _pre_sort_, _pre_define_, _js_replace_
|
|
1088
1089
|
|
|
@@ -1153,7 +1154,7 @@ class Compiler(CompilerBase):
|
|
|
1153
1154
|
|
|
1154
1155
|
content = self.auto_read(self.target_js)
|
|
1155
1156
|
if modules is None: modules = []
|
|
1156
|
-
new_modules, new_content = [],""
|
|
1157
|
+
new_modules, new_content = [], ""
|
|
1157
1158
|
for line in content.split('\n'):
|
|
1158
1159
|
m = re.search(self.JS_IMPORT_PAT, line)
|
|
1159
1160
|
if not m:
|
|
@@ -1199,7 +1200,7 @@ class Compiler(CompilerBase):
|
|
|
1199
1200
|
"""
|
|
1200
1201
|
return re.sub(r'import[^\n]*\n', '', raw)
|
|
1201
1202
|
|
|
1202
|
-
def generate_total_js(self, usr_modules, t_imps: list[str], f_sorts, f_replaces, g_replaces) -> str:
|
|
1203
|
+
def generate_total_js(self, usr_modules, t_imps: list[str], f_sorts, f_replaces, g_replaces, min_js_files=None) -> str:
|
|
1203
1204
|
"""
|
|
1204
1205
|
生成总的main.js
|
|
1205
1206
|
按照如下顺序组合:
|
|
@@ -1213,6 +1214,7 @@ class Compiler(CompilerBase):
|
|
|
1213
1214
|
:param f_sorts: dict{module_name: sort_priority}
|
|
1214
1215
|
:param f_replaces: dict{module_name: dict{old: new}}
|
|
1215
1216
|
:param g_replaces: dict{old: new}
|
|
1217
|
+
:param min_js_files: list[str] # .min.js文件路径列表
|
|
1216
1218
|
:return: str
|
|
1217
1219
|
"""
|
|
1218
1220
|
arena_name = const.ARENA_NAMES.get(config.arena, const.ARENA_NAMES['green']) # like green -> spawn_and_swamp
|
|
@@ -1220,6 +1222,13 @@ class Compiler(CompilerBase):
|
|
|
1220
1222
|
total_js = f"const __VERSION__ = '{const.VERSION}';\nconst __PYTHON_VERSION__ = '{python_version_info}';" + self.TOTAL_INSERT_AT_HEAD + f"\nexport var LANGUAGE = '{config.language}';\n"
|
|
1221
1223
|
total_js += f"const __AUTHOR__ = '{const.AUTHOR}';\nconst __AUTHOR_CN__ = '{const.BILIBILI_NAME}';"
|
|
1222
1224
|
|
|
1225
|
+
# 添加.min.js文件的import语句
|
|
1226
|
+
if min_js_files:
|
|
1227
|
+
for min_js_path in min_js_files:
|
|
1228
|
+
min_js_filename = os.path.basename(min_js_path)
|
|
1229
|
+
total_js += f"\nimport \"./{min_js_filename}\";"
|
|
1230
|
+
total_js += "\n"
|
|
1231
|
+
|
|
1223
1232
|
core.lprint(WAIT, LOC_GENERATING_TOTAL_MAIN_JS, end="", ln=config.language)
|
|
1224
1233
|
|
|
1225
1234
|
# TODO: IMPS donot work
|
|
@@ -1285,19 +1294,29 @@ class Compiler(CompilerBase):
|
|
|
1285
1294
|
def find_add_pure_js_files(self, sorts, modules):
|
|
1286
1295
|
"""
|
|
1287
1296
|
找到所有的纯js文件,并添加到modules中
|
|
1297
|
+
忽略.min.js文件,这些文件会被单独处理
|
|
1288
1298
|
:param sorts:
|
|
1289
1299
|
:param modules:
|
|
1290
|
-
:return:
|
|
1300
|
+
:return: list 返回所有.min.js文件的列表
|
|
1291
1301
|
"""
|
|
1302
|
+
min_js_files = []
|
|
1292
1303
|
for root, dirs, files in os.walk(self.lib_dir):
|
|
1293
1304
|
for file in files:
|
|
1294
1305
|
if file.endswith('.js') and file not in modules:
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1306
|
+
# 如果是.min.js文件,不拷贝到target,而是记录到单独列表
|
|
1307
|
+
if file.endswith('.min.js'):
|
|
1308
|
+
fpath = str(os.path.join(root, file))
|
|
1309
|
+
min_js_files.append(fpath)
|
|
1310
|
+
else:
|
|
1311
|
+
# 普通js文件,按原逻辑处理
|
|
1312
|
+
fpath = str(os.path.join(root, file))
|
|
1313
|
+
fname = file.replace('\\', '/')
|
|
1314
|
+
# copy file to target
|
|
1315
|
+
shutil.copy(fpath, os.path.join(self.target_dir, fname))
|
|
1316
|
+
sorts[fname] = self.__parse_js_file_sort(fpath)
|
|
1317
|
+
modules.append("./" + fname)
|
|
1318
|
+
|
|
1319
|
+
return min_js_files
|
|
1301
1320
|
|
|
1302
1321
|
def compile(self, paste=False):
|
|
1303
1322
|
"""
|
|
@@ -1308,8 +1327,7 @@ class Compiler(CompilerBase):
|
|
|
1308
1327
|
imps, jimps, sorts, defs, reps = self.pre_compile()
|
|
1309
1328
|
self.transcrypt_cmd()
|
|
1310
1329
|
imports, modules = self.analyze_rebuild_main_js(defs, jimps)
|
|
1311
|
-
self.find_add_pure_js_files(sorts, modules)
|
|
1312
|
-
total_js = imports + "\n" + self.generate_total_js(replace_src_prefix(modules), imps, sorts, self.FILE_STRONG_REPLACE, reps)
|
|
1330
|
+
min_js_files = self.find_add_pure_js_files(sorts, modules)
|
|
1313
1331
|
|
|
1314
1332
|
core.lprint(WAIT, LOC_EXPORTING_TOTAL_MAIN_JS, end="", ln=config.language)
|
|
1315
1333
|
|
|
@@ -1320,12 +1338,28 @@ class Compiler(CompilerBase):
|
|
|
1320
1338
|
if not mjs_path.endswith('js'):
|
|
1321
1339
|
mjs_path = os.path.join(mjs_path, 'main.mjs')
|
|
1322
1340
|
|
|
1341
|
+
# 获取目标目录路径
|
|
1342
|
+
dir_path = os.path.dirname(mjs_path)
|
|
1343
|
+
build_dir_path = os.path.dirname(build_main_mjs)
|
|
1344
|
+
|
|
1345
|
+
# 复制.min.js文件到目标目录
|
|
1346
|
+
for min_js_path in min_js_files:
|
|
1347
|
+
min_js_filename = os.path.basename(min_js_path)
|
|
1348
|
+
# 复制到build目录
|
|
1349
|
+
shutil.copy(min_js_path, os.path.join(build_dir_path, min_js_filename))
|
|
1350
|
+
# 复制到最终导出目录
|
|
1351
|
+
shutil.copy(min_js_path, os.path.join(dir_path, min_js_filename))
|
|
1352
|
+
|
|
1353
|
+
# 生成total_js,传入.min.js文件列表
|
|
1354
|
+
total_js = imports + "\n" + self.generate_total_js(
|
|
1355
|
+
replace_src_prefix(modules), imps, sorts, self.FILE_STRONG_REPLACE, reps, min_js_files
|
|
1356
|
+
)
|
|
1357
|
+
|
|
1323
1358
|
# write main.mjs
|
|
1324
1359
|
with open(build_main_mjs, 'w', encoding='utf-8') as f:
|
|
1325
1360
|
f.write(total_js)
|
|
1326
1361
|
|
|
1327
1362
|
# export main.mjs
|
|
1328
|
-
dir_path = os.path.dirname(mjs_path)
|
|
1329
1363
|
if not os.path.exists(dir_path):
|
|
1330
1364
|
core.error('Compiler.compile', core.lformat(LOC_EXPORT_DIR_PATH_NOT_EXISTS, [dir_path]), head='\n', ln=config.language)
|
|
1331
1365
|
with open(mjs_path, 'w', encoding='utf-8') as f:
|
pyscreeps_arena/core/const.py
CHANGED
pyscreeps_arena/project.7z
CHANGED
|
Binary file
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
pyscreeps_arena/__init__.py,sha256=GWrCpZnrzPwbBzhNqk8gTvV4VSwkP2DbxK8lR0E_SzY,3223
|
|
2
2
|
pyscreeps_arena/build.py,sha256=DQeGLnID2FjpsWTbnqwt2cOp28olWK68U67bfbFJSOU,177
|
|
3
|
-
pyscreeps_arena/compiler.py,sha256=
|
|
3
|
+
pyscreeps_arena/compiler.py,sha256=RdJNwEvWOzS36UhwM6wxK2_bV2JtMBaNg6dLotVKj2k,66843
|
|
4
4
|
pyscreeps_arena/localization.py,sha256=Dr0G6n8DvT6syfC0urqwjccYpEPEfcwYyJx3f9s-6a8,6031
|
|
5
|
-
pyscreeps_arena/project.7z,sha256=
|
|
5
|
+
pyscreeps_arena/project.7z,sha256=CGsjtI5zDu_hKQaaHORHqvFTYwNaUYUBp0m8YYcDH_Y,567508
|
|
6
6
|
pyscreeps_arena/core/__init__.py,sha256=qoP_rx1TpbDLJoTm5via4XPwEPaV1FXr1SYvoVoHGms,41
|
|
7
7
|
pyscreeps_arena/core/basic.py,sha256=DFvyDTsTXf2bQtnS9s254TrkshvRwajaHcvTyVvJyqw,2790
|
|
8
8
|
pyscreeps_arena/core/config.py,sha256=x_JhVHlVZqB3qA7UyACVnwZjg2gZU-BIs49UxZzwCoE,637
|
|
9
|
-
pyscreeps_arena/core/const.py,sha256=
|
|
9
|
+
pyscreeps_arena/core/const.py,sha256=mMQEMFyGcYLBy__nLuQ55VmeUO72yWvtJi6syC810N8,590
|
|
10
10
|
pyscreeps_arena/core/core.py,sha256=3Nty8eLKPNgwnYk_sVNBPrWuKxBXI2od8nfEezsEAZQ,5157
|
|
11
11
|
pyscreeps_arena/core/main.py,sha256=-FNSOEjksNlDfCbUqsjtPSUW8vT3qxEdfzXqT5Tdsik,170
|
|
12
12
|
pyscreeps_arena/core/utils.py,sha256=N9OOkORvrqnJakayaFp9qyS0apWhB9lBK4xyyYkhFdo,215
|
|
@@ -40,8 +40,8 @@ pyscreeps_arena/ui/qmapv/test_simple_array.py,sha256=hPnLXcFrn6I1X4JXFM3RVpBPhU_
|
|
|
40
40
|
pyscreeps_arena/ui/qrecipe/__init__.py,sha256=2Guvr9k5kGkZboiVC0aNF4u48LRbmcCm2dqOhEF52Tw,59
|
|
41
41
|
pyscreeps_arena/ui/qrecipe/model.py,sha256=s3lr_DXtsBgt8bVg1_wLz-dX88QKi77mNkqM5VJsGwE,13200
|
|
42
42
|
pyscreeps_arena/ui/qrecipe/qrecipe.py,sha256=z57VLmlpMripdpGtVCkKR0csJQhw5-WpocZK5l2xTVg,39398
|
|
43
|
-
pyscreeps_arena-0.5.
|
|
44
|
-
pyscreeps_arena-0.5.
|
|
45
|
-
pyscreeps_arena-0.5.
|
|
46
|
-
pyscreeps_arena-0.5.
|
|
47
|
-
pyscreeps_arena-0.5.
|
|
43
|
+
pyscreeps_arena-0.5.8a0.dist-info/METADATA,sha256=EmaCm8n8kVGQ1BmZO0hhXqtHdr3tpZawaume2Fh-aqE,2356
|
|
44
|
+
pyscreeps_arena-0.5.8a0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
45
|
+
pyscreeps_arena-0.5.8a0.dist-info/entry_points.txt,sha256=pnpuPPadwQsxQPaR1rXzUo0fUvhOcC7HTHlf7TYXr7M,141
|
|
46
|
+
pyscreeps_arena-0.5.8a0.dist-info/top_level.txt,sha256=l4uLyMR2NOy41ngBMh795jOHTFk3tgYKy64-9cgjVng,16
|
|
47
|
+
pyscreeps_arena-0.5.8a0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|