@konoui/mjimage 0.0.31 → 0.0.33
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/dist/index.cjs +30 -0
- package/dist/index.d.cts +1389 -0
- package/dist/index.d.ts +1389 -0
- package/dist/index.js +10971 -0
- package/package.json +23 -14
- package/dist/mjs/cmd/index.d.ts +0 -1
- package/dist/mjs/cmd/index.js +0 -49
- package/dist/mjs/index.d.ts +0 -6
- package/dist/mjs/index.js +0 -22
- package/dist/mjs/lib/calculator/calc.d.ts +0 -275
- package/dist/mjs/lib/calculator/calc.js +0 -1397
- package/dist/mjs/lib/calculator/efficiency.d.ts +0 -24
- package/dist/mjs/lib/calculator/efficiency.js +0 -82
- package/dist/mjs/lib/calculator/helper.d.ts +0 -6
- package/dist/mjs/lib/calculator/helper.js +0 -21
- package/dist/mjs/lib/calculator/index.d.ts +0 -3
- package/dist/mjs/lib/calculator/index.js +0 -19
- package/dist/mjs/lib/controller/controller.d.ts +0 -168
- package/dist/mjs/lib/controller/controller.js +0 -897
- package/dist/mjs/lib/controller/events.d.ts +0 -171
- package/dist/mjs/lib/controller/events.js +0 -102
- package/dist/mjs/lib/controller/game.d.ts +0 -5
- package/dist/mjs/lib/controller/game.js +0 -29
- package/dist/mjs/lib/controller/index.d.ts +0 -10
- package/dist/mjs/lib/controller/index.js +0 -26
- package/dist/mjs/lib/controller/managers.d.ts +0 -83
- package/dist/mjs/lib/controller/managers.js +0 -194
- package/dist/mjs/lib/controller/player-efficiency.d.ts +0 -24
- package/dist/mjs/lib/controller/player-efficiency.js +0 -153
- package/dist/mjs/lib/controller/player.d.ts +0 -12
- package/dist/mjs/lib/controller/player.js +0 -85
- package/dist/mjs/lib/controller/replay.d.ts +0 -10
- package/dist/mjs/lib/controller/replay.js +0 -31
- package/dist/mjs/lib/controller/river.d.ts +0 -19
- package/dist/mjs/lib/controller/river.js +0 -52
- package/dist/mjs/lib/controller/state-machine.d.ts +0 -67
- package/dist/mjs/lib/controller/state-machine.js +0 -771
- package/dist/mjs/lib/controller/wall.d.ts +0 -24
- package/dist/mjs/lib/controller/wall.js +0 -117
- package/dist/mjs/lib/core/constants.d.ts +0 -73
- package/dist/mjs/lib/core/constants.js +0 -73
- package/dist/mjs/lib/core/index.d.ts +0 -2
- package/dist/mjs/lib/core/index.js +0 -18
- package/dist/mjs/lib/core/lexer.d.ts +0 -14
- package/dist/mjs/lib/core/lexer.js +0 -53
- package/dist/mjs/lib/core/parser.d.ts +0 -120
- package/dist/mjs/lib/core/parser.js +0 -612
- package/dist/mjs/lib/image/image.d.ts +0 -42
- package/dist/mjs/lib/image/image.js +0 -361
- package/dist/mjs/lib/image/index.d.ts +0 -1
- package/dist/mjs/lib/image/index.js +0 -17
- package/dist/mjs/lib/measure-text/index.d.ts +0 -19
- package/dist/mjs/lib/measure-text/index.js +0 -49
- package/dist/mjs/lib/myassert/index.d.ts +0 -1
- package/dist/mjs/lib/myassert/index.js +0 -8
- package/dist/mjs/lib/table/index.d.ts +0 -2
- package/dist/mjs/lib/table/index.js +0 -18
- package/dist/mjs/lib/table/table-parser.d.ts +0 -127
- package/dist/mjs/lib/table/table-parser.js +0 -105
- package/dist/mjs/lib/table/table.d.ts +0 -12
- package/dist/mjs/lib/table/table.js +0 -248
|
@@ -1,612 +0,0 @@
|
|
|
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
|
-
};
|
|
26
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.Parser = exports.BlockOther = exports.BlockHand = exports.BlockIsolated = exports.BlockRun = exports.BlockThree = exports.BlockPair = exports.BlockShoKan = exports.BlockDaiKan = exports.BlockAnKan = exports.BlockPon = exports.BlockChi = exports.Block = exports.Tile = exports.tileSortFunc = void 0;
|
|
28
|
-
exports.isNum5or0 = isNum5or0;
|
|
29
|
-
exports.isNum5 = isNum5;
|
|
30
|
-
exports.isNum0 = isNum0;
|
|
31
|
-
var lexer_1 = require("./lexer");
|
|
32
|
-
var _1 = require("./");
|
|
33
|
-
var tileSortFunc = function (i, j) {
|
|
34
|
-
var _a;
|
|
35
|
-
if (i.t == j.t) {
|
|
36
|
-
if (i.n == 0)
|
|
37
|
-
return 5 - j.n;
|
|
38
|
-
if (j.n == 0)
|
|
39
|
-
return i.n - 5;
|
|
40
|
-
return i.n - j.n;
|
|
41
|
-
}
|
|
42
|
-
var lookup = (_a = {},
|
|
43
|
-
_a[_1.TYPE.M] = 1,
|
|
44
|
-
_a[_1.TYPE.P] = 2,
|
|
45
|
-
_a[_1.TYPE.S] = 3,
|
|
46
|
-
_a[_1.TYPE.Z] = 4,
|
|
47
|
-
_a[_1.TYPE.BACK] = 5,
|
|
48
|
-
_a);
|
|
49
|
-
return lookup[i.t] - lookup[j.t];
|
|
50
|
-
};
|
|
51
|
-
exports.tileSortFunc = tileSortFunc;
|
|
52
|
-
function isType(v) {
|
|
53
|
-
for (var _i = 0, _a = Object.values(_1.TYPE); _i < _a.length; _i++) {
|
|
54
|
-
var t = _a[_i];
|
|
55
|
-
if (t == v) {
|
|
56
|
-
return [t, true];
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return [_1.TYPE.BACK, false];
|
|
60
|
-
}
|
|
61
|
-
var Tile = (function () {
|
|
62
|
-
function Tile(t, n, ops) {
|
|
63
|
-
if (ops === void 0) { ops = []; }
|
|
64
|
-
this.t = t;
|
|
65
|
-
this.n = n;
|
|
66
|
-
this.ops = ops;
|
|
67
|
-
}
|
|
68
|
-
Tile.from = function (s) {
|
|
69
|
-
var tiles = new Parser(s).tiles();
|
|
70
|
-
if (tiles.length != 1)
|
|
71
|
-
throw new Error("input is not a single tile ".concat(s));
|
|
72
|
-
return tiles[0];
|
|
73
|
-
};
|
|
74
|
-
Tile.prototype.toString = function () {
|
|
75
|
-
if (this.t === _1.TYPE.BACK)
|
|
76
|
-
return this.t;
|
|
77
|
-
return "".concat(this.ops.join("")).concat(this.n).concat(this.t);
|
|
78
|
-
};
|
|
79
|
-
Tile.prototype.toJSON = function () {
|
|
80
|
-
return this.toString();
|
|
81
|
-
};
|
|
82
|
-
Tile.prototype.clone = function (override) {
|
|
83
|
-
var _a, _b;
|
|
84
|
-
var t = (_a = override === null || override === void 0 ? void 0 : override.t) !== null && _a !== void 0 ? _a : this.t;
|
|
85
|
-
var n = (_b = override === null || override === void 0 ? void 0 : override.n) !== null && _b !== void 0 ? _b : this.n;
|
|
86
|
-
var ops = this.ops.filter(function (v) { return (override === null || override === void 0 ? void 0 : override.remove) != v; });
|
|
87
|
-
var s = new Set(__spreadArray([], ops, true));
|
|
88
|
-
if (override === null || override === void 0 ? void 0 : override.add)
|
|
89
|
-
s.add(override.add);
|
|
90
|
-
return new Tile(t, n, Array.from(s));
|
|
91
|
-
};
|
|
92
|
-
Tile.prototype.has = function (op) {
|
|
93
|
-
return this.ops.includes(op);
|
|
94
|
-
};
|
|
95
|
-
Tile.prototype.isNum = function () {
|
|
96
|
-
return this.t == _1.TYPE.M || this.t == _1.TYPE.P || this.t == _1.TYPE.S;
|
|
97
|
-
};
|
|
98
|
-
Tile.prototype.equals = function (t, ignoreRed) {
|
|
99
|
-
if (ignoreRed === void 0) { ignoreRed = false; }
|
|
100
|
-
var ok = this.n == t.n;
|
|
101
|
-
if (ignoreRed)
|
|
102
|
-
ok || (ok = isNum5or0(this) && isNum5or0(t));
|
|
103
|
-
return this.t == t.t && ok;
|
|
104
|
-
};
|
|
105
|
-
Tile.prototype.imageSize = function (scale) {
|
|
106
|
-
var h = parseFloat((_1.TILE_CONTEXT.HEIGHT * scale).toPrecision(5));
|
|
107
|
-
var w = parseFloat((_1.TILE_CONTEXT.WIDTH * scale).toPrecision(5));
|
|
108
|
-
var size = this.has(_1.OPERATOR.HORIZONTAL)
|
|
109
|
-
? { width: h, height: w, baseWidth: w, baseHeight: h }
|
|
110
|
-
: { width: w, height: h, w: w, baseWidth: w, baseHeight: h };
|
|
111
|
-
if (this.has(_1.OPERATOR.TSUMO) || this.has(_1.OPERATOR.DORA))
|
|
112
|
-
size.width += w * _1.TILE_CONTEXT.TEXT_SCALE;
|
|
113
|
-
return size;
|
|
114
|
-
};
|
|
115
|
-
return Tile;
|
|
116
|
-
}());
|
|
117
|
-
exports.Tile = Tile;
|
|
118
|
-
function isNum5or0(t) {
|
|
119
|
-
return isNum0(t) || isNum5(t);
|
|
120
|
-
}
|
|
121
|
-
function isNum5(t) {
|
|
122
|
-
return t.isNum() && t.n == 5;
|
|
123
|
-
}
|
|
124
|
-
function isNum0(t) {
|
|
125
|
-
return t.isNum() && t.n == 0;
|
|
126
|
-
}
|
|
127
|
-
var Block = (function () {
|
|
128
|
-
function Block(tiles, type) {
|
|
129
|
-
this._tiles = tiles;
|
|
130
|
-
this._type = type;
|
|
131
|
-
if (this._type == _1.BLOCK.CHI) {
|
|
132
|
-
this._tiles = __spreadArray([], this._tiles, true).sort(function (a, b) {
|
|
133
|
-
if (a.has(_1.OPERATOR.HORIZONTAL))
|
|
134
|
-
return -1;
|
|
135
|
-
if (b.has(_1.OPERATOR.HORIZONTAL))
|
|
136
|
-
return 1;
|
|
137
|
-
return (0, exports.tileSortFunc)(a, b);
|
|
138
|
-
});
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
if (this._type == _1.BLOCK.SHO_KAN) {
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
if (this._type != _1.BLOCK.IMAGE_DISCARD) {
|
|
145
|
-
this._tiles = __spreadArray([], this._tiles, true).sort(exports.tileSortFunc);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
Block.from = function (v) {
|
|
149
|
-
var tiles = new Parser(v.tiles).tiles();
|
|
150
|
-
return blockWrapper(tiles, v.type);
|
|
151
|
-
};
|
|
152
|
-
Block.prototype.serialize = function () {
|
|
153
|
-
return {
|
|
154
|
-
tiles: this.toString(),
|
|
155
|
-
type: this.type,
|
|
156
|
-
};
|
|
157
|
-
};
|
|
158
|
-
Block.prototype.toJSON = function () {
|
|
159
|
-
return this.serialize();
|
|
160
|
-
};
|
|
161
|
-
Object.defineProperty(Block.prototype, "type", {
|
|
162
|
-
get: function () {
|
|
163
|
-
return this._type;
|
|
164
|
-
},
|
|
165
|
-
enumerable: false,
|
|
166
|
-
configurable: true
|
|
167
|
-
});
|
|
168
|
-
Object.defineProperty(Block.prototype, "tiles", {
|
|
169
|
-
get: function () {
|
|
170
|
-
return this._tiles;
|
|
171
|
-
},
|
|
172
|
-
enumerable: false,
|
|
173
|
-
configurable: true
|
|
174
|
-
});
|
|
175
|
-
Block.prototype.is = function (type) {
|
|
176
|
-
return this._type == type;
|
|
177
|
-
};
|
|
178
|
-
Block.prototype.isCalled = function () {
|
|
179
|
-
return [
|
|
180
|
-
_1.BLOCK.PON.toString(),
|
|
181
|
-
_1.BLOCK.CHI.toString(),
|
|
182
|
-
_1.BLOCK.DAI_KAN.toString(),
|
|
183
|
-
_1.BLOCK.SHO_KAN.toString(),
|
|
184
|
-
_1.BLOCK.AN_KAN.toString(),
|
|
185
|
-
].includes(this._type.toString());
|
|
186
|
-
};
|
|
187
|
-
Block.prototype.clone = function (override) {
|
|
188
|
-
var rp = override === null || override === void 0 ? void 0 : override.replace;
|
|
189
|
-
var tiles = __spreadArray([], this.tiles, true);
|
|
190
|
-
if (rp)
|
|
191
|
-
tiles[rp.idx] = rp.tile;
|
|
192
|
-
return blockWrapper(tiles, this._type);
|
|
193
|
-
};
|
|
194
|
-
Block.prototype.imageSize = function (scale) {
|
|
195
|
-
var bh = this.tiles[0].imageSize(scale).baseHeight;
|
|
196
|
-
var bw = this.tiles[0].imageSize(scale).baseWidth;
|
|
197
|
-
if (this.is(_1.BLOCK.SHO_KAN))
|
|
198
|
-
return { width: bw * 2 + bh, height: Math.max(bw * 2, bh) };
|
|
199
|
-
var maxHeight = this.tiles.reduce(function (max, t) {
|
|
200
|
-
var h = t.imageSize(scale).height;
|
|
201
|
-
return h > max ? h : max;
|
|
202
|
-
}, 0);
|
|
203
|
-
var sumWidth = this.tiles.reduce(function (sum, t) {
|
|
204
|
-
return sum + t.imageSize(scale).width;
|
|
205
|
-
}, 0);
|
|
206
|
-
return { width: sumWidth, height: maxHeight };
|
|
207
|
-
};
|
|
208
|
-
return Block;
|
|
209
|
-
}());
|
|
210
|
-
exports.Block = Block;
|
|
211
|
-
var toStringForSame = function (tiles) {
|
|
212
|
-
var ret = "";
|
|
213
|
-
for (var _i = 0, tiles_1 = tiles; _i < tiles_1.length; _i++) {
|
|
214
|
-
var v = tiles_1[_i];
|
|
215
|
-
if (v.t == _1.TYPE.BACK)
|
|
216
|
-
return tiles.join("");
|
|
217
|
-
ret += v.toString().slice(0, -1);
|
|
218
|
-
}
|
|
219
|
-
return "".concat(ret).concat(tiles[0].t);
|
|
220
|
-
};
|
|
221
|
-
var toStringForHand = function (tiles) {
|
|
222
|
-
var preType = tiles[0].t;
|
|
223
|
-
var ret = "";
|
|
224
|
-
for (var i = 0; i < tiles.length; i++) {
|
|
225
|
-
var tile = tiles[i];
|
|
226
|
-
var type = tile.t;
|
|
227
|
-
var nop = type == _1.TYPE.BACK ? tile.toString() : tile.toString().slice(0, -1);
|
|
228
|
-
if (type != preType)
|
|
229
|
-
if (preType != _1.TYPE.BACK)
|
|
230
|
-
ret += preType;
|
|
231
|
-
preType = type;
|
|
232
|
-
ret += nop;
|
|
233
|
-
}
|
|
234
|
-
var last = tiles.at(-1);
|
|
235
|
-
if (last.t != _1.TYPE.BACK)
|
|
236
|
-
ret += last.t;
|
|
237
|
-
return ret;
|
|
238
|
-
};
|
|
239
|
-
var BlockChi = (function (_super) {
|
|
240
|
-
__extends(BlockChi, _super);
|
|
241
|
-
function BlockChi(tiles) {
|
|
242
|
-
return _super.call(this, tiles, _1.BLOCK.CHI) || this;
|
|
243
|
-
}
|
|
244
|
-
BlockChi.prototype.toString = function () {
|
|
245
|
-
return toStringForSame(this.tiles);
|
|
246
|
-
};
|
|
247
|
-
return BlockChi;
|
|
248
|
-
}(Block));
|
|
249
|
-
exports.BlockChi = BlockChi;
|
|
250
|
-
var BlockPon = (function (_super) {
|
|
251
|
-
__extends(BlockPon, _super);
|
|
252
|
-
function BlockPon(tiles) {
|
|
253
|
-
return _super.call(this, tiles, _1.BLOCK.PON) || this;
|
|
254
|
-
}
|
|
255
|
-
BlockPon.prototype.toString = function () {
|
|
256
|
-
return toStringForSame(this.tiles);
|
|
257
|
-
};
|
|
258
|
-
return BlockPon;
|
|
259
|
-
}(Block));
|
|
260
|
-
exports.BlockPon = BlockPon;
|
|
261
|
-
var BlockAnKan = (function (_super) {
|
|
262
|
-
__extends(BlockAnKan, _super);
|
|
263
|
-
function BlockAnKan(tiles) {
|
|
264
|
-
var _this = this;
|
|
265
|
-
var ftiles = tiles.filter(function (v) { return v.t != _1.TYPE.BACK; });
|
|
266
|
-
var sample = ftiles[0];
|
|
267
|
-
if (ftiles.length < tiles.length) {
|
|
268
|
-
if (isNum5or0(sample)) {
|
|
269
|
-
var t = new Tile(sample.t, 5);
|
|
270
|
-
_this = _super.call(this, [new Tile(sample.t, 0), t, t, t], _1.BLOCK.AN_KAN) || this;
|
|
271
|
-
return _this;
|
|
272
|
-
}
|
|
273
|
-
_this = _super.call(this, [sample, sample, sample, sample], _1.BLOCK.AN_KAN) || this;
|
|
274
|
-
return _this;
|
|
275
|
-
}
|
|
276
|
-
_this = _super.call(this, tiles, _1.BLOCK.AN_KAN) || this;
|
|
277
|
-
return _this;
|
|
278
|
-
}
|
|
279
|
-
Object.defineProperty(BlockAnKan.prototype, "tilesWithBack", {
|
|
280
|
-
get: function () {
|
|
281
|
-
var sample = this.tiles[0];
|
|
282
|
-
if (isNum5or0(sample)) {
|
|
283
|
-
return [
|
|
284
|
-
new Tile(_1.TYPE.BACK, 0),
|
|
285
|
-
new Tile(sample.t, 0),
|
|
286
|
-
new Tile(sample.t, 5),
|
|
287
|
-
new Tile(_1.TYPE.BACK, 0),
|
|
288
|
-
];
|
|
289
|
-
}
|
|
290
|
-
return [new Tile(_1.TYPE.BACK, 0), sample, sample, new Tile(_1.TYPE.BACK, 0)];
|
|
291
|
-
},
|
|
292
|
-
enumerable: false,
|
|
293
|
-
configurable: true
|
|
294
|
-
});
|
|
295
|
-
BlockAnKan.from = function (v) {
|
|
296
|
-
return _super.from.call(this, v);
|
|
297
|
-
};
|
|
298
|
-
BlockAnKan.prototype.toString = function () {
|
|
299
|
-
return toStringForHand(this.tilesWithBack);
|
|
300
|
-
};
|
|
301
|
-
return BlockAnKan;
|
|
302
|
-
}(Block));
|
|
303
|
-
exports.BlockAnKan = BlockAnKan;
|
|
304
|
-
var BlockDaiKan = (function (_super) {
|
|
305
|
-
__extends(BlockDaiKan, _super);
|
|
306
|
-
function BlockDaiKan(tiles) {
|
|
307
|
-
return _super.call(this, tiles, _1.BLOCK.DAI_KAN) || this;
|
|
308
|
-
}
|
|
309
|
-
BlockDaiKan.prototype.toString = function () {
|
|
310
|
-
return toStringForSame(this.tiles);
|
|
311
|
-
};
|
|
312
|
-
return BlockDaiKan;
|
|
313
|
-
}(Block));
|
|
314
|
-
exports.BlockDaiKan = BlockDaiKan;
|
|
315
|
-
var BlockShoKan = (function (_super) {
|
|
316
|
-
__extends(BlockShoKan, _super);
|
|
317
|
-
function BlockShoKan(tiles) {
|
|
318
|
-
return _super.call(this, tiles, _1.BLOCK.SHO_KAN) || this;
|
|
319
|
-
}
|
|
320
|
-
BlockShoKan.prototype.toString = function () {
|
|
321
|
-
return toStringForSame(this.tiles);
|
|
322
|
-
};
|
|
323
|
-
return BlockShoKan;
|
|
324
|
-
}(Block));
|
|
325
|
-
exports.BlockShoKan = BlockShoKan;
|
|
326
|
-
var BlockPair = (function (_super) {
|
|
327
|
-
__extends(BlockPair, _super);
|
|
328
|
-
function BlockPair(tile1, tile2) {
|
|
329
|
-
return _super.call(this, [tile1, tile2], _1.BLOCK.PAIR) || this;
|
|
330
|
-
}
|
|
331
|
-
BlockPair.prototype.toString = function () {
|
|
332
|
-
return toStringForSame(this.tiles);
|
|
333
|
-
};
|
|
334
|
-
return BlockPair;
|
|
335
|
-
}(Block));
|
|
336
|
-
exports.BlockPair = BlockPair;
|
|
337
|
-
var BlockThree = (function (_super) {
|
|
338
|
-
__extends(BlockThree, _super);
|
|
339
|
-
function BlockThree(tiles) {
|
|
340
|
-
return _super.call(this, tiles, _1.BLOCK.THREE) || this;
|
|
341
|
-
}
|
|
342
|
-
BlockThree.prototype.toString = function () {
|
|
343
|
-
return toStringForSame(this.tiles);
|
|
344
|
-
};
|
|
345
|
-
return BlockThree;
|
|
346
|
-
}(Block));
|
|
347
|
-
exports.BlockThree = BlockThree;
|
|
348
|
-
var BlockRun = (function (_super) {
|
|
349
|
-
__extends(BlockRun, _super);
|
|
350
|
-
function BlockRun(tiles) {
|
|
351
|
-
return _super.call(this, tiles, _1.BLOCK.RUN) || this;
|
|
352
|
-
}
|
|
353
|
-
BlockRun.prototype.toString = function () {
|
|
354
|
-
return toStringForSame(this.tiles);
|
|
355
|
-
};
|
|
356
|
-
return BlockRun;
|
|
357
|
-
}(Block));
|
|
358
|
-
exports.BlockRun = BlockRun;
|
|
359
|
-
var BlockIsolated = (function (_super) {
|
|
360
|
-
__extends(BlockIsolated, _super);
|
|
361
|
-
function BlockIsolated(tile) {
|
|
362
|
-
return _super.call(this, [tile], _1.BLOCK.ISOLATED) || this;
|
|
363
|
-
}
|
|
364
|
-
BlockIsolated.prototype.toString = function () {
|
|
365
|
-
return this.tiles[0].toString();
|
|
366
|
-
};
|
|
367
|
-
return BlockIsolated;
|
|
368
|
-
}(Block));
|
|
369
|
-
exports.BlockIsolated = BlockIsolated;
|
|
370
|
-
var BlockHand = (function (_super) {
|
|
371
|
-
__extends(BlockHand, _super);
|
|
372
|
-
function BlockHand(tiles) {
|
|
373
|
-
return _super.call(this, tiles, _1.BLOCK.HAND) || this;
|
|
374
|
-
}
|
|
375
|
-
BlockHand.prototype.toString = function () {
|
|
376
|
-
return toStringForHand(this.tiles);
|
|
377
|
-
};
|
|
378
|
-
return BlockHand;
|
|
379
|
-
}(Block));
|
|
380
|
-
exports.BlockHand = BlockHand;
|
|
381
|
-
var BlockOther = (function (_super) {
|
|
382
|
-
__extends(BlockOther, _super);
|
|
383
|
-
function BlockOther(tiles, type) {
|
|
384
|
-
return _super.call(this, tiles, type) || this;
|
|
385
|
-
}
|
|
386
|
-
BlockOther.prototype.toString = function () {
|
|
387
|
-
if (this.is(_1.BLOCK.IMAGE_DISCARD))
|
|
388
|
-
return this.tiles.join("");
|
|
389
|
-
return toStringForHand(this.tiles);
|
|
390
|
-
};
|
|
391
|
-
return BlockOther;
|
|
392
|
-
}(Block));
|
|
393
|
-
exports.BlockOther = BlockOther;
|
|
394
|
-
var blockWrapper = function (tiles, type) {
|
|
395
|
-
switch (type) {
|
|
396
|
-
case _1.BLOCK.CHI:
|
|
397
|
-
return new BlockChi([tiles[0], tiles[1], tiles[2]]);
|
|
398
|
-
case _1.BLOCK.PON:
|
|
399
|
-
return new BlockPon([tiles[0], tiles[1], tiles[2]]);
|
|
400
|
-
case _1.BLOCK.AN_KAN:
|
|
401
|
-
return new BlockAnKan(tiles);
|
|
402
|
-
case _1.BLOCK.DAI_KAN:
|
|
403
|
-
return new BlockDaiKan(tiles);
|
|
404
|
-
case _1.BLOCK.SHO_KAN:
|
|
405
|
-
return new BlockShoKan(tiles);
|
|
406
|
-
case _1.BLOCK.THREE:
|
|
407
|
-
return new BlockThree(tiles);
|
|
408
|
-
case _1.BLOCK.RUN:
|
|
409
|
-
return new BlockRun(tiles);
|
|
410
|
-
case _1.BLOCK.PAIR:
|
|
411
|
-
return new BlockPair(tiles[0], tiles[1]);
|
|
412
|
-
case _1.BLOCK.ISOLATED:
|
|
413
|
-
return new BlockIsolated(tiles[0]);
|
|
414
|
-
case _1.BLOCK.HAND:
|
|
415
|
-
return new BlockHand(tiles);
|
|
416
|
-
default:
|
|
417
|
-
return new BlockOther(tiles, type);
|
|
418
|
-
}
|
|
419
|
-
};
|
|
420
|
-
var Parser = (function () {
|
|
421
|
-
function Parser(input) {
|
|
422
|
-
this.input = input;
|
|
423
|
-
this.maxInputLength = 600;
|
|
424
|
-
this.input = input.replace(/\s/g, "");
|
|
425
|
-
}
|
|
426
|
-
Parser.prototype.parse = function () {
|
|
427
|
-
var parsed = this.tileSeparators();
|
|
428
|
-
return this.makeBlocks(parsed);
|
|
429
|
-
};
|
|
430
|
-
Parser.prototype.tiles = function () {
|
|
431
|
-
return this.tileSeparators().filter(function (v) { return v != _1.INPUT_SEPARATOR; });
|
|
432
|
-
};
|
|
433
|
-
Parser.prototype.tileSeparators = function () {
|
|
434
|
-
var l = new lexer_1.Lexer(this.input);
|
|
435
|
-
var res = [];
|
|
436
|
-
var cluster = [];
|
|
437
|
-
this.validate(this.input);
|
|
438
|
-
for (;;) {
|
|
439
|
-
l.skipWhitespace();
|
|
440
|
-
var char = l.char;
|
|
441
|
-
if (char === l.eof)
|
|
442
|
-
break;
|
|
443
|
-
if (char == _1.INPUT_SEPARATOR) {
|
|
444
|
-
res.push(_1.INPUT_SEPARATOR);
|
|
445
|
-
l.readChar();
|
|
446
|
-
continue;
|
|
447
|
-
}
|
|
448
|
-
var _a = isTypeAlias(char, cluster), type = _a[0], isType_1 = _a[1];
|
|
449
|
-
if (isType_1) {
|
|
450
|
-
if (type == _1.TYPE.BACK) {
|
|
451
|
-
res.push(new Tile(type, 0));
|
|
452
|
-
l.readChar();
|
|
453
|
-
continue;
|
|
454
|
-
}
|
|
455
|
-
res.push.apply(res, makeTiles(cluster, type));
|
|
456
|
-
cluster = [];
|
|
457
|
-
l.readChar();
|
|
458
|
-
continue;
|
|
459
|
-
}
|
|
460
|
-
else {
|
|
461
|
-
var _b = isOperator(l), t = _b[0], isOp = _b[1];
|
|
462
|
-
if (isOp) {
|
|
463
|
-
cluster.push(t);
|
|
464
|
-
l.readChar();
|
|
465
|
-
continue;
|
|
466
|
-
}
|
|
467
|
-
var _c = isNumber(char), n = _c[0], isNum = _c[1];
|
|
468
|
-
if (!isNum)
|
|
469
|
-
throw new Error("encounter unexpected number. n: ".concat(n, ", current: ").concat(char, ", input: ").concat(l.input));
|
|
470
|
-
cluster.push(new Tile(_1.TYPE.BACK, n));
|
|
471
|
-
}
|
|
472
|
-
l.readChar();
|
|
473
|
-
}
|
|
474
|
-
if (cluster.length > 0)
|
|
475
|
-
throw new Error("remaining values ".concat(cluster.toString()));
|
|
476
|
-
return res;
|
|
477
|
-
};
|
|
478
|
-
Parser.prototype.makeBlocks = function (tiles) {
|
|
479
|
-
var cluster = [];
|
|
480
|
-
var res = [];
|
|
481
|
-
if (tiles.length == 0)
|
|
482
|
-
return res;
|
|
483
|
-
for (var _i = 0, tiles_2 = tiles; _i < tiles_2.length; _i++) {
|
|
484
|
-
var t = tiles_2[_i];
|
|
485
|
-
if (t == _1.INPUT_SEPARATOR) {
|
|
486
|
-
var type_1 = detectBlockType(cluster);
|
|
487
|
-
var b_1 = blockWrapper(cluster, type_1);
|
|
488
|
-
res.push(b_1);
|
|
489
|
-
cluster = [];
|
|
490
|
-
continue;
|
|
491
|
-
}
|
|
492
|
-
cluster.push(t);
|
|
493
|
-
}
|
|
494
|
-
var type = detectBlockType(cluster);
|
|
495
|
-
var b = blockWrapper(cluster, type);
|
|
496
|
-
res.push(b);
|
|
497
|
-
cluster = [];
|
|
498
|
-
return res;
|
|
499
|
-
};
|
|
500
|
-
Parser.prototype.validate = function (input) {
|
|
501
|
-
if (input.length == 0)
|
|
502
|
-
return;
|
|
503
|
-
if (input.length > this.maxInputLength)
|
|
504
|
-
throw new Error("exceeded maximum input length(".concat(input.length, ")"));
|
|
505
|
-
var lastChar = input.charAt(input.length - 1);
|
|
506
|
-
var _a = isTypeAlias(lastChar, [new Tile(_1.TYPE.BACK, 1)]), _ = _a[0], isKind = _a[1];
|
|
507
|
-
if (!isKind)
|
|
508
|
-
throw new Error("last character(".concat(lastChar, ") is not type value"));
|
|
509
|
-
};
|
|
510
|
-
return Parser;
|
|
511
|
-
}());
|
|
512
|
-
exports.Parser = Parser;
|
|
513
|
-
function detectBlockType(tiles) {
|
|
514
|
-
if (tiles.length === 0)
|
|
515
|
-
return _1.BLOCK.UNKNOWN;
|
|
516
|
-
if (tiles.length === 1) {
|
|
517
|
-
if (tiles[0].has(_1.OPERATOR.DORA))
|
|
518
|
-
return _1.BLOCK.IMAGE_DORA;
|
|
519
|
-
if (tiles[0].has(_1.OPERATOR.TSUMO))
|
|
520
|
-
return _1.BLOCK.TSUMO;
|
|
521
|
-
return _1.BLOCK.HAND;
|
|
522
|
-
}
|
|
523
|
-
var sameAll = tiles.every(function (v) { return v.equals(tiles[0], true); });
|
|
524
|
-
var numOfHorizontals = tiles.filter(function (v) {
|
|
525
|
-
return v.has(_1.OPERATOR.HORIZONTAL);
|
|
526
|
-
}).length;
|
|
527
|
-
var numOfTsumoDoraTiles = tiles.filter(function (v) { return v.has(_1.OPERATOR.TSUMO) || v.has(_1.OPERATOR.DORA); }).length;
|
|
528
|
-
var numOfBackTiles = tiles.filter(function (v) { return v.t == _1.TYPE.BACK; }).length;
|
|
529
|
-
if (numOfTsumoDoraTiles > 0)
|
|
530
|
-
return _1.BLOCK.UNKNOWN;
|
|
531
|
-
if (numOfHorizontals == 0 && numOfBackTiles == 0)
|
|
532
|
-
return _1.BLOCK.HAND;
|
|
533
|
-
if (tiles.length === 3 && numOfBackTiles === 0) {
|
|
534
|
-
if (sameAll)
|
|
535
|
-
return _1.BLOCK.PON;
|
|
536
|
-
if (numOfHorizontals == 1 && areConsecutiveTiles(tiles))
|
|
537
|
-
return _1.BLOCK.CHI;
|
|
538
|
-
return _1.BLOCK.IMAGE_DISCARD;
|
|
539
|
-
}
|
|
540
|
-
if (tiles.length == 4 && numOfBackTiles == 2)
|
|
541
|
-
return _1.BLOCK.AN_KAN;
|
|
542
|
-
if (tiles.length == 4 && sameAll) {
|
|
543
|
-
if (numOfHorizontals == 1)
|
|
544
|
-
return _1.BLOCK.DAI_KAN;
|
|
545
|
-
if (numOfHorizontals == 2)
|
|
546
|
-
return _1.BLOCK.SHO_KAN;
|
|
547
|
-
}
|
|
548
|
-
if (numOfHorizontals == 1)
|
|
549
|
-
return _1.BLOCK.IMAGE_DISCARD;
|
|
550
|
-
return _1.BLOCK.UNKNOWN;
|
|
551
|
-
}
|
|
552
|
-
function areConsecutiveTiles(tiles) {
|
|
553
|
-
tiles = __spreadArray([], tiles, true).sort(exports.tileSortFunc);
|
|
554
|
-
for (var i = 0; i < tiles.length - 1; i++) {
|
|
555
|
-
var n = tiles[i].n, np = tiles[i + 1].n;
|
|
556
|
-
var type = tiles[i].t, kp = tiles[i + 1].t;
|
|
557
|
-
if (n == 0)
|
|
558
|
-
n = 5;
|
|
559
|
-
if (np == 0)
|
|
560
|
-
np = 5;
|
|
561
|
-
if (type !== kp)
|
|
562
|
-
return false;
|
|
563
|
-
if (n + 1 !== np)
|
|
564
|
-
return false;
|
|
565
|
-
}
|
|
566
|
-
return true;
|
|
567
|
-
}
|
|
568
|
-
function makeTiles(cluster, k) {
|
|
569
|
-
return cluster.map(function (v) {
|
|
570
|
-
return new Tile(k, v.n, v.ops);
|
|
571
|
-
});
|
|
572
|
-
}
|
|
573
|
-
function isTypeAlias(s, cluster) {
|
|
574
|
-
var _a = isType(s), k = _a[0], ok = _a[1];
|
|
575
|
-
if (ok)
|
|
576
|
-
return [k, true];
|
|
577
|
-
var isAlias = s === "w" || s === "d";
|
|
578
|
-
if (isAlias && cluster.length > 0) {
|
|
579
|
-
for (var i = 0; i < cluster.length; i++) {
|
|
580
|
-
var t = cluster[i];
|
|
581
|
-
if (s === "d") {
|
|
582
|
-
cluster[i] = t.clone({ n: t.n + 4 });
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
return [_1.TYPE.Z, true];
|
|
586
|
-
}
|
|
587
|
-
return [_1.TYPE.BACK, false];
|
|
588
|
-
}
|
|
589
|
-
function isNumber(v) {
|
|
590
|
-
var valid = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
|
|
591
|
-
return [Number(v), valid.includes(v)];
|
|
592
|
-
}
|
|
593
|
-
function isOperator(l) {
|
|
594
|
-
var ops = Object.values(_1.OPERATOR);
|
|
595
|
-
if (!ops.includes(l.char))
|
|
596
|
-
return [new Tile(_1.TYPE.BACK, 0), false];
|
|
597
|
-
var found = [];
|
|
598
|
-
for (var i = 0; i < 4; i++) {
|
|
599
|
-
var c = l.peekCharN(i);
|
|
600
|
-
if (ops.includes(c))
|
|
601
|
-
found.push(c);
|
|
602
|
-
else {
|
|
603
|
-
var _a = isNumber(c), n = _a[0], ok = _a[1];
|
|
604
|
-
if (!ok)
|
|
605
|
-
break;
|
|
606
|
-
for (var i_1 = 0; i_1 < found.length; i_1++)
|
|
607
|
-
l.readChar();
|
|
608
|
-
return [new Tile(_1.TYPE.BACK, n, found), true];
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
return [new Tile(_1.TYPE.BACK, 0), false];
|
|
612
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { Tile, Block } from "../core";
|
|
2
|
-
import { Svg, G, Image, Use } from "@svgdotjs/svg.js";
|
|
3
|
-
export interface ImageHelperConfig {
|
|
4
|
-
scale?: number;
|
|
5
|
-
imageHostPath?: string;
|
|
6
|
-
imageHostUrl?: string;
|
|
7
|
-
imageExt?: "svg" | "webp";
|
|
8
|
-
svgSprite?: boolean;
|
|
9
|
-
}
|
|
10
|
-
declare class BaseHelper {
|
|
11
|
-
readonly tileWidth: number;
|
|
12
|
-
readonly tileHeight: number;
|
|
13
|
-
readonly imageHostPath: string;
|
|
14
|
-
readonly imageHostUrl: string;
|
|
15
|
-
readonly imageExt: string;
|
|
16
|
-
readonly scale: number;
|
|
17
|
-
readonly svgSprite: boolean;
|
|
18
|
-
constructor(props?: ImageHelperConfig);
|
|
19
|
-
protected getDiffTileHeightWidth(t: Tile): number;
|
|
20
|
-
private image;
|
|
21
|
-
createImage(tile: Tile, x: number, y: number): Image | Use;
|
|
22
|
-
createTextImage(tile: Tile, x: number, y: number, t: string): G;
|
|
23
|
-
createRotate90Image(tile: Tile, x: number, y: number, adjustY?: boolean): G;
|
|
24
|
-
createStick(v: 100 | 1000): Image | Use;
|
|
25
|
-
static buildID(tile: Tile | 100 | 1000): string;
|
|
26
|
-
buildURL(tile: Tile | 100 | 1000): string;
|
|
27
|
-
}
|
|
28
|
-
export declare class ImageHelper extends BaseHelper {
|
|
29
|
-
readonly blockMargin: number;
|
|
30
|
-
createBlockHandDiscard(block: Block): G;
|
|
31
|
-
createBlockPonChiKan(block: Block): G;
|
|
32
|
-
}
|
|
33
|
-
export declare const createHand: (helper: ImageHelper, blocks: Block[]) => {
|
|
34
|
-
e: G;
|
|
35
|
-
width: number;
|
|
36
|
-
height: number;
|
|
37
|
-
};
|
|
38
|
-
export declare const drawBlocks: (svg: Svg, blocks: Block[], config?: ImageHelperConfig, params?: {
|
|
39
|
-
responsive: boolean;
|
|
40
|
-
}) => void;
|
|
41
|
-
export declare const optimizeSVG: (draw: Svg) => void;
|
|
42
|
-
export {};
|