pyscreeps-arena 0.5.9a0__py3-none-any.whl → 0.5.9b0__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.
@@ -8,6 +8,7 @@ import shutil
8
8
  import chardet
9
9
  import subprocess
10
10
  import pyperclip
11
+ import datetime
11
12
  from colorama import Fore
12
13
  from typing import List, Optional, Tuple, Union
13
14
 
@@ -114,8 +115,8 @@ export var loop = function () {
114
115
  timeLine = get.cpu_us();
115
116
  if (get._SCH_FLAG) sch.handle();
116
117
  stepCost = get.cpu_us() - timeLine;
117
- std.show_usage ();
118
- print("knowCost:", knowCost, "monitorCost:", monitorCost, "stepCost:", stepCost);
118
+ //std.show_usage ();
119
+ //print("knowCost:", knowCost, "monitorCost:", monitorCost, "stepCost:", stepCost);
119
120
  if (know.draw) know.draw();
120
121
  };
121
122
  """
@@ -648,6 +649,82 @@ class Compiler_Utils(Compiler_Const):
648
649
 
649
650
  return result
650
651
 
652
+ @staticmethod
653
+ def stage_called_replace(caller_name: str, content: str) -> str:
654
+ """
655
+ 移除 '@<caller_name>(...)' 装饰器行,并在文末添加对应的 _<caller_name>Login 调用。
656
+
657
+ 对于类方法: _<caller_name>Login("ClassName", "method_name", a, b, ...)
658
+ 对于普通函数: _<caller_name>Login("", "function_name", a, b, ...)
659
+ """
660
+ calls_to_add = []
661
+ deletions = []
662
+
663
+ # 1. 收集所有类定义的位置和缩进
664
+ class_pattern = re.compile(r'^(\s*)class\s+(\w+)', re.MULTILINE)
665
+ classes = [(m.start(), len(m.group(1)), m.group(2))
666
+ for m in class_pattern.finditer(content)]
667
+
668
+ # 2. 查找所有 @<caller_name>(...) 装饰器(支持多行参数)
669
+ decorator_pattern = re.compile(
670
+ r'^\s*@\s*' + re.escape(caller_name) + r'\s*\((.*?)\)\s*$\n?',
671
+ re.MULTILINE | re.DOTALL
672
+ )
673
+
674
+ for dec_match in decorator_pattern.finditer(content):
675
+ dec_start = dec_match.start()
676
+ dec_end = dec_match.end()
677
+ # 提取装饰器的参数
678
+ params_str = dec_match.group(1).strip()
679
+
680
+ # 查找接下来的函数定义(跳过可能的空行)
681
+ after_decorator = content[dec_end:]
682
+ func_match = re.search(r'^(\s*)def\s+([^\s\(]+)', after_decorator, re.MULTILINE)
683
+
684
+ if not func_match:
685
+ continue
686
+
687
+ func_indent_len = len(func_match.group(1))
688
+ func_name = func_match.group(2)
689
+
690
+ # 3. 确定类名:查找装饰器前最近的、缩进小于函数缩进的类
691
+ class_name = ""
692
+ for cls_pos, cls_indent_len, cls_name in reversed(classes):
693
+ if cls_pos < dec_match.start() and func_indent_len > cls_indent_len:
694
+ class_name = cls_name
695
+ break
696
+
697
+ # 4. 处理参数,保持参数的格式
698
+ # 移除参数中的换行和多余空格,保持参数列表的格式
699
+ params = []
700
+ if params_str:
701
+ # 简单处理参数,保持引号内的内容不变
702
+ # 这里可以根据需要进行更复杂的参数解析
703
+ params = [p.strip() for p in params_str.split(',') if p.strip()]
704
+
705
+ # 构建参数部分的字符串
706
+ params_part = ""
707
+ if params:
708
+ params_part = ", " + ", ".join(params)
709
+
710
+ # 5. 记录删除位置和调用信息
711
+ deletions.append((dec_start, dec_end))
712
+ calls_to_add.append(f'_{caller_name}Login("{class_name}", "{func_name}"{params_part})')
713
+
714
+ # 6. 应用删除(倒序避免位置偏移)
715
+ if not deletions:
716
+ return content
717
+
718
+ result = content
719
+ for start, end in sorted(deletions, key=lambda x: x[0], reverse=True):
720
+ result = result[:start] + result[end:]
721
+
722
+ # 7. 在文末添加调用
723
+ if calls_to_add:
724
+ result = '\n'.join(calls_to_add) + '\n' + result
725
+
726
+ return result
727
+
651
728
  @staticmethod
652
729
  def process_mate_code(code):
653
730
  # 用于存储匹配到的信息
@@ -1077,10 +1154,13 @@ class Compiler(CompilerBase):
1077
1154
  with open(fpath, 'w', encoding='utf-8') as f:
1078
1155
  f.write(new_content)
1079
1156
 
1080
- # ------------------------------------ 自定义:调用stage_recursive_replace ------------------------------------ #
1157
+ # ------------------------------------ 自定义:调用stage_recursive_replace和stage_called_replace ------------------------------------ #
1081
1158
  for fpath in py_fpath:
1082
1159
  content = self.auto_read(fpath)
1083
1160
  content = self.stage_recursive_replace(content) # 调用stage_recursive_replace
1161
+ # 调用stage_called_replace处理四个装饰器
1162
+ for caller in ['behavior', 'sequence', 'selector', 'parallel']:
1163
+ content = self.stage_called_replace(caller, content)
1084
1164
  with open(fpath, 'w', encoding='utf-8') as f:
1085
1165
  f.write(content)
1086
1166
 
@@ -1217,12 +1297,22 @@ class Compiler(CompilerBase):
1217
1297
  :param min_js_files: list[str] # .min.js文件路径列表
1218
1298
  :return: str
1219
1299
  """
