pyscreeps-arena 0.4a2__tar.gz → 0.4a4__tar.gz

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.
Files changed (21) hide show
  1. {pyscreeps-arena-0.4a2 → pyscreeps-arena-0.4a4}/PKG-INFO +1 -1
  2. {pyscreeps-arena-0.4a2 → pyscreeps-arena-0.4a4}/pyscreeps_arena/compiler.py +86 -11
  3. {pyscreeps-arena-0.4a2 → pyscreeps-arena-0.4a4}/pyscreeps_arena.egg-info/PKG-INFO +1 -1
  4. {pyscreeps-arena-0.4a2 → pyscreeps-arena-0.4a4}/setup.py +1 -1
  5. {pyscreeps-arena-0.4a2 → pyscreeps-arena-0.4a4}/pyscreeps_arena/__init__.py +0 -0
  6. {pyscreeps-arena-0.4a2 → pyscreeps-arena-0.4a4}/pyscreeps_arena/build.py +0 -0
  7. {pyscreeps-arena-0.4a2 → pyscreeps-arena-0.4a4}/pyscreeps_arena/core/__init__.py +0 -0
  8. {pyscreeps-arena-0.4a2 → pyscreeps-arena-0.4a4}/pyscreeps_arena/core/basic.py +0 -0
  9. {pyscreeps-arena-0.4a2 → pyscreeps-arena-0.4a4}/pyscreeps_arena/core/config.py +0 -0
  10. {pyscreeps-arena-0.4a2 → pyscreeps-arena-0.4a4}/pyscreeps_arena/core/const.py +0 -0
  11. {pyscreeps-arena-0.4a2 → pyscreeps-arena-0.4a4}/pyscreeps_arena/core/core.py +0 -0
  12. {pyscreeps-arena-0.4a2 → pyscreeps-arena-0.4a4}/pyscreeps_arena/core/main.py +0 -0
  13. {pyscreeps-arena-0.4a2 → pyscreeps-arena-0.4a4}/pyscreeps_arena/core/utils.py +0 -0
  14. {pyscreeps-arena-0.4a2 → pyscreeps-arena-0.4a4}/pyscreeps_arena/localization.py +0 -0
  15. {pyscreeps-arena-0.4a2 → pyscreeps-arena-0.4a4}/pyscreeps_arena/project.7z +0 -0
  16. {pyscreeps-arena-0.4a2 → pyscreeps-arena-0.4a4}/pyscreeps_arena.egg-info/SOURCES.txt +0 -0
  17. {pyscreeps-arena-0.4a2 → pyscreeps-arena-0.4a4}/pyscreeps_arena.egg-info/dependency_links.txt +0 -0
  18. {pyscreeps-arena-0.4a2 → pyscreeps-arena-0.4a4}/pyscreeps_arena.egg-info/entry_points.txt +0 -0
  19. {pyscreeps-arena-0.4a2 → pyscreeps-arena-0.4a4}/pyscreeps_arena.egg-info/requires.txt +0 -0
  20. {pyscreeps-arena-0.4a2 → pyscreeps-arena-0.4a4}/pyscreeps_arena.egg-info/top_level.txt +0 -0
  21. {pyscreeps-arena-0.4a2 → pyscreeps-arena-0.4a4}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyscreeps-arena
3
- Version: 0.4a2
3
+ Version: 0.4a4
4
4
  Summary: Python api|interface to play game: Screeps: Arena.
5
5
  Author-email: 2229066748@qq.com
6
6
  Maintainer: Eagle'sBaby
@@ -140,6 +140,7 @@ class GameFlag{{
140
140
  }}
141
141
  }};
142
142
  const GameScoreCollector = GameStructureSpawn;
143
+ const RESOURCE_SCORE = "undefined";
143
144
  const RESOURCE_SCORE_X = "undefined";
144
145
  const RESOURCE_SCORE_Y = "undefined";
145
146
  const RESOURCE_SCORE_Z = "undefined";
@@ -150,6 +151,7 @@ class GameAreaEffect{{
150
151
  constructor(){{
151
152
  }}
152
153
  }};
154
+ const RESOURCE_SCORE = "undefined";
153
155
  const RESOURCE_SCORE_X = "undefined";
154
156
  const RESOURCE_SCORE_Y = "undefined";
155
157
  const RESOURCE_SCORE_Z = "undefined";
@@ -164,15 +166,11 @@ class GameFlag{{
164
166
  constructor(){{
165
167
  }}
166
168
  }};
