@konoui/mjimage 0.0.1 → 0.0.2
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.
- package/README.md +2 -2
- package/dist/mjs/cmd/index.d.ts +1 -0
- package/dist/mjs/cmd/index.js +49 -0
- package/dist/mjs/index.d.ts +1 -1
- package/dist/mjs/index.js +1 -1
- package/dist/mjs/lib/calculator/index.d.ts +284 -0
- package/dist/mjs/lib/calculator/index.js +1390 -0
- package/dist/mjs/lib/constants.d.ts +22 -2
- package/dist/mjs/lib/constants.js +28 -9
- package/dist/mjs/lib/controller/controller.d.ts +223 -0
- package/dist/mjs/lib/controller/controller.js +862 -0
- package/dist/mjs/lib/controller/efficiency.d.ts +36 -0
- package/dist/mjs/lib/controller/efficiency.js +217 -0
- package/dist/mjs/lib/controller/events.d.ts +172 -0
- package/dist/mjs/lib/controller/events.js +102 -0
- package/dist/mjs/lib/controller/game.d.ts +5 -0
- package/dist/mjs/lib/controller/game.js +29 -0
- package/dist/mjs/lib/controller/index.d.ts +10 -0
- package/dist/mjs/lib/controller/index.js +26 -0
- package/dist/mjs/lib/controller/managers.d.ts +89 -0
- package/dist/mjs/lib/controller/managers.js +212 -0
- package/dist/mjs/lib/controller/player.d.ts +12 -0
- package/dist/mjs/lib/controller/player.js +88 -0
- package/dist/mjs/lib/controller/replay.d.ts +10 -0
- package/dist/mjs/lib/controller/replay.js +34 -0
- package/dist/mjs/lib/controller/river.d.ts +19 -0
- package/dist/mjs/lib/controller/river.js +55 -0
- package/dist/mjs/lib/controller/state-machine.d.ts +116 -0
- package/dist/mjs/lib/controller/state-machine.js +733 -0
- package/dist/mjs/lib/controller/wall.d.ts +30 -0
- package/dist/mjs/lib/controller/wall.js +115 -0
- package/dist/mjs/lib/image.d.ts +3 -2
- package/dist/mjs/lib/image.js +78 -17
- package/dist/mjs/lib/lexer.d.ts +2 -1
- package/dist/mjs/lib/lexer.js +7 -0
- package/dist/mjs/lib/measure-text.d.ts +19 -0
- package/dist/mjs/lib/measure-text.js +52 -0
- package/dist/mjs/lib/mjai/event.d.ts +117 -0
- package/dist/mjs/lib/mjai/event.js +348 -0
- package/dist/mjs/lib/mjimage.js +3 -5
- package/dist/mjs/lib/parser.d.ts +51 -7
- package/dist/mjs/lib/parser.js +276 -42
- package/dist/mjs/lib/table-parser.d.ts +8 -6
- package/dist/mjs/lib/table-parser.js +12 -11
- package/dist/mjs/lib/table.d.ts +1 -1
- package/package.json +16 -8
- package/dist/index.html +0 -17763
- package/dist/mjs/lib/context.d.ts +0 -12
- package/dist/mjs/lib/context.js +0 -33
- package/dist/svg/_0.svg +0 -1
- package/dist/svg/m0.svg +0 -1
- package/dist/svg/m1.svg +0 -1
- package/dist/svg/m2.svg +0 -1
- package/dist/svg/m3.svg +0 -1
- package/dist/svg/m4.svg +0 -1
- package/dist/svg/m5.svg +0 -1
- package/dist/svg/m6.svg +0 -1
- package/dist/svg/m7.svg +0 -1
- package/dist/svg/m8.svg +0 -1
- package/dist/svg/m9.svg +0 -1
- package/dist/svg/p0.svg +0 -1
- package/dist/svg/p1.svg +0 -1
- package/dist/svg/p2.svg +0 -1
- package/dist/svg/p3.svg +0 -1
- package/dist/svg/p4.svg +0 -1
- package/dist/svg/p5.svg +0 -1
- package/dist/svg/p6.svg +0 -1
- package/dist/svg/p7.svg +0 -1
- package/dist/svg/p8.svg +0 -1
- package/dist/svg/p9.svg +0 -1
- package/dist/svg/s0.svg +0 -1
- package/dist/svg/s1.svg +0 -1
- package/dist/svg/s2.svg +0 -1
- package/dist/svg/s3.svg +0 -1
- package/dist/svg/s4.svg +0 -1
- package/dist/svg/s5.svg +0 -1
- package/dist/svg/s6.svg +0 -1
- package/dist/svg/s7.svg +0 -1
- package/dist/svg/s8.svg +0 -1
- package/dist/svg/s9.svg +0 -1
- package/dist/svg/stick100.svg +0 -1
- package/dist/svg/stick1000.svg +0 -1
- package/dist/svg/z1.svg +0 -1
- package/dist/svg/z2.svg +0 -1
- package/dist/svg/z3.svg +0 -1
- package/dist/svg/z4.svg +0 -1
- package/dist/svg/z5.svg +0 -1
- package/dist/svg/z6.svg +0 -1
- package/dist/svg/z7.svg +0 -1
- package/dist/tiles.1417fc37.svg +0 -1
package/dist/mjs/lib/parser.js
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
18
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
19
|
+
if (ar || !(i in from)) {
|
|
20
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
21
|
+
ar[i] = from[i];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
25
|
+
};
|
|
2
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Parser = exports.Block = exports.Tile = exports.isKind = exports.tileSortFunc = void 0;
|
|
27
|
+
exports.Parser = exports.blockWrapper = exports.BlockIsolated = exports.BlockRun = exports.BlockThree = exports.BlockPair = exports.BlockShoKan = exports.BlockDaiKan = exports.BlockAnKan = exports.BlockPon = exports.BlockChi = exports.Block = exports.Tile = exports.isKind = exports.tileSortFunc = void 0;
|
|
4
28
|
var lexer_1 = require("./lexer");
|
|
5
29
|
var constants_1 = require("./constants");
|
|
6
30
|
var tileSortFunc = function (i, j) {
|
|
@@ -18,7 +42,6 @@ var tileSortFunc = function (i, j) {
|
|
|
18
42
|
_a[constants_1.KIND.S] = 3,
|
|
19
43
|
_a[constants_1.KIND.Z] = 4,
|
|
20
44
|
_a[constants_1.KIND.BACK] = 5,
|
|
21
|
-
_a[constants_1.KIND.SEPARATOR] = 6,
|
|
22
45
|
_a);
|
|
23
46
|
return lookup[i.k] - lookup[j.k];
|
|
24
47
|
};
|
|
@@ -34,23 +57,41 @@ function isKind(v) {
|
|
|
34
57
|
}
|
|
35
58
|
exports.isKind = isKind;
|
|
36
59
|
var Tile = (function () {
|
|
37
|
-
function Tile(k, n,
|
|
60
|
+
function Tile(k, n, ops) {
|
|
61
|
+
if (ops === void 0) { ops = []; }
|
|
38
62
|
this.k = k;
|
|
39
63
|
this.n = n;
|
|
40
|
-
this.
|
|
64
|
+
this.ops = ops;
|
|
41
65
|
}
|
|
42
66
|
Tile.prototype.toString = function () {
|
|
43
|
-
if (this.k === constants_1.KIND.BACK
|
|
67
|
+
if (this.k === constants_1.KIND.BACK)
|
|
44
68
|
return this.k;
|
|
45
|
-
|
|
46
|
-
|
|
69
|
+
return "".concat(this.ops.join("")).concat(this.n).concat(this.k);
|
|
70
|
+
};
|
|
71
|
+
Tile.prototype.clone = function () {
|
|
72
|
+
return new Tile(this.k, this.n, __spreadArray([], this.ops, true));
|
|
73
|
+
};
|
|
74
|
+
Tile.prototype.has = function (op) {
|
|
75
|
+
return this.ops.includes(op);
|
|
76
|
+
};
|
|
77
|
+
Tile.prototype.add = function (op) {
|
|
78
|
+
this.ops.push(op);
|
|
79
|
+
this.ops = Array.from(new Set(this.ops));
|
|
80
|
+
return this;
|
|
81
|
+
};
|
|
82
|
+
Tile.prototype.remove = function (op) {
|
|
83
|
+
this.ops = this.ops.filter(function (v) { return v != op; });
|
|
84
|
+
return this;
|
|
85
|
+
};
|
|
86
|
+
Tile.prototype.isNum = function () {
|
|
87
|
+
return this.k == constants_1.KIND.M || this.k == constants_1.KIND.P || this.k == constants_1.KIND.S;
|
|
47
88
|
};
|
|
48
89
|
Tile.prototype.equals = function (t, ignoreRed) {
|
|
49
90
|
if (ignoreRed === void 0) { ignoreRed = false; }
|
|
50
|
-
var ok = this.n
|
|
91
|
+
var ok = this.n == t.n;
|
|
51
92
|
if (ignoreRed)
|
|
52
93
|
ok || (ok = (this.n == 5 && t.n == 0) || (this.n == 0 && t.n == 5));
|
|
53
|
-
return this.k
|
|
94
|
+
return this.k == t.k && ok;
|
|
54
95
|
};
|
|
55
96
|
return Tile;
|
|
56
97
|
}());
|
|
@@ -61,40 +102,204 @@ var Block = (function () {
|
|
|
61
102
|
this.type = type;
|
|
62
103
|
if (type == constants_1.BLOCK.CHI) {
|
|
63
104
|
tiles.sort(function (a, b) {
|
|
64
|
-
if (a.
|
|
105
|
+
if (a.has(constants_1.OPERATOR.HORIZONTAL))
|
|
65
106
|
return -1;
|
|
66
|
-
if (b.
|
|
107
|
+
if (b.has(constants_1.OPERATOR.HORIZONTAL))
|
|
67
108
|
return 1;
|
|
68
109
|
return (0, exports.tileSortFunc)(a, b);
|
|
69
110
|
});
|
|
70
111
|
return;
|
|
71
112
|
}
|
|
113
|
+
if (type == constants_1.BLOCK.SHO_KAN) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
72
116
|
if (type != constants_1.BLOCK.DISCARD) {
|
|
73
117
|
tiles.sort(exports.tileSortFunc);
|
|
74
118
|
}
|
|
75
119
|
}
|
|
76
120
|
Block.prototype.toString = function () {
|
|
77
|
-
var
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
121
|
+
var _a = this.tiles.reduce(function (a, b) {
|
|
122
|
+
return [a[0] && a[1].k == b.k, b];
|
|
123
|
+
}, [true, this.tiles[0]]), sameAll = _a[0], _ = _a[1];
|
|
124
|
+
var ret = "";
|
|
125
|
+
if (sameAll) {
|
|
126
|
+
for (var _i = 0, _b = this.tiles; _i < _b.length; _i++) {
|
|
127
|
+
var v = _b[_i];
|
|
128
|
+
ret += v.toString().slice(0, -1);
|
|
129
|
+
}
|
|
130
|
+
return "".concat(ret).concat(this.tiles[0].k);
|
|
131
|
+
}
|
|
132
|
+
for (var _c = 0, _d = this.tiles; _c < _d.length; _c++) {
|
|
133
|
+
var t = _d[_c];
|
|
134
|
+
ret += t.toString();
|
|
135
|
+
}
|
|
136
|
+
return ret;
|
|
137
|
+
};
|
|
138
|
+
Block.prototype.is = function (type) {
|
|
139
|
+
return this.type == type;
|
|
140
|
+
};
|
|
141
|
+
Block.prototype.isCalled = function () {
|
|
142
|
+
return [
|
|
143
|
+
constants_1.BLOCK.PON.toString(),
|
|
144
|
+
constants_1.BLOCK.CHI.toString(),
|
|
145
|
+
constants_1.BLOCK.AN_KAN.toString(),
|
|
146
|
+
constants_1.BLOCK.DAI_KAN.toString(),
|
|
147
|
+
constants_1.BLOCK.SHO_KAN.toString(),
|
|
148
|
+
].includes(this.type.toString());
|
|
149
|
+
};
|
|
150
|
+
Block.prototype.equals = function (b) {
|
|
151
|
+
if (this.tiles.length != b.tiles.length)
|
|
152
|
+
return false;
|
|
153
|
+
var ab = this.tiles;
|
|
154
|
+
var bb = b.tiles;
|
|
155
|
+
if (this.is(constants_1.BLOCK.CHI) || b.is(constants_1.BLOCK.CHI)) {
|
|
156
|
+
ab = b.clone().tiles.sort(exports.tileSortFunc);
|
|
157
|
+
bb = this.clone().tiles.sort(exports.tileSortFunc);
|
|
81
158
|
}
|
|
82
|
-
|
|
159
|
+
for (var i = 0; i < b.tiles.length; i++) {
|
|
160
|
+
if (!ab[i].equals(bb[i], true))
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
return true;
|
|
164
|
+
};
|
|
165
|
+
Block.prototype.minTile = function () {
|
|
166
|
+
if (this.is(constants_1.BLOCK.CHI))
|
|
167
|
+
return this.clone().tiles.sort(exports.tileSortFunc)[0];
|
|
168
|
+
return this.tiles[0];
|
|
169
|
+
};
|
|
170
|
+
Block.prototype.clone = function () {
|
|
171
|
+
var tiles = this.tiles.map(function (t) { return new Tile(t.k, t.n, __spreadArray([], t.ops, true)); });
|
|
172
|
+
return (0, exports.blockWrapper)(tiles, this.type);
|
|
83
173
|
};
|
|
84
174
|
return Block;
|
|
85
175
|
}());
|
|
86
176
|
exports.Block = Block;
|
|
177
|
+
var BlockChi = (function (_super) {
|
|
178
|
+
__extends(BlockChi, _super);
|
|
179
|
+
function BlockChi(tiles) {
|
|
180
|
+
return _super.call(this, tiles, constants_1.BLOCK.CHI) || this;
|
|
181
|
+
}
|
|
182
|
+
return BlockChi;
|
|
183
|
+
}(Block));
|
|
184
|
+
exports.BlockChi = BlockChi;
|
|
185
|
+
var BlockPon = (function (_super) {
|
|
186
|
+
__extends(BlockPon, _super);
|
|
187
|
+
function BlockPon(tiles) {
|
|
188
|
+
return _super.call(this, tiles, constants_1.BLOCK.PON) || this;
|
|
189
|
+
}
|
|
190
|
+
return BlockPon;
|
|
191
|
+
}(Block));
|
|
192
|
+
exports.BlockPon = BlockPon;
|
|
193
|
+
var BlockAnKan = (function (_super) {
|
|
194
|
+
__extends(BlockAnKan, _super);
|
|
195
|
+
function BlockAnKan(tiles) {
|
|
196
|
+
return _super.call(this, tiles, constants_1.BLOCK.AN_KAN) || this;
|
|
197
|
+
}
|
|
198
|
+
BlockAnKan.prototype.toString = function () {
|
|
199
|
+
var tiles = this.tiles.map(function (t) { return t.clone(); });
|
|
200
|
+
tiles[1] = new Tile(constants_1.KIND.BACK, 0);
|
|
201
|
+
tiles[2] = new Tile(constants_1.KIND.BACK, 0);
|
|
202
|
+
return tiles.reduce(function (s, t) {
|
|
203
|
+
return "".concat(s).concat(t.toString());
|
|
204
|
+
}, "");
|
|
205
|
+
};
|
|
206
|
+
return BlockAnKan;
|
|
207
|
+
}(Block));
|
|
208
|
+
exports.BlockAnKan = BlockAnKan;
|
|
209
|
+
var BlockDaiKan = (function (_super) {
|
|
210
|
+
__extends(BlockDaiKan, _super);
|
|
211
|
+
function BlockDaiKan(tiles) {
|
|
212
|
+
return _super.call(this, tiles, constants_1.BLOCK.DAI_KAN) || this;
|
|
213
|
+
}
|
|
214
|
+
return BlockDaiKan;
|
|
215
|
+
}(Block));
|
|
216
|
+
exports.BlockDaiKan = BlockDaiKan;
|
|
217
|
+
var BlockShoKan = (function (_super) {
|
|
218
|
+
__extends(BlockShoKan, _super);
|
|
219
|
+
function BlockShoKan(tiles) {
|
|
220
|
+
return _super.call(this, tiles, constants_1.BLOCK.SHO_KAN) || this;
|
|
221
|
+
}
|
|
222
|
+
return BlockShoKan;
|
|
223
|
+
}(Block));
|
|
224
|
+
exports.BlockShoKan = BlockShoKan;
|
|
225
|
+
var BlockPair = (function (_super) {
|
|
226
|
+
__extends(BlockPair, _super);
|
|
227
|
+
function BlockPair(tile1, tile2) {
|
|
228
|
+
return _super.call(this, [tile1, tile2], constants_1.BLOCK.PAIR) || this;
|
|
229
|
+
}
|
|
230
|
+
return BlockPair;
|
|
231
|
+
}(Block));
|
|
232
|
+
exports.BlockPair = BlockPair;
|
|
233
|
+
var BlockSet = (function (_super) {
|
|
234
|
+
__extends(BlockSet, _super);
|
|
235
|
+
function BlockSet(tiles) {
|
|
236
|
+
return _super.call(this, tiles, constants_1.BLOCK.SET) || this;
|
|
237
|
+
}
|
|
238
|
+
return BlockSet;
|
|
239
|
+
}(Block));
|
|
240
|
+
var BlockThree = (function (_super) {
|
|
241
|
+
__extends(BlockThree, _super);
|
|
242
|
+
function BlockThree(tiles) {
|
|
243
|
+
return _super.call(this, tiles) || this;
|
|
244
|
+
}
|
|
245
|
+
return BlockThree;
|
|
246
|
+
}(BlockSet));
|
|
247
|
+
exports.BlockThree = BlockThree;
|
|
248
|
+
var BlockRun = (function (_super) {
|
|
249
|
+
__extends(BlockRun, _super);
|
|
250
|
+
function BlockRun(tiles) {
|
|
251
|
+
return _super.call(this, tiles) || this;
|
|
252
|
+
}
|
|
253
|
+
return BlockRun;
|
|
254
|
+
}(BlockSet));
|
|
255
|
+
exports.BlockRun = BlockRun;
|
|
256
|
+
var BlockIsolated = (function (_super) {
|
|
257
|
+
__extends(BlockIsolated, _super);
|
|
258
|
+
function BlockIsolated(tile) {
|
|
259
|
+
return _super.call(this, [tile], constants_1.BLOCK.ISOLATED) || this;
|
|
260
|
+
}
|
|
261
|
+
return BlockIsolated;
|
|
262
|
+
}(Block));
|
|
263
|
+
exports.BlockIsolated = BlockIsolated;
|
|
264
|
+
var blockWrapper = function (tiles, type) {
|
|
265
|
+
switch (type) {
|
|
266
|
+
case constants_1.BLOCK.CHI:
|
|
267
|
+
return new BlockChi([tiles[0], tiles[1], tiles[2]]);
|
|
268
|
+
case constants_1.BLOCK.PON:
|
|
269
|
+
return new BlockPon([tiles[0], tiles[1], tiles[2]]);
|
|
270
|
+
case constants_1.BLOCK.AN_KAN:
|
|
271
|
+
return new BlockAnKan(tiles);
|
|
272
|
+
case constants_1.BLOCK.DAI_KAN:
|
|
273
|
+
return new BlockDaiKan(tiles);
|
|
274
|
+
case constants_1.BLOCK.SHO_KAN:
|
|
275
|
+
return new BlockShoKan(tiles);
|
|
276
|
+
case constants_1.BLOCK.SET:
|
|
277
|
+
if (tiles[0].equals(tiles[1], true))
|
|
278
|
+
return new BlockThree(tiles);
|
|
279
|
+
return new BlockRun(tiles);
|
|
280
|
+
case constants_1.BLOCK.PAIR:
|
|
281
|
+
return new BlockPair(tiles[0], tiles[1]);
|
|
282
|
+
case constants_1.BLOCK.ISOLATED:
|
|
283
|
+
return new BlockIsolated(tiles[0]);
|
|
284
|
+
default:
|
|
285
|
+
return new Block(tiles, type);
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
exports.blockWrapper = blockWrapper;
|
|
87
289
|
var Parser = (function () {
|
|
88
290
|
function Parser(input) {
|
|
89
291
|
this.input = input;
|
|
90
|
-
this.maxInputLength =
|
|
292
|
+
this.maxInputLength = 600;
|
|
91
293
|
this.input = input.replace(/\s/g, "");
|
|
92
294
|
}
|
|
93
295
|
Parser.prototype.parse = function () {
|
|
94
|
-
var parsed = this.
|
|
296
|
+
var parsed = this.tileSeparators();
|
|
95
297
|
return this.makeBlocks(parsed);
|
|
96
298
|
};
|
|
97
|
-
Parser.prototype.
|
|
299
|
+
Parser.prototype.tiles = function () {
|
|
300
|
+
return this.tileSeparators().filter(function (v) { return v != constants_1.INPUT_SEPARATOR; });
|
|
301
|
+
};
|
|
302
|
+
Parser.prototype.tileSeparators = function () {
|
|
98
303
|
var l = new lexer_1.Lexer(this.input);
|
|
99
304
|
var res = [];
|
|
100
305
|
var cluster = [];
|
|
@@ -104,6 +309,11 @@ var Parser = (function () {
|
|
|
104
309
|
var char = l.char;
|
|
105
310
|
if (char === l.eof)
|
|
106
311
|
break;
|
|
312
|
+
if (char == constants_1.INPUT_SEPARATOR) {
|
|
313
|
+
res.push(constants_1.INPUT_SEPARATOR);
|
|
314
|
+
l.readChar();
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
107
317
|
var _a = isKindAlias(char, cluster), k = _a[0], isKind_1 = _a[1];
|
|
108
318
|
if (isKind_1) {
|
|
109
319
|
if (k == constants_1.KIND.BACK) {
|
|
@@ -111,11 +321,6 @@ var Parser = (function () {
|
|
|
111
321
|
l.readChar();
|
|
112
322
|
continue;
|
|
113
323
|
}
|
|
114
|
-
if (k == constants_1.KIND.SEPARATOR) {
|
|
115
|
-
res.push(new Tile(k, -1));
|
|
116
|
-
l.readChar();
|
|
117
|
-
continue;
|
|
118
|
-
}
|
|
119
324
|
res.push.apply(res, makeTiles(cluster, k));
|
|
120
325
|
cluster = [];
|
|
121
326
|
l.readChar();
|
|
@@ -124,14 +329,13 @@ var Parser = (function () {
|
|
|
124
329
|
else {
|
|
125
330
|
var _b = isOperator(l), t = _b[0], isOp = _b[1];
|
|
126
331
|
if (isOp) {
|
|
127
|
-
l.readChar();
|
|
128
332
|
cluster.push(t);
|
|
129
333
|
l.readChar();
|
|
130
334
|
continue;
|
|
131
335
|
}
|
|
132
336
|
var _c = isNumber(char), n = _c[0], isNum = _c[1];
|
|
133
337
|
if (!isNum)
|
|
134
|
-
throw new Error("encounter unexpected number: ".concat(n, " ").concat(char));
|
|
338
|
+
throw new Error("encounter unexpected number. n: ".concat(n, ", current: ").concat(char, ", input: ").concat(l.input));
|
|
135
339
|
cluster.push(new Tile(constants_1.KIND.BACK, n));
|
|
136
340
|
}
|
|
137
341
|
l.readChar();
|
|
@@ -147,9 +351,9 @@ var Parser = (function () {
|
|
|
147
351
|
return res;
|
|
148
352
|
for (var _i = 0, tiles_1 = tiles; _i < tiles_1.length; _i++) {
|
|
149
353
|
var t = tiles_1[_i];
|
|
150
|
-
if (t
|
|
354
|
+
if (t == constants_1.INPUT_SEPARATOR) {
|
|
151
355
|
var type_1 = detectBlockType(cluster);
|
|
152
|
-
var b_1 =
|
|
356
|
+
var b_1 = (0, exports.blockWrapper)(cluster, type_1);
|
|
153
357
|
res.push(b_1);
|
|
154
358
|
cluster = [];
|
|
155
359
|
continue;
|
|
@@ -157,7 +361,7 @@ var Parser = (function () {
|
|
|
157
361
|
cluster.push(t);
|
|
158
362
|
}
|
|
159
363
|
var type = detectBlockType(cluster);
|
|
160
|
-
var b =
|
|
364
|
+
var b = (0, exports.blockWrapper)(cluster, type);
|
|
161
365
|
res.push(b);
|
|
162
366
|
cluster = [];
|
|
163
367
|
return res;
|
|
@@ -166,7 +370,7 @@ var Parser = (function () {
|
|
|
166
370
|
if (input.length == 0)
|
|
167
371
|
return;
|
|
168
372
|
if (input.length > this.maxInputLength)
|
|
169
|
-
throw new Error("exceeded maximum input length");
|
|
373
|
+
throw new Error("exceeded maximum input length(".concat(input.length, ")"));
|
|
170
374
|
var lastChar = input.charAt(input.length - 1);
|
|
171
375
|
var _a = isKindAlias(lastChar, [new Tile(constants_1.KIND.BACK, 1)]), _ = _a[0], isKind = _a[1];
|
|
172
376
|
if (!isKind)
|
|
@@ -179,22 +383,28 @@ function detectBlockType(tiles) {
|
|
|
179
383
|
if (tiles.length === 0)
|
|
180
384
|
return constants_1.BLOCK.UNKNOWN;
|
|
181
385
|
if (tiles.length === 1) {
|
|
182
|
-
if (tiles[0].
|
|
386
|
+
if (tiles[0].has(constants_1.OPERATOR.DORA))
|
|
183
387
|
return constants_1.BLOCK.DORA;
|
|
184
|
-
if (tiles[0].
|
|
388
|
+
if (tiles[0].has(constants_1.OPERATOR.TSUMO))
|
|
185
389
|
return constants_1.BLOCK.TSUMO;
|
|
186
390
|
return constants_1.BLOCK.HAND;
|
|
187
391
|
}
|
|
188
392
|
var sameAll = tiles.filter(function (v) { return v.equals(tiles[0], true); }).length == tiles.length;
|
|
189
|
-
var numOfHorizontals = tiles.filter(function (v) {
|
|
190
|
-
|
|
393
|
+
var numOfHorizontals = tiles.filter(function (v) {
|
|
394
|
+
return v.has(constants_1.OPERATOR.HORIZONTAL);
|
|
395
|
+
}).length;
|
|
396
|
+
var numOfTsumoDoraTiles = tiles.filter(function (v) { return v.has(constants_1.OPERATOR.TSUMO) || v.has(constants_1.OPERATOR.DORA); }).length;
|
|
191
397
|
var numOfBackTiles = tiles.filter(function (v) { return v.k == constants_1.KIND.BACK; }).length;
|
|
192
398
|
if (numOfTsumoDoraTiles > 0)
|
|
193
399
|
return constants_1.BLOCK.UNKNOWN;
|
|
194
400
|
if (numOfHorizontals == 0 && numOfBackTiles == 0)
|
|
195
401
|
return constants_1.BLOCK.HAND;
|
|
196
402
|
if (tiles.length === 3) {
|
|
197
|
-
|
|
403
|
+
if (sameAll)
|
|
404
|
+
return constants_1.BLOCK.PON;
|
|
405
|
+
if (numOfHorizontals == 1 && areConsecutiveTiles(tiles))
|
|
406
|
+
return constants_1.BLOCK.CHI;
|
|
407
|
+
return constants_1.BLOCK.DISCARD;
|
|
198
408
|
}
|
|
199
409
|
if (tiles.length == 4 && numOfBackTiles == 2)
|
|
200
410
|
return constants_1.BLOCK.AN_KAN;
|
|
@@ -208,9 +418,25 @@ function detectBlockType(tiles) {
|
|
|
208
418
|
return constants_1.BLOCK.DISCARD;
|
|
209
419
|
return constants_1.BLOCK.UNKNOWN;
|
|
210
420
|
}
|
|
421
|
+
function areConsecutiveTiles(tiles) {
|
|
422
|
+
tiles = tiles.map(function (t) { return t.clone(); }).sort(exports.tileSortFunc);
|
|
423
|
+
for (var i = 0; i < tiles.length - 1; i++) {
|
|
424
|
+
var n = tiles[i].n, np = tiles[i + 1].n;
|
|
425
|
+
var k = tiles[i].k, kp = tiles[i + 1].k;
|
|
426
|
+
if (n == 0)
|
|
427
|
+
n = 5;
|
|
428
|
+
if (np == 0)
|
|
429
|
+
np = 5;
|
|
430
|
+
if (k !== kp)
|
|
431
|
+
return false;
|
|
432
|
+
if (n + 1 !== np)
|
|
433
|
+
return false;
|
|
434
|
+
}
|
|
435
|
+
return true;
|
|
436
|
+
}
|
|
211
437
|
function makeTiles(cluster, k) {
|
|
212
438
|
return cluster.map(function (v) {
|
|
213
|
-
return new Tile(k, v.n, v.
|
|
439
|
+
return new Tile(k, v.n, v.ops);
|
|
214
440
|
});
|
|
215
441
|
}
|
|
216
442
|
function isKindAlias(s, cluster) {
|
|
@@ -232,13 +458,21 @@ function isNumber(v) {
|
|
|
232
458
|
return [Number(v), valid.includes(v)];
|
|
233
459
|
}
|
|
234
460
|
function isOperator(l) {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
461
|
+
var ops = Object.values(constants_1.OPERATOR);
|
|
462
|
+
if (!ops.includes(l.char))
|
|
463
|
+
return [new Tile(constants_1.KIND.BACK, 0), false];
|
|
464
|
+
var found = [];
|
|
465
|
+
for (var i = 0; i < 4; i++) {
|
|
466
|
+
var c = l.peekCharN(i);
|
|
467
|
+
if (ops.includes(c))
|
|
468
|
+
found.push(c);
|
|
469
|
+
else {
|
|
470
|
+
var _a = isNumber(c), n = _a[0], ok = _a[1];
|
|
239
471
|
if (!ok)
|
|
240
|
-
|
|
241
|
-
|
|
472
|
+
break;
|
|
473
|
+
for (var i_1 = 0; i_1 < found.length; i_1++)
|
|
474
|
+
l.readChar();
|
|
475
|
+
return [new Tile(constants_1.KIND.BACK, n, found), true];
|
|
242
476
|
}
|
|
243
477
|
}
|
|
244
478
|
return [new Tile(constants_1.KIND.BACK, 0), false];
|
|
@@ -55,7 +55,7 @@ declare const tableInputSchema: z.ZodObject<{
|
|
|
55
55
|
score?: number | undefined;
|
|
56
56
|
}>>>;
|
|
57
57
|
board: z.ZodObject<{
|
|
58
|
-
round: z.ZodDefault<z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"1w1" | "1w2" | "1w3" | "1w4" | "2w1" | "2w2" | "2w3" | "2w4">, z.ZodLiteral<"1w1" | "1w2" | "1w3" | "1w4" | "2w1" | "2w2" | "2w3" | "2w4">, ...z.ZodLiteral<"1w1" | "1w2" | "1w3" | "1w4" | "2w1" | "2w2" | "2w3" | "2w4">[]]>>>;
|
|
58
|
+
round: z.ZodDefault<z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"1w1" | "1w2" | "1w3" | "1w4" | "2w1" | "2w2" | "2w3" | "2w4" | "3w1" | "3w2" | "3w3" | "3w4" | "4w1" | "4w2" | "4w3" | "4w4">, z.ZodLiteral<"1w1" | "1w2" | "1w3" | "1w4" | "2w1" | "2w2" | "2w3" | "2w4" | "3w1" | "3w2" | "3w3" | "3w4" | "4w1" | "4w2" | "4w3" | "4w4">, ...z.ZodLiteral<"1w1" | "1w2" | "1w3" | "1w4" | "2w1" | "2w2" | "2w3" | "2w4" | "3w1" | "3w2" | "3w3" | "3w4" | "4w1" | "4w2" | "4w3" | "4w4">[]]>>>;
|
|
59
59
|
sticks: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
60
60
|
reach: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
61
61
|
dead: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
@@ -69,7 +69,7 @@ declare const tableInputSchema: z.ZodObject<{
|
|
|
69
69
|
doras: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
|
|
70
70
|
front: z.ZodDefault<z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"1w" | "2w" | "3w" | "4w">, z.ZodLiteral<"1w" | "2w" | "3w" | "4w">, ...z.ZodLiteral<"1w" | "2w" | "3w" | "4w">[]]>>>;
|
|
71
71
|
}, "strict", z.ZodTypeAny, {
|
|
72
|
-
round: "1w1" | "1w2" | "1w3" | "1w4" | "2w1" | "2w2" | "2w3" | "2w4";
|
|
72
|
+
round: "1w1" | "1w2" | "1w3" | "1w4" | "2w1" | "2w2" | "2w3" | "2w4" | "3w1" | "3w2" | "3w3" | "3w4" | "4w1" | "4w2" | "4w3" | "4w4";
|
|
73
73
|
sticks: {
|
|
74
74
|
reach: number;
|
|
75
75
|
dead: number;
|
|
@@ -77,7 +77,7 @@ declare const tableInputSchema: z.ZodObject<{
|
|
|
77
77
|
doras: string[];
|
|
78
78
|
front: "1w" | "2w" | "3w" | "4w";
|
|
79
79
|
}, {
|
|
80
|
-
round?: "1w1" | "1w2" | "1w3" | "1w4" | "2w1" | "2w2" | "2w3" | "2w4" | undefined;
|
|
80
|
+
round?: "1w1" | "1w2" | "1w3" | "1w4" | "2w1" | "2w2" | "2w3" | "2w4" | "3w1" | "3w2" | "3w3" | "3w4" | "4w1" | "4w2" | "4w3" | "4w4" | undefined;
|
|
81
81
|
sticks?: {
|
|
82
82
|
reach?: number | undefined;
|
|
83
83
|
dead?: number | undefined;
|
|
@@ -107,7 +107,7 @@ declare const tableInputSchema: z.ZodObject<{
|
|
|
107
107
|
score: number;
|
|
108
108
|
};
|
|
109
109
|
board: {
|
|
110
|
-
round: "1w1" | "1w2" | "1w3" | "1w4" | "2w1" | "2w2" | "2w3" | "2w4";
|
|
110
|
+
round: "1w1" | "1w2" | "1w3" | "1w4" | "2w1" | "2w2" | "2w3" | "2w4" | "3w1" | "3w2" | "3w3" | "3w4" | "4w1" | "4w2" | "4w3" | "4w4";
|
|
111
111
|
sticks: {
|
|
112
112
|
reach: number;
|
|
113
113
|
dead: number;
|
|
@@ -117,7 +117,7 @@ declare const tableInputSchema: z.ZodObject<{
|
|
|
117
117
|
};
|
|
118
118
|
}, {
|
|
119
119
|
board: {
|
|
120
|
-
round?: "1w1" | "1w2" | "1w3" | "1w4" | "2w1" | "2w2" | "2w3" | "2w4" | undefined;
|
|
120
|
+
round?: "1w1" | "1w2" | "1w3" | "1w4" | "2w1" | "2w2" | "2w3" | "2w4" | "3w1" | "3w2" | "3w3" | "3w4" | "4w1" | "4w2" | "4w3" | "4w4" | undefined;
|
|
121
121
|
sticks?: {
|
|
122
122
|
reach?: number | undefined;
|
|
123
123
|
dead?: number | undefined;
|
|
@@ -174,6 +174,8 @@ export interface ScoreBoardInput {
|
|
|
174
174
|
};
|
|
175
175
|
frontPlace: BoardWind;
|
|
176
176
|
}
|
|
177
|
+
export type TableWind = keyof typeof WIND_MAP;
|
|
178
|
+
export type TableRound = keyof typeof ROUND_MAP;
|
|
177
179
|
type BoardRound = (typeof ROUND_MAP)[keyof typeof ROUND_MAP];
|
|
178
180
|
type BoardWind = (typeof WIND_MAP)[keyof typeof WIND_MAP];
|
|
179
181
|
export declare const parse: (s: string) => {
|
|
@@ -203,7 +205,7 @@ export declare const parseTableInput: (s: string) => {
|
|
|
203
205
|
score: number;
|
|
204
206
|
};
|
|
205
207
|
board: {
|
|
206
|
-
round: "1w1" | "1w2" | "1w3" | "1w4" | "2w1" | "2w2" | "2w3" | "2w4";
|
|
208
|
+
round: "1w1" | "1w2" | "1w3" | "1w4" | "2w1" | "2w2" | "2w3" | "2w4" | "3w1" | "3w2" | "3w3" | "3w4" | "4w1" | "4w2" | "4w3" | "4w4";
|
|
207
209
|
sticks: {
|
|
208
210
|
reach: number;
|
|
209
211
|
dead: number;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var _a;
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.convertInput = exports.parseTableInput = exports.parse = void 0;
|
|
4
5
|
var js_yaml_1 = require("js-yaml");
|
|
@@ -15,12 +16,12 @@ var windInputSchema = zod_1.z
|
|
|
15
16
|
.optional()
|
|
16
17
|
.default({ discard: "", hand: "", score: 25000 });
|
|
17
18
|
var windInputsSchema = zod_1.z
|
|
18
|
-
.object({
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
.object((_a = {},
|
|
20
|
+
_a[constants_1.WIND.EAST] = windInputSchema,
|
|
21
|
+
_a[constants_1.WIND.SOUTH] = windInputSchema,
|
|
22
|
+
_a[constants_1.WIND.WEST] = windInputSchema,
|
|
23
|
+
_a[constants_1.WIND.NORTH] = windInputSchema,
|
|
24
|
+
_a))
|
|
24
25
|
.strict();
|
|
25
26
|
function unionOfLiterals(constants) {
|
|
26
27
|
var literals = constants.map(function (x) { return zod_1.z.literal(x); });
|
|
@@ -68,10 +69,10 @@ var convertInput = function (i) {
|
|
|
68
69
|
return i[w].discard.replace(/\r?\n/g, "");
|
|
69
70
|
};
|
|
70
71
|
var discards = {
|
|
71
|
-
front: new parser_1.Parser(f(m.front)).
|
|
72
|
-
right: new parser_1.Parser(f(m.right)).
|
|
73
|
-
opposite: new parser_1.Parser(f(m.opposite)).
|
|
74
|
-
left: new parser_1.Parser(f(m.left)).
|
|
72
|
+
front: new parser_1.Parser(f(m.front)).tiles(),
|
|
73
|
+
right: new parser_1.Parser(f(m.right)).tiles(),
|
|
74
|
+
opposite: new parser_1.Parser(f(m.opposite)).tiles(),
|
|
75
|
+
left: new parser_1.Parser(f(m.left)).tiles(),
|
|
75
76
|
};
|
|
76
77
|
var hands = {
|
|
77
78
|
front: new parser_1.Parser(i[m.front].hand).parse(),
|
|
@@ -84,7 +85,7 @@ var convertInput = function (i) {
|
|
|
84
85
|
frontPlace: constants_1.WIND_MAP[frontPlace],
|
|
85
86
|
sticks: i.board.sticks,
|
|
86
87
|
doras: i.board.doras.map(function (v) {
|
|
87
|
-
return new parser_1.Parser(v).
|
|
88
|
+
return new parser_1.Parser(v).tiles()[0];
|
|
88
89
|
}),
|
|
89
90
|
scores: {
|
|
90
91
|
front: i[m.front].score,
|
package/dist/mjs/lib/table.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ImageHelper, ImageHelperConfig } from "./image";
|
|
2
2
|
import { Svg, G } from "@svgdotjs/svg.js";
|
|
3
|
-
import { FontContext } from "./
|
|
3
|
+
import { FontContext } from "./measure-text";
|
|
4
4
|
import { ScoreBoardInput, DiscardsInput, HandsInput } from "./table-parser";
|
|
5
5
|
export declare const createTable: (helper: ImageHelper, fontCtx: FontContext, handsProps: HandsInput, discardsProps: DiscardsInput, scoreBoardProps: ScoreBoardInput) => {
|
|
6
6
|
e: G;
|
package/package.json
CHANGED
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@konoui/mjimage",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Generates Mahjong tiles in SVG format.",
|
|
5
|
+
"author": "konoui",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": "github.com/konoui/mjimage",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"mahjong"
|
|
10
|
+
],
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
5
14
|
"scripts": {
|
|
6
15
|
"start": "parcel",
|
|
7
16
|
"build": "parcel build",
|
|
8
17
|
"dev": "parcel src/index.html",
|
|
9
18
|
"test": "jest",
|
|
19
|
+
"cmd": "ts-node ./src/cmd/index.ts",
|
|
10
20
|
"svg-sprite": "svg-sprite -C svg-sprite.config.json -shape-transform-svgo svgo.json static/svg/*.svg",
|
|
11
21
|
"tsc": "tsc --declaration --outDir ./dist/mjs",
|
|
12
|
-
"prepublishOnly": "rm -rf ./dist && npm run tsc && cp -rf ./static/svg ./dist/mjs/svg/"
|
|
22
|
+
"prepublishOnly": "rm -rf ./dist && npm run tsc && cp -rf ./static/svg ./dist/mjs/svg/",
|
|
23
|
+
"deploy": "./scripts/sync.sh personal"
|
|
13
24
|
},
|
|
14
25
|
"types": "dist/mjs/index.d.ts",
|
|
15
26
|
"files": [
|
|
@@ -39,11 +50,6 @@
|
|
|
39
50
|
"staticPath": "static/svg",
|
|
40
51
|
"staticOutPath": "svg"
|
|
41
52
|
},
|
|
42
|
-
"author": "konoui",
|
|
43
|
-
"license": "MIT",
|
|
44
|
-
"publishConfig": {
|
|
45
|
-
"access": "public"
|
|
46
|
-
},
|
|
47
53
|
"devDependencies": {
|
|
48
54
|
"@parcel/transformer-inline-string": "^2.9.3",
|
|
49
55
|
"@parcel/transformer-typescript-tsc": "^2.9.3",
|
|
@@ -65,7 +71,9 @@
|
|
|
65
71
|
},
|
|
66
72
|
"dependencies": {
|
|
67
73
|
"@svgdotjs/svg.js": "^3.2.0",
|
|
74
|
+
"eventmit": "^2.0.4",
|
|
68
75
|
"js-yaml": "^4.1.0",
|
|
76
|
+
"xstate": "^5.7.0",
|
|
69
77
|
"zod": "^3.22.4"
|
|
70
78
|
}
|
|
71
79
|
}
|