1220
- arena_name = const.ARENA_NAMES.get(config.arena, const.ARENA_NAMES['green']) # like green -> spawn_and_swamp
1300
+ arena_name = const.ARENA_NAMES.get(config.arena, const.ARENA_NAMES["green"]) # like green -> spawn_and_swamp
1221
1301
  self.TOTAL_INSERT_AT_HEAD += self.ARENA_IMPORTS_GETTER[arena_name]() # add arena imports
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"
1223
- total_js += f"const __AUTHOR__ = '{const.AUTHOR}';\nconst __AUTHOR_CN__ = '{const.BILIBILI_NAME}';"
1302
+ current_time = datetime.datetime.now()
1303
+ timestamp_ms = int(current_time.timestamp() * 1000)
1304
+ timestring = current_time.strftime("%Y-%m-%d %H:%M")
1305
+
1306
+ total_js = f"""const __VERSION__ = '{const.VERSION}';
1307
+ const __PYTHON_VERSION__ = '{python_version_info}';""" + self.TOTAL_INSERT_AT_HEAD + f"""
1308
+ export var LANGUAGE = '{config.language}';
1309
+ """
1310
+
1311
+ total_js += f"export var TIMESTAMP = {timestamp_ms};\n"
1312
+ total_js += f"export var TIMESTRING = '{timestring}';\n"
1313
+ total_js += f"""const __AUTHOR__ = '{const.AUTHOR}';
1314
+ const __AUTHOR_CN__ = '{const.BILIBILI_NAME}';"""
1224
1315
 
1225
- # 添加.min.js文件的import语句
1226
1316
  if min_js_files:
1227
1317
  for min_js_path in min_js_files:
1228
1318
  min_js_filename = os.path.basename(min_js_path)
@@ -1342,14 +1432,6 @@ class Compiler(CompilerBase):
1342
1432
  dir_path = os.path.dirname(mjs_path)
1343
1433
  build_dir_path = os.path.dirname(build_main_mjs)
1344
1434
 
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
1435
  # 生成total_js,传入.min.js文件列表