167
- import {{ RESOURCE_SCORE, ScoreCollector as GameScoreCollector, AreaEffect as GameAreaEffect, EFFECT_DAMAGE, EFFECT_FREEZE }} from 'arena/season_{config.season}/collect_and_control/basic';
169
+ import {{ ScoreCollector as GameScoreCollector, AreaEffect as GameAreaEffect, EFFECT_DAMAGE, EFFECT_FREEZE }} from 'arena/season_{config.season}/collect_and_control/{"advanced" if config.level in ["advance", "advanced"] else "basic"}';
168
170
 
169
- {'''import ("arena/season_{config.season}/collect_and_control/advanced")
170
- .then((module) => {{ const RESOURCE_SCORE_X = module.RESOURCE_SCORE_X; const RESOURCE_SCORE_Y = module.RESOURCE_SCORE_Y; const RESOURCE_SCORE_Z = module.RESOURCE_SCORE_Z; }})
171
- .catch((error) => {{ const RESOURCE_SCORE_X = "undefined"; const RESOURCE_SCORE_Y = "undefined"; const RESOURCE_SCORE_Z = "undefined"; }});''' if config.level in ['advanced', 'advanced'] else '''
172
- const RESOURCE_SCORE_X = "undefined";
173
- const RESOURCE_SCORE_Y = "undefined";
174
- const RESOURCE_SCORE_Z = "undefined";
175
- '''}
171
+ {f"import {{ RESOURCE_SCORE_X, RESOURCE_SCORE_Y, RESOURCE_SCORE_Z }} from 'arena/season_{config.season}/collect_and_control/advanced';" if config.level in ["advance", "advanced"] else 'const RESOURCE_SCORE_X = "undefined"; const RESOURCE_SCORE_Y = "undefined"; const RESOURCE_SCORE_Z = "undefined";'}
172
+
173
+ {"const RESOURCE_SCORE = 'undefined';" if config.level in ["advance", "advanced"] else f"import {{ RESOURCE_SCORE }} from 'arena/season_{config.season}/collect_and_control/basic';"}
176
174
  """,
177
175
  const.ARENA_GRAY: lambda: f"""
