-
Notifications
You must be signed in to change notification settings - Fork 0
/
tikzgamemap.dtx
1365 lines (1283 loc) · 40.8 KB
/
tikzgamemap.dtx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% \iffalse meta-comment
%<*internal|tgm1>
\def\Version{2019/02/19 v0.1}
%</internal|tgm1>
%<*internal>
\iffalse
%</internal>
%<*internal>
\fi
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX\else
\expandafter\begingroup
\fi
%</internal>
%<*install>
\input docstrip.tex
\keepsilent
\askforoverwritefalse
\preamble
---------------------------------------------------------------------------
tikzgamemap --- Maps for interactive fiction with TikZ
Author: Alex Ball
E-mail: [email protected]
License: Released under the LaTeX Project Public License v1.3c or later
See: http://www.latex-project.org/lppl.txt
---------------------------------------------------------------------------
\endpreamble
\postamble
Copyright (C) 2019 by Alex Ball <[email protected]>
This work may be distributed and/or modified under the
conditions of the LaTeX Project Public License (LPPL), either
version 1.3c of this license or (at your option) any later
version. The latest version of this license is in the file:
http://www.latex-project.org/lppl.txt
This work is "maintained" (as per LPPL maintenance status) by
Alex Ball.
\endpostamble
\usedir{tex/latex/\jobname}
\generate{
\file{tgm1.sty}{\from{\jobname.dtx}{tgm1}}
}
%</install>
%<install>\endbatchfile
%<*internal>
\usedir{source/latex/\jobname}
\generate{
\file{\jobname.ins}{\from{\jobname.dtx}{install}}
}
\nopreamble\nopostamble
\ifx\fmtname\nameofplainTeX
\expandafter\endbatchfile
\else
\expandafter\endgroup
\fi
%</internal>
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{tikzgamemap.dtx}
%</driver>
%<tgm1>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<tgm1>\ProvidesPackage{tgm1}
%<*tgm1>
[\Version\space Maps for interactive fiction with TikZ]
%</tgm1>
%<*driver>
\documentclass[12pt]{article}
% Page Layout
\usepackage[a4paper,hmargin=30mm,vmargin=25mm,nohead]{geometry}
% Typography
% \usepackage[charter,expert]{mathdesign}
% \makeatletter
% \def\hrulefill{\leavevmode\leaders \hrule height \rulethickness \hfill\kern\z@}
% \makeatother
\usepackage{iftex}
\ifPDFTeX
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[scaled=0.95,tabular]{sourceserifpro}
\usepackage[scaled=0.95,tabular]{sourcesanspro}
\usepackage[varl,varqu]{zi4}
\else
\usepackage[no-math]{fontspec}
\setmainfont
[Scale=MatchLowercase
,Ligatures=TeX
]%
{Source Serif Pro}
\setsansfont
[Scale=MatchLowercase
,Ligatures=TeX
,StylisticSet=4
,BoldFont={Source Sans Pro Bold}
,ItalicFont={Source Sans Pro Italic}
,BoldItalicFont={Source Sans Pro Bold Italic}
]%
{Source Sans Pro}
\setmonofont
[Scale=MatchLowercase
,RawFeature={extend=0.83}
,BoldFont={Source Code Pro Bold}
,BoldItalicFont={Source Code Pro Bold}
,AutoFakeSlant=0.2
,ItalicFeatures={StylisticSet=2,StylisticSet=3}
,BoldItalicFeatures={FakeSlant=0.2,StylisticSet=2,StylisticSet=3}
]%
{Source Code Pro}
\fi
\usepackage[italic]{mathastext}
% Improving the look of the documentation
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
\usepackage{multicol}
\usepackage{enumitem}
\setlist[itemize,enumerate]{%
topsep={0pt plus 0.05em},%
partopsep={0pt plus 0.05em},%
itemsep={6pt plus 0.05em minus 0.05em},%
parsep={0pt plus 0.05em},%
}
\usepackage[bookmarks,raiselinks,pageanchor,hyperindex,colorlinks,pdfencoding=auto]{hyperref}
\usepackage{bookmark}
\usepackage{etoolbox}
\usepackage{xstring}
\usepackage{tcolorbox,doc}
\makeatletter
\renewenvironment{theglossary}{%
\bgroup
\glossary@prologue
\GlossaryParms \let\item\@idxitem \ignorespaces
}{%
\egroup
}
\makeatother
\tcbuselibrary{documentation,breakable,minted}
\colorlet{Option}{violet}
\colorlet{Command}{red!75!black}
\colorlet{Environment}{blue!75!black}
\colorlet{Value}{olive!75!black}
\colorlet{Color}{cyan!75!black}
\tcbset
{ listing engine=minted
, minted options=
{ breaklines
, fontsize=\footnotesize
, linenos
, numbersep=20pt
, firstnumber=last
}
, index format=pgf
, color command=Command
, color environment=Environment
, color key=Option
, color value=Value
, color color=Color
, colbacktitle=ExampleFrame!33!ExampleBack
, docexample/.append style = {parskip}
}
\renewcommand{\theFancyVerbLine}{\footnotesize\itshape\color{gray}\arabic{FancyVerbLine}}
\let\tcbcs=\cs
\renewcommand*{\cs}[1]{\textcolor{Command}{\tcbcs{#1}}}
\def\sqbrackets#1{%
\texttt{\textcolor{Option}{[}#1\textcolor{Option}{]}}}
\def\brackets#1{%
\texttt{\textcolor{Environment}{\char`\{}#1\textcolor{Environment}{\char`\}}}}
\def\marg#1{%
\textcolor{Environment}{\ttfamily\char`\{}\meta{#1}\textcolor{Environment}{\ttfamily\char`\}}}
\newcommand*{\env}[1]{\textcolor{Environment}{\ttfamily #1}}
\newcommand*{\key}[1]{\textcolor{Option}{\ttfamily #1}}
\newcommand*{\val}[1]{\textcolor{Value}{\ttfamily #1}}
\makeatletter
\renewenvironment{macro}[1]{%
\StrSubstitute{#1}{\detokenize{@}}{"@}[\MyName]%
\edef\saved@macroname{\expandafter\string\csname #1\endcsname}%
\let\saved@indexname\saved@macroname
\index{\MyName @\tcbIndexPrintComC {\MyName}|(emph}%
}{%
\ifdef{\MyName}{}{%
\errmessage{You have closed a macro environment you have not opened on \the\inputlineno.}%
}
\index{\MyName @\tcbIndexPrintComC {\MyName}|)}%
}
\renewenvironment{environment}[1]{%
\StrSubstitute{#1}{\detokenize{@}}{"@}[\MyName]%
\edef\saved@macroname{#1}%
\let\saved@indexname\saved@macroname
\index{\MyName @\tcbIndexPrintEnvCA {\MyName}|(emph}%
\index{Environments!\MyName @\tcbIndexPrintEnvC {\MyName}|(emph}%
}{%
\ifdef{\MyName}{}{%
\errmessage{You have closed an environment environment you have not opened on \the\inputlineno.}%
}
\index{Environments!\MyName @\tcbIndexPrintEnvC {\MyName}|)}%
\index{\MyName @\tcbIndexPrintEnvCA {\MyName}|)}%
}
\makeatother
\newenvironment{optionkey}[1]{%
\def\MyName{#1}%
\index{\MyName@\tcbIndexPrintKeyCA {\MyName}|(emph}%
\index{Keys!\MyName@\tcbIndexPrintKeyC {\MyName}|(emph}%
}{%
\ifdef{\MyName}{}{%
\errmessage{You have closed an optionkey environment you have not opened on \the\inputlineno.}%
}
\index{Keys!\MyName@\tcbIndexPrintKeyC {\MyName}|)}%
\index{\MyName@\tcbIndexPrintKeyCA {\MyName}|)}%
}
\newenvironment{optionvalue}[1]{%
\def\MyName{#1}%
\index{\MyName@\tcbIndexPrintValCA {\MyName}|(emph}%
\index{Values!\MyName@\tcbIndexPrintValC {\MyName}|(emph}%
}{%
\ifdef{\MyName}{}{%
\errmessage{You have closed an optionvalue environment you have not opened on \the\inputlineno.}%
}
\index{Values!\MyName@\tcbIndexPrintValC {\MyName}|)}%
\index{\MyName@\tcbIndexPrintValCA {\MyName}|)}%
}
\makeatletter
\newcommand{\resetmintedformat}{%
% Comments
\expandafter\def\csname PYGdefault@tok@c\endcsname{\let\PYGdefault@it=\textit\def\PYGdefault@tc####1{\textcolor{gray}{####1}}}
% Command sequences
\expandafter\def\csname PYGdefault@tok@k\endcsname{\def\PYGdefault@tc####1{\textcolor{Command}{####1}}}
% Optional arguments
\expandafter\def\csname PYGdefault@tok@na\endcsname{\def\PYGdefault@tc####1{\textcolor{Option}{####1}}}
% Braces
\expandafter\def\csname PYGdefault@tok@nb\endcsname{\def\PYGdefault@tc####1{\textcolor{Environment}{####1}}}
}
\apptocmd{\minted@checkstyle}{\resetmintedformat}{}{}
\makeatother
\newcommand{\pkg}[1]{\href{http://www.ctan.org/pkg/#1}{\textsf{#1}}}
\MakeShortVerb{\|}
\makeatletter
\let\PrintMacroName\@gobble
\let\PrintEnvName\@gobble
\renewenvironment{tcb@manual@entry}{\begin{list}{}{%
\setlength{\topsep}{0pt}
\setlength{\partopsep}{0pt}
\setlength{\leftmargin}{\kvtcb@doc@left}%
\setlength{\itemindent}{0pt}%
\setlength{\itemsep}{0pt}%
\setlength{\parsep}{0pt}%
\setlength{\rightmargin}{\kvtcb@doc@right}%
}\item}{\end{list}}
\makeatother
% This bit inspired by ydoc
\makeatletter
\newwrite\ydocwrite
\def\ydocfname{\jobname.tcbtemp}
\def\ydoc@catcodes{%
\let\do\@makeother
\dospecials
\catcode`\\=\active
\catcode`\^^M=\active
\catcode`\ =\active
}
\def\macrocode{%
\begingroup
\ydoc@catcodes
\macro@code
}
\def\endmacrocode{}
\begingroup
\endlinechar\m@ne
\@firstofone{%
\catcode`\|=0\relax
\catcode`\(=1\relax
\catcode`\)=2\relax
\catcode`\*=14\relax
\catcode`\{=12\relax
\catcode`\}=12\relax
\catcode`\ =12\relax
\catcode`\%=12\relax
\catcode`\\=\active
\catcode`\^^M=\active
\catcode`\ =\active
}*
|gdef|macro@code#1^^M% \end{macrocode}(*
|endgroup|expandafter|macro@@code|expandafter(|ydoc@removeline#1|noexpand|lastlinemacro)*
)*
|gdef|ydoc@removeline#1^^M(|noexpand|firstlinemacro)*
|gdef|ydoc@defspecialmacros(*
|def^^M(|noexpand|newlinemacro)*
|def (|noexpand|spacemacro)*
|def\(|noexpand|bslashmacro)*
)*
|gdef|ydoc@defrevspecialmacros(*
|def|newlinemacro(|noexpand^^M)*
|def|spacemacro(|noexpand )*
|def|bslashmacro(|noexpand\)*
)*
|endgroup
\def\macro@@code#1{%
{\ydoc@defspecialmacros
\xdef\themacrocode{#1}}%
\PrintMacroCode
\end{macrocode}%
}
\def\PrintMacroCode{%
\begingroup
\let\firstlinemacro\empty
\let\lastlinemacro\empty
\def\newlinemacro{^^J}%
\let\bslashmacro\bslash
\let\spacemacro\space
\immediate\openout\ydocwrite=\ydocfname\relax
\immediate\write\ydocwrite{\themacrocode}%
\immediate\closeout\ydocwrite
\let\input\@input
\tcbinputlisting{breakable,listing only,docexample,listing file=\ydocfname}%
\endgroup
}
\makeatother
\usepackage{tgm1}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
\GetFileInfo{\jobname.dtx}
\DoNotIndex{\newcommand,\newenvironment}
\title{\textsf{tikzgamemap} --- Maps for interactive fiction with TikZ\thanks{This file
describes version \fileversion, last revised \filedate.}
}
\author{Alex Ball\thanks{E-mail: [email protected]}}
\date{Released \filedate}
\maketitle
\changes{v0.1}{2019/02/19}{First public release}
\begin{abstract}
While interactive fiction can come in many different varieties, there is a class
of works that follows the tradition established by \emph{[Colossal Cave]
Adventure} and Infocom games such as \emph{Zork}. Players typically move between
areas or rooms using the eight cardinal and primary intercardinal points of the
compass, as well as up, down, in and out. This package provides some shortcut
methods for mapping out such game spaces using the graph-drawing facilities of
TikZ.
\end{abstract}
\section{Introduction}
If you have ever played a text adventure game in the Infocom style, you will
probably recognise the following as being a fairly typical passage.
\begin{tcolorbox}[docexample,sidebyside,righthand width=0.15\linewidth]
\textbf{Woodland Clearing}
\medskip
Though the tall oaks of the wood tower above you on all sides, here the leaf
mulch gives way to scrubby grass and wild flowers, and for once you get a clear
view of the bright blue sky. Footpaths lead away through the trees to the north,
southwest and southeast.
\medskip
There is a brass lamp here.
\tcblower
\centering
\begin{gamemap}
\graph{
"Woodland\\Clearing" [exits={n,sw,se}]
};
\end{gamemap}
\par
\end{tcolorbox}
In the language of Inform, one of the systems for writing such games, the
Woodland Clearing in this example is a \emph{room}. The player can travel to other
rooms by moving in one of twelve possible directions: north, northeast, east,
southeast, south, southwest, west, northwest, up, down, in and out. As a player,
in order to keep track of these rooms and how they connect, it is often a good
idea to record your progress in a simple map; so you might represent this room
like the picture on the right of the passage.
The aim of this package is to make it as easy and as natural as possible to
build up a map of the game world as you play, using TikZ as a graphical backend.
\section{Usage}
\subsection{Loading}
Eventually, this package may support multiple input styles, but at the moment
it only supports one, \texttt{tgm1}, which you load in the usual way.
\begin{dispListing}
\usepackage{tgm1}
\end{dispListing}
\subsection{Setting up}
\begin{docEnvironment}{gamemap}{\oarg{options}}
This is the outer environment that needs to surround the map. It is a wrapper
around the \env{tikzpicture} environment, so you can pass TikZ options to
it, use TikZ commands within it and use it like \env{tikzpicture} with, say,
the \pkg{standalone} class.
\end{docEnvironment}
As well as the standard ones, you can also use these options with \env{gamemap}:
\begin{docKey}{set grid}{=\marg{dimension}\marg{dimension}}%
{no default, initially \brackets{8em}\brackets{5em}}
Sets the $x$ and $y$ dimensions of the grid used to lay out rooms, so by default
the centre of a room at (1, 1) will be 8em to the right and 5em above the origin.
It also adjusts the aspect ratio of the compass points so that, in this case,
northeast will be somewhat nearer to east than north.
\end{docKey}
\begin{docKey}{set compass points}{=\marg{number/dimension}\marg{number/dimension}}%
{initially \brackets{8em}\brackets{5em}}
Adjusts the aspect ratio of the compass points without affecting the $x$ and $y$
dimensions of the grid, which you can set independently using the normal \key{x}
and \key{y} options. Since this is all about the ratio, the values you give can
be numbers or dimensions, so long as you are consistent.
\end{docKey}
The above options set the values of the following commands, which you can use
wherever TikZ expects an angle:
\begin{multicols}{4}
\begin{docCommand}{tgmN}{}North\end{docCommand}
\begin{docCommand}{tgmNNE}{}North-northeast\end{docCommand}
\begin{docCommand}{tgmNE}{}Northeast\end{docCommand}
\begin{docCommand}{tgmENE}{}East-northeast\end{docCommand}
\begin{docCommand}{tgmE}{}East\end{docCommand}
\begin{docCommand}{tgmESE}{}East-southeast\end{docCommand}
\begin{docCommand}{tgmSE}{}Southeast\end{docCommand}
\begin{docCommand}{tgmSSE}{}South-southeast\end{docCommand}
\begin{docCommand}{tgmS}{}South\end{docCommand}
\begin{docCommand}{tgmSSW}{}South-southwest\end{docCommand}
\begin{docCommand}{tgmSW}{}Southwest\end{docCommand}
\begin{docCommand}{tgmWSW}{}West-southwest\end{docCommand}
\begin{docCommand}{tgmW}{}West\end{docCommand}
\begin{docCommand}{tgmWNW}{}West-northwest\end{docCommand}
\begin{docCommand}{tgmNW}{}Northwest\end{docCommand}
\begin{docCommand}{tgmNNW}{}North-northwest\end{docCommand}
\end{multicols}
Within the environment, you will also need this:
\begin{docCommand}{graph}{\oarg{options}\marg{routes};}
This activates the regular TikZ graph-drawing syntax parsing. Add routes through
the game world within this command. Unfortunately, none of the regular graph
drawing layouts is particularly suitable for automatically placing rooms, so
until I can find or write one, your best bet is probably to pass ‘\docValue{no
placement}’ as the option.
\end{docCommand}
\subsection{Drawing a room}
To draw a room, simply type the name within double quotes. If you want line
breaks, add them manually.
\begin{dispExample*}{sidebyside,righthand width=0.333\linewidth}
\begin{gamemap}
\graph{ "Woodland\\Clearing" };
\end{gamemap}
\end{dispExample*}
You can refer to the room again later in the same graph by giving its ID, which
is normally the same as its name. To give it a different ID, write the room
initially as \meta{ID}\slash\meta{name}, e.g.\@
\tcbox[docexample,size=small,on line]{|wc/"Woodland\textbackslash\textbackslash
Clearing"|}. This is useful if you have to write it several times and want to
save some typing, or if the game tries to confuse you by giving multiple rooms
the same name.
You can change the appearance of the room with the following options:
\begin{docKey}{entry}{}{no value}
Marks the room as being the starting point on the map. Visually, it gives the
room a double border.
\end{docKey}
\begin{docKey}{tunnel}{}{no value}
Marks the room as appearing on another map as well, so that you can split the
game world across several maps. Visually, it gives the room a thick border.
\end{docKey}
\begin{docKey}{exit}{=\meta{direction}}{no default, initially empty}
Marks an unexplored exit from the room. Possible values include \docValue{n},
\docValue{ne}, \docValue{e}, \docValue{se}, \docValue{s}, \docValue{sw},
\docValue{w}, and \docValue{nw}. The values \docValue{u}, \docValue{d},
\docValue{in}, \docValue{o} are special: by default they get positioned NNE,
SSW, ESE and WNW respectively, but you can specify the exact angle as a value
of the direction, as in \val{u=}\meta{angle}; if you do, the whole argument must
be wrapped in braces.
In some games you may find that to exit the room you have to do something
instead of moving in a given direction. For such cases you can use the
\docValue{act} value, which takes two arguments:
\val{act=}\marg{label}\marg{angle}.
\end{docKey}
\begin{docKey}{note}{=\meta{label specification}}{no default, initially empty}
Since you don't have room for long strings in the exit label, you can use this
key to position a note by the room to decode the letter or symbol you used. The
syntax is the same as for the regular \key{label} option, but this injects the
\key{note node} style.
\end{docKey}
\begin{dispExample*}{sidebyside,righthand width=0.333\linewidth}
\begin{gamemap}
\graph{
"Treetop" [exit={act={\S}{90}},
note={[text=red]270:\S\ Call Skylar}]
};
\end{gamemap}
\end{dispExample*}
\begin{docKey}{exits}{=\marg{list of directions}}{no default, initially empty}
To give more than one exit at once, pass a comma separated list to this option,
wrapped in braces.
\end{docKey}
\begin{dispExample*}{sidebyside,righthand width=0.333\linewidth}
\begin{gamemap}
\graph{
"Woodland\\Clearing"
[entry,exits={n,sw,se,u=150}]
};
\end{gamemap}
\end{dispExample*}
To keep things simple, I recommend you only pass options to a room the first
time you mention it within a graph.
\subsection{Positioning rooms}
As mentioned above, the ‘\key{no placement}’ option is currently the best
one to pass to the \cs{graph} command. This means rooms get positioned at the
(0, 0) position unless you override this with the \key{x} or \key{y} room
options or (more likely) both.
If you have to lay out several rooms in a row or column,
you can wrap them in braces and give the common \key{x} or \key{y} value as an
option just inside the opening brace, like so:
\begin{dispExample*}{sidebyside,righthand width=0.333\linewidth}
\begin{gamemap}
\graph [no placement] {
{ [y=1]
"Woodland\\Clearing" [x=1,exits={n,sw,se}],
"Fallen\\Tree" [x=2,tunnel,exits=w]
}
};
\end{gamemap}
\end{dispExample*}
\subsection{Connecting rooms}
The advantage of the TikZ graph syntax is that it naturally lends itself to the
kind of exploration you do in text adventures.
\begin{enumerate}
\item Write down the room you are in, marking unexplored exits.
\item When exploring an exit, remove it from the room options, and use
‘\texttt{--} \oarg{options}’ to mark a route. Then write down the next room.
\item If you back-track, use a comma to mark the end of the current route and
start a new one.
\end{enumerate}
You can use regular TikZ drawing options to customize the appearance of the
route (e.g. \key{dashed}, \key{dotted}) but this package provides a few that
draw exits at either end and shape the route accordingly.
The simplest and most common case is where a route is symmetrical.
\begin{docKey}{going}{=\meta{direction}}{no default, initially empty}
The direction can be \docValue{n}, \docValue{ne}, \docValue{e}, \docValue{se},
\docValue{s}, \docValue{sw}, \docValue{w}, \docValue{nw}, \docValue{u},
\docValue{d}, \docValue{in}, or \docValue{o}. The beginning of the path will
be labelled with the given exit, and the end will be labelled with its inverse.
\end{docKey}
\begin{dispExample*}{sidebyside,righthand width=0.333\linewidth}
\begin{gamemap}
\graph [no placement] {
"Fallen\\Tree" [x=2,y=1] -- [going=w]
"Woodland\\Clearing" [x=1,y=1] -- [going=u]
"Treetop" [x=1,y=2]
};
\end{gamemap}
\end{dispExample*}
If the route is asymmetrical, or you need to explicitly position the non-compass
exits, use the following option instead.
\begin{docKey}{go}{=\marg{direction}\marg{direction}}{no defaults, initially empty}
The directions can be \docValue{n}, \docValue{ne}, \docValue{e}, \docValue{se},
\docValue{s}, \docValue{sw}, \docValue{w}, \docValue{nw}, \docValue{u},
\docValue{d}, \docValue{in}, \docValue{o}, \docValue{act}, or \docValue{null}.
The beginning of the path will be labelled with the first given exit, and the
end will be labelled with the second. You can explicitly place the non-compass
exits at a certain angle around the room circumference by giving the angle as a
value of the direction, as in \val{u=}\meta{angle}. If you use the \val{null}
direction, no label will be drawn (indicating a one-way route), and you should
definitely specify an angle to avoid disappointment. Use the
\val{act=}\marg{label}\marg{angle} option to specify a custom exit.
\end{docKey}
\begin{dispExample*}{sidebyside,righthand width=0.333\linewidth}
\begin{gamemap}
\graph [no placement] {
"Fallen\\Tree" [x=1.4,y=0] -- [go={n}{se}]
"Woodland\\Clearing" [x=1,y=1,exits={n,sw}]
-- [go={u=0}{d=180}] "Treetop" [x=2,y=1]
-- [go={act={\S}{270}}{null=110}]
"Eyrie" [x=2.2,y=0,exit=d]
};
\end{gamemap}
\end{dispExample*}
Sometimes a game gives up all pretence of realism and includes a set of
asymmetric routes deliberately designed to confuse you. For situations such as
these, the following option can be used.
\begin{docKey}{maze}{=\marg{direction}\marg{direction}}{no defaults, initially empty}
The directions can be \docValue{n}, \docValue{ne}, \docValue{e}, \docValue{se},
\docValue{s}, \docValue{sw}, \docValue{w}, \docValue{nw}, \docValue{u},
\docValue{d}, \docValue{in}, \docValue{o}, \docValue{act}, or \docValue{null}.
This behaves much like \key{go} except that the route is drawn straight between
the rooms, without any attempt to place the exits logically. Any angles given as
arguments to a direction are thus ignored. Use \val{null} to avoid drawing an
exit at all and \val{act=}\marg{label} to use a custom exit label.
\end{docKey}
\begin{dispExample*}{sidebyside,righthand width=0.27\linewidth}
\begin{gamemap}[set grid={8em}{6em}]
\graph [no placement] {
a/"Twisty\\Bit" [x=0,y=2,exit=nw] -- [maze={w}{sw}]
b/"Twisty\\Bit" [x=1,y=1.5] -- [maze={e}{n}]
c/"Twisty\\Bit" [x=1,y=0.5] -- [maze={nw}{null}]
d/"Twisty\\Bit" [x=0,y=1] -- [maze={sw}{null}]
e/"Twisty\\Bit" [x=0,y=0,exit=se],
a -- [maze={sw}{s}] c,
a -- [maze={ne}{nw}] d,
b -- [maze={ne}{s}] d,
b -- [maze={nw}{w}] e,
c -- [maze={se}{e}] e
};
\end{gamemap}
\end{dispExample*}
\subsection{Customizing how things look}
\begin{docKey}{tgmnode}{}{see section~\ref{sec:room-options} for initial value}
This TikZ style is applied to all the room nodes.
\end{docKey}
\begin{docKey}{note node}{}{see section~\ref{sec:room-options} for initial value}
This TikZ style is applied to all notes attached to room nodes.
\end{docKey}
\begin{docKey}{label node}{}{see section~\ref{sec:exits} for initial value}
This TikZ style is applied to all the exit labels.
\end{docKey}
\begin{docKey}{exit node}{}{initially \key{label node}}
This TikZ style is applied to exits drawn by the \refKey*{exit} option. It
just applies the \key{label node} style initially.
\end{docKey}
\begin{docKey}{transit node}{}{initially \key{label node}}
This TikZ style is applied to exits drawn by the \refKey*{go}, \refKey*{going}
and \refKey*{maze} options. It just applies the \key{label node} style
initially.
\end{docKey}
\begin{docKey}{tgmedge}{}{see section~\ref{sec:route-options} for initial value}
This TikZ style is applied to all the route edges.
\end{docKey}
You can replace the defaults or append options using \cs{tikzset} in the normal
way.
\begin{dispExample*}{sidebyside,righthand width=0.18\linewidth}
\tikzset{tgmnode/.append style = {fill=yellow!25},
exit node/.append style = {fill=red!10,rectangle},
label node/.append style = {fill=green!10}}
\begin{gamemap}
\graph[no placement]{
"Woodland\\Clearing" [exits={n,sw}] -- [go={se}{ne}]
"Fallen Tree" [y=-1]
};
\end{gamemap}
\end{dispExample*}
\begin{dispExample*}{sidebyside,righthand width=0.25\linewidth}
\begin{gamemap}
\graph[no placement]{
"Woodland\\Clearing"
[exits={n,sw},uturn={W}{180}]
};
\end{gamemap}
\end{dispExample*}
\StopEventually{%
\clearpage
\PrintChanges
\PrintIndex
}
\clearpage
\section{Implementation}
\setcounter{FancyVerbLine}{20}%
\DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \iffalse %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%<*tgm1>
% \fi %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% \subsection{Dependencies}
%
% This package is based on TikZ. The |graph| library provides the graph syntax,
% the |quotes| library allows you to use the quotes syntax to label nodes and
% edges, and |shapes.misc| provides the rounded rectangle shape.
%
% \begin{macrocode}
\RequirePackage{etoolbox}
\RequirePackage{tikz}
\usetikzlibrary{graphs, quotes, shapes.misc}
% \end{macrocode}
%
% \subsection{Setting the aspect ratio}
%
% To allow for configurability, we use macros instead of angles for compass
% point directions. The cardinal compass points are at constant angles; we could
% hard code them, but for consistency with the rest we don't.
%
% \begin{macro}{tgmE}
% \begin{macro}{tgmN}
% \begin{macro}{tgmW}
% \begin{macro}{tgmS}
% \begin{macro}{tgmEE}
% \begin{macrocode}
\def\tgmE{0}
\def\tgmN{90}
\def\tgmW{180}
\def\tgmS{270}
\def\tgmEE{360}
% \end{macrocode}
%
% The usefulness of \cs{tgmEE} will become clear in a moment.
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{optionkey}{set compass points}
% The remaining directions need to be set with reference to whatever aspect
% ratio is used for the grid on which the rooms are laid out. The
% \key{set compass points} key takes two arguments: the relative horizontal
% and vertical size of the grid respectively.
%
% \begin{macrocode}
\tikzset
{ set compass points/.code n args = {2}{%
% \end{macrocode}
%
% The angles for the primary intercardinal points are calculated from
% $\tan^{-1} (y/x)$.
%
% \begin{macro}{tgmNE}
% \begin{macro}{tgmNW}
% \begin{macro}{tgmSW}
% \begin{macro}{tgmSE}
% \begin{macrocode}
\pgfmathsetmacro{\tgmNE}{atan2(#2, #1)}%
\pgfmathsetmacro{\tgmNW}{atan2(#2, -#1)}%
\pgfmathsetmacro{\tgmSW}{add(atan2(-#2, -#1), 360)}%
\pgfmathsetmacro{\tgmSE}{add(atan2(-#2, #1), 360)}%
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% We now calculate the angles for the points between the eight defined so far.
% It turns out that taking the mean of the angles either side gives a more
% aesthetically pleasing result than the strict geometric solution.
%
% \begin{macro}{tgmENE}
% \begin{macro}{tgmNNE}
% \begin{macro}{tgmNNW}
% \begin{macro}{tgmWNW}
% \begin{macro}{tgmWSW}
% \begin{macro}{tgmSSW}
% \begin{macro}{tgmSSE}
% \begin{macro}{tgmESE}
% \begin{macrocode}
\pgfmathsetmacro{\tgmENE}{divide(add(\tgmE, \tgmNE), 2)}%
\pgfmathsetmacro{\tgmNNE}{divide(add(\tgmNE, \tgmN ), 2)}%
\pgfmathsetmacro{\tgmNNW}{divide(add(\tgmN, \tgmNW), 2)}%
\pgfmathsetmacro{\tgmWNW}{divide(add(\tgmNW, \tgmW ), 2)}%
\pgfmathsetmacro{\tgmWSW}{divide(add(\tgmW, \tgmSW), 2)}%
\pgfmathsetmacro{\tgmSSW}{divide(add(\tgmSW, \tgmS ), 2)}%
\pgfmathsetmacro{\tgmSSE}{divide(add(\tgmS, \tgmSE), 2)}%
\pgfmathsetmacro{\tgmESE}{divide(add(\tgmSE, \tgmEE), 2)}%
}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{optionkey}
%
% \begin{optionkey}{set grid}
% We provide a convenience option for setting the $x$ and $y$ vectors and the
% compass points at the same time.
%
% \begin{macrocode}
, set grid/.code n args = {2}{%
\pgfkeys{tikz,x = #1}%
\pgfkeys{tikz,y = #2}%
\pgfkeys{tikz,set compass points = {#1}{#2}}%
}
% \end{macrocode}
% \end{optionkey}
%
% \subsection{Room options}\label{sec:room-options}
%
% \begin{optionkey}{tgmnode}
% The \key{tgmnode} key is the base style used for rooms.
%
% \begin{macrocode}
, tgmnode/.style =
{ text depth = 0.2em
, align = center
, draw = black!20
, thick
, fill = white
, rounded rectangle
, inner sep = 1.25ex
}
% \end{macrocode}
% \end{optionkey}
%
% \begin{optionkey}{entry}
% The \key{entry} key is an alias for a double border.
%
% \begin{macrocode}
, entry/.style =
{ double
}
% \end{macrocode}
% \end{optionkey}
%
% \begin{optionkey}{tunnel}
% The \key{tunnel} key is an alias for a thick border.
%
% \begin{macrocode}
, tunnel/.style =
{ ultra thick
}
% \end{macrocode}
% \end{optionkey}
%
% \begin{optionkey}{note node}
% The \key{note node} style makes the text size smaller.
%
% \begin{macrocode}
, note node/.style =
{ label distance=0pt
, /tikz/font=\scriptsize
}
% \end{macrocode}
% \end{optionkey}
%
% \begin{optionkey}{note}
% The \key{note} key applies a label to the outside of the node.
%
% \begin{macrocode}
, note/.code = {%
\pgfutil@ifnextchar[%]
{ \tgm@note@opt }%
{ \tgm@note@nonopt }%
#1\pgf@nil
}
% \end{macrocode}
% \end{optionkey}
%
% These are the helper macros for parsing arguments to the \key{note} option.
% \begin{macrocode}
}
\def\tgm@note@opt[#1]#2\pgf@nil{%
\pgfkeys{ tikz,label = {[note node, #1]#2} }
}
\def\tgm@note@nonopt#1\pgf@nil{%
\pgfkeys{ tikz,label = {[note node]#1} }
}
% \end{macrocode}
%
% \subsection{Exits}\label{sec:exits}
%
% \begin{optionkey}{label node}
% \begin{optionkey}{exit node}
% \begin{optionkey}{transit node}
% The \key{label node} option controls the appearance of the exits that are drawn
% on the periphery of the rooms. This base style is inherited by \key{exit node}
% and \key{transit node}, which could be amended to do different things.
%
% \begin{macrocode}
\tikzset
{ label node/.style =
{ label distance = -0.5em - 0.2pt
, font = \tiny
, minimum size = 1em
, circle
, thin
, inner sep = 0pt
, fill = white
, draw = black!20
}
, exit node/.style =
{ label node
}
, transit node/.style =
{ label node
}
% \end{macrocode}
% \end{optionkey}
% \end{optionkey}
% \end{optionkey}
%
% \subsubsection{Exits as labels on nodes}
%
% \begin{optionkey}{exit}
% The \key{exit} option is used to draw an exit as a label around the room node.
% Its value must be drawn from an authority list, and determines both the label
% text and the angle at which it is drawn.
%
% For the compass directions, the angle is fixed.
%
% \begin{macrocode}
, exit/.is choice
, exit/e/.style = { label={[exit node]\tgmE:E} }
, exit/ne/.style = { label={[exit node]\tgmNE:\textsc{ne}} }
, exit/n/.style = { label={[exit node]\tgmN:N} }
, exit/nw/.style = { label={[exit node]\tgmNW:\textsc{nw}} }
, exit/w/.style = { label={[exit node]\tgmW:W} }
, exit/sw/.style = { label={[exit node]\tgmSW:\textsc{sw}} }
, exit/s/.style = { label={[exit node]\tgmS:S} }
, exit/se/.style = { label={[exit node]\tgmSE:\textsc{se}} }
% \end{macrocode}
%
% For the non-compass directions, the angle has a default that can be overridden
% by an argument value.
%
% \begin{macrocode}
, exit/u/.style = { label={[exit node]#1:U} }
, exit/u/.default = { \tgmNNE }
, exit/d/.style = { label={[exit node]#1:D} }
, exit/d/.default = { \tgmSSW }
, exit/in/.style = { label={[exit node]#1:in} }
, exit/in/.default = { \tgmESE }
, exit/o/.style = { label={[exit node]#1:O} }
, exit/o/.default = { \tgmWNW }
% \end{macrocode}
%
% The \val{act} direction allows a custom label.
%
% \begin{macrocode}
, exit/act/.style 2 args = {label={[exit node]#2:{#1}}}
% \end{macrocode}
% \end{optionkey}
%
% \begin{optionkey}{exits}
% We supply the \key{exits} key to allow more than one exit to be specified at
% once.
%
% \begin{macrocode}
, exits/.style = { exit/.list={#1} }
% \end{macrocode}
% \end{optionkey}