pywargame 0.3.1__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 (150) hide show
  1. pywargame/__init__.py +2 -0
  2. pywargame/common/__init__.py +3 -0
  3. pywargame/common/collector.py +87 -0
  4. pywargame/common/dicedraw.py +363 -0
  5. pywargame/common/drawdice.py +40 -0
  6. pywargame/common/singleton.py +22 -0
  7. pywargame/common/test.py +25 -0
  8. pywargame/common/verbose.py +59 -0
  9. pywargame/common/verboseguard.py +53 -0
  10. pywargame/cyberboard/__init__.py +18 -0
  11. pywargame/cyberboard/archive.py +283 -0
  12. pywargame/cyberboard/base.py +63 -0
  13. pywargame/cyberboard/board.py +462 -0
  14. pywargame/cyberboard/cell.py +200 -0
  15. pywargame/cyberboard/collect.py +49 -0
  16. pywargame/cyberboard/collectgbx0pwd.py +30 -0
  17. pywargame/cyberboard/collectgbxext.py +30 -0
  18. pywargame/cyberboard/collectgsnexp.py +32 -0
  19. pywargame/cyberboard/collectgsnext.py +30 -0
  20. pywargame/cyberboard/draw.py +396 -0
  21. pywargame/cyberboard/exporter.py +1132 -0
  22. pywargame/cyberboard/extractor.py +240 -0
  23. pywargame/cyberboard/features.py +17 -0
  24. pywargame/cyberboard/gamebox.py +81 -0
  25. pywargame/cyberboard/gbxexp.py +76 -0
  26. pywargame/cyberboard/gbxext.py +64 -0
  27. pywargame/cyberboard/gsnexp.py +147 -0
  28. pywargame/cyberboard/gsnext.py +59 -0
  29. pywargame/cyberboard/head.py +111 -0
  30. pywargame/cyberboard/image.py +76 -0
  31. pywargame/cyberboard/main.py +47 -0
  32. pywargame/cyberboard/mark.py +102 -0
  33. pywargame/cyberboard/palette.py +36 -0
  34. pywargame/cyberboard/piece.py +169 -0
  35. pywargame/cyberboard/player.py +36 -0
  36. pywargame/cyberboard/scenario.py +115 -0
  37. pywargame/cyberboard/testgrid.py +156 -0
  38. pywargame/cyberboard/tile.py +121 -0
  39. pywargame/cyberboard/tray.py +68 -0
  40. pywargame/cyberboard/windows.py +41 -0
  41. pywargame/cyberboard/zeropwd.py +45 -0
  42. pywargame/cyberboard.py +2728 -0
  43. pywargame/gbx0pwd.py +2776 -0
  44. pywargame/gbxextract.py +2795 -0
  45. pywargame/gsnexport.py +16499 -0
  46. pywargame/gsnextract.py +2790 -0
  47. pywargame/latex/__init__.py +2 -0
  48. pywargame/latex/collect.py +34 -0
  49. pywargame/latex/latexexporter.py +4010 -0
  50. pywargame/latex/main.py +184 -0
  51. pywargame/vassal/__init__.py +66 -0
  52. pywargame/vassal/base.py +139 -0
  53. pywargame/vassal/board.py +243 -0
  54. pywargame/vassal/buildfile.py +60 -0
  55. pywargame/vassal/chart.py +79 -0
  56. pywargame/vassal/chessclock.py +197 -0
  57. pywargame/vassal/collect.py +98 -0
  58. pywargame/vassal/collectpatch.py +28 -0
  59. pywargame/vassal/command.py +21 -0
  60. pywargame/vassal/documentation.py +322 -0
  61. pywargame/vassal/dumpcollect.py +28 -0
  62. pywargame/vassal/dumpvsav.py +28 -0
  63. pywargame/vassal/element.py +439 -0
  64. pywargame/vassal/exporter.py +89 -0
  65. pywargame/vassal/extension.py +101 -0
  66. pywargame/vassal/folder.py +103 -0
  67. pywargame/vassal/game.py +940 -0
  68. pywargame/vassal/gameelements.py +1091 -0
  69. pywargame/vassal/globalkey.py +127 -0
  70. pywargame/vassal/globalproperty.py +433 -0
  71. pywargame/vassal/grid.py +573 -0
  72. pywargame/vassal/map.py +1061 -0
  73. pywargame/vassal/mapelements.py +1020 -0
  74. pywargame/vassal/merge.py +57 -0
  75. pywargame/vassal/merger.py +460 -0
  76. pywargame/vassal/moduledata.py +275 -0
  77. pywargame/vassal/mrgcollect.py +31 -0
  78. pywargame/vassal/patch.py +44 -0
  79. pywargame/vassal/patchcollect.py +28 -0
  80. pywargame/vassal/player.py +83 -0
  81. pywargame/vassal/save.py +495 -0
  82. pywargame/vassal/skel.py +380 -0
  83. pywargame/vassal/trait.py +224 -0
  84. pywargame/vassal/traits/__init__.py +36 -0
  85. pywargame/vassal/traits/area.py +50 -0
  86. pywargame/vassal/traits/basic.py +35 -0
  87. pywargame/vassal/traits/calculatedproperty.py +22 -0
  88. pywargame/vassal/traits/cargo.py +29 -0
  89. pywargame/vassal/traits/click.py +41 -0
  90. pywargame/vassal/traits/clone.py +28 -0
  91. pywargame/vassal/traits/delete.py +24 -0
  92. pywargame/vassal/traits/deselect.py +32 -0
  93. pywargame/vassal/traits/dynamicproperty.py +112 -0
  94. pywargame/vassal/traits/globalcommand.py +55 -0
  95. pywargame/vassal/traits/globalhotkey.py +26 -0
  96. pywargame/vassal/traits/globalproperty.py +54 -0
  97. pywargame/vassal/traits/hide.py +67 -0
  98. pywargame/vassal/traits/label.py +76 -0
  99. pywargame/vassal/traits/layer.py +105 -0
  100. pywargame/vassal/traits/mark.py +20 -0
  101. pywargame/vassal/traits/mask.py +85 -0
  102. pywargame/vassal/traits/mat.py +26 -0
  103. pywargame/vassal/traits/moved.py +35 -0
  104. pywargame/vassal/traits/movefixed.py +51 -0
  105. pywargame/vassal/traits/nonrect.py +95 -0
  106. pywargame/vassal/traits/nostack.py +55 -0
  107. pywargame/vassal/traits/place.py +104 -0
  108. pywargame/vassal/traits/prototype.py +20 -0
  109. pywargame/vassal/traits/report.py +34 -0
  110. pywargame/vassal/traits/restrictaccess.py +28 -0
  111. pywargame/vassal/traits/restrictcommand.py +32 -0
  112. pywargame/vassal/traits/return.py +40 -0
  113. pywargame/vassal/traits/rotate.py +62 -0
  114. pywargame/vassal/traits/sendto.py +59 -0
  115. pywargame/vassal/traits/sheet.py +129 -0
  116. pywargame/vassal/traits/skel.py +9 -0
  117. pywargame/vassal/traits/stack.py +28 -0
  118. pywargame/vassal/traits/submenu.py +27 -0
  119. pywargame/vassal/traits/trail.py +61 -0
  120. pywargame/vassal/traits/trigger.py +72 -0
  121. pywargame/vassal/turn.py +272 -0
  122. pywargame/vassal/upgrade.py +191 -0
  123. pywargame/vassal/vmod.py +323 -0
  124. pywargame/vassal/vsav.py +100 -0
  125. pywargame/vassal/widget.py +358 -0
  126. pywargame/vassal/withtraits.py +634 -0
  127. pywargame/vassal/xml.py +4 -0
  128. pywargame/vassal/zone.py +399 -0
  129. pywargame/vassal.py +12500 -0
  130. pywargame/vmodpatch.py +12548 -0
  131. pywargame/vsavdump.py +12533 -0
  132. pywargame/vslmerge.py +13015 -0
  133. pywargame/wgexport.py +16689 -0
  134. pywargame/ztexport.py +14351 -0
  135. pywargame/zuntzu/__init__.py +5 -0
  136. pywargame/zuntzu/base.py +82 -0
  137. pywargame/zuntzu/collect.py +38 -0
  138. pywargame/zuntzu/countersheet.py +250 -0
  139. pywargame/zuntzu/dicehand.py +48 -0
  140. pywargame/zuntzu/exporter.py +936 -0
  141. pywargame/zuntzu/gamebox.py +154 -0
  142. pywargame/zuntzu/map.py +36 -0
  143. pywargame/zuntzu/piece.py +37 -0
  144. pywargame/zuntzu/scenario.py +208 -0
  145. pywargame/zuntzu/ztexp.py +115 -0
  146. pywargame-0.3.1.dist-info/METADATA +353 -0
  147. pywargame-0.3.1.dist-info/RECORD +150 -0
  148. pywargame-0.3.1.dist-info/WHEEL +5 -0
  149. pywargame-0.3.1.dist-info/licenses/LICENSE +5 -0
  150. pywargame-0.3.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,573 @@