178
176
  class GameBodyPart{{
@@ -326,7 +324,7 @@ class Compiler_Utils(Compiler_Const):
326
324
  return '\n'.join(result) # 将处理后的所有代码行连接成一个字符串,并返回最终结果 | join all processed lines into a string and return
327
325
 
328
326
  def find_chain_import(self, fpath: str, search_dirs: list[str], project_path: str = None, records: dict[str, None] = None) -> list[str]:
329
- """
327
+ r"""
330
328
  查找文件中的所有import语句,并返回所有import的文件路径 | find all import statements in a file and return the paths of all imported files
331
329
  PY_IMPORT_PAT: re.compile(r'\s+from\s+(.+)(?=\s+import)\s+import\s+\*')
332
330
  :param fpath: str 目标文件路径 | target file path
@@ -384,6 +382,81 @@ class Compiler_Utils(Compiler_Const):
384
382
 
385
383
  return imps
386
384
 
385
+ def find_chain_import2(self, fpath: str, search_dirs: list[str], project_path: str = None, records: dict[str, None] = None) -> list[str]:
386
+ r"""
387
+ 查找文件中的所有import语句,并返回所有import的文件路径 | find all import statements in a file and return the paths of all imported files
388
+ PY_IMPORT_PAT: re.compile(r'\s+from\s+(.+)(?=\s+import)\s+import\s+\*')
389
+ :param fpath: str 目标文件路径 | target file path
390
+ :param search_dirs: list[str] 搜索目录 | search directories
391
+ :param project_path=None: str python项目中的概念,指根文件所在的目录。如果不指定,默认使用第一次调用时给定的fpath,并且稍后的递归会全部使用此路径 |
392
+ concept in python-project, refers to the directory where the root file is located. If not specified, the fpath given at the first call is used by default, and all subsequent recursions will use this path
393
+ :param records=None: dict[str, None] 记录已经查找过的文件路径,避免重复查找 | record the file paths that have been searched to avoid duplicate searches
394
+ """
395
+ if records is None:
396
+ records = {}
397
+ if not os.path.exists(fpath):
398
+ core.error('Compiler.find_chain_import', core.lformat(LOC_FILE_NOT_EXISTS, [fpath]), head='\n', ln=config.language)
399
+ imps = []
400
+ content = self.auto_read(fpath)
401
+ project_path = project_path or os.path.dirname(fpath)
402
+
403
+ # 添加根目录和 src 目录到 search_dirs
404
+ root_dir = os.path.dirname(project_path) # 根目录
405
+ src_dir = os.path.join(root_dir, 'src') # src 目录
406
+ if root_dir not in search_dirs:
407
+ search_dirs = [root_dir] + search_dirs
408
+ if src_dir not in search_dirs:
409
+ search_dirs = [src_dir] + search_dirs
410
+
411
+ for no, line in enumerate(content.split('\n')):
412
+ m = self.PY_IMPORT_PAT.match(line)
413
+ if m:
414
+ target = m.group(1)
415
+ target_path = project_path
416
+
417
+ ## 向前定位 | locate forward
418
+ if target.startswith('.'):
419
+ target_path = os.path.dirname(fpath) # 因为使用了相对路径,所以需要先定位到当前文件所在的目录 |
420
+ # because relative path is used, need to locate the directory where the current file is located first
421
+ count = 0
422
+ for c in target:
423
+ if c == '.':
424
+ count += 1
425
+ else:
426
+ break
427
+ if count > 1:
428
+ for _ in range(count - 1):
429
+ target_path = os.path.dirname(target_path)
430
+
431
+ ## 向后定位 | locate backward
432
+ while (_idx := target.find('.')) != -1:
433
+ first_name = target[:_idx]
434
+ target_path = os.path.join(target_path, first_name)
435
+ target = target[_idx + 1:]
436
+
437
+ ## 检查是否存在 | check if exists
438
+ this_path = os.path.join(target_path, target)
439
+ if os.path.isdir(this_path):
440
+ this_path = os.path.join(this_path, '__init__.py')
441
+ else:
442
+ this_path += '.py'
443
+
444
+ if not os.path.exists(this_path):
445
+ # 如果当前路径不存在,尝试在 search_dirs 中查找
446
+ for search_dir in search_dirs:
447
+ search_path = os.path.join(search_dir, target.replace('.', os.sep)) + ('.py' if not os.path.isdir(this_path) else os.sep + '__init__.py')
448
+ if os.path.exists(search_path):
449
+ this_path = search_path
450
+ break
451
+ else:
452
+ core.error('Compiler.find_chain_import', core.lformat(LOC_CHAIN_FILE_NOT_EXISTS, [fpath, no + 1, this_path]), head='\n', ln=config.language)
453
+ if this_path not in records:
454
+ records[this_path] = None
455
+ tmp = self.find_chain_import(this_path, search_dirs, project_path, records) + [this_path]
456
+ imps.extend(tmp)
457
+
458
+ return imps
459
+
387
460
  @staticmethod
388
461
  def relist_pyimports_to_jsimports(base_dir:str, pyimps:list[str]) -> list[str]:
389
462
  """
@@ -402,7 +475,7 @@ class Compiler_Utils(Compiler_Const):
402
475
  # ---------- 自定义函数 ---------- #
403
476
  @staticmethod
404
477
  def stage_recursive_replace(content:str) -> str:
405
- """
478
+ r"""
406
479
  替换'@recursive'为'@recursive(<fname>)', 其中<fname>为被装饰器标记的函数名 |
407
480
  Replace '@recursive' with '@recursive(<fname>)', where <fname> is the name of the decorated function.
408
481
 
@@ -414,7 +487,9 @@ class Compiler_Utils(Compiler_Const):
414
487
 
415
488
  class CompilerBase(Compiler_Utils):
416
489
 
417
- def __init__(self, src_dir, build_dir):
490
+ def __init__(self):
491
+ src_dir = "src"
492
+ build_dir = "build"
418
493
  # check
419
494
  if not os.path.exists(src_dir):
420
495
  core.error('Compiler.__init__', core.lformat(LOC_FILE_NOT_EXISTS, ['src', src_dir]), head='\n', ln=config.language)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyscreeps-arena
3
- Version: 0.4a2
3
+ Version: 0.4a4
4
4
  Summary: Python api|interface to play game: Screeps: Arena.
5
5
  Author-email: 2229066748@qq.com
6
6
  Maintainer: Eagle'sBaby
@@ -7,7 +7,7 @@ with open(r"T:\New_PC\Import_Project\uploads\pyscreeps-arena_upload\pyscreeps-ar
7
7
  long_description = f.read()
8
8
  setup(
9
9
  name='pyscreeps-arena',
10
- version='0.4a2',
10
+ version='0.4a4',
11
11
  description='Python api|interface to play game: Screeps: Arena.',
12
12
  long_description=long_description,
13
13
  long_description_content_type='text/markdown',