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,35 @@
1
+ ## BEGIN_IMPORT
2
+ from common import VerboseGuard
3
+ from .. trait import Trait
4
+ ## END_IMPORT
5
+
6
+ # --------------------------------------------------------------------
7
+ class BasicTrait(Trait):
8
+ ID = 'piece'
9
+ def __init__(self,
10
+ name = '',
11
+ filename = '', # Can be empty
12
+ gpid = '', # Can be empty
13
+ cloneKey = '', # Deprecated
14
+ deleteKey = ''): # Deprecated
15
+ '''Create a basic unit (VASSAL.counters.BasicPiece)'''
16
+ self.setType(cloneKey = cloneKey, # CLONEKEY
17
+ deleteKey = deleteKey, # DELETEKEY
18
+ filename = filename, # IMAGE
19
+ name = name) # NAME
20
+ self.setState(map = 'null', # MAPID (possibly 'null')
21
+ x = 0,
22
+ y = 0,
23
+ gpid = gpid,
24
+ properties = 0) # PROPERTY COUNT (followed by [; KEY; VALUE]+)
25
+
26
+ def getProperties(self):
27
+ n = int(self._state[4])
28
+ return {k: v for k, v in zip(self._state[5::2],
29
+ self._state[6::2])}
30
+
31
+ Trait.known_traits.append(BasicTrait)
32
+
33
+ #
34
+ # EOF
35
+ #
@@ -0,0 +1,22 @@
1
+ ## BEGIN_IMPORT
2
+ from common import VerboseGuard
3
+ from .. trait import Trait
4
+ ## END_IMPORT
5
+
6
+ # --------------------------------------------------------------------
7
+ class CalculatedTrait(Trait):
8
+ ID = 'calcProp'
9
+ def __init__(self,name='',expression='',description=''):
10
+ '''Define a trait that calculates a property'''
11
+ super(CalculatedTrait,self).__init__()
12
+ self.setType(name = name,
13
+ expression = expression,
14
+ description = description)
15
+ self.setState()
16
+
17
+
18
+ Trait.known_traits.append(CalculatedTrait)
19
+
20
+ #
21
+ # EOF
22
+ #
@@ -0,0 +1,29 @@
1
+ ## BEGIN_IMPORT
2
+ from common import VerboseGuard
3
+ from .. trait import Trait
4
+ ## END_IMPORT
5
+
6
+ class CargoTrait(Trait):
7
+ ID = 'matPiece'
8
+ NO_MAT = 'noMat'
9
+
10
+ def __init__(self,
11
+ description = '',
12
+ maintainRelativeFacing = True,
13
+ detectionDistanceX = 0,
14
+ detectionDistanceY = 0,
15
+ attachKey = '',
16
+ detachKey = ''):
17
+ self.setType(description = description,
18
+ maintainRelativeFacing = maintainRelativeFacing,
19
+ detectionDistanceX = detectionDistanceX,
20
+ detectionDistanceY = detectionDistanceY,
21
+ attachKey = attachKey,
22
+ detachKey = detachKey)
23
+ self.setState(mat = CargoTrait.NO_MAT)
24
+
25
+ Trait.known_traits.append(CargoTrait)
26
+
27
+ #
28
+ # EOF
29
+ #
@@ -0,0 +1,41 @@
1
+ ## BEGIN_IMPORT
2
+ from common import VerboseGuard
3
+ from .. trait import Trait
4
+ ## END_IMPORT
5
+
6
+ # --------------------------------------------------------------------
7
+ class ClickTrait(Trait):
8
+ ID = 'button'
9
+ def __init__(self,
10
+ key = '',
11
+ x = 0,
12
+ y = 0,
13
+ width = 0,
14
+ height = 0,
15
+ description = '',
16
+ context = False,
17
+ whole = True,
18
+ version = 1,
19
+ points = []):
20
+ '''Create a click trait (static property)'''
21
+ super(ClickTrait,self).__init__()
22
+ self.setType(key = key,
23
+ x = x,
24
+ y = y,
25
+ width = width,
26
+ height = height,
27
+ description = description,
28
+ context = context,
29
+ whole = whole,
30
+ version = version,
31
+ npoints = len(points),
32
+ points = ';'.join([f'{p[0]};{p[1]}'
33
+ for p in points]))
34
+ self.setState()
35
+
36
+
37
+ Trait.known_traits.append(ClickTrait)
38
+
39
+ #
40
+ # EOF
41
+ #
@@ -0,0 +1,28 @@
1
+ ## BEGIN_IMPORT
2
+ from common import VerboseGuard
3
+ from .. trait import Trait
4
+ from .. base import *
5
+ ## END_IMPORT
6
+
7
+ # --------------------------------------------------------------------
8
+ class CloneTrait(Trait):
9
+ ID = 'clone'
10
+ def __init__(self,
11
+ command = '',
12
+ key = '',
13
+ description = ''):
14
+ '''Create a clone trait (VASSAL.counter.Clone)'''
15
+ super().__init__()
16
+
17
+ self.setType(command = command, # Context menu name
18
+ key = key, # Context menu key
19
+ description = description)
20
+ self.setState(state='')
21
+
22
+
23
+
24
+ Trait.known_traits.append(CloneTrait)
25
+
26
+ #
27
+ # EOF
28
+ #
@@ -0,0 +1,24 @@
1
+ ## BEGIN_IMPORT
2
+ from common import VerboseGuard
3
+ from .. trait import Trait
4
+ from .. base import *
5
+ ## END_IMPORT
6
+
7
+ # --------------------------------------------------------------------
8
+ class DeleteTrait(Trait):
9
+ ID = 'delete'
10
+ def __init__(self,
11
+ name = 'Delete',
12
+ key = key('D')):
13
+ '''Create a delete trait (VASSAL.counters.Delete)'''
14
+ super(DeleteTrait,self).__init__()
15
+ self.setType(name = name,
16
+ key = key,
17
+ dummy = '')
18
+ self.setState()
19
+
20
+ Trait.known_traits.append(DeleteTrait)
21
+
22
+ #
23
+ # EOF
24
+ #
@@ -0,0 +1,32 @@
1
+ ## BEGIN_IMPORT
2
+ from common import VerboseGuard
3
+ from .. trait import Trait
4
+ ## END_IMPORT
5
+
6
+ # --------------------------------------------------------------------
7
+ class DeselectTrait(Trait):
8
+ ID = 'deselect'
9
+ THIS = 'D' # Deselect only this piece
10
+ ALL = 'A' # Deselect all pieces
11
+ ONLY = 'S' # Select this piece only
12
+ def __init__(self,
13
+ command = '',
14
+ key = '',
15
+ description = '',
16
+ unstack = False,
17
+ deselect = THIS):
18
+ '''Create a deselect trait'''
19
+ super(DeselectTrait,self).__init__()
20
+ self.setType(command = command,
21
+ key = key,
22
+ description = description,
23
+ unstack = unstack,
24
+ deselect = deselect)
25
+ self.setState()
26
+
27
+
28
+ Trait.known_traits.append(DeselectTrait)
29
+
30
+ #
31
+ # EOF
32
+ #
@@ -0,0 +1,112 @@
1
+ ## BEGIN_IMPORT
2
+ from common import VerboseGuard
3
+ from .. trait import Trait
4
+ ## END_IMPORT
5
+
6
+ # --------------------------------------------------------------------
7
+ #
8
+ #
9
+ class ChangePropertyTrait(Trait):
10
+ DIRECT = 'P'
11
+ INCREMENT = 'I'
12
+ PROMPT = 'R'
13
+ def __init__(self,
14
+ *commands,
15
+ numeric = False,
16
+ min = 0,
17
+ max = 100,
18
+ wrap = False):
19
+ '''Base class for property (piece or global) change traits.
20
+
21
+ Encodes constraints and commands.
22
+ '''
23
+ # assert name is not None and len(name) > 0, \
24
+ # 'No name specified for ChangePropertyTriat'
25
+ super(ChangePropertyTrait,self).__init__()
26
+ self._constraints = self.encodeConstraints(numeric,wrap,min,max)
27
+ self._commands = self.encodeCommands(commands)
28
+
29
+ def encodeConstraints(self,numeric,wrap,min,max):
30
+ isnum = f'{numeric}'.lower()
31
+ iswrap = f'{wrap}'.lower()
32
+ return f'{isnum},{min},{max},{iswrap}'
33
+
34
+ def decodeConstraints(self,constraints):
35
+ f = Trait.decodeKeys(constraints)
36
+ return f[0]=='true',f[3]=='true',int(f[1]),int(f[2])
37
+
38
+ def encodeCommands(self,commands):
39
+ cmds = []
40
+ for cmd in commands:
41
+ # print(cmd)
42
+ com = cmd[0] + ':' + cmd[1].replace(',',r'\,') + ':' + cmd[2]
43
+ if cmd[2] == self.DIRECT:
44
+ com += r'\,'+cmd[3].replace(',',r'\\,').replace(':',r'\:')
45
+ elif cmd[2] == self.INCREMENT:
46
+ com += r'\,'+cmd[3].replace(',',r'\\,').replace(':',r'\:')
47
+ cmds.append(com)
48
+ # print(cmds)
49
+ return ','.join(cmds)
50
+
51
+ def decodeCommands(self,commands):
52
+ cmds = Trait.decodeKeys(commands)
53
+ ret = []
54
+ for cmd in cmds:
55
+ parts = Trait.decodeKeys(cmd,':')
56
+ # print('parts',parts)
57
+ if parts[-1][0] == self.DIRECT:
58
+ parts = parts[:-1]+Trait.decodeKeys(parts[-1],',')
59
+ if parts[-1][0] == self.INCREMENT:
60
+ parts = parts[:-1]+Trait.decodeKeys(parts[-1],',')
61
+ ret.append(parts)
62
+ # print(commands,parts)
63
+ return ret
64
+
65
+ def getCommands(self):
66
+ return self.decodeCommands(self['commands'])
67
+
68
+ def setCommands(self,commands):
69
+ self['commands'] = self.encodeCommands(commands)
70
+
71
+ def check(self):
72
+ assert len(self['name']) > 0,\
73
+ f'No name given for ChangePropertyTrait'
74
+
75
+
76
+ # --------------------------------------------------------------------
77
+ class DynamicPropertyTrait(ChangePropertyTrait):
78
+ ID = 'PROP'
79
+ def __init__(self,
80
+ *commands,
81
+ name = '',
82
+ value = 0,
83
+ numeric = False,
84
+ min = 0,
85
+ max = 100,
86
+ wrap = False,
87
+ description = ''):
88
+ '''Commands are
89
+
90
+ - menu
91
+ - key
92
+ - Type (only 'P' for now)
93
+ - Expression
94
+ '''
95
+ super(DynamicPropertyTrait,self).__init__(*commands,
96
+ numeric = numeric,
97
+ min = min,
98
+ max = max,
99
+ wrap = wrap)
100
+ # print(commands,'Name',name)
101
+ self.setType(name = name,
102
+ constraints = self._constraints,
103
+ commands = self._commands,
104
+ description = description)
105
+ self.setState(value=value)
106
+
107
+
108
+ Trait.known_traits.append(DynamicPropertyTrait)
109
+
110
+ #
111
+ # EOF
112
+ #
@@ -0,0 +1,55 @@
1
+ ## BEGIN_IMPORT
2
+ from common import VerboseGuard
3
+ from .. trait import Trait
4
+ ## END_IMPORT
5
+
6
+ # --------------------------------------------------------------------
7
+ class GlobalCommandTrait(Trait):
8
+ ID = 'globalkey'
9
+ def __init__(self,
10
+ commandName = '',
11
+ key = '', # Command received
12
+ globalKey = '', # Command to send to targets
13
+ properties = '', # Filter target on this expression
14
+ ranged = False,
15
+ range = 1,
16
+ reportSingle = True,
17
+ fixedRange = True,
18
+ rangeProperty = '',
19
+ description = '',
20
+ deckSelect = '-1',
21
+ target = ''):
22
+ '''Create a global key command in piece. This sends a key
23
+ command to near-by counters, as if invoked by a global key
24
+ (module window) command.
25
+
26
+ This is _different_ from GlobalHotkeyTrait in that this does
27
+ not invoke and actual module window global hot key, but rather
28
+ sends the command directly to a near-by counter (just how
29
+ close depends on the range or rangeProperty parameter).
30
+
31
+ The `deckSelect` select either _all_ (value -1) or specified
32
+ number of pieces from deck.
33
+
34
+ (VASSAL.counters.CounterGlobalKeyCommand)
35
+
36
+ '''
37
+ self.setType(commandName = commandName,
38
+ key = key,
39
+ globalKey = globalKey,
40
+ properties = properties,
41
+ ranged = ranged,
42
+ range = range,
43
+ reportSingle = reportSingle,
44
+ fixedRange = fixedRange,
45
+ rangeProperty = rangeProperty,
46
+ description = description,
47
+ deckSelect = deckSelect,
48
+ target = target)
49
+ self.setState()
50
+
51
+ Trait.known_traits.append(GlobalCommandTrait)
52
+
53
+ #
54
+ # EOF
55
+ #
@@ -0,0 +1,26 @@
1
+ ## BEGIN_IMPORT
2
+ from common import VerboseGuard
3
+ from .. trait import Trait
4
+ ## END_IMPORT
5
+
6
+ # --------------------------------------------------------------------
7
+ class GlobalHotkeyTrait(Trait):
8
+ ID = 'globalhotkey'
9
+ def __init__(self,
10
+ name = '', # Command received
11
+ key = '', # Command key received
12
+ globalHotkey = '', # Key to send
13
+ description = ''):
14
+ '''Create a global key command in piece
15
+ (VASSAL.counters.GlobalHotkey)'''
16
+ self.setType(name = name,
17
+ key = key,
18
+ globalHotkey = globalHotkey,
19
+ description = description)
20
+ self.setState()
21
+
22
+ Trait.known_traits.append(GlobalHotkeyTrait)
23
+
24
+ #
25
+ # EOF
26
+ #
@@ -0,0 +1,54 @@
1
+ ## BEGIN_IMPORT
2
+ from common import VerboseGuard
3
+ from .. trait import Trait
4
+ from . dynamicproperty import ChangePropertyTrait
5
+ ## END_IMPORT
6
+
7
+ # --------------------------------------------------------------------
8
+ class GlobalPropertyTrait(ChangePropertyTrait):
9
+ # The real value of CURRENT_ZONE causes problems when copying the
10
+ # trait, since it contains slashes. Maybe a solition is to make
11
+ # it a raw string with escaped slashes? No, that's already done
12
+ # below when setting the type. However, the default in the Java
13
+ # code is the CURRENT_ZONE real value, so setting this to the
14
+ # empty string should make it be that value.
15
+ ID = 'setprop'
16
+ CURRENT_ZONE = 'Current Zone/Current Map/Module'
17
+ NAMED_ZONE = 'Named Zone'
18
+ NAMED_MAP = 'Named Map'
19
+ DIRECT = 'P'
20
+ def __init__(self,
21
+ *commands,
22
+ name = '',
23
+ numeric = False,
24
+ min = 0,
25
+ max = 100,
26
+ wrap = False,
27
+ description = '',
28
+ level = CURRENT_ZONE,
29
+ search = ''):
30
+ '''Commands are
31
+
32
+ - menu
33
+ - key
34
+ - Type (only 'P' for now)
35
+ - Expression
36
+ '''
37
+ super(GlobalPropertyTrait,self).__init__(*commands,
38
+ numeric = numeric,
39
+ min = min,
40
+ max = max,
41
+ wrap = wrap)
42
+ self.setType(name = name,
43
+ constraints = self._constraints,
44
+ commands = self._commands,
45
+ description = description,
46
+ level = level.replace('/',r'\/'),
47
+ search = search)
48
+ self.setState()
49
+
50
+ Trait.known_traits.append(GlobalPropertyTrait)
51
+
52
+ #
53
+ # EOF
54
+ #
@@ -0,0 +1,67 @@
1
+ ## BEGIN_IMPORT
2
+ from common import VerboseGuard
3
+ from .. trait import Trait
4
+ from .. base import *
5
+ ## END_IMPORT
6
+
7
+ # --------------------------------------------------------------------
8
+ class HideTrait(Trait):
9
+ ID = 'hide'
10
+ ANY_SIDE = 'side:'
11
+ ANY_PLAYER = 'player:'
12
+ SIDES = 'sides:'
13
+ @classmethod
14
+ def encodeAccess(cls,spec):
15
+ if isinstance(spec,list) and len(spec) == 1:
16
+ spec = spec[0]
17
+ if isinstance(spec,str):
18
+ if spec == cls.ANY_SIDE: return cls.ANY_SIDE
19
+ if spec == cls.ANY_PLAYER: return cls.ANY_PLAYER
20
+ return cls.SIDES+":"+spec
21
+ return cls.SIDES+':'.join(spec)
22
+
23
+ @classmethod
24
+ def decodeAccess(cls,spec):
25
+ if spec.startswith(cls.ANY_SIDE): return cls.ANY_SIDE
26
+ if spec.startswith(cls.ANY_PLAYER): return cls.ANY_PLAYER
27
+ if spec.startswith(cls.SIDES): return spec.split(':')[1:]
28
+ return None
29
+
30
+ def __init__(self,
31
+ key = '',
32
+ command = '',
33
+ bgColor = rgb(0x0,0x0,0x0),
34
+ access = [],
35
+ transparency = 1, # between 0 and 1
36
+ description = '',
37
+ disableAutoReportMove = False,
38
+ state = 'null'):
39
+ '''Create a hide trait (VASSAL.counter.Hideable)'''
40
+
41
+ super().__init__()
42
+ spec = self.encodeAccess(access)
43
+
44
+ self.setType(key = key, # Context menu key
45
+ command = command, # Context menu name
46
+ bgColor = bgColor,
47
+ access = spec,
48
+ transparency = transparency,
49
+ description = description,
50
+ disableAutoReportMove = disableAutoReportMove)
51
+ self.setState(hiddenBy = state)
52
+
53
+ def getAccess(self):
54
+ return self.decodeAccess(self['access'])
55
+
56
+ def setAccess(self, access = []):
57
+ self['access'] = self.encodeAccess(access)
58
+
59
+
60
+
61
+
62
+
63
+ Trait.known_traits.append(HideTrait)
64
+
65
+ #
66
+ # EOF
67
+ #
@@ -0,0 +1,76 @@
1
+ ## BEGIN_IMPORT
2
+ from common import VerboseGuard
3
+ from .. trait import Trait
4
+ ## END_IMPORT
5
+
6
+ class LabelTraitCodes:
7
+ TOP = 't'
8
+ BOTTOM = 'b'
9
+ CENTER = 'c'
10
+ LEFT = 'l'
11
+ RIGHT = 'r'
12
+ PLAIN = 0
13
+ BOLD = 1
14
+ ITALIC = 2
15
+
16
+ # --------------------------------------------------------------------
17
+ class LabelTrait(Trait):
18
+ ID = 'label'
19
+ def __init__(self,
20
+ label = None,
21
+ labelKey = '',
22
+ menuCommand ='Change label',
23
+ fontSize = 10,
24
+ background = 'none',
25
+ foreground = '255,255,255',
26
+ vertical = LabelTraitCodes.TOP,
27
+ verticalOff = 0,
28
+ horizontal = LabelTraitCodes.CENTER,
29
+ horizontalOff = 0,
30
+ verticalJust = LabelTraitCodes.BOTTOM,
31
+ horizontalJust = LabelTraitCodes.CENTER,
32
+ nameFormat = '$pieceName$ ($label$)',
33
+ fontFamily = 'Dialog',
34
+ fontStyle = LabelTraitCodes.PLAIN,
35
+ rotate = 0,
36
+ propertyName = 'TextLabel',
37
+ description = '',
38
+ alwaysUseFormat = False):
39
+ '''Create a label trait (can be edited property)
40
+
41
+ Note that rotation comes last in the operations. That is,
42
+ `horizontal...` and `vertical...` must be specified as if the
43
+ label is not rotated, and then rotation is applied.
44
+
45
+ Negative vertical offset moves the label _up_.
46
+
47
+ '''
48
+ super(LabelTrait,self).__init__()
49
+ if not background or background == 'none': background = ''
50
+ if not foreground or foreground == 'none': foreground = ''
51
+ self.setType(labelKey = labelKey,
52
+ menuCommand = menuCommand,
53
+ fontSize = fontSize,
54
+ background = background,
55
+ foreground = foreground,
56
+ vertical = vertical,
57
+ verticalOff = verticalOff,
58
+ horizontal = horizontal,
59
+ horizontalOff = horizontalOff,
60
+ verticalJust = verticalJust,
61
+ horizontalJust = horizontalJust,
62
+ nameFormat = nameFormat,
63
+ fontFamily = fontFamily,
64
+ fontStyle = fontStyle,
65
+ rotate = rotate,
66
+ propertyName = propertyName,
67
+ description = description,
68
+ alwaysUseFormat = alwaysUseFormat)
69
+ self.setState(label = (nameFormat if label is None else label))
70
+
71
+
72
+ Trait.known_traits.append(LabelTrait)
73
+
74
+ #
75
+ # EOF
76
+ #