1354
1436
  total_js = imports + "\n" + self.generate_total_js(
1355
1437
  replace_src_prefix(modules), imps, sorts, self.FILE_STRONG_REPLACE, reps, min_js_files
@@ -1365,6 +1447,14 @@ class Compiler(CompilerBase):
1365
1447
  with open(mjs_path, 'w', encoding='utf-8') as f:
1366
1448
  f.write(total_js)
1367
1449
 
1450
+ # 复制.min.js文件到目标目录
1451
+ for min_js_path in min_js_files:
1452
+ min_js_filename = os.path.basename(min_js_path)
1453
+ # 复制到build目录
1454
+ shutil.copy(min_js_path, os.path.join(build_dir_path, min_js_filename))
1455
+ # 复制到最终导出目录
1456
+ shutil.copy(min_js_path, os.path.join(dir_path, min_js_filename))
1457
+
1368
1458
  core.lprint(GREEN.format('[6/6]'), LOC_DONE, " ", LOC_EXPORTING_TOTAL_MAIN_JS_FINISH, sep="", head="\r", ln=config.language)
1369
1459
 
1370
1460
  if mjs_path != build_main_mjs:
@@ -9,7 +9,7 @@
9
9
  #
10
10
  import re
11
11
 
12
- VERSION = "0.5.9a0"
12
+ VERSION = "0.5.9b0"
13
13
  AUTHOR = "●ω<🤍♪"
14
14
  STEAM_ID = "1029562896"
15
15
  GITHUB_NAME = "EagleBaby"
Binary file
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyscreeps-arena
3
- Version: 0.5.9a0
3
+ Version: 0.5.9b0
4
4
  Summary: Python api|interface to play game: Screeps: Arena.
5
5
  Author-email: 2229066748@qq.com
6
6
  Maintainer: Eagle'sBaby
@@ -1,8 +1,8 @@
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=RdJNwEvWOzS36UhwM6wxK2_bV2JtMBaNg6dLotVKj2k,66843
3
+ pyscreeps_arena/compiler.py,sha256=QLmpxt_qoCQHp9EQ4wnDAuKndlV1rA8E6_DFEUatEuw,70509
4
4
  pyscreeps_arena/localization.py,sha256=Dr0G6n8DvT6syfC0urqwjccYpEPEfcwYyJx3f9s-6a8,6031
5
- pyscreeps_arena/project.7z,sha256=yl-JXQwkItO8EkDrITPLSBU3krG4Hz6-z6PjDPl2Xpk,581577
5
+ pyscreeps_arena/project.7z,sha256=25YVsfwEr9Ksx33oShFGB7iAGwta2uJD1IVuf5JVXLU,546405
6
6
  pyscreeps_arena/afters/__init__.py,sha256=Ze8NKQoMEzIJ3WlyR8Jhhdq21gSXJUtGoINzB8iaQyE,254
7
7
  pyscreeps_arena/afters/after_config.py,sha256=Tw8Qry0KAM3hDasmXArKoS1crPuwfiAfWiEeAcKrPdo,2455
8
8
  pyscreeps_arena/afters/after_custom.py,sha256=pgI5xkY4X7w_NHFufQ5PUGxpCrv9Ayw6VWFwVJCHLFw,3226
@@ -11,7 +11,7 @@ pyscreeps_arena/afters/after_prefab.py,sha256=H_2LJbr_7e2yCtxWStxze259-py3TXQlyP
11
11
  pyscreeps_arena/core/__init__.py,sha256=qoP_rx1TpbDLJoTm5via4XPwEPaV1FXr1SYvoVoHGms,41
12
12
  pyscreeps_arena/core/basic.py,sha256=DFvyDTsTXf2bQtnS9s254TrkshvRwajaHcvTyVvJyqw,2790
13
13
  pyscreeps_arena/core/config.py,sha256=x_JhVHlVZqB3qA7UyACVnwZjg2gZU-BIs49UxZzwCoE,637
14
- pyscreeps_arena/core/const.py,sha256=VP43eR7T0YugXN9wm5WQQF7yME6Q2yA50x9gnEUcp9U,590
14
+ pyscreeps_arena/core/const.py,sha256=RQesh9t-dNiLegCOBHMqlF_TFcIuL-cTghUVR3X55BA,590
15
15
  pyscreeps_arena/core/core.py,sha256=3Nty8eLKPNgwnYk_sVNBPrWuKxBXI2od8nfEezsEAZQ,5157
16
16
  pyscreeps_arena/core/main.py,sha256=-FNSOEjksNlDfCbUqsjtPSUW8vT3qxEdfzXqT5Tdsik,170
17
17
  pyscreeps_arena/core/utils.py,sha256=N9OOkORvrqnJakayaFp9qyS0apWhB9lBK4xyyYkhFdo,215
@@ -45,8 +45,8 @@ pyscreeps_arena/ui/qmapv/test_simple_array.py,sha256=hPnLXcFrn6I1X4JXFM3RVpBPhU_
45
45
  pyscreeps_arena/ui/qrecipe/__init__.py,sha256=2Guvr9k5kGkZboiVC0aNF4u48LRbmcCm2dqOhEF52Tw,59
46
46
  pyscreeps_arena/ui/qrecipe/model.py,sha256=s3lr_DXtsBgt8bVg1_wLz-dX88QKi77mNkqM5VJsGwE,13200
47
47
  pyscreeps_arena/ui/qrecipe/qrecipe.py,sha256=z57VLmlpMripdpGtVCkKR0csJQhw5-WpocZK5l2xTVg,39398
48
- pyscreeps_arena-0.5.9a0.dist-info/METADATA,sha256=WO8MT9aDrX2NK1eOY2UyHPflms4IeaY0ZtUur_yhUPQ,2356
49
- pyscreeps_arena-0.5.9a0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
50
- pyscreeps_arena-0.5.9a0.dist-info/entry_points.txt,sha256=pnpuPPadwQsxQPaR1rXzUo0fUvhOcC7HTHlf7TYXr7M,141
51
- pyscreeps_arena-0.5.9a0.dist-info/top_level.txt,sha256=l4uLyMR2NOy41ngBMh795jOHTFk3tgYKy64-9cgjVng,16
52
- pyscreeps_arena-0.5.9a0.dist-info/RECORD,,
48
+ pyscreeps_arena-0.5.9b0.dist-info/METADATA,sha256=2f9814ViuZUlIAKwsXO_i-1nnnQGjerGRb3Ur0r8eAU,2356
49
+ pyscreeps_arena-0.5.9b0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
50
+ pyscreeps_arena-0.5.9b0.dist-info/entry_points.txt,sha256=pnpuPPadwQsxQPaR1rXzUo0fUvhOcC7HTHlf7TYXr7M,141
51
+ pyscreeps_arena-0.5.9b0.dist-info/top_level.txt,sha256=l4uLyMR2NOy41ngBMh795jOHTFk3tgYKy64-9cgjVng,16
52
+ pyscreeps_arena-0.5.9b0.dist-info/RECORD,,