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.
- pywargame/__init__.py +2 -0
- pywargame/common/__init__.py +3 -0
- pywargame/common/collector.py +87 -0
- pywargame/common/dicedraw.py +363 -0
- pywargame/common/drawdice.py +40 -0
- pywargame/common/singleton.py +22 -0
- pywargame/common/test.py +25 -0
- pywargame/common/verbose.py +59 -0
- pywargame/common/verboseguard.py +53 -0
- pywargame/cyberboard/__init__.py +18 -0
- pywargame/cyberboard/archive.py +283 -0
- pywargame/cyberboard/base.py +63 -0
- pywargame/cyberboard/board.py +462 -0
- pywargame/cyberboard/cell.py +200 -0
- pywargame/cyberboard/collect.py +49 -0
- pywargame/cyberboard/collectgbx0pwd.py +30 -0
- pywargame/cyberboard/collectgbxext.py +30 -0
- pywargame/cyberboard/collectgsnexp.py +32 -0
- pywargame/cyberboard/collectgsnext.py +30 -0
- pywargame/cyberboard/draw.py +396 -0
- pywargame/cyberboard/exporter.py +1132 -0
- pywargame/cyberboard/extractor.py +240 -0
- pywargame/cyberboard/features.py +17 -0
- pywargame/cyberboard/gamebox.py +81 -0
- pywargame/cyberboard/gbxexp.py +76 -0
- pywargame/cyberboard/gbxext.py +64 -0
- pywargame/cyberboard/gsnexp.py +147 -0
- pywargame/cyberboard/gsnext.py +59 -0
- pywargame/cyberboard/head.py +111 -0
- pywargame/cyberboard/image.py +76 -0
- pywargame/cyberboard/main.py +47 -0
- pywargame/cyberboard/mark.py +102 -0
- pywargame/cyberboard/palette.py +36 -0
- pywargame/cyberboard/piece.py +169 -0
- pywargame/cyberboard/player.py +36 -0
- pywargame/cyberboard/scenario.py +115 -0
- pywargame/cyberboard/testgrid.py +156 -0
- pywargame/cyberboard/tile.py +121 -0
- pywargame/cyberboard/tray.py +68 -0
- pywargame/cyberboard/windows.py +41 -0
- pywargame/cyberboard/zeropwd.py +45 -0
- pywargame/cyberboard.py +2728 -0
- pywargame/gbx0pwd.py +2776 -0
- pywargame/gbxextract.py +2795 -0
- pywargame/gsnexport.py +16499 -0
- pywargame/gsnextract.py +2790 -0
- pywargame/latex/__init__.py +2 -0
- pywargame/latex/collect.py +34 -0
- pywargame/latex/latexexporter.py +4010 -0
- pywargame/latex/main.py +184 -0
- pywargame/vassal/__init__.py +66 -0
- pywargame/vassal/base.py +139 -0
- pywargame/vassal/board.py +243 -0
- pywargame/vassal/buildfile.py +60 -0
- pywargame/vassal/chart.py +79 -0
- pywargame/vassal/chessclock.py +197 -0
- pywargame/vassal/collect.py +98 -0
- pywargame/vassal/collectpatch.py +28 -0
- pywargame/vassal/command.py +21 -0
- pywargame/vassal/documentation.py +322 -0
- pywargame/vassal/dumpcollect.py +28 -0
- pywargame/vassal/dumpvsav.py +28 -0
- pywargame/vassal/element.py +439 -0
- pywargame/vassal/exporter.py +89 -0
- pywargame/vassal/extension.py +101 -0
- pywargame/vassal/folder.py +103 -0
- pywargame/vassal/game.py +940 -0
- pywargame/vassal/gameelements.py +1091 -0
- pywargame/vassal/globalkey.py +127 -0
- pywargame/vassal/globalproperty.py +433 -0
- pywargame/vassal/grid.py +573 -0
- pywargame/vassal/map.py +1061 -0
- pywargame/vassal/mapelements.py +1020 -0
- pywargame/vassal/merge.py +57 -0
- pywargame/vassal/merger.py +460 -0
- pywargame/vassal/moduledata.py +275 -0
- pywargame/vassal/mrgcollect.py +31 -0
- pywargame/vassal/patch.py +44 -0
- pywargame/vassal/patchcollect.py +28 -0
- pywargame/vassal/player.py +83 -0
- pywargame/vassal/save.py +495 -0
- pywargame/vassal/skel.py +380 -0
- pywargame/vassal/trait.py +224 -0
- pywargame/vassal/traits/__init__.py +36 -0
- pywargame/vassal/traits/area.py +50 -0
- pywargame/vassal/traits/basic.py +35 -0
- pywargame/vassal/traits/calculatedproperty.py +22 -0
- pywargame/vassal/traits/cargo.py +29 -0
- pywargame/vassal/traits/click.py +41 -0
- pywargame/vassal/traits/clone.py +28 -0
- pywargame/vassal/traits/delete.py +24 -0
- pywargame/vassal/traits/deselect.py +32 -0
- pywargame/vassal/traits/dynamicproperty.py +112 -0
- pywargame/vassal/traits/globalcommand.py +55 -0
- pywargame/vassal/traits/globalhotkey.py +26 -0
- pywargame/vassal/traits/globalproperty.py +54 -0
- pywargame/vassal/traits/hide.py +67 -0
- pywargame/vassal/traits/label.py +76 -0
- pywargame/vassal/traits/layer.py +105 -0
- pywargame/vassal/traits/mark.py +20 -0
- pywargame/vassal/traits/mask.py +85 -0
- pywargame/vassal/traits/mat.py +26 -0
- pywargame/vassal/traits/moved.py +35 -0
- pywargame/vassal/traits/movefixed.py +51 -0
- pywargame/vassal/traits/nonrect.py +95 -0
- pywargame/vassal/traits/nostack.py +55 -0
- pywargame/vassal/traits/place.py +104 -0
- pywargame/vassal/traits/prototype.py +20 -0
- pywargame/vassal/traits/report.py +34 -0
- pywargame/vassal/traits/restrictaccess.py +28 -0
- pywargame/vassal/traits/restrictcommand.py +32 -0
- pywargame/vassal/traits/return.py +40 -0
- pywargame/vassal/traits/rotate.py +62 -0
- pywargame/vassal/traits/sendto.py +59 -0
- pywargame/vassal/traits/sheet.py +129 -0
- pywargame/vassal/traits/skel.py +9 -0
- pywargame/vassal/traits/stack.py +28 -0
- pywargame/vassal/traits/submenu.py +27 -0
- pywargame/vassal/traits/trail.py +61 -0
- pywargame/vassal/traits/trigger.py +72 -0
- pywargame/vassal/turn.py +272 -0
- pywargame/vassal/upgrade.py +191 -0
- pywargame/vassal/vmod.py +323 -0
- pywargame/vassal/vsav.py +100 -0
- pywargame/vassal/widget.py +358 -0
- pywargame/vassal/withtraits.py +634 -0
- pywargame/vassal/xml.py +4 -0
- pywargame/vassal/zone.py +399 -0
- pywargame/vassal.py +12500 -0
- pywargame/vmodpatch.py +12548 -0
- pywargame/vsavdump.py +12533 -0
- pywargame/vslmerge.py +13015 -0
- pywargame/wgexport.py +16689 -0
- pywargame/ztexport.py +14351 -0
- pywargame/zuntzu/__init__.py +5 -0
- pywargame/zuntzu/base.py +82 -0
- pywargame/zuntzu/collect.py +38 -0
- pywargame/zuntzu/countersheet.py +250 -0
- pywargame/zuntzu/dicehand.py +48 -0
- pywargame/zuntzu/exporter.py +936 -0
- pywargame/zuntzu/gamebox.py +154 -0
- pywargame/zuntzu/map.py +36 -0
- pywargame/zuntzu/piece.py +37 -0
- pywargame/zuntzu/scenario.py +208 -0
- pywargame/zuntzu/ztexp.py +115 -0
- pywargame-0.3.1.dist-info/METADATA +353 -0
- pywargame-0.3.1.dist-info/RECORD +150 -0
- pywargame-0.3.1.dist-info/WHEEL +5 -0
- pywargame-0.3.1.dist-info/licenses/LICENSE +5 -0
- pywargame-0.3.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env python
|
2
|
+
import sys
|
3
|
+
sys.path.append('..')
|
4
|
+
|
5
|
+
from common import Verbose, VerboseGuard
|
6
|
+
from common.collector import Collector
|
7
|
+
|
8
|
+
|
9
|
+
if __name__ == '__main__':
|
10
|
+
from argparse import ArgumentParser, FileType
|
11
|
+
|
12
|
+
ap = ArgumentParser(description='Collect to single script')
|
13
|
+
ap.add_argument('output',
|
14
|
+
type=FileType('w'),
|
15
|
+
nargs='?',
|
16
|
+
default='cyberboard.py',
|
17
|
+
help='Output script name')
|
18
|
+
ap.add_argument('-v','--verbose',action='store_true',
|
19
|
+
help='Be verbose')
|
20
|
+
|
21
|
+
args = ap.parse_args()
|
22
|
+
|
23
|
+
Verbose().setVerbose(args.verbose)
|
24
|
+
|
25
|
+
c = Collector(executable=False)
|
26
|
+
c.run(args.output,
|
27
|
+
'../common/singleton.py',
|
28
|
+
'../common/verbose.py',
|
29
|
+
'../common/verboseguard.py',
|
30
|
+
'features.py',
|
31
|
+
'archive.py',
|
32
|
+
'base.py',
|
33
|
+
'head.py',
|
34
|
+
'image.py',
|
35
|
+
'tile.py',
|
36
|
+
'piece.py',
|
37
|
+
'mark.py',
|
38
|
+
'draw.py',
|
39
|
+
'cell.py',
|
40
|
+
'board.py',
|
41
|
+
'gamebox.py',
|
42
|
+
'scenario.py',
|
43
|
+
'player.py',
|
44
|
+
'windows.py',
|
45
|
+
'palette.py',
|
46
|
+
'tray.py',
|
47
|
+
'extractor.py')
|
48
|
+
|
49
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env python
|
2
|
+
import sys
|
3
|
+
sys.path.append('..')
|
4
|
+
|
5
|
+
from common import Verbose, VerboseGuard
|
6
|
+
from common.collector import Collector
|
7
|
+
|
8
|
+
|
9
|
+
if __name__ == '__main__':
|
10
|
+
from argparse import ArgumentParser, FileType
|
11
|
+
|
12
|
+
ap = ArgumentParser(description='Collect to single script')
|
13
|
+
ap.add_argument('output',
|
14
|
+
type=FileType('w'),
|
15
|
+
nargs='?',
|
16
|
+
default='gbx0pwd.py',
|
17
|
+
help='Output script name')
|
18
|
+
ap.add_argument('-v','--verbose',action='store_true',
|
19
|
+
help='Be verbose')
|
20
|
+
|
21
|
+
args = ap.parse_args()
|
22
|
+
|
23
|
+
Verbose().setVerbose(args.verbose)
|
24
|
+
|
25
|
+
c = Collector()
|
26
|
+
c.run(args.output,
|
27
|
+
'cyberboard.py',
|
28
|
+
'zeropwd.py')
|
29
|
+
|
30
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env python
|
2
|
+
import sys
|
3
|
+
sys.path.append('..')
|
4
|
+
|
5
|
+
from common import Verbose, VerboseGuard
|
6
|
+
from common.collector import Collector
|
7
|
+
|
8
|
+
|
9
|
+
if __name__ == '__main__':
|
10
|
+
from argparse import ArgumentParser, FileType
|
11
|
+
|
12
|
+
ap = ArgumentParser(description='Collect to single script')
|
13
|
+
ap.add_argument('output',
|
14
|
+
type=FileType('w'),
|
15
|
+
nargs='?',
|
16
|
+
default='gbxextract.py',
|
17
|
+
help='Output script name')
|
18
|
+
ap.add_argument('-v','--verbose',action='store_true',
|
19
|
+
help='Be verbose')
|
20
|
+
|
21
|
+
args = ap.parse_args()
|
22
|
+
|
23
|
+
Verbose().setVerbose(args.verbose)
|
24
|
+
|
25
|
+
c = Collector()
|
26
|
+
c.run(args.output,
|
27
|
+
'cyberboard.py',
|
28
|
+
'gbxext.py')
|
29
|
+
|
30
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env python
|
2
|
+
import sys
|
3
|
+
sys.path.append('..')
|
4
|
+
|
5
|
+
from common import Verbose, VerboseGuard
|
6
|
+
from common.collector import Collector
|
7
|
+
|
8
|
+
|
9
|
+
if __name__ == '__main__':
|
10
|
+
from argparse import ArgumentParser, FileType
|
11
|
+
|
12
|
+
ap = ArgumentParser(description='Collect to single script')
|
13
|
+
ap.add_argument('output',
|
14
|
+
type=FileType('w'),
|
15
|
+
nargs='?',
|
16
|
+
default='gsnexport.py',
|
17
|
+
help='Output script name')
|
18
|
+
ap.add_argument('-v','--verbose',action='store_true',
|
19
|
+
help='Be verbose')
|
20
|
+
|
21
|
+
args = ap.parse_args()
|
22
|
+
|
23
|
+
Verbose().setVerbose(args.verbose)
|
24
|
+
|
25
|
+
c = Collector()
|
26
|
+
c.run(args.output,
|
27
|
+
'../vassal/vassal.py',
|
28
|
+
'cyberboard.py',
|
29
|
+
'exporter.py',
|
30
|
+
'gsnexp.py')
|
31
|
+
|
32
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env python
|
2
|
+
import sys
|
3
|
+
sys.path.append('..')
|
4
|
+
|
5
|
+
from common import Verbose, VerboseGuard
|
6
|
+
from common.collector import Collector
|
7
|
+
|
8
|
+
|
9
|
+
if __name__ == '__main__':
|
10
|
+
from argparse import ArgumentParser, FileType
|
11
|
+
|
12
|
+
ap = ArgumentParser(description='Collect to single script')
|
13
|
+
ap.add_argument('output',
|
14
|
+
type=FileType('w'),
|
15
|
+
nargs='?',
|
16
|
+
default='gsnextract.py',
|
17
|
+
help='Output script name')
|
18
|
+
ap.add_argument('-v','--verbose',action='store_true',
|
19
|
+
help='Be verbose')
|
20
|
+
|
21
|
+
args = ap.parse_args()
|
22
|
+
|
23
|
+
Verbose().setVerbose(args.verbose)
|
24
|
+
|
25
|
+
c = Collector()
|
26
|
+
c.run(args.output,
|
27
|
+
'cyberboard.py',
|
28
|
+
'gsnext.py')
|
29
|
+
|
30
|
+
|
@@ -0,0 +1,396 @@
|
|
1
|
+
## BEGIN_IMPORT
|
2
|
+
from common import VerboseGuard
|
3
|
+
from . image import GBXImage
|
4
|
+
from . base import CbFont
|
5
|
+
## END_IMPORT
|
6
|
+
|
7
|
+
# ====================================================================
|
8
|
+
class GBXDraw:
|
9
|
+
def __init__(self,ar):
|
10
|
+
'''Base class for drawing objects'''
|
11
|
+
self._flags = ar.dword()
|
12
|
+
self._left = ar.word()
|
13
|
+
self._top = ar.word()
|
14
|
+
self._right = ar.word()
|
15
|
+
self._bottom = ar.word()
|
16
|
+
|
17
|
+
def isSecondPass(self):
|
18
|
+
return self._flags & 0x00000008
|
19
|
+
|
20
|
+
def bbWidth(self):
|
21
|
+
return self._right - self._left
|
22
|
+
|
23
|
+
def bbHeight(self):
|
24
|
+
return self._bottom - self._top
|
25
|
+
|
26
|
+
def centerX(self):
|
27
|
+
return (self._left + self._right)//2
|
28
|
+
|
29
|
+
def centerY(self):
|
30
|
+
return (self._top + self._bottom)//2
|
31
|
+
|
32
|
+
def center(self):
|
33
|
+
return (self.centerX(),self.centerY())
|
34
|
+
|
35
|
+
def upperLeft(self):
|
36
|
+
return (self._left,self._top)
|
37
|
+
|
38
|
+
def lowerRight(self):
|
39
|
+
return (self._right,self._bottom)
|
40
|
+
|
41
|
+
def bbSize(self):
|
42
|
+
return (self.bbWidth(),self.bbHeight())
|
43
|
+
|
44
|
+
@classmethod
|
45
|
+
def hex(cls,val):
|
46
|
+
if val == 0xFF000000:
|
47
|
+
h = 'none'
|
48
|
+
else:
|
49
|
+
b = (val >> 16) & 0xFF
|
50
|
+
g = (val >> 8) & 0xFF
|
51
|
+
r = (val >> 0) & 0xFF
|
52
|
+
h = f'rgb({r},{g},{b})'
|
53
|
+
return h
|
54
|
+
|
55
|
+
def toDict(self,calc):
|
56
|
+
return None
|
57
|
+
|
58
|
+
def baseDict(self):
|
59
|
+
return {
|
60
|
+
'left': self._left,
|
61
|
+
'top': self._top,
|
62
|
+
'right': self._right,
|
63
|
+
'bottom': self._bottom,
|
64
|
+
'x': self.centerX(),
|
65
|
+
'y': self.centerY()
|
66
|
+
}
|
67
|
+
|
68
|
+
def svg(self,dwg,g,defmap):
|
69
|
+
print(f'{self.__class__}.svg method not implemented')
|
70
|
+
pass
|
71
|
+
|
72
|
+
def __str__(self):
|
73
|
+
return (f'Flags:{self._flags:08x} '
|
74
|
+
+ f'({self._left},{self._top})x({self._right},{self._bottom})')
|
75
|
+
|
76
|
+
# --------------------------------------------------------------------
|
77
|
+
class GBXRectangle(GBXDraw):
|
78
|
+
def __init__(self,ar):
|
79
|
+
'''Draw a rectangle'''
|
80
|
+
with VerboseGuard(f'Reading rectangle'):
|
81
|
+
super(GBXRectangle,self).__init__(ar)
|
82
|
+
self._fill = ar.dword()
|
83
|
+
self._line = ar.dword()
|
84
|
+
self._width = ar.word()
|
85
|
+
|
86
|
+
def svg(self,dwg,g,defmap):
|
87
|
+
r = g.add(dwg.rect(insert=(self.upperLeft()),
|
88
|
+
size=(self.bbSize()),
|
89
|
+
fill=self.hex(self._fill),
|
90
|
+
stroke=self.hex(self._line),
|
91
|
+
stroke_width=self._width))
|
92
|
+
|
93
|
+
def __str__(self):
|
94
|
+
return 'Rectangle: '+super(GBXRectangle,self).__str__()
|
95
|
+
|
96
|
+
# --------------------------------------------------------------------
|
97
|
+
class GBXEllipse(GBXRectangle):
|
98
|
+
def __init__(self,ar):
|
99
|
+
'''Draw an ellipse'''
|
100
|
+
with VerboseGuard(f'Reading ellipse'):
|
101
|
+
super(GBXEllipse,self).__init__(ar)
|
102
|
+
|
103
|
+
def svg(self,dwg,g,defmap):
|
104
|
+
'''Create SVG object'''
|
105
|
+
g.add(dwg.ellipse(center=(self.centerX(),self.centerY()),
|
106
|
+
r=(self.bbWidth(),self.bbHeight()),
|
107
|
+
fill=self.hex(self._fill),
|
108
|
+
stroke=self.hex(self._line),
|
109
|
+
stroke_width=self._width))
|
110
|
+
def __str__(self):
|
111
|
+
return 'Ellipse: '+super(GBXRectangle,self).__str__()
|
112
|
+
|
113
|
+
# --------------------------------------------------------------------
|
114
|
+
class GBXLine(GBXDraw):
|
115
|
+
def __init__(self,ar):
|
116
|
+
'''Draw a line'''
|
117
|
+
with VerboseGuard(f'Reading line'):
|
118
|
+
super(GBXLine,self).__init__(ar)
|
119
|
+
self._x0 = ar.word()
|
120
|
+
self._y0 = ar.word()
|
121
|
+
self._x1 = ar.word()
|
122
|
+
self._y1 = ar.word()
|
123
|
+
self._line = ar.dword()
|
124
|
+
self._width = ar.word()
|
125
|
+
|
126
|
+
def svg(self,dwg,g,defmap):
|
127
|
+
'''Create SVG object'''
|
128
|
+
g.add(dwg.line(start=(self._x0,self._y0),
|
129
|
+
end=(self._x1,self._y1),
|
130
|
+
stroke=self.hex(self._line),
|
131
|
+
stroke_width=self._width))
|
132
|
+
|
133
|
+
|
134
|
+
def __str__(self):
|
135
|
+
return 'Line: ' + super(GBXLine,self).__str__()
|
136
|
+
# f'({self._x0},{self._y0}) -> ({self._x1},{self._y1})')
|
137
|
+
|
138
|
+
|
139
|
+
# --------------------------------------------------------------------
|
140
|
+
class GBXTile(GBXDraw):
|
141
|
+
def __init__(self,ar):
|
142
|
+
'''Draw a tile'''
|
143
|
+
with VerboseGuard(f'Reading tile'):
|
144
|
+
super(GBXTile,self).__init__(ar)
|
145
|
+
self._id = ar.word()
|
146
|
+
|
147
|
+
def svgDef(self,dwg,tileManager,markManager,defmap):
|
148
|
+
'''Create SVG definition from image'''
|
149
|
+
if self._id in defmap:
|
150
|
+
return
|
151
|
+
|
152
|
+
img = tileManager.image(self._id)
|
153
|
+
data = GBXImage.b64encode(img)
|
154
|
+
if data is None:
|
155
|
+
return
|
156
|
+
|
157
|
+
iden = f'tile_{self._id:04x}'
|
158
|
+
img = dwg.defs.add(dwg.image(id=iden,href=(data),
|
159
|
+
size=(img.width,img.height)))
|
160
|
+
defmap[self._id] = img
|
161
|
+
|
162
|
+
def svg(self,dwg,g,defmap):
|
163
|
+
'''Create SVG object'''
|
164
|
+
if self._id not in defmap: return
|
165
|
+
|
166
|
+
g.add(dwg.use(defmap[self._id],
|
167
|
+
insert=(self._left,self._top)))
|
168
|
+
|
169
|
+
def __str__(self):
|
170
|
+
return f'Tile: {self._id} ' + super(GBXTile,self).__str__()
|
171
|
+
|
172
|
+
# --------------------------------------------------------------------
|
173
|
+
class GBXText(GBXDraw):
|
174
|
+
def __init__(self,ar):
|
175
|
+
'''Draw text'''
|
176
|
+
with VerboseGuard(f'Reading text'):
|
177
|
+
super(GBXText,self).__init__(ar)
|
178
|
+
self._angle = ar.word()
|
179
|
+
self._color = ar.dword()
|
180
|
+
self._text = ar.str()
|
181
|
+
self._font = CbFont(ar)
|
182
|
+
|
183
|
+
def svg(self,dwg,g,defmap):
|
184
|
+
'''Create SVG object'''
|
185
|
+
g.add(dwg.text(self._text,
|
186
|
+
insert=(self._left,self._bottom),
|
187
|
+
rotate=[self._angle],
|
188
|
+
fill=self.hex(self._color),
|
189
|
+
font_family='monospace' if self._font._name == '' else self._font._name,
|
190
|
+
font_size=self._font._size,
|
191
|
+
font_weight='bold' if self._font.isBold() else 'normal',
|
192
|
+
font_style='italic' if self._font.isItalic() else 'normal',
|
193
|
+
text_decoration='underline' if self._font.isUnderline() else 'none'))
|
194
|
+
|
195
|
+
def __str__(self):
|
196
|
+
return f'Text: "{self._text}" '+super(GBXText,self).__str__()
|
197
|
+
|
198
|
+
# --------------------------------------------------------------------
|
199
|
+
class GBXPolyline(GBXDraw):
|
200
|
+
def __init__(self,ar):
|
201
|
+
'''Draw a polyline'''
|
202
|
+
with VerboseGuard(f'Reading polyline'):
|
203
|
+
super(GBXPolyline,self).__init__(ar)
|
204
|
+
self._fill = ar.dword()
|
205
|
+
self._line = ar.dword()
|
206
|
+
self._width = ar.word()
|
207
|
+
n = (ar.word() if Features().size_size != 8 else
|
208
|
+
ar.size())
|
209
|
+
self._points = [[ar.word(),ar.word()] for _ in range(n)]
|
210
|
+
|
211
|
+
def svg(self,dwg,g,defmap):
|
212
|
+
'''Create SVG object'''
|
213
|
+
g.add(dwg.polyline(self._points,
|
214
|
+
fill=self.hex(self._fill),
|
215
|
+
stroke=self.hex(self._line),
|
216
|
+
stroke_width=self._width))
|
217
|
+
|
218
|
+
def __str__(self):
|
219
|
+
return f'Polyline: {len(self._points)} '+super(GBXPolyline,self).__str__()
|
220
|
+
|
221
|
+
# --------------------------------------------------------------------
|
222
|
+
class GBXBitmap(GBXDraw):
|
223
|
+
CNT = 0
|
224
|
+
|
225
|
+
def __init__(self,ar):
|
226
|
+
'''Draw a bitmap'''
|
227
|
+
with VerboseGuard(f'Reading bitmap'):
|
228
|
+
super(GBXBitmap,self).__init__(ar)
|
229
|
+
sav = f'B{GBXBitmap.CNT:04d}.png'
|
230
|
+
GBXBitmap.CNT += 1
|
231
|
+
self._scale = ar.word()
|
232
|
+
self._img = GBXImage(ar,save=None)
|
233
|
+
|
234
|
+
def svg(self,dwg,g,defmap):
|
235
|
+
'''Create SVG object'''
|
236
|
+
data = GBXImage.b64encode(self._img._img)
|
237
|
+
size = self._img._img.width, self._img._img.height
|
238
|
+
g.add(dwg.image(insert=(self._left,self._top),
|
239
|
+
size=size,
|
240
|
+
href=(data)))
|
241
|
+
|
242
|
+
def __str__(self):
|
243
|
+
return f'Bitmap: {self._img} ' + super(GBXBitmap,self).__str__()
|
244
|
+
|
245
|
+
# --------------------------------------------------------------------
|
246
|
+
class GBXPiece(GBXDraw):
|
247
|
+
def __init__(self,ar):
|
248
|
+
'''Draw a piece'''
|
249
|
+
with VerboseGuard(f'Reading piece (draw)'):
|
250
|
+
super(GBXPiece,self).__init__(ar)
|
251
|
+
self._id = ar.iden()
|
252
|
+
|
253
|
+
def toDict(self,calc=None):
|
254
|
+
d = {'type': 'Piece',
|
255
|
+
'id': self._id,
|
256
|
+
'pixel': self.baseDict()
|
257
|
+
}
|
258
|
+
if calc is not None:
|
259
|
+
d['grid'] = calc(*self.center())
|
260
|
+
return d
|
261
|
+
|
262
|
+
def __str__(self):
|
263
|
+
return f'Piece: {self._id} ' + super(GBXPiece,self).__str__()
|
264
|
+
|
265
|
+
# --------------------------------------------------------------------
|
266
|
+
class GBXMark(GBXDraw):
|
267
|
+
def __init__(self,ar):
|
268
|
+
'''Draw a mark tile'''
|
269
|
+
with VerboseGuard(f'Reading mark (draw)'):
|
270
|
+
super(GBXMark,self).__init__(ar)
|
271
|
+
self._id = ar.size()
|
272
|
+
self._mid = ar.iden()
|
273
|
+
self._ang = ar.word()
|
274
|
+
|
275
|
+
def toDict(self,calc=None):
|
276
|
+
d = {'type': 'Mark',
|
277
|
+
'id': self._mid,
|
278
|
+
'pixel': self.baseDict()
|
279
|
+
}
|
280
|
+
if calc is not None:
|
281
|
+
d['grid'] = calc(*self.center())
|
282
|
+
return d
|
283
|
+
def svgDef(self,dwg,tileManager,markManager,defmap):
|
284
|
+
'''Create SVG def from mark'''
|
285
|
+
if self._id in defmap:
|
286
|
+
return
|
287
|
+
|
288
|
+
data = GBXImage.b64encode(tileManager.image(self._id))
|
289
|
+
if data is None:
|
290
|
+
return
|
291
|
+
|
292
|
+
iden = f'mark_{self._id:04x}'
|
293
|
+
img = dwg.defs.add(dwg.image(id=iden,href=(data)))
|
294
|
+
defmap[self._id] = img
|
295
|
+
|
296
|
+
def svg(self,dwg,g,defmap):
|
297
|
+
'''Create SVG object'''
|
298
|
+
if self._id not in defmap: return
|
299
|
+
|
300
|
+
g.add(dwg.use(defmap[self._id],
|
301
|
+
insert=(self._left,self._top)))
|
302
|
+
|
303
|
+
def __str__(self):
|
304
|
+
return f'Mark: {self._id}/{self._mid} ' + super(GBXMark,self).__str__()
|
305
|
+
|
306
|
+
# --------------------------------------------------------------------
|
307
|
+
class GBXLineObj(GBXLine):
|
308
|
+
def __init__(self,ar):
|
309
|
+
'''Line object via reference'''
|
310
|
+
with VerboseGuard(f'Reading line object'):
|
311
|
+
super(GBXLineObj,self).__init__(ar)
|
312
|
+
|
313
|
+
self._id = ar.iden()
|
314
|
+
|
315
|
+
def __str__(self):
|
316
|
+
return f'Line: {self._id} ' + super(GBXLineObj,self).__str__()
|
317
|
+
|
318
|
+
|
319
|
+
# --------------------------------------------------------------------
|
320
|
+
class GBXDrawList:
|
321
|
+
RECT = 0
|
322
|
+
ELLIPSE = 1
|
323
|
+
LINE = 2
|
324
|
+
TILE = 3
|
325
|
+
TEXT = 4
|
326
|
+
POLYLINE = 5
|
327
|
+
BITMAP = 6
|
328
|
+
PIECE = 0x80
|
329
|
+
MARK = 0x81
|
330
|
+
LINEOBJ = 0x82
|
331
|
+
|
332
|
+
TMAP = { RECT: GBXRectangle,
|
333
|
+
ELLIPSE: GBXEllipse,
|
334
|
+
LINE: GBXLine,
|
335
|
+
TILE: GBXTile,
|
336
|
+
TEXT: GBXText,
|
337
|
+
POLYLINE: GBXPolyline,
|
338
|
+
BITMAP: GBXBitmap,
|
339
|
+
PIECE: GBXPiece,
|
340
|
+
MARK: GBXMark,
|
341
|
+
LINEOBJ: GBXLineObj}
|
342
|
+
|
343
|
+
def __init__(self,ar):
|
344
|
+
'''A list of drawn objects'''
|
345
|
+
with VerboseGuard(f'Reading draw list'):
|
346
|
+
n = ar.sub_size()
|
347
|
+
|
348
|
+
self._obj = [self._readObj(ar) for n in range(n)]
|
349
|
+
|
350
|
+
def toDict(self,calc=None):
|
351
|
+
with VerboseGuard(f'Making dictionary from draw list at pass'):
|
352
|
+
ret = []
|
353
|
+
for i in self._obj:
|
354
|
+
d = i.toDict(calc)
|
355
|
+
if d is None:
|
356
|
+
continue
|
357
|
+
|
358
|
+
ret.append(d)
|
359
|
+
|
360
|
+
return ret
|
361
|
+
|
362
|
+
def _readObj(self,ar):
|
363
|
+
'''Read one object'''
|
364
|
+
tpe = ar.word()
|
365
|
+
cls = self.TMAP.get(tpe,None)
|
366
|
+
if cls is None:
|
367
|
+
raise RuntimeError(f'Unknown type of draw: {tpe}')
|
368
|
+
|
369
|
+
return cls(ar)
|
370
|
+
|
371
|
+
def svgDefs(self,dwg,tileManager,markManager,defmap):
|
372
|
+
'''Create SVG defs'''
|
373
|
+
with VerboseGuard(f'Create SVG defs from draw list'):
|
374
|
+
for i in self._obj:
|
375
|
+
if type(i) not in [GBXTile,GBXMark]: continue
|
376
|
+
|
377
|
+
i.svgDef(dwg,tileManager,markManager,defmap)
|
378
|
+
|
379
|
+
def svg(self,dwg,g,passNo,defmap):
|
380
|
+
'''Create SVG objects'''
|
381
|
+
with VerboseGuard(f'Drawing SVG from draw list at pass {passNo}'
|
382
|
+
f' ({len(self._obj)} objects)') as gg:
|
383
|
+
for i in self._obj:
|
384
|
+
if passNo == 1 and i.isSecondPass():
|
385
|
+
continue
|
386
|
+
elif passNo == 2 and not i.isSecondPass():
|
387
|
+
continue
|
388
|
+
gg(f'Drawing {i}')
|
389
|
+
i.svg(dwg,g,defmap)
|
390
|
+
|
391
|
+
def __str__(self):
|
392
|
+
return '\n '.join([str(o) for o in self._obj])
|
393
|
+
|
394
|
+
#
|
395
|
+
# EOF
|
396
|
+
#
|