pyscreeps-arena 0.3.6__py3-none-any.whl → 0.5.8.0__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.
Files changed (43) hide show
  1. pyscreeps_arena/__init__.py +59 -2
  2. pyscreeps_arena/compiler.py +616 -73
  3. pyscreeps_arena/core/config.py +1 -1
  4. pyscreeps_arena/core/const.py +6 -5
  5. pyscreeps_arena/localization.py +10 -0
  6. pyscreeps_arena/project.7z +0 -0
  7. pyscreeps_arena/ui/P2PY.py +108 -0
  8. pyscreeps_arena/ui/__init__.py +12 -0
  9. pyscreeps_arena/ui/creeplogic_edit.py +14 -0
  10. pyscreeps_arena/ui/map_render.py +705 -0
  11. pyscreeps_arena/ui/mapviewer.py +14 -0
  12. pyscreeps_arena/ui/project_ui.py +215 -0
  13. pyscreeps_arena/ui/qcreeplogic/__init__.py +3 -0
  14. pyscreeps_arena/ui/qcreeplogic/model.py +72 -0
  15. pyscreeps_arena/ui/qcreeplogic/qcreeplogic.py +770 -0
  16. pyscreeps_arena/ui/qmapker/__init__.py +1 -0
  17. pyscreeps_arena/ui/qmapker/qmapmarker.py +339 -0
  18. pyscreeps_arena/ui/qmapker/qvariable.py +303 -0
  19. pyscreeps_arena/ui/qmapker/test_compact_variable.py +61 -0
  20. pyscreeps_arena/ui/qmapker/test_qmapmarker.py +71 -0
  21. pyscreeps_arena/ui/qmapker/test_qvariable.py +49 -0
  22. pyscreeps_arena/ui/qmapker/to_code.py +100 -0
  23. pyscreeps_arena/ui/qmapv/__init__.py +3 -0
  24. pyscreeps_arena/ui/qmapv/qcinfo.py +567 -0
  25. pyscreeps_arena/ui/qmapv/qco.py +441 -0
  26. pyscreeps_arena/ui/qmapv/qmapv.py +728 -0
  27. pyscreeps_arena/ui/qmapv/test_array_drag.py +191 -0
  28. pyscreeps_arena/ui/qmapv/test_drag.py +107 -0
  29. pyscreeps_arena/ui/qmapv/test_qcinfo.py +169 -0
  30. pyscreeps_arena/ui/qmapv/test_qco_drag.py +7 -0
  31. pyscreeps_arena/ui/qmapv/test_qmapv.py +224 -0
  32. pyscreeps_arena/ui/qmapv/test_simple_array.py +303 -0
  33. pyscreeps_arena/ui/qrecipe/__init__.py +1 -0
  34. pyscreeps_arena/ui/qrecipe/model.py +434 -0
  35. pyscreeps_arena/ui/qrecipe/qrecipe.py +914 -0
  36. pyscreeps_arena/ui/rs_icon.py +43 -0
  37. {pyscreeps_arena-0.3.6.dist-info → pyscreeps_arena-0.5.8.0.dist-info}/METADATA +15 -3
  38. pyscreeps_arena-0.5.8.0.dist-info/RECORD +47 -0
  39. {pyscreeps_arena-0.3.6.dist-info → pyscreeps_arena-0.5.8.0.dist-info}/WHEEL +1 -1
  40. pyscreeps_arena-0.5.8.0.dist-info/entry_points.txt +4 -0
  41. pyscreeps_arena-0.3.6.dist-info/RECORD +0 -17
  42. pyscreeps_arena-0.3.6.dist-info/entry_points.txt +0 -2
  43. {pyscreeps_arena-0.3.6.dist-info → pyscreeps_arena-0.5.8.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,14 @@
1
+ import sys
2
+ from PyQt6.QtWidgets import QApplication
3
+ from pyscreeps_arena.ui.qmapker.qmapmarker import QPSAMapMarker
4
+
5
+
6
+ def run_mapviewer():
7
+ app = QApplication(sys.argv)
8
+ window = QPSAMapMarker()
9
+ window.show()
10
+ sys.exit(app.exec())
11
+
12
+
13
+ if __name__ == '__main__':
14
+ run_mapviewer()
@@ -0,0 +1,215 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ 项目创建UI界面
4
+ """
5
+ import sys
6
+ import os
7
+ from pathlib import Path
8
+ from PyQt6.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout,
9
+ QHBoxLayout, QLabel, QLineEdit, QPushButton,
10
+ QFileDialog, QMessageBox)
11
+ from PyQt6.QtCore import Qt
12
+ from PyQt6.QtGui import QFont
13
+ from PyQt6.QtGui import QIcon
14
+ from pyscreeps_arena.core import const
15
+ from pyscreeps_arena.ui.rs_icon import get_pixmap
16
+
17
+
18
+
19
+ class ProjectCreatorUI(QMainWindow):
20
+ def __init__(self):
21
+ super().__init__()
22
+ self._proj_name = ""
23
+ self._proj_path = ""
24
+ self._init_ui()
25
+
26
+ def _init_ui(self):
27
+ """初始化UI界面"""
28
+ self.setWindowTitle("PyScreeps Arena - 项目创建器")
29
+ self.setWindowIcon(QIcon(get_pixmap()))
30
+ self.setFixedSize(500, 350)
31
+
32
+ # 主窗口部件
33
+ central_widget = QWidget()
34
+ self.setCentralWidget(central_widget)
35
+ layout = QVBoxLayout(central_widget)
36
+ layout.setSpacing(15)
37
+ layout.setContentsMargins(30, 30, 30, 30)
38
+
39
+ # 标题
40
+ title = QLabel("PyScreeps Arena")
41
+ title.setAlignment(Qt.AlignmentFlag.AlignCenter)
42
+ title_font = QFont()
43
+ title_font.setPointSize(18)
44
+ title_font.setBold(True)
45
+ title.setFont(title_font)
46
+ layout.addWidget(title)
47
+
48
+ # 项目信息
49
+ info_widget = QWidget()
50
+ info_layout = QVBoxLayout(info_widget)
51
+ info_layout.setSpacing(8)
52
+
53
+ # 版本信息
54
+ version_label = QLabel(f"版本: {const.VERSION}")
55
+ version_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
56
+ info_layout.addWidget(version_label)
57
+
58
+ # 作者信息
59
+ author_label = QLabel(f"作者: {const.AUTHOR}")
60
+ author_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
61
+ info_layout.addWidget(author_label)
62
+
63
+ # GitHub信息
64
+ github_label = QLabel(f"GitHub: {const.GITHUB_NAME}")
65
+ github_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
66
+ info_layout.addWidget(github_label)
67
+
68
+ layout.addWidget(info_widget)
69
+
70
+ # 分隔线
71
+ separator = QLabel("─" * 50)
72
+ separator.setAlignment(Qt.AlignmentFlag.AlignCenter)
73
+ separator.setStyleSheet("color: #ccc;")
74
+ layout.addWidget(separator)
75
+
76
+ # 项目输入区域
77
+ input_widget = QWidget()
78
+ input_layout = QVBoxLayout(input_widget)
79
+ input_layout.setSpacing(12)
80
+
81
+ # 项目名称输入
82
+ name_layout = QHBoxLayout()
83
+ name_label = QLabel("项目名称:")
84
+ name_label.setFixedWidth(80)
85
+ self._name_input = QLineEdit()
86
+ self._name_input.setPlaceholderText("输入项目名称...")
87
+ self._name_input.textChanged.connect(self._on_name_changed)
88
+ name_layout.addWidget(name_label)
89
+ name_layout.addWidget(self._name_input)
90
+ input_layout.addLayout(name_layout)
91
+
92
+ # 项目路径输入
93
+ path_layout = QHBoxLayout()
94
+ path_label = QLabel("保存位置:")
95
+ path_label.setFixedWidth(80)
96
+ self._path_input = QLineEdit()
97
+ self._path_input.setPlaceholderText("选择项目保存位置...")
98
+ self._path_input.setReadOnly(True)
99
+ # 默认桌面路径
100
+ desktop_path = os.path.join(os.path.expanduser("~"), "Desktop")
101
+ if os.path.exists(desktop_path):
102
+ self._path_input.setText(desktop_path)
103
+ self._proj_path = desktop_path
104
+ path_layout.addWidget(path_label)
105
+ path_layout.addWidget(self._path_input)
106
+
107
+ # 浏览按钮
108
+ browse_btn = QPushButton("浏览...")
109
+ browse_btn.setFixedWidth(60)
110
+ browse_btn.clicked.connect(self._browse_path)
111
+ path_layout.addWidget(browse_btn)
112
+
113
+ input_layout.addLayout(path_layout)
114
+ layout.addWidget(input_widget)
115
+
116
+ # 按钮区域
117
+ button_layout = QHBoxLayout()
118
+ button_layout.addStretch()
119
+
120
+ # 创建按钮
121
+ self._create_btn = QPushButton("创建项目")
122
+ self._create_btn.setFixedSize(100, 35)
123
+ self._create_btn.clicked.connect(self._create_project)
124
+ self._create_btn.setEnabled(False)
125
+ button_layout.addWidget(self._create_btn)
126
+
127
+ # 取消按钮
128
+ cancel_btn = QPushButton("取消")
129
+ cancel_btn.setFixedSize(80, 35)
130
+ cancel_btn.clicked.connect(self.close)
131
+ button_layout.addWidget(cancel_btn)
132
+
133
+ layout.addLayout(button_layout)
134
+ layout.addStretch()
135
+
136
+ def _on_name_changed(self, text):
137
+ """项目名称改变时的处理"""
138
+ self._proj_name = text.strip()
139
+ self._create_btn.setEnabled(bool(self._proj_name and self._proj_path))
140
+
141
+ def _browse_path(self):
142
+ """浏览选择路径"""
143
+ current_path = self._path_input.text() or os.path.expanduser("~")
144
+ path = QFileDialog.getExistingDirectory(
145
+ self, "选择项目保存位置", current_path
146
+ )
147
+ if path:
148
+ self._path_input.setText(path)
149
+ self._proj_path = path
150
+ self._create_btn.setEnabled(bool(self._proj_name and self._proj_path))
151
+
152
+ def _create_project(self):
153
+ """创建项目"""
154
+ if not self._proj_name or not self._proj_path:
155
+ return
156
+
157
+ # 构建完整路径
158
+ full_path = os.path.join(self._proj_path, self._proj_name)
159
+
160
+ # 检查路径是否已存在
161
+ if os.path.exists(full_path):
162
+ reply = QMessageBox.question(
163
+ self, "路径已存在",
164
+ f"路径 '{full_path}' 已存在。\n是否继续?",
165
+ QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No
166
+ )
167
+ if reply != QMessageBox.StandardButton.Yes:
168
+ return
169
+
170
+ try:
171
+ # 创建项目
172
+ self._extract_project_template(full_path)
173
+
174
+ QMessageBox.information(
175
+ self, "成功",
176
+ f"项目 '{self._proj_name}' 创建成功!\n路径: {full_path}"
177
+ )
178
+ self.close()
179
+
180
+ except Exception as e:
181
+ QMessageBox.critical(
182
+ self, "错误",
183
+ f"项目创建失败:\n{str(e)}"
184
+ )
185
+
186
+ def _extract_project_template(self, target_path):
187
+ """提取项目模板"""
188
+ # 获取当前包路径
189
+ this_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
190
+ project_7z_path = os.path.join(this_path, 'project.7z')
191
+
192
+ if not os.path.exists(project_7z_path):
193
+ raise FileNotFoundError(f"项目模板文件不存在: {project_7z_path}")
194
+
195
+ # 创建目标目录
196
+ os.makedirs(target_path, exist_ok=True)
197
+
198
+ # 解压项目模板
199
+ import py7zr
200
+ with py7zr.SevenZipFile(project_7z_path, mode='r') as archive:
201
+ archive.extractall(path=target_path)
202
+
203
+ print(f"[DEBUG] 项目模板已解压到: {target_path}") # 调试输出
204
+
205
+
206
+ def run_project_creator():
207
+ """运行项目创建器UI"""
208
+ app = QApplication(sys.argv)
209
+ window = ProjectCreatorUI()
210
+ window.show()
211
+ sys.exit(app.exec())
212
+
213
+
214
+ if __name__ == '__main__':
215
+ run_project_creator()
@@ -0,0 +1,3 @@
1
+ from pyscreeps_arena.ui.qcreeplogic.qcreeplogic import QPSACreepLogic
2
+
3
+
@@ -0,0 +1,72 @@
1
+ from typing import List, Optional, Union
2
+ from pyscreeps_arena.ui.qrecipe.model import PartsVector
3
+
4
+ class NamedRecipe:
5
+ def __init__(self, name: str, recipe: List[str]):
6
+ self.name = name
7
+ self.recipe = recipe
8
+
9
+ class CreepLogicSettings:
10
+ """
11
+ 爬虫逻辑设置类,用于定义爬虫的基本属性和行为。
12
+ """
13
+
14
+ def __init__(self):
15
+ # ---------------------- 爬虫本体 | Creep --------------------------- #
16
+ self.draw: bool = False # 是否绘制爬虫信息
17
+ self.layer: int = 10 # 爬虫绘制图层,默认为10
18
+
19
+ # ---------------------- 流程与结构 | Flow & Struct --------------------------- #
20
+ self.link: Union[List[str], str, None] = None # 爬虫逻辑链接
21
+ self.once: bool = True # 是否禁用死亡后重生
22
+
23
+ # ---------------------- 孵化选项 | Spawning --------------------------- #
24
+ self.spawnable = True # 是否可以孵化标志
25
+ self.recipe: Union[List[str], NamedRecipe] = ["MOVE"] # 爬虫配方,默认为["MOVE"]
26
+ self.optimise: bool = True # 自动优化配方标志
27
+ self.extension: bool = True # 使用extension标志
28
+ self.direction: Optional[int] = None # 出生方向
29
+
30
+ # ---------------------- 基本信息 | Basic Info --------------------------- #
31
+ self.name: str = "" # 爬虫名称
32
+
33
+ def to_dict(self) -> dict:
34
+ """
35
+ 将设置转换为字典格式
36
+ """
37
+ return {
38
+ "name": self.name,
39
+ "draw": self.draw,
40
+ "layer": self.layer,
41
+ "link": self.link,
42
+ "once": self.once,
43
+ "spawnable": self.spawnable,
44
+ "recipe": self.recipe if isinstance(self.recipe, list) else self.recipe.name,
45
+ "optimise": self.optimise,
46
+ "extension": self.extension,
47
+ "direction": self.direction
48
+ }
49
+
50
+ @classmethod
51
+ def from_dict(cls, data: dict) -> "CreepLogicSettings":
52
+ """
53
+ 从字典格式创建设置对象
54
+ """
55
+ settings = cls()
56
+ settings.name = data.get("name", "")
57
+ settings.draw = data.get("draw", False)
58
+ settings.layer = data.get("layer", 10)
59
+ settings.link = data.get("link", None)
60
+ settings.once = data.get("once", True)
61
+ settings.spawnable = data.get("spawnable", True)
62
+ settings.recipe = data.get("recipe", ["MOVE"])
63
+ settings.optimise = data.get("optimise", True)
64
+ settings.extension = data.get("extension", True)
65
+ settings.direction = data.get("direction", None)
66
+ return settings
67
+
68
+ def reset(self):
69
+ """
70
+ 重置所有设置为默认值
71
+ """
72
+ self.__init__()