1
+ ## BEGIN_IMPORT
2
+ from common import VerboseGuard
3
+ from . base import *
4
+ from . element import Element
5
+ ## END_IMPORT
6
+
7
+ # --------------------------------------------------------------------
8
+ HEX_WIDTH = 88.50779626676963
9
+ HEX_HEIGHT = 102.2
10
+ RECT_WIDTH = 80
11
+ RECT_HEIGHT = 80
12
+ # --------------------------------------------------------------------
13
+ class BaseGrid(Element):
14
+ def __init__(self,zone,tag,node=None,
15
+ color = rgb(0,0,0),
16
+ cornersLegal = False,
17
+ dotsVisible = False,
18
+ dx = HEX_WIDTH, # Meaning seems reversed!
19
+ dy = HEX_HEIGHT,
20
+ edgesLegal = False,
21
+ sideways = False,
22
+ snapTo = True,
23
+ visible = True,
24
+ x0 = 0,
25
+ y0 = 32):
26
+ super(BaseGrid,self).__init__(zone,tag,node=node,
27
+ color = color,
28
+ cornersLegal = cornersLegal,
29
+ dotsVisible = dotsVisible,
30
+ dx = dx,
31
+ dy = dy,
32
+ edgesLegal = edgesLegal,
33
+ sideways = sideways,
34
+ snapTo = snapTo,
35
+ visible = visible,
36
+ x0 = x0,
37
+ y0 = y0)
38
+ def getZone(self):
39
+ ## BEGIN_IMPORT
40
+ from . zone import Zone
41
+ ## END_IMPORT
42
+ z = self.getParent(Zone)
43
+ return z
44
+ def getZonedGrid(self):
45
+ z = self.getZone()
46
+ if z is not None:
47
+ return z.getZonedGrid()
48
+ return None
49
+ def getBoard(self):
50
+ z = self.getZonedGrid()
51
+ if z is not None:
52
+ return z.getBoard()
53
+ return self.getParent(Board)
54
+ def getPicker(self):
55
+ z = self.getBoard()
56
+ if z is not None:
57
+ return z.getPicker()
58
+ return None
59
+ def getMap(self):
60
+ b = self.getPicker()
61
+ if b is not None:
62
+ return b.getMap()
63
+ return None
64
+ def getNumbering(self):
65
+ pass
66
+ def getLocation(self,loc):
67
+ numbering = self.getNumbering()
68
+ if numbering is None or len(numbering) < 1:
69
+ return None
70
+
71
+ return numbering[0].getLocation(loc)
72
+
73
+ # --------------------------------------------------------------------
74
+ class BaseNumbering(Element):
75
+ def __init__(self,grid,tag,node=None,
76
+ color = rgb(255,0,0),
77
+ first = 'H',
78
+ fontSize = 24,
79
+ hDescend = False,
80
+ hDrawOff = 0,
81
+ hLeading = 1,
82
+ hOff = 0,
83
+ hType = 'A',
84
+ locationFormat = '$gridLocation$',
85
+ rotateText = 0,
86
+ sep = '',
87
+ stagger = True,
88
+ vDescend = False,
89
+ vDrawOff = 32,
90
+ vLeading = 0,
91
+ vOff = 0,
92
+ vType = 'N',
93
+ visible = True):
94
+ super(BaseNumbering,self).__init__(grid,tag,node=node,
95
+ color = color,
96
+ first = first,
97
+ fontSize = fontSize,
98
+ hDescend = hDescend,
99
+ hDrawOff = hDrawOff,
100
+ hLeading = hLeading,
101
+ hOff = hOff,
102
+ hType = hType,
103
+ locationFormat = locationFormat,
104
+ rotateText = rotateText,
105
+ sep = sep,
106
+ stagger = stagger,
107
+ vDescend = vDescend,
108
+ vDrawOff = vDrawOff,
109
+ vLeading = vLeading,
110
+ vOff = vOff,
111
+ vType = vType,
112
+ visible = visible)
113
+ def getGrid(self): return getParent(BaseGrid)
114
+
115
+ def _getMatcher(self,tpe,leading):
116
+ if tpe == 'A':
117
+ return \
118
+ '-?(?:A+|B+|C+|D+|E+|F+|G+|H+|I+|' + \
119
+ 'J+|K+|L+|M+|N+|O+|P+|Q+|R+|S+|T+|' + \
120
+ 'U+|V+|W+|X+|Y+|Z+)'
121
+
122
+ return f'-?[0-9]{{{int(leading)+1},}}'
123
+
124
+ def _getIndex(self,name,tpe):
125
+ if tpe == 'A':
126
+ negative = name.startswith('-')
127
+ if negative:
128
+ name = name[1:]
129
+
130
+ value = 0
131
+ for num,let in enumerate(name):
132
+ if not let.isupper():
133
+ continue
134
+ if num < len(name) - 1:
135
+ value += 26
136
+ else:
137
+ value += ord(let)-ord('A')
138
+
139
+ if negative:
140
+ value *= -1
141
+
142
+ return value
143
+
144
+ return int(name)
145
+
146
+ def _getCenter(self,col,row):
147
+ '''Convert col and row index to picture coordinates'''
148
+ print('Dummy GetCenter')
149
+ pass
150
+
151
+ def getLocation(self,loc):
152
+ '''Get picture coordinates from grid location'''
153
+ from re import match
154
+
155
+ first = self['first']
156
+ vType = self['vType']
157
+ hType = self['hType']
158
+ vOff = int(self['vOff'])
159
+ hOff = int(self['hOff'])
160
+ sep = self['sep']
161
+ colPat = self._getMatcher(hType,self['hLeading'])
162
+ rowPat = self._getMatcher(vType,self['vLeading'])
163
+ patts = ((colPat,rowPat) if first == 'H' else (rowPat,colPat))
164
+ colGrp = 1 if first == 'H' else 2
165
+ rowGrp = 2 if first == 'H' else 1
166
+ patt = sep.join([f'({p})' for p in patts])
167
+ matched = match(patt,loc)
168
+ if not matched:
169
+ return None
170
+
171
+ rowStr = matched[rowGrp]
172
+ colStr = matched[colGrp]
173
+ rowNum = self._getIndex(rowStr,vType)
174
+ colNum = self._getIndex(colStr,hType)
175
+
176
+ ret = self._getCenter(colNum-hOff, rowNum-vOff);
177
+ #print(f'Get location of "{loc}" -> {rowNum},{colNum} -> {ret}')
178
+ return ret
179
+
180
+
181
+ # --------------------------------------------------------------------
182
+ class HexGrid(BaseGrid):
183
+ TAG = Element.BOARD+'HexGrid'
184
+ def __init__(self,zone,node=None,**kwargs):
185
+ super(HexGrid,self).__init__(zone,self.TAG,node=node,**kwargs)
186
+
187
+ def addNumbering(self,**kwargs):
188
+ '''Add a `Numbering` element to this
189
+
190
+ Parameters
191
+ ----------
192
+ kwargs : dict
193
+ Dictionary of attribute key-value pairs
194
+
195
+ Returns
196
+ -------
197
+ element : Numbering
198
+ The added element
199
+ '''
200
+ return self.add(HexNumbering,**kwargs)
201
+ def getNumbering(self):
202
+ return self.getAllElements(HexNumbering)
203
+ def getDeltaX(self):
204
+ return float(self['dx'])
205
+ def getDeltaY(self):
206
+ return float(self['dy'])
207
+ def getXOffset(self):
208
+ return int(self['x0'])
209
+ def getYOffset(self):
210
+ return int(self['y0'])
211
+ def getMaxRows(self):
212
+ from math import floor
213
+ height = self.getZone().getHeight()
214
+ return floor(height / self.getDeltaX() + .5)
215
+ def getMaxCols(self):
216
+ from math import floor
217
+ width = self.getZone().getWidth()
218
+ return floor(width / self.getDeltaY() + .5)
219
+
220
+ registerElement(HexGrid)
221
+
222
+ # --------------------------------------------------------------------
223
+ class SquareGrid(BaseGrid):
224
+ TAG = Element.BOARD+'SquareGrid'
225
+ def __init__(self,zone,node=None,
226
+ dx = RECT_WIDTH,
227
+ dy = RECT_HEIGHT,
228
+ edgesLegal = False,
229
+ x0 = 0,
230
+ y0 = int(0.4*RECT_HEIGHT),
231
+ **kwargs):
232
+ super(SquareGrid,self).__init__(zone,self.TAG,node=node,
233
+ dx = dx,
234
+ dy = dy,
235
+ edgesLegal = edgesLegal,
236
+ x0 = x0,
237
+ y0 = y0,
238
+ **kwargs)
239
+ def addNumbering(self,**kwargs):
240
+ '''Add a `Numbering` element to this
241
+
242
+ Parameters
243
+ ----------
244
+ kwargs : dict
245
+ Dictionary of attribute key-value pairs
246
+
247
+ Returns
248
+ -------
249
+ element : Numbering
250
+ The added element
251
+ '''
252
+ return self.add(SquareNumbering,**kwargs)
253
+ def getNumbering(self):
254
+ return self.getAllElements(SquareNumbering)
255
+ def getDeltaX(self):
256
+ return float(self['dx'])
257
+ def getDeltaY(self):
258
+ return float(self['dy'])
259
+ def getXOffset(self):
260
+ return int(self['x0'])
261
+ def getYOffset(self):
262
+ return int(self['y0'])
263
+ def getMaxRows(self):
264
+ from math import floor
265
+ height = self.getZone().getHeight()
266
+ return floor(height / self.getDeltaY() + .5)
267
+ def getMaxCols(self):
268
+ from math import floor
269
+ width = self.getZone().getWidth()
270
+ return floor(width / self.getDeltaX() + .5)
271
+
272
+ registerElement(SquareGrid)
273
+
274
+ # --------------------------------------------------------------------
275
+ class HexNumbering(BaseNumbering):
276
+ TAG = Element.BOARD+'mapgrid.HexGridNumbering'
277
+ def __init__(self,grid,node=None,**kwargs):
278
+ super(HexNumbering,self).__init__(grid,self.TAG,node=node,**kwargs)
279
+
280
+ def getGrid(self):
281
+ g = self.getParent(HexGrid)
282
+ return g
283
+
284
+ def _getCenter(self,col,row):
285
+ '''Convert col and row index to picture coordinates'''
286
+ from math import floor
287
+
288
+ stagger = self['stagger'] == 'true'
289
+ sideways = self.getGrid()['sideways'] == 'true'
290
+ hDesc = self['hDescend'] == 'true'
291
+ vDesc = self['vDescend'] == 'true'
292
+ xOff = self.getGrid().getXOffset()
293
+ yOff = self.getGrid().getYOffset()
294
+ hexW = self.getGrid().getDeltaX()
295
+ hexH = self.getGrid().getDeltaY()
296
+ zxOff = self.getGrid().getZone().getXOffset()
297
+ zyOff = self.getGrid().getZone().getYOffset()
298
+ maxRows = self.getGrid().getMaxRows()
299
+ maxCols = self.getGrid().getMaxCols()
300
+ # print(f' Col: {col}')
301
+ # print(f' Row: {row}')
302
+ # print(f' Stagger: {stagger}')
303
+ # print(f' Sideways: {sideways}')
304
+ # print(f' hDesc: {hDesc}')
305
+ # print(f' vDesc: {vDesc}')
306
+ # print(f' maxRows: {maxRows}')
307
+ # print(f' maxCols: {maxCols}')
308
+
309
+ # This code from HexGridNumbering.java
310
+ if stagger:
311
+ if sideways:
312
+ if col % 2 != 0:
313
+ if hDesc:
314
+ row += 1
315
+ else:
316
+ row -= 1
317
+ else:
318
+ if col % 2 != 0:
319
+ if vDesc:
320
+ row += 1
321
+ else:
322
+ row -= 1
323
+
324
+ if sideways:
325
+ if vDesc:
326
+ col = maxRows - col
327
+ if hDesc:
328
+ row = maxCols - row
329
+ else:
330
+ if hDesc:
331
+ col = maxCols - col
332
+ if vDesc:
333
+ row = maxRows - row
334
+
335
+
336
+ x = col * hexW + xOff
337
+ if col % 2 == 0:
338
+ y = row * hexH
339
+ else:
340
+ y = row * hexH + hexH / 2
341
+ y += yOff
342
+
343
+ # print(f' Col: {col}')
344
+ # print(f' Row: {row}')
345
+ # print(f' hexW: {hexW}')
346
+ # print(f' hexH: {hexH}')
347
+ # print(f' xOff: {xOff}')
348
+ # print(f' yOff: {yOff}')
349
+ # print(f' x: {x}')
350
+ # print(f' y: {y}')
351
+
352
+ if sideways:
353
+ x, y = y, x
354
+
355
+ return int(floor(x+.5)),int(floor(y+.5))
356
+
357
+ # if sideways:
358
+ # maxRows, maxCols = maxCols, maxRows
359
+ #
360
+ # if stagger:
361
+ # if sideways:
362
+ # if col % 2 != 0:
363
+ # row += 1 if hDesc else -1
364
+ # else:
365
+ # if col % 2 != 0:
366
+ # row += 1 if vDesc else -1
367
+ #
368
+ # if hDesc:
369
+ # col = maxCols - col
370
+ # if vDesc:
371
+ # row = maxRows - row
372
+ #
373
+ # print(f' Col: {col}')
374
+ # print(f' Row: {row}')
375
+ # print(f' hexW: {hexW}')
376
+ # print(f' hexH: {hexH}')
377
+ # print(f' xOff: {xOff}')
378
+ # print(f' yOff: {yOff}')
379
+ #
380
+ # x = col * hexW + xOff
381
+ # y = row * hexH + yOff + (hexH/2 if col % 2 != 0 else 0)
382
+ #
383
+ # print(f' Col: {col}')
384
+ # print(f' Row: {row}')
385
+ # print(f' hexW: {hexW}')
386
+ # print(f' hexH: {hexH}')
387
+ # print(f' xOff: {xOff}')
388
+ # print(f' yOff: {yOff}')
389
+ # print(f' x: {x}')
390
+ # print(f' y: {y}')
391
+ #
392
+ # x = int(floor(x + .5))
393
+ # y = int(floor(y + .5))
394
+ # if sideways:
395
+ # # print(f'Swap coordinates because {sideways}')
396
+ # x, y = y, x
397
+ #
398
+ # return x,y
399
+
400
+ registerElement(HexNumbering)
401
+
402
+ # --------------------------------------------------------------------
403
+ class SquareNumbering(BaseNumbering):
404
+ TAG = Element.BOARD+'mapgrid.SquareGridNumbering'
405
+ def __init__(self,grid,node=None,hType='N',**kwargs):
406
+ super(SquareNumbering,self).__init__(grid,self.TAG,node=node,
407
+ hType=hType,**kwargs)
408
+ def getGrid(self):
409
+ return self.getParent(SquareGrid)
410
+
411
+ def getCenter(self,col,row):
412
+ hDesc = self['hDescend'] == 'true'
413
+ vDesc = self['vDescend'] == 'true'
414
+ xOff = self.getGrid().getXOffset()
415
+ yOff = self.getGrid().getYOffset()
416
+ squareW = self.getGrid().getDeltaX()
417
+ squareH = self.getGrid().getDeltaY()
418
+ maxRows = self.getGrid().getMaxRows()
419
+ maxCols = self.getGrid().getMaxCols()
420
+
421
+ if vDesc: row = maxRows - row
422
+ if hDesc: col = maxCols - col
423
+
424
+ x = col * squareW + xOff
425
+ y = row * squareH + yOff
426
+
427
+ return x,y
428
+
429
+ registerElement(SquareNumbering)
430
+
431
+ # --------------------------------------------------------------------
432
+ class RegionGrid(Element):
433
+ TAG = Element.BOARD+'RegionGrid'
434
+ def __init__(self,zone,node=None,snapto=True,fontsize=9,visible=True):
435
+ super(RegionGrid,self).__init__(zone,self.TAG,node=node,
436
+ snapto = snapto,
437
+ fontsize = fontsize,
438
+ visible = visible)
439
+
440
+ def getZone(self):
441
+ ## BEGIN_IMPORT
442
+ from . zone import Zone
443
+ ## END_IMPORT
444
+ return self.getParent(Zone)
445
+ def getZoneGrid(self):
446
+ z = self.getZone()
447
+ if z is not None:
448
+ return z.getBoard()
449
+ return None
450
+ def getBoard(self):
451
+ z = self.getZonedGrid()
452
+ if z is not None:
453
+ return z.getBoard()
454
+ return self.getParent(Board)
455
+ def getMap(self):
456
+ b = self.getBoard()
457
+ if b is not None:
458
+ return b.getMap()
459
+ return None
460
+ def getRegions(self):
461
+ return self.getElementsByKey(Region,'name')
462
+ def checkName(self,name):
463
+ '''Get unique name'''
464
+ poss = len([e for e in self.getRegions()
465
+ if e == name or e.startswith(name+'_')])
466
+ if poss == 0:
467
+ return name
468
+
469
+ return name + f'_{poss}'
470
+ def addRegion(self,**kwargs):
471
+ '''Add a `Region` element to this
472
+
473
+ Parameters
474
+ ----------
475
+ kwargs : dict
476
+ Dictionary of attribute key-value pairs
477
+
478
+ Returns
479
+ -------
480
+ element : Region
481
+ The added element
482
+ '''
483
+ return self.add(Region,**kwargs)
484
+ def getLocation(self,loc):
485
+ for r in self.getRegions().values():
486
+ if loc == r['name']:
487
+ return int(r['originx']),int(r['originy'])
488
+
489
+ return None
490
+
491
+ registerElement(RegionGrid)
492
+
493
+ # --------------------------------------------------------------------
494
+ class Region(Element):
495
+ TAG = Element.BOARD+'Region'
496
+ UNIQUE = ['name']
497
+ def __init__(self,grid,node=None,
498
+ name = '',
499
+ originx = 0,
500
+ originy = 0,
501
+ alsoPiece = True,
502
+ piece = None,
503
+ prefix = ''):
504
+ fullName = name + ("@"+prefix if len(prefix) else "")
505
+ realName = grid.checkName(fullName) if node is None else fullName
506
+ super(Region,self).__init__(grid,
507
+ self.TAG,
508
+ node = node,
509
+ name = realName,
510
+ originx = originx,
511
+ originy = originy)
512
+
513
+ if node is None and alsoPiece:
514
+ m = self.getMap()
515
+ b = self.getBoard()
516
+ if m is not None and b is not None:
517
+ if piece is None:
518
+ g = m.getGame()
519
+ pieces = g.getSpecificPieces(name,asdict=False)
520
+ piece = pieces[0] if len(pieces) > 0 else None
521
+
522
+ if piece is not None:
523
+ # bname = m['mapName']
524
+ bname = b['name']
525
+ #print(f'Adding at-start name={name} location={realName} '
526
+ # f'owning board={bname}')
527
+ a = m.addAtStart(name = name,
528
+ location = realName,
529
+ useGridLocation = True,
530
+ owningBoard = bname,
531
+ x = 0,
532
+ y = 0)
533
+ p = a.addPiece(piece)
534
+ if p is None:
535
+ print(f'EEE Failed to add piece {name} ({piece}) to add-start {a}')
536
+ #if p is not None:
537
+ # print(f'Added piece {name} in region')
538
+ #else:
539
+ # print(f'Could not find piece {name}')
540
+
541
+ def getGrid(self):
542
+ return self.getParent(RegionGrid)
543
+ def getZone(self):
544
+ g = self.getGrid()
545
+ if g is not None:
546
+ return g.getZone()
547
+ return None
548
+ def getZonedGrid(self):
549
+ z = self.getZone()
550
+ if z is not None:
551
+ return z.getZonedGrid()
552
+ return None
553
+ def getBoard(self):
554
+ z = self.getZonedGrid()
555
+ if z is not None:
556
+ return z.getBoard()
557
+ return self.getParent(Board)
558
+ def getPicker(self):
559
+ z = self.getBoard()
560
+ if z is not None:
561
+ return z.getPicker()
562
+ return None
563
+ def getMap(self):
564
+ b = self.getPicker()
565
+ if b is not None:
566
+ return b.getMap()
567
+ return None
568
+
569
+ registerElement(Region)
570
+
571
+ #
572
+ # EOF
573
+ #