Debian Codegraph @

texmf-dist/source/latex/wargame/util/export.dtx

raw
1 % \iffalse
2 % ====================================================================
3 % \fi
4 %
5 % \subsection{The \texttt{wgexport} class}
6 % \label{sec:impl:util}
7 %
8 % This document class is used for exporting game component to be used
9 % in a VASSAL module
10 % libraries.
11 %
12 % \iffalse
13 %<*exportcls>
14 %\fi
15 %
16 % Class identification and load \texttt{wargame} package
17 %
18 % \begin{macrocode}
19 \ProvidesClass{wgexport}
20 \PassOptionsToClass{multi=tikzpicture,varwidth=false}{standalone}
21 \DeclareOption{noterrainpic}{%
22 \PassOptionsToPackage{\CurrentOption}{wargame}}
23 \DeclareOption{terrainpic}{%
24 \PassOptionsToPackage{\CurrentOption}{wargame}}
25 \DeclareOption*{%
26 \PassOptionsToClass{\CurrentOption}{standalone}}
27 \ProcessOptions\relax
28 \LoadClass{standalone}
29 \RequirePackage{wargame}
30 % \end{macrocode}
31 %
32 % We need a few utilities before we get to the actual environment.
33 % First, we need a tools to write out literal left and right curly
34 % braces. We do a bit of catcode hackery to accomplish that.
35 %
36 % \begin{macrocode}
37 \begingroup
38 \catcode`\^^I=12
39 \def\@tabchar{^^I}
40 \catcode`<=1 \catcode`>=2
41 \catcode`{=12 \catcode`}=12
42 \gdef\@lbchar<{>
43 \gdef\@rbchar<}>
44 \endgroup
45 % \end{macrocode}
46 %
47 % Above, we temporarily set the tab, and left and right curly brace
48 % characters to be regular letters (12), and the catcodes of less than
49 % and greater than to be those of left and right curly braces
50 % respectively. We then define the macros \cs{@tabchar},
51 % \cs{@lbchar}, and \cs{@rbchar} to produce literal characters.
52 % \LaTeX already has \cs{@percentchar}.
53 %
54 % Everything we do should go inside this environment. The single
55 % optional argument is the file name stem of the output JSON file.
56 %
57 % \begin{macrocode}
58 \newenvironment{imagelist}[1][\jobname]{%
59 \newwrite\mk@out%
60 \def\mk@i{}%
61 \def\mk@w{\immediate\write\mk@out}%
62 \immediate\openout\mk@out=#1.json
63 \mk@w{[}
64 }{
65 \mk@w{\mk@i \@lbchar "name":"End of list", "category": "<<eol>>",
66 "subcategory": "" \@rbchar }
67 \mk@w{]}
68 \immediate\closeout\mk@out
69 }
70 % \end{macrocode}
71 %
72 %
73 % Preceed all images (\textsf{tikzpicture}) with this command
74 %
75 %
76 % First argument is the name of the image. This can be anything.
77 % Note that for counters, if the name ends in \texttt{flipped} then it
78 % is considered the backside of a counter.
79 %
80 % Second argument is the type of image. Recognised types are
81 %
82 % \begin{itemize}
83 % \item \texttt{board} for boards
84 % \item \texttt{oob} for OOBs
85 % \item \texttt{chart} for charts
86 % \item \texttt{counter} for counters
87 % \item \texttt{front} for front page
88 % \end{itemize}
89 %
90 % Other types can be used, and the images will be exported, but the
91 % Python script pays no particular attention to those then. Use for
92 % example to prepare images for help or the like.
93 %
94 % The third argument is the sub type. This is most relevant for the
95 % counters. Sub types can be anything, but since the counters will
96 % receive different prototypes based on the sub type, it makes sense
97 % to divide into sub types a la
98 %
99 % \begin{itemize}
100 % \item factions
101 % \item common markers
102 % \end{itemize}
103 %
104 % The faction sub types should just be the name of the faction.
105 % E.g., Allies, Axis, Soviet, NATO, Warsaw Pact. Spaces should not
106 % matter.
107 %
108 % For common markers, there are a few names that are recognised
109 % specifically by the Python script. These are
110 %
111 % \begin{itemize}
112 % \item \texttt{common}
113 % \item \texttt{all}
114 % \item \texttt{marker}
115 % \item \texttt{markers}
116 % \end{itemize}
117 %
118 % Counters that has these sub-types will no be considered to belong
119 % to any faction.
120 %
121 % Note that the Python script uses the faction names to guess the
122 % players of the game, and uses them in several places.
123 %
124 %
125 % \begin{macrocode}
126 \def\info{%
127 \@ifstar{\@@info{,}}{\@@info{\@rbchar,}}}
128 \def\@@info#1#2#3#4{%
129 \chit@dbg{2}{Making image `#2' of type `#3'/`#4' on page \thepage}%
130 \mk@w{ \@lbchar}%
131 \mk@w{ \space "name": "#2",}%
132 \mk@w{ \space "category": "#3",}%
133 \mk@w{ \space "subcategory": "#4", }%
134 \mk@w{ \space "number": \thepage #1}%
135 \let\oldmk@i\mk@i%
136 \ifx#1,\relax\edef\mk@i{\mk@i\space\space}\fi}
137 \def\endinfo{%
138 \let\mk@i\oldmk@i%
139 \mk@w{ \space \@rbchar,}}
140 % \end{macrocode}
141 %
142 % Make separate images for each counter (single sided).
143 %
144 % First optional argument is the group to put the chits into.
145 % Second optional argument is options to give to each Tikz picture
146 % environment. Third, mandatory, argument is the list of chit
147 % identifiers to render.
148 %
149 % \begin{macrocode}
150 \def\wg@add@drop@margin{%
151 \@ifundefined{wg@drop@margin}{}{
152 \dimen0=\wg@drop@margin
153 % \ifwg@chit@drop
154 \ifdim\dimen0>0pt%
155 \path ($(current bounding box.north east)+(45:\wg@drop@margin)$)
156 -- ($(current bounding box.south west)+(225:\wg@drop@margin)$);
157 \fi}}
158 \def\chitimages{%
159 \@ifnextchar[{\@chitimages}{\chitimages[]}%]
160 }%
161 \def\@chitimages[#1]{%
162 \@ifnextchar[{\@@chitimages[#1]}{\@@chitimages[#1][]}%]
163 }%
164 \def\@@chitimages[#1][#2]#3{%
165 \begingroup%
166 \let\chit@report\do@chit@report%
167 \let\natoapp@report\do@natoapp@report%
168 \chit@dbg{2}{chits to make images of `#3'}%
169 \foreach[count=\ti from 0] \t/\x in #3{%
170 \chit@dbg{2}{^^JRow: `\t' (`\x')}
171 \ifx\t\empty\else% Ignore empty rows
172 \chit@dbg{5}{^^JSubcategory: `\x' (default `#1')}
173 % Take sub-category or default
174 \ifx\t\x\def\x{#1}\else\ifx\x\empty\def\x{#1}\fi\fi
175 \foreach \u/\m in \t{%
176 \ifx\u\empty\else% Ignore empty cells
177 \ifx\u\chit@blank\else%
178 \ifx\u\chit@oob@vspacer\else%
179 \ifx\u\chit@oob@spacer\else%
180 \chit@dbg{2}{Next chit `\u' with possible multiplicity
181 `\m'}%
182 \chit@dbg{1}{Next chit `\u' not `\chit@blank',
183 `\chit@oob@vspacer', `\chit@oob@spacer'}
184 \ifx\m\@empty\def\m{1}\fi% If no multiplicity defined
185 \ifx\u\m\def\m{1}\fi% If the same as unit
186 \chit@dbg{2}{Next chit `\u' multiplicity `\m'}%
187 %% We only make one copy of the chit, since we can duplicate
188 %% it in VASSAL
189 \begin{info}*{\u}{counter}{\x}
190 \nopagecolor%
191 \gdef\wg@drop@margin{0pt}%
192 \begin{tikzpicture}[chit has drop=false,#2]
193 \chit[\u=\ti]%
194 \wg@add@drop@margin%
195 \end{tikzpicture}
196 \end{info}%
197 %% \foreach \n in {1,...,\m}{% Make a number of copies
198 %% \ifx\u\chit@blank%
199 %% \chit@dbg{3}{Ignoring blank chit:\u}%
200 %% \else%
201 %% \info{\u}{counter}{#2}
202 %% \begin{tikzpicture}
203 %% \chit[\u=\ti](\c,\r)%
204 %% \end{tikzpicture}
205 %% \fi%
206 %% }%
207 \fi%
208 \fi%
209 \fi%
210 \fi%
211 }%
212 \chit@dbg{2}{End of inner loop}%
213 \fi%
214 }%
215 \chit@dbg{2}{End of outer loop}%
216 \endgroup%
217 }
218 % \end{macrocode}
219 %
220 % Make separate images for each counter (double sided). The back-side
221 % counters must be defined by append `\texttt{ flipped}' the front
222 % face name.
223 %
224 % First optional argument is the group to put the chits into.
225 % Second optional argument is options to give to each Tikz picture
226 % environment. Third, mandatory, argument is the list of chit
227 % identifiers to render.
228 %
229 % \begin{macrocode}
230 \def\doublechitimages{%
231 \@ifnextchar[{\@doublechitimages}{\doublechitimages[]}%]
232 }%
233 \def\@doublechitimages[#1]{%
234 \@ifnextchar[{\@@doublechitimages[#1]}{\@@doublechitimages[#1][]}%]
235 }%
236 \def\@@doublechitimages[#1][#2]#3{%
237 \begingroup%
238 \let\chit@report\do@chit@report%
239 \let\natoapp@report\do@natoapp@report%
240 \foreach[count=\ti from 0] \t/\x in #3{%
241 \ifx\t\empty\else% Ignore empty rows
242 \chit@dbg{5}{^^JSubcategory: `\x' (default `#1')}
243 % Take sub-category or default
244 \ifx\t\x\def\x{#1}\else\ifx\x\empty\def\x{#1}\fi\fi
245 \foreach \u/\m in \t{%
246 \ifx\u\empty\else% Ignore empty cells
247 \ifx\u\chit@blank\else%
248 \ifx\u\chit@oob@vspacer\else%
249 \ifx\u\chit@oob@spacer\else%
250 \chit@dbg{2}{Next chit `\u' with possible multiplicity `\m'}%
251 \ifx\m\@empty\def\m{1}\fi% If not multiplicity defined
252 \ifx\u\m\def\m{1}\fi% If the same as unit
253 \chit@dbg{2}{Next chit `\u' multiplicity `\m'}%
254 %% Flipped chit
255 \edef\s{\u\space flipped}%
256 %% We only make one copy of the chit, since we can duplicate
257 %% it in VASSAL
258 \begin{info}*{\u}{counter}{\x}%
259 \nopagecolor%
260 \gdef\wg@drop@margin{0pt}%
261 \begin{tikzpicture}[chit has drop=false,#2]%
262 \chit[\u=\ti]%
263 \wg@add@drop@margin%
264 \end{tikzpicture}%
265 \end{info}%
266 \begin{info}*{\s}{counter}{\x}%
267 \nopagecolor%
268 \begin{tikzpicture}[chit has drop=false,#2]%
269 \chit[\s=\ti]%
270 \wg@add@drop@margin%
271 \end{tikzpicture}%
272 \end{info}%
273 %% \foreach \n in {1,...,\m}{% Make a number of copies
274 %% \ifx\u\chit@blank%
275 %% \chit@dbg{3}{Ignoring blank chit:\u}%
276 %% \else%
277 %% \info{\u}{counter}{#2}
278 %% \begin{tikzpicture}
279 %% \chit[\u=\ti](\c,\r)%
280 %% \end{tikzpicture}
281 %% \fi%
282 %% }%
283 \fi%
284 \fi%
285 \fi%
286 \fi%
287 }%
288 \fi%
289 }%
290 \endgroup%
291 }
292 % \end{macrocode}
293 %
294 % Special for boards, we have the environment \textsf{boardimage}.
295 % Like \cs{info} we must specify the name and sub-category of the
296 % board, but the category is assumed to be \texttt{board} (though the
297 % optional argument can specify a different category).
298 %
299 % Within this environment some specific styles are defined that allows
300 % the user to specify VASSAL zones on the board. For this to work
301 % properly, the parent \textsf{tikzpicture} \emph{must} have the style
302 % \texttt{zoned}. This style will record the bounding box of the
303 % picture which we will need to calculate VASSAL coordinates later
304 % on.
305 %
306 % Other styles are \texttt{zone scope}, to be applied to
307 % \texttt{scope}s in the picture, and \texttt{zone path} to be applied
308 % to \texttt{path}s (or \cs{draw}, \cs{fill}, or the like) in the
309 % picture. These will record coordinates of these elements in side
310 % the picture. The Python script will then define VASSAL zones based
311 % on these coordinates.
312 %
313 % For \texttt{zone scope} applied to a \texttt{scope}, what is
314 % recorded are
315 %
316 % \begin{itemize}
317 % \item The current coordinate transformation matrix
318 % \item The current translation
319 % \item The bounding box, within the current transformation and
320 % translation.
321 % \end{itemize}
322 %
323 % To define a zone in the board, simply enclose it in a
324 %
325 % \begin{verbatim}
326 % \begin{scope}[zone scope=name]
327 % ...
328 % \end{scope}
329 % \end{verbatim}
330 %
331 % The \meta{name} will be the name of the scope. If this contains the
332 % sub-string \texttt{hex} (upper, lower, or mixed case), then the zone
333 % will get a hex grid with numbering attached to it.
334 %
335 % If the \meta{name} contains the sub-string \texttt{turn} (any case),
336 % then it is assumed to be a turn track and a rectangular grid will be
337 % attached. The column and row separator will be set to \texttt{T},
338 % so that it won't collide with the main zone. Similar if \meta{name}
339 % contains \texttt{oob}, except the separator is set to \texttt{O}.
340 %
341 % If \meta{name} contains the sub-string \texttt{pool}, then it is
342 % assumed to be a pool of counters, and \emph{no} grid is attached.
343 %
344 % For \texttt{zone path} applied to a \texttt{path}, what is recorded
345 % is the path coordinates (as straight line segments) in the global
346 % coordinate system.
347 %
348 % Both styles take one argument --- the name of the zone. If that
349 % name contains the sub-string \texttt{hex} anywhere in the name, then
350 % the zone is assumed to contain a hex grid. Otherwise, a rectangular
351 % grid (of fixed size) will be applied to it.
352 %
353 % The environment \texttt{boardimage} also records the coordinate
354 % options currently in use (keys \texttt{hex/first row is},
355 % \texttt{hex/row direction is}, and so on), as well as the current
356 % label option (as defined by \texttt{every hex} or \texttt{every hex
357 % node}).
358 %
359 %
360 % The information extracted is written to the
361 % \cs{jobname}\texttt{.json} file as a sub-object (with name given by
362 % the first optional argument) of the image object. In that way, we
363 % can later on easily get the information from our catalogue of
364 % images.
365 %
366 % Note, the styles \texttt{zoned}, \texttt{zone scope}, and
367 % \texttt{zone path} are defined in \texttt{wargame} to be dummies so
368 % that one can have them in the definition of the board without
369 % impact.
370 % \begin{macrocode}
371 \def\mk@transform{%
372 \pgfgettransformentries{\mxx}{\mxy}{\myx}{\myy}{\ptdx}{\ptdy}
373 \wg@pt@to@cm{\ptdx}\edef\dx{\pgfmathresult}
374 \wg@pt@to@cm{\ptdy}\edef\dy{\pgfmathresult}
375 \mk@w{ \mk@i "xx": \mxx,}
376 \mk@w{ \mk@i "xy": \mxy,}
377 \mk@w{ \mk@i "yx": \myx,}
378 \mk@w{ \mk@i "yy": \myy,}
379 \mk@w{ \mk@i "dx": \dx,}
380 \mk@w{ \mk@i "dy": \dy,}
381 }
382 % \end{macrocode}
383 % \begin{macrocode}
384 \def\mk@bb#1{%
385 \wg@get@bb{#1}
386 \mk@w{ \mk@i "lower left": [\llx,\lly],}
387 \mk@w{ \mk@i "upper right": [\urx,\ury],}
388 \begingroup
389 \wg@get@global@nchor{#1}{south west}
390 \mk@w{ \mk@i "global lower left": [\tmp@x,\tmp@y],}
391 \wg@get@global@nchor{#1}{north east}
392 \mk@w{ \mk@i "global upper right": [\tmp@x,\tmp@y]}
393 \endgroup
394 }
395 \def\mk@pos#1(#2){%
396 \wg@dbg{10}{^^JMarking `#2' with `#1' - start}
397 \coordinate[transform shape] (tmp) at (#2) {};
398 \wg@get@nchor{tmp}{center}
399 \wg@dbg{3}{^^JMarking `#2' with `#1' - `\tmp@x',\tmp@y'}
400 \tikzset{zone point={#1}{\tmp@x}{\tmp@y}}
401 }
402 % \end{macrocode}
403 %
404 % For the key \texttt{zone path} to work, we need to be able to record
405 % the path as it moves along. To that end, we make a custom
406 % decoration that will do that for us, and, once the path is finished,
407 % write the path to our JSON file.
408 %
409 % \begin{macrocode}
410 \pgfdeclaredecoration{record path construction}{initial}{%
411 \state{initial}[width=0pt,next state=more]{
412 \begingroup
413 \pgf@decorate@inputsegment@first
414 \ptpoint@to@cm{\the\pgf@x}{\the\pgf@y}
415 \xdef\wg@path{[\x,\y]}
416 \endgroup
417 }%
418 \state{more}[width=\pgfdecoratedinputsegmentremainingdistance]{%
419 \begingroup
420 \pgf@decorate@inputsegment@last
421 \ptpoint@to@cm{\the\pgf@x}{\the\pgf@y}
422 \xdef\wg@path{\wg@path,[\x,\y]}
423 \endgroup
424 }
425 \state{final}{%
426 \begingroup
427 \pgf@decorate@inputsegment@last
428 \ptpoint@to@cm{\the\pgf@x}{\the\pgf@y}
429 \xdef\wg@path{\wg@path,[\x,\y]}
430 \endgroup
431 \mk@w{ \mk@i "zone path \wg@record@path@name": \@lbchar}
432 \mk@w{ \mk@i\space "path": [\wg@path] \@rbchar,}
433 }
434 }%
435 % \end{macrocode}
436 %
437 % Now we can make our environment
438 %
439 % The first thing we do is to use the \cs{info} macro to mark the
440 % image. Then we open our JSON file. We make a short-hand macro for
441 % writing to that file. The macro \cs{bd@i} records the current
442 % indention (which is important in JSON)
443 %
444 % \begin{macrocode}
445 \newenvironment{boardimage}[3][board]{%
446 \def\bd@n{#2}
447 \newcount\mk@point
448 \mk@point=0
449 \let\oomk@i\mk@i%
450 \let\markpos\mk@pos%
451 % \end{macrocode}
452 %
453 %
454 % Then, to extract the label option, we make a dummy \texttt{node}
455 % with the styles \texttt{every hex} and \texttt{every hex node}, so
456 % we can extract that option.
457 %
458 % \begin{macrocode}
459 \info{dummy}{<<dummy>>}{}%
460 %\tikz{}%
461 \tikz{\scoped[%
462 every hex/.try,every hex node/.try,
463 ]{%
464 \def\hex@col{0}%
465 \def\hex@row{0}%
466 \node[hex,inner sep=0,outer sep=0]{%
467 %\message{^^JHex label: `\meaning\hex@label'}%
468 \global\let\mk@label\hex@label}}}%
469 % \end{macrocode}
470 %
471 % The next thing we do is to make an object. The first things we put
472 % in are the units used (``cm''), and the grid options.
473 %
474 % \begin{macrocode}
475 \info*{#2}{#1}{#3}%
476 \mk@w{ \mk@i "zones": \@lbchar}%
477 \edef\mk@i{\mk@i\space}
478 %% Everything is made into centimeters
479 \mk@w{ \mk@i "units": "cm",}
480 \hex@dbg{3}{Label: `\meaning\mk@label'}
481 \@ifundefined{mk@label}{}{\mk@w{ \mk@i "labels": "\mk@label",}}
482 %% Write out coordinate options as "coords" object
483 \mk@w{ \mk@i"coords": \@lbchar}%
484 \mk@w{ \mk@i "row": \@lbchar}%
485 \mk@w{ \mk@i\space "offset": \hex@coords@row@off,}%
486 \mk@w{ \mk@i\space "factor": \hex@coords@row@fac \@rbchar,}%
487 \mk@w{ \mk@i "column": \@lbchar}%
488 \mk@w{ \mk@i\space "offset": \hex@coords@col@off,}%
489 \mk@w{ \mk@i\space "factor": \hex@coords@col@fac,}%
490 \mk@w{ \mk@i\space "top short": "\hex@top@short@col",}%
491 \mk@w{ \mk@i\space "bottom short": "\hex@bot@short@col" \@rbchar}%
492 \mk@w{ \mk@i\@rbchar,}%
493 % \end{macrocode}
494 %
495 % We then monkey-patch \cs{boardframe} to also output coordinates to
496 % our JSON file. Note that this will probably be embedded in a
497 % different object.
498 %
499 % \begin{macrocode}
500 %%
501 \let\oldbo@rdframe\bo@rdframe%
502 \def\bo@rdframe[##1](##2)(##3){%
503 \oldbo@rdframe[##1](##2)(##3)%
504 \mk@w{ \mk@i"board frame": \@lbchar}
505 \mk@w{ \mk@i\space "lower left": [\llx,\lly],}
506 \mk@w{ \mk@i\space "upper right": [\urx,\ury],}
507 \mk@w{ \mk@i\space "margin": \margin,}
508 \mk@w{ \mk@i\space "width": \w,}
509 \mk@w{ \mk@i\space "height": \h \@rbchar,}}%
510 % \end{macrocode}
511 %
512 % Next, we make the style \texttt{zoned} to be applied to the
513 % \texttt{tikzpicture} environment. This records the bounding box of
514 % the full picture.
515 %
516 % \begin{macrocode}
517 \tikzset{
518 zoned/.code={% Apply to whole picture
519 \pgfkeys{%
520 % This needs to be done in the picture!
521 /tikz/execute at end picture={%
522 \mk@w{ \mk@i "zoned": \@lbchar}
523 \mk@transform%
524 \mk@bb{current bounding box}
525 \mk@w{ \mk@i \@rbchar,}
526 }
527 }
528 },
529 % \end{macrocode}
530 %
531 % The next style is the \texttt{zone scope}. At the start of the
532 % scope we record the current transformation matrix. Then we install
533 % a handler to extract the bounding box at the end of the scope. Note
534 % that we increase indention here.
535 %
536 % \begin{macrocode}
537 zone scope/.code={%
538 \mk@w{ \mk@i"zone scope ##1": \@lbchar}
539 \let\omk@i\mk@i
540 \edef\mk@i{\mk@i\space}
541 \mk@transform%
542 %\bd@w{ \@rbchar,}
543 \gdef\wg@export@box{##1}%
544 \pgfkeys{%
545 /tikz/local bounding box=wg export box,
546 /tikz/execute at end scope={
547 \mk@bb{wg export box}
548 \let\mk@i\omk@i
549 \mk@w{ \mk@i\@rbchar,}},
550 } % pgfkeys
551 }, % zone scope
552 % \end{macrocode}
553 % The next style gets the global coordinates of the current (0,0)
554 % point - f.ex. in a node - and outputs that
555 % \begin{macrocode}
556 zone point/.code n args={3}{
557 \pgf@xa=##2 cm
558 \pgf@ya=##3 cm
559 \pgfpointtransformed{\pgfpoint{\pgf@xa}{\pgf@ya}}
560 % \pgfpointtransformed{\pgfpoint{0pt}{0pt}}
561 \pgf@xa=\pgf@x
562 \pgf@ya=\pgf@y
563 \wg@pt@to@cm{\the\pgf@xa}\edef\px{\pgfmathresult}
564 \wg@pt@to@cm{\the\pgf@ya}\edef\py{\pgfmathresult}
565 \advance\mk@point1
566 \global\mk@point=\mk@point
567 \mk@w{ \mk@i "point\the\mk@point": \@lbchar "name": "##1", "type": "point", "coords": [\px,\py]
568 \@rbchar, }
569 %\message{^^JZone point \the\mk@point\space ##1: ##2,##3 -> \px,\py}
570 },
571 zone oob point/.code n args={3}{
572 \pgf@xa=##2 cm
573 \pgf@ya=##3 cm
574 \advance\[email protected]
575 \advance\[email protected]
576 \pgfpointtransformed{\pgfpoint{\pgf@xa}{\pgf@ya}}
577 % \pgfpointtransformed{\pgfpoint{0pt}{0pt}}
578 \pgf@xa=\pgf@x
579 \pgf@ya=\pgf@y
580 \wg@pt@to@cm{\the\pgf@xa}\edef\px{\pgfmathresult}
581 \wg@pt@to@cm{\the\pgf@ya}\edef\py{\pgfmathresult}
582 \advance\mk@point1
583 \global\mk@point=\mk@point
584 \mk@w{ \mk@i "point\the\mk@point": \@lbchar "name": "##1",
585 "parent": "\wg@export@box", "type": "point", "coords": [\px,\py]
586 \@rbchar, }
587 %\message{^^JZone point \the\mk@point\space ##1: ##2,##3 -> \px,\py}
588 },
589 zone global point/.code n args={3}{
590 \advance\mk@point1
591 \global\mk@point=\mk@point
592 \mk@w{ \mk@i "point\the\mk@point": \@lbchar "name": "##1", "type": "point", "coords": [\px,\py]
593 \@rbchar, }
594 },
595 % \end{macrocode}
596 %
597 % The \texttt{zone path} style is a bit more simple, but only because
598 % the bulk of the work is done in a decoration. We need to be able to
599 % pass a name to that decoration, s we make a key for that. The user
600 % need not think about that though.
601 %
602 % \begin{macrocode}
603 /pgf/decoration/record path name/.store in=\wg@record@path@name,
604 zone path/.style={%
605 postaction={decorate,decoration={
606 record path construction,
607 record path name=##1}}
608 } % zone path
609 }% tikzset
610 }
611 % \end{macrocode}
612 %
613 % That finishes the first part of the environment. At the end of the
614 % environment, we simple write the name of the picture, and close our
615 % JSON output.
616 %
617 % \begin{macrocode}
618 {%
619 \mk@w{ \mk@i "name": "\bd@n" }%
620 \let\mk@i\oomk@i%
621 \mk@w{ \mk@i\@rbchar}%
622 \endinfo%
623 }
624 % \end{macrocode}
625 %
626 % Make battle markers. Mandatory argument is how many markers,
627 % optional is the group to add the markers to.
628 %
629 % \begin{macrocode}
630 \def\wg@gennumberm@rkers#1#2#3#4{
631 \chit@dbg{2}{Numbered markers: Type=`#1' Max=`#2' Category=`#3'}
632 \def\markers{}
633 \def\keys{}
634 \foreach \i in {1,...,#2}{%
635 \xdef\keys{/tikz/#1 \i/.style={/tikz/#1=\i},\keys}
636 \xdef\markers{\markers,#1 \i}}
637 {%
638 \nopagecolor\pgfkeysalsofrom{\keys}\chitimages[#3][#4]{\markers}}}%
639 \tikzset{
640 wg hidden unit/.pic={},
641 wg hidden unit/.style={
642 chit={
643 no chit drop,
644 frame={draw=none,fill=none},
645 full=wg hidden unit}}}
646 %
647 % First optional argument are extra styles
648 % Second is category
649 % Third is number of markers
650 %
651 \def\battlemarkers{%
652 \@ifnextchar[{\@battlemarkers}{\battlemarkers[]}%]
653 }%
654 \def\@battlemarkers[#1]{%
655 \@ifnextchar[{\@@battlemarkers[#1]}{\battlemarkers[#1][BattleMarkers]}%]
656 }%
657 \def\@@battlemarkers[#1][#2]#3{%
658 \wg@gennumberm@rkers{battle marker}{#3}{#2}{#1}%
659 \chit@dbg{1}{Make a hidden unit and add to Markers category}
660 {%
661 \nopagecolor%
662 \chitimages[Markers]{{wg hidden unit}}%
663 %
664 \info{battle-marker-icon}{icon}{}%
665 \tikz[scale=.7,transform shape,auto icon more/.try]{%
666 \pic{battle marker=0};}%
667 \info{clear-battles-icon}{icon}{}
668 \tikz[scale=.4,transform shape,auto icon more/.try]{%
669 \pic{eliminate icon};
670 \pic[scale=.7,transform shape] at (-.3,0) {battle marker=0};}%
671 }%
672 }
673 % \end{macrocode}
674 %
675 % Make odds markers. Mandatory argument is a list of odds and fill colours.
676 % Optional is the group to add the markers to.
677 %
678 % \begin{macrocode}
679 \def\wg@gencolorm@rkers#1#2#3#4{%
680 \def\markers{}
681 \def\keys{}
682 \foreach \o/\f/\n [count=\i] in {#2}{%
683 \ifx\n\f\def\n{\o}\fi%
684 \ifx\o\f\def\f{white}\fi%
685 \chit@dbg{3}{Colour no `\i' marker `#1 \n' w/fill `\f' text `\o'}%
686 \protected@xdef\keys{/tikz/#1 \n/.style={/tikz/#1={\o,\f}},\keys}
687 \xdef\markers{\markers,#1 \n}
688 }%
689 {%
690 \nopagecolor%
691 \pgfkeysalsofrom{\keys}%
692 \chitimages[#3][#4]{\markers}%
693 }%
694 }%
695 %
696 % First optional argument are extra styles
697 % Second is category
698 % Third is marker list
699 %
700 \def\oddsmarkers{%
701 \@ifnextchar[{\@oddsmarkers}{\oddsmarkers[]}%]
702 }%
703 \def\@oddsmarkers[#1]{%
704 \@ifnextchar[{\@@oddsmarkers[#1]}{\oddsmarkers[#1][OddsMarkers]}%]
705 }%
706 \def\@@oddsmarkers[#1][#2]#3{%
707 \wg@gencolorm@rkers{odds marker}{#3}{#2}{#1}%
708 \info{odds-battles-icon}{icon}{}
709 \tikz[scale=.5,transform shape,auto icon more/.try]{%
710 \pic{odds marker={?:?,white}}}
711 \info{resolve-battles-icon}{icon}{}
712 \tikz[scale=.3,transform shape,auto icon more/.try]{%
713 \pic{dice};
714 \pic[scale=1.2,transform shape] at (-.2,-.2) {battle marker=0};}%
715 }
716 % \end{macrocode}
717 %
718 % Make results markers. Mandatory argument is a list of results and
719 % fill colours. Optional is the group to add the markers to.
720 %
721 %
722 % First optional argument are extra styles
723 % Second is category
724 % Third is marker list
725 %
726 % \begin{macrocode}
727 \def\resultmarkers{%
728 \@ifnextchar[{\@resultmarkers}{\resultmarkers[]}%]
729 }%
730 \def\@resultmarkers[#1]{%
731 \@ifnextchar[{\@@resultmarkers[#1]}{\resultmarkers[#1][ResultMarkers]}%]
732 }%
733 \def\@@resultmarkers[#1][#2]#3{%
734 \wg@gencolorm@rkers{result marker}{#3}{#2}{#1}}%
735 % \end{macrocode}
736 %
737 % Common icons used by many modules
738 %
739 % \begin{macrocode}
740 \DeclareRobustCommand\commonicons[3][]{%
741 \begingroup%
742 \nopagecolor%
743 \tikzset{auto icon/.style={scale=.4,transform shape,#1}}%
744 %
745 \info{pool-icon}{icon}{}
746 \tikz[auto icon,auto icon more/.try]{\pic{pool icon};}
747 %
748 \info{oob-icon}{icon}{}%
749 \tikz[auto icon,auto icon more/.try]{\pic{oob icon={#2}{#3}};}%
750 %
751 \info{flip-icon}{icon}{}%
752 \tikz[auto icon,auto icon more/.try]{\pic{flip icon};}%
753 %
754 \info{eliminate-icon}{icon}{}%
755 \tikz[auto icon,auto icon more/.try]{\pic{eliminate icon};}%
756 %
757 \info{restore-icon}{icon}{}%
758 \tikz[auto icon,auto icon more/.try]{\pic{restore icon};}%
759 %
760 \info{dice-icon}{icon}{}%
761 \tikz[auto icon,scale=.9,auto icon more/.try]{\pic{dice};}%
762 %
763 \info{unit-icon}{icon}{}%
764 \tikz[auto icon,scale=.7,auto icon more/.try]{%
765 \chit[fill=#2,
766 symbol={[
767 scale line widths,
768 line width=1pt,
769 faction=friend,
770 command=land,
771 main=infantry,
772 scale=1.3](0,-.15)}]}%
773 %
774 \info{layer-icon}{icon}{}%
775 \begin{tikzpicture}[scale=.25]
776 \foreach \i in {-1,0,1}{
777 \scoped[shift={(0,\i*.15)}]{
778 \draw[black,fill=white] (-.5,0)
779 --(0,.3)--(.5,0)--(0,-.3)--cycle;
780 }
781 }
782 \end{tikzpicture}%
783 %
784 \info{los-icon}{icon}{}
785 \begin{tikzpicture}[scale=.25]
786 \draw[scale line widths,line width=2pt,fill=white](-.5,0)
787 to[out=70,in=110] (.5,0)
788 to[out=-110,in=-70] cycle;
789 \begin{scope}[even odd rule]
790 \clip circle(.2);
791 \fill circle(.2) (125:.18) circle(.1);
792 \end{scope}
793 \end{tikzpicture}%
794 %
795 \endgroup%
796 }
797 % \end{macrocode}
798 %
799 % \subsubsection{Making dice}
800 % \begin{Syntax}
801 % \cs{dice}\oarg{tikz-options}\oarg{node-options}\marg{name}\marg{name}\marg{list}
802 % \end{Syntax}
803 % \begin{enumerate}
804 % \item \meta{tikz-options}
805 % \item \meta{node-options}
806 % \item \meta{name} - an identifier - e.g., the same as \meta{shape}.
807 % \item \meta{shape} - one of \texttt{d4}, \texttt{d6}, \texttt{d8},
808 % \texttt{d10}, \texttt{d12}, or \texttt{d20}.
809 % \item \meta{list} - list of pairs
810 % \meta{value}\texttt{/}\meta{printed}, where \meta{value} is the
811 % value, and \meta{printed} is the shown value. If \meta{printed} is
812 % left out, then \meta{value} is used.
813 % \end{enumerate}
814 %
815 % \begin{macrocode}
816 \def\dice{%
817 \@ifnextchar[{\wg@dice}{\wg@dice[]}%]
818 }
819 \def\wg@dice[#1]{%
820 \@ifnextchar[{\wg@@dice{#1}}{\wg@@dice{#1}[]} %]
821 }
822 \def\wg@@dice#1[#2]#3#4#5{%
823 \foreach \v/\p in {#5}{%
824 \info{#3-\v}{die-roll}{#3}
825 \tikz[#1]{
826 %\node[shape=#4,transform shape,draw=none,fill=black,opacity=.5]
827 %at (.05,-.03){};
828 \node[shape=#4,#2,transform shape,
829 chit drop,
830 node contents={\p}
831 ]{};\wg@add@drop@margin{}}}}
832 % \end{macrocode}
833 %
834 % \subsubsection{Hooks into chits, etc.}
835 %
836 % TO BE DONE: We could add hook the \texttt{hex} shape that would
837 % allow us to write out the settings for each of these. This would
838 % allow us to make data files that contain the information available
839 % in the \LaTeX{} code.
840 %
841 % If one then assumed that for example the upper left corner holds the
842 % start-up hex, then one could use that information.
843 %
844 % The code below exports the chit information to the JSON file.
845 % Together with the battle, odds, and result markers stuff above, this
846 % allows the exporter to almost automatically set up battle odds and
847 % result calculations. The fields exported are
848 %
849 % \begin{itemize}
850 % \item Left and right identifiers
851 % \item Upper left, upper right, lower left, and lower right
852 % identifiers. (some care must be taken if these contains graphics
853 % and not just text.)
854 % \item Factors
855 % \item NATO symbol
856 % \begin{itemize}
857 % \item Faction, command, echelon
858 % \item Mains
859 % \item Left, right, top, and bottom attributes and modifiers
860 % \item Below attribute
861 % \end{itemize}
862 % \end{itemize}
863 %
864 % The exporter can set up prototypes for NATO types, echelons,
865 % etc. The exporter can also set factors as marks on the units.
866 %
867 % \begin{macrocode}
868 \tikzset{
869 zone turn/.store in=\zone@turn,
870 zone mult/.store in=\zone@mult
871 }
872 \def\@chit@rep@line#1#2{%
873 \@ifundefined{#2}{}{
874 \edef\wg@chit@tmp{\csname #2\endcsname}
875 {\escapechar=`/
876 \xdef\tmp{\detokenize\expandafter{\wg@chit@tmp} \@empty}}
877 % \message{^^J\meaning\@tmp -> \meaning\tmp}
878 \mk@w{ \mk@i\space "#1": "\tmp",}}}
879
880 \def\do@chit@report{%
881 \chit@dbg{3}{Start of Chit Report}
882 \mk@w{ \mk@i "chit": \@lbchar}
883 \chit@dbg{3}{Report - ID}
884 \@ifundefined{id}{} {\mk@w{ \mk@i\space "id": "\id", }}%
885 \chit@dbg{3}{Report - Symbol: `\meaning\chit@symbol'}
886 \@ifundefined{chit@symbol}{}{\mk@w{ \mk@i\space "symbol": "true", }}%
887 \chit@dbg{3}{Report - Full: `\meaning\chit@full'}
888 \@chit@rep@line{full}{chit@full}
889 \chit@dbg{3}{Report - Factors: `\meaning\chit@factors'}
890 \@chit@rep@line{factors}{chit@factors}%
891 \chit@dbg{3}{Report - Left: `\meaning\chit@left'}
892 \@chit@rep@line{left}{chit@left}%
893 \chit@dbg{3}{Report - Right: : `\meaning\chit@right'}
894 \@chit@rep@line{right}{chit@right}%
895 \chit@dbg{3}{Report - Upper left: `\meaning\chit@upper@left'}
896 \@chit@rep@line{upper left}{chit@upper@left}%
897 \chit@dbg{3}{Report - Lower left: `\meaning\chit@lower@left'}
898 \@chit@rep@line{lower left}{chit@lower@left}%
899 \chit@dbg{3}{Report - Upper right: `\meaning\chit@upper@right}
900 \@chit@rep@line{upper right}{chit@upper@right}%
901 \chit@dbg{3}{Report - Lower right: `\meaning\chit@lower@right'}
902 \@chit@rep@line{lower right}{chit@lower@right}%
903 \chit@dbg{3}{Report - End comma}
904 \mk@w{ \mk@i\space "end": 0}
905 \@ifundefined{chit@symbol}{
906 \mk@w{ \mk@i \@rbchar }
907 }{
908 \mk@w{ \mk@i \@rbchar, }% NATOAPP6c will follow
909 }%
910 \chit@dbg{3}{End of Chit Report}
911 }
912 % \end{macrocode}
913 % Report out NATO App6 symbol settings
914 % \begin{macrocode}
915 \def\do@natoapp@report{%
916 \mk@w{ \mk@i "natoapp6c": \@lbchar}
917 \@chit@rep@line{id}{\id}
918 \@chit@rep@line{faction}{natoapp@fac}
919 \@chit@rep@line{command}{natoapp@cmd}
920 \@chit@rep@line{echelon}{natoapp@ech}
921 \@chit@rep@line{main}{natoapp@main}
922 \@chit@rep@line{left}{natoapp@left}
923 \@chit@rep@line{right}{natoapp@right}
924 \@chit@rep@line{upper}{natoapp@upper}
925 \@chit@rep@line{lower}{natoapp@lower}
926 \@chit@rep@line{below}{natoapp@below}
927 \mk@w{ \mk@i\space "end": 0}
928 \mk@w{ \mk@i \@rbchar}
929 }
930 \tikzset{
931 chit drop margin/.store in=\wg@drop@margin,
932 chit drop shadows/.code={
933 \pgfkeysalso{%
934 /tikz/every chit node/.prefix style={chit drop={#1}},
935 /tikz/chit has drop=true}
936 },
937 chit drop shadows/.default=,
938 marker drop shadows/.code={
939 \pgfkeysalso{%
940 /tikz/every battle marker/.prefix style={chit drop={#1}},
941 /tikz/every odds marker/.prefix style={chit drop={#1}},
942 /tikz/every result marker/.prefix style={chit drop={#1}},
943 /tikz/auto icon more/.prefix style={no chit drop}}},
944 marker drop shadows/.default={
945 chit has drop=false,
946 shadow xshift=0.04cm,
947 shadow yshift=-0.04cm,
948 shadow blur radius=0.04cm}
949 }
950
951
952 % \end{macrocode}
953 %
954 %
955 % \iffalse
956 %</exportcls>
957 %\fi