-
Notifications
You must be signed in to change notification settings - Fork 1
/
mahjong-hand.sty
123 lines (116 loc) · 4.5 KB
/
mahjong-hand.sty
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
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mahjong-hand}
\RequirePackage{xcolor}
\RequirePackage{graphicx}
\RequirePackage{tikz}
\usetikzlibrary{fit,shapes.misc}
\newlength{\@mahjongtileheight}
\newlength{\@mahjongtilewidth}
\newlength{\@mahjongtilexoffset}
\newlength{\@mahjongtilerightedge}
\newlength{\@mahjongtilecornerradius}
\newlength{\@mahjongtilesymbolheight}
\definecolor{tilebackcolor}{RGB}{255, 89, 89}
\def\@TilePause #1#2#3{\addtolength{\@mahjongtilexoffset}{0.5\@mahjongtilewidth}\global\@mahjongtilexoffset=\@mahjongtilexoffset}
\def\@DrawNormalTile #1{
\addtolength{\@mahjongtilerightedge}{\@mahjongtilewidth}
\node [
fit={(\@mahjongtilexoffset,0pt)(\@mahjongtilerightedge,\@mahjongtileheight)},
draw=black,
inner sep=0pt,
rounded corners=\@mahjongtilecornerradius
] (rect) {};
\node [inner sep=0pt,anchor=center] (tile) at (rect.center) {
\includegraphics[height=\@mahjongtilesymbolheight] {#1}
};
\setlength{\@mahjongtilexoffset}{\@mahjongtilerightedge}
\global\@mahjongtilexoffset=\@mahjongtilexoffset}
\def\@DrawNormalBack #1{
\addtolength{\@mahjongtilerightedge}{\@mahjongtilewidth}
\node [
fit={(\@mahjongtilexoffset,0pt)(\@mahjongtilerightedge,\@mahjongtileheight)},
draw=black,
inner sep=0pt,
rounded corners=\@mahjongtilecornerradius,
fill=tilebackcolor
] (rect) {};
\setlength{\@mahjongtilexoffset}{\@mahjongtilerightedge}
\global\@mahjongtilexoffset=\@mahjongtilexoffset}
\def\@DrawRotatedTile #1{
\addtolength{\@mahjongtilerightedge}{\@mahjongtileheight}
\node [
fit={(\@mahjongtilexoffset,0pt)(\@mahjongtilerightedge,\@mahjongtilewidth)},
draw=black,
inner sep=0pt,
rounded corners=\@mahjongtilecornerradius
] (rect) {};
\node [inner sep=0pt,anchor=center] (tile) at (rect.center) {
\includegraphics[height=\@mahjongtilesymbolheight, angle=270] {#1}
};
\setlength{\@mahjongtilexoffset}{\@mahjongtilerightedge}
\global\@mahjongtilexoffset=\@mahjongtilexoffset}
\def\@DrawRotatedBack{
\addtolength{\@mahjongtilerightedge}{\@mahjongtileheight}
\node [
fit={(\@mahjongtilexoffset,0pt)(\@mahjongtilerightedge,\@mahjongtilewidth)},
draw=black,
inner sep=0pt,
rounded corners=\@mahjongtilecornerradius,
fill=tilebackcolor
] (rect) {};
\setlength{\@mahjongtilexoffset}{\@mahjongtilerightedge}
\global\@mahjongtilexoffset=\@mahjongtilexoffset}
\def\@DrawTile #1#2{%
\setlength{\@mahjongtilerightedge}{\@mahjongtilexoffset}%
\ifx#2*%
\expandafter\@DrawRotatedTile%
\else%
\expandafter\@DrawNormalTile%
\fi {tiles/#1.pdf}}
\def\@DrawTileBack #1#2#3{%
\setlength{\@mahjongtilerightedge}{\@mahjongtilexoffset}%
\ifx#3*%
\expandafter\@DrawRotatedBack%
\else%
\expandafter\@DrawNormalBack%
\fi}
\def\DrawHand #1#2{%
\setlength{\@mahjongtileheight}{#2}%
\setlength{\@mahjongtilewidth}{0.75\@mahjongtileheight}%
\setlength{\@mahjongtilexoffset}{0pt}%
\setlength{\@mahjongtilecornerradius}{0.1\@mahjongtileheight}%
\setlength{\@mahjongtilesymbolheight}{0.9\@mahjongtileheight}%
\begin{tikzpicture}[baseline=0pt]\expandafter\@ParserHead#1\relax\relax\relax\end{tikzpicture}}
\def\@SkipFirst #1{\@MoveHead}
\def\@HeadStep #1#2#3{\@ProcessCharsX#1#2#3\@ParserHead#1#3}
\newif\ifissuite
\def\@MoveHead #1#2#3{%
\issuitefalse%
\ifx#2m\issuitetrue\fi%
\ifx#2p\issuitetrue\fi%
\ifx#2s\issuitetrue\fi%
\ifx#2z\issuitetrue\fi%
\ifissuite\expandafter\@SkipFirst%
\else\expandafter\@HeadStep\fi#1#2#3}
\def\@EatTwo #1#2{}
\def\@ParserHead #1#2{\ifx#2\relax\expandafter\@EatTwo\else\expandafter\@MoveHead\fi#1#2}
\def\@ProcessCharsX #1#2#3{\ifx#2*\expandafter\relax\else\@ProcessCharsY#1#2#3\fi}
\newtoks\nexttile
\def\@ProcessCharsY #1#2#3{%
\nexttile={\@ProcessCharsZ}%
\ifx#2~\nexttile={\@TilePause}\fi%
\ifx#2?\nexttile={\@DrawTileBack}\fi%
\the\nexttile#1#2#3}
\def\@ProcessCharsZ #1#2#3{%
\ifx#1z\@ProcessHonor#2#3\fi%
\ifx#1m\ifx#20\@DrawTile{Man5-Dora}#3\else\@DrawTile{Man#2}#3\fi\fi%
\ifx#1p\ifx#20\@DrawTile{Pin5-Dora}#3\else\@DrawTile{Pin#2}#3\fi\fi%
\ifx#1s\ifx#20\@DrawTile{Sou5-Dora}#3\else\@DrawTile{Sou#2}#3\fi\fi}
\def\@ProcessHonor #1#2{%
\ifx#11\@DrawTile{Ton}#2\fi%
\ifx#12\@DrawTile{Nan}#2\fi%
\ifx#13\@DrawTile{Shaa}#2\fi%
\ifx#14\@DrawTile{Pei}#2\fi%
\ifx#15\@DrawTile{Haku}#2\fi%
\ifx#16\@DrawTile{Hatsu}#2\fi%
\ifx#17\@DrawTile{Chun}#2\fi}