forked from kobalab/Majiang
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpaiga.html
188 lines (158 loc) · 5.45 KB
/
paiga.html
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
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=800">
<title>電脳麻将: 牌画入力</title>
<meta name="description" content="簡単な記法で牌画を入力">
<link rel="icon" type="image/png" href="icon.png">
<link rel="apple-touch-icon" type="image/png" href="icon.png">
<link rel="stylesheet" type="text/css" href="css/style.css" />
<script src="js/jquery-2.1.4.min.js"></script>
<script>
$(function(){
var w = 24, h = 34;
var imgbase = 'http://www.mahjong.org/images/haiga/';
var img = {
_: 'ura.gif',
m0: 'man5red.gif',
m1: 'man1.gif', m2: 'man2.gif', m3: 'man3.gif',
m4: 'man4.gif', m5: 'man5.gif', m6: 'man6.gif',
m7: 'man7.gif', m8: 'man8.gif', m9: 'man9.gif',
p0: 'pin5red.gif',
p1: 'pin1.gif', p2: 'pin2.gif', p3: 'pin3.gif',
p4: 'pin4.gif', p5: 'pin5.gif', p6: 'pin6.gif',
p7: 'pin7.gif', p8: 'pin8.gif', p9: 'pin9.gif',
s0: 'sou5red.gif',
s1: 'sou1.gif', s2: 'sou2.gif', s3: 'sou3.gif',
s4: 'sou4.gif', s5: 'sou5.gif', s6: 'sou6.gif',
s7: 'sou7.gif', s8: 'sou8.gif', s9: 'sou9.gif',
z1: 'ton.gif', z2: 'nan.gif', z3: 'sha.gif', z4: 'pei.gif',
z5: 'haku.gif', z6: 'hatu.gif', z7: 'tyun.gif',
m0_: 'yman5red.gif',
m1_: 'yman1.gif', m2_: 'yman2.gif', m3_: 'yman3.gif',
m4_: 'yman4.gif', m5_: 'yman5.gif', m6_: 'yman6.gif',
m7_: 'yman7.gif', m8_: 'yman8.gif', m9_: 'yman9.gif',
p0_: 'ypin5red.gif',
p1_: 'ypin1.gif', p2_: 'ypin2.gif', p3_: 'ypin3.gif',
p4_: 'ypin4.gif', p5_: 'ypin5.gif', p6_: 'ypin6.gif',
p7_: 'ypin7.gif', p8_: 'ypin8.gif', p9_: 'ypin9.gif',
s0_: 'ysou5red.gif',
s1_: 'ysou1.gif', s2_: 'ysou2.gif', s3_: 'ysou3.gif',
s4_: 'ysou4.gif', s5_: 'ysou5.gif', s6_: 'ysou6.gif',
s7_: 'ysou7.gif', s8_: 'ysou8.gif', s9_: 'ysou9.gif',
z1_: 'yton.gif', z2_: 'ynan.gif', z3_: 'ysha.gif', z4_: 'ypei.gif',
z5_: 'yhaku.gif', z6_: 'yhatu.gif', z7_: 'ytyun.gif'
};
function markup(match, mark) {
if (! mark.length) return '';
var html = '<span style="white-space:pre;">', url, v = 0;
for (var pai of mark.match(/[mpsz](?:\d+[\-\=]?)+|[ _]|.+/g)) {
if (pai == ' ') {
html += ' ';
}
else if (pai == '_') {
url = imgbase + img._;
html += '<img src="'+url+'" width="'+w+'" height="'+h+'"'
+ ' alt="'+pai+'">';
}
else if (pai.match(/^[mpsz](?:\d+[\-\=]?)+/)) {
var s = pai[0];
for (var n of pai.match(/\d[\-\=]?/g)) {
var d = n[1] || ''; n = n[0];
if (d == '=' && ! v) {
html += '<span style="display:inline-block;width:'
+h+'px;">';
v = 1;
}
else if (! d) {
if (v) html += '</span>';
v = 0;
}
if (d == '-' || d == '=') {
url = imgbase + img[s+n+'_'];
html += '<img src="'+url+'" width="'+h+'" height="'+w+'"'
+ (d == '='
? ' style="vertical-align:bottom;"'
: '')
+ ' alt="'+(s+n+d)+'">';
}
else {
url = imgbase + img[s+n];
html += '<img src="'+url+'" width="'+w+'" height="'+h+'"'
+ ' alt="'+(s+n)+'">';
}
}
}
else {
html += '<span style="color:red;">' + pai + '</span>'
}
}
if (v) html += '</span>';
html += '</span>';
return html;
}
function parse(text) {
var html = text.replace(/{(.*?)}/g, markup);
return html;
}
$('input[type="submit"]').on('click', function(event){
var html = parse($('form textarea').val());
$('#paiga div')
.empty()
.append($('<p><br>'+html.replace(/\n/g,'<br>')+'<br></p>'));
$('#paiga textarea').val(html).select();
return false;
});
$('input[type="reset"]').on('click', function(event){
$('form textarea').val('');
$('#paiga div').empty();
$('#paiga textarea').val('');
return false;
});
});
</script>
<style>
form {
width: 680px;
}
#paiga {
width: 680px;
}
#paiga div {
color: black;
background: white;
}
#paiga div p {
margin: 1em;
}
textarea {
font-family: monospace;
font-size: auto;
box-sizing: border-box;
width: 100%;
}
</style>
</head>
<body>
<div id="navi">
<a href="index.html">電脳麻将</a> |
<a href="autoplay.html">自動対戦</a> |
<a href="paipu.html">牌譜</a> |
<a href="paili.html">牌理</a> |
<a href="hule.html">和了点計算</a> |
牌画入力
</div>
<form>
<textarea rows="10">このような記述ができます。
{s067z1 z1}(ツモ) {p2-13} {z66=6-6} {_z77_} { }(ドラ){m1}
</textarea><br>
<input type="submit" value="変換">
<input type="reset" value="消去">
</form>
<div id="paiga">
<div></div>
<textarea rows="20"></textarea>
</div>
</body>
</html>