@konoui/mjimage 0.0.30 → 0.0.31

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.
@@ -24,6 +24,7 @@ exports.DoubleCalculator = exports.deserializeWinResult = exports.N19 = exports.
24
24
  var constants_1 = require("../core/constants");
25
25
  var helper_1 = require("./helper");
26
26
  var parser_1 = require("../core/parser");
27
+ var myassert_1 = require("../myassert");
27
28
  var Hand = (function () {
28
29
  function Hand(input, allowBackBlock) {
29
30
  var _a;
@@ -88,13 +89,10 @@ var Hand = (function () {
88
89
  if (this.drawn != null) {
89
90
  var drawn_1 = this.drawn;
90
91
  var idx = tiles.findIndex(function (t) { return t.equals(drawn_1); });
91
- if (idx < 0)
92
- throw new Error("[debug] hand has drawn: ".concat(this.drawn, " but no tile in hands: ").concat(tiles.join("")));
93
- else
94
- tiles[idx] = tiles[idx].clone({ add: constants_1.OPERATOR.TSUMO });
92
+ (0, myassert_1.assert)(idx >= 0, "hand has drawn: ".concat(this.drawn, " but no tile in hands: ").concat(tiles.join("")));
93
+ tiles[idx] = tiles[idx].clone({ add: constants_1.OPERATOR.TSUMO });
95
94
  }
96
- if (tiles.length < 1)
97
- throw new Error("[debug] no tiles in hand ".concat(tiles.length, ", called: ").concat(this.called, ", data: ").concat(JSON.stringify(this.data, null, 2)));
95
+ (0, myassert_1.assert)(tiles.length > 0, "no tiles in hand ".concat(tiles.length, ", called: ").concat(this.called, ", data: ").concat(JSON.stringify(this.data, null, 2)));
98
96
  return tiles;
99
97
  },
100
98
  enumerable: false,
@@ -2,13 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Efficiency = void 0;
4
4
  var core_1 = require("../core");
5
+ var myassert_1 = require("../myassert");
5
6
  var calc_1 = require("./calc");
6
7
  var Efficiency = (function () {
7
8
  function Efficiency() {
8
9
  }
9
10
  Efficiency.calcCandidates = function (hand, choices) {
10
- if (choices.length == 0)
11
- throw new Error("[debug] choices to discard is zero");
11
+ (0, myassert_1.assert)(choices.length > 0, "choices to discard is zero");
12
12
  var ret = [];
13
13
  for (var _i = 0, choices_1 = choices; _i < choices_1.length; _i++) {
14
14
  var t = choices_1[_i];
@@ -34,13 +34,10 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
34
34
  }
35
35
  return to.concat(ar || Array.prototype.slice.call(from));
36
36
  };
37
- var __importDefault = (this && this.__importDefault) || function (mod) {
38
- return (mod && mod.__esModule) ? mod : { "default": mod };
39
- };
40
37
  Object.defineProperty(exports, "__esModule", { value: true });
41
38
  exports.Observer = exports.BaseActor = exports.ActorHand = exports.Controller = void 0;
42
- var assert_1 = __importDefault(require("assert"));
43
39
  var xstate_1 = require("xstate");
40
+ var myassert_1 = require("../myassert");
44
41
  var core_1 = require("../core/");
45
42
  var calculator_1 = require("../calculator");
46
43
  var parser_1 = require("../core/parser");
@@ -159,7 +156,7 @@ var Controller = (function () {
159
156
  var e = selected.events[0];
160
157
  switch (selected.type) {
161
158
  case "RON":
162
- (0, assert_1.default)(e.choices.RON, "ron choice is none");
159
+ (0, myassert_1.assert)(e.choices.RON, "ron choice is none");
163
160
  this.actor.send({
164
161
  type: selected.type,
165
162
  iam: e.wind,
@@ -171,7 +168,7 @@ var Controller = (function () {
171
168
  });
172
169
  break;
173
170
  case "DAI_KAN":
174
- (0, assert_1.default)(e.choices.DAI_KAN, "daikan choice is none");
171
+ (0, myassert_1.assert)(e.choices.DAI_KAN, "daikan choice is none");
175
172
  this.actor.send({
176
173
  type: selected.type,
177
174
  iam: e.wind,
@@ -181,8 +178,8 @@ var Controller = (function () {
181
178
  case "CHI":
182
179
  case "PON":
183
180
  var c = e.choices[selected.type];
184
- (0, assert_1.default)(c, "".concat(selected.type, " choice is none"));
185
- (0, assert_1.default)(selected.events.length == 1, "found more than one selected: ".concat(JSON.stringify(selected, null, 2)));
181
+ (0, myassert_1.assert)(c, "".concat(selected.type, " choice is none"));
182
+ (0, myassert_1.assert)(selected.events.length == 1, "found more than one selected: ".concat(JSON.stringify(selected, null, 2)));
186
183
  this.actor.send({
187
184
  type: selected.type,
188
185
  iam: e.wind,
@@ -192,12 +189,12 @@ var Controller = (function () {
192
189
  }
193
190
  else if (sample.type == "CHOICE_AFTER_DRAWN") {
194
191
  var selected = (0, events_1.prioritizeDrawnEvents)(events);
195
- (0, assert_1.default)(selected.events.length == 1, "found more than one selected: ".concat(JSON.stringify(selected, null, 2)));
192
+ (0, myassert_1.assert)(selected.events.length == 1, "found more than one selected: ".concat(JSON.stringify(selected, null, 2)));
196
193
  var e = selected.events[0];
197
194
  var w = e.wind;
198
195
  switch (selected.type) {
199
196
  case "TSUMO":
200
- (0, assert_1.default)(e.choices.TSUMO, "tsumo choice is none");
197
+ (0, myassert_1.assert)(e.choices.TSUMO, "tsumo choice is none");
201
198
  this.actor.send({
202
199
  type: selected.type,
203
200
  ret: (0, calculator_1.deserializeWinResult)(e.choices.TSUMO),
@@ -207,7 +204,7 @@ var Controller = (function () {
207
204
  break;
208
205
  case "REACH":
209
206
  var candidates = e.choices[selected.type];
210
- (0, assert_1.default)(candidates, "".concat(selected.type, " candidates is none"));
207
+ (0, myassert_1.assert)(candidates, "".concat(selected.type, " candidates is none"));
211
208
  this.actor.send({
212
209
  type: selected.type,
213
210
  tile: parser_1.Tile.from(candidates[0].tile),
@@ -216,7 +213,7 @@ var Controller = (function () {
216
213
  break;
217
214
  case "DISCARD":
218
215
  var tiles = e.choices[selected.type];
219
- (0, assert_1.default)(tiles, "".concat(selected.type, " choice is none"));
216
+ (0, myassert_1.assert)(tiles, "".concat(selected.type, " choice is none"));
220
217
  this.actor.send({
221
218
  type: selected.type,
222
219
  tile: parser_1.Tile.from(tiles[0]).clone({ remove: core_1.OPERATOR.TSUMO }),
@@ -225,7 +222,7 @@ var Controller = (function () {
225
222
  break;
226
223
  case "AN_KAN": {
227
224
  var choices = e.choices[selected.type];
228
- (0, assert_1.default)(choices, "".concat(selected.type, " choice is none"));
225
+ (0, myassert_1.assert)(choices, "".concat(selected.type, " choice is none"));
229
226
  this.actor.send({
230
227
  type: selected.type,
231
228
  block: parser_1.BlockAnKan.from(choices[0]),
@@ -235,7 +232,7 @@ var Controller = (function () {
235
232
  }
236
233
  case "SHO_KAN": {
237
234
  var choices = e.choices[selected.type];
238
- (0, assert_1.default)(choices, "".concat(selected.type, " choice is none"));
235
+ (0, myassert_1.assert)(choices, "".concat(selected.type, " choice is none"));
239
236
  this.actor.send({
240
237
  type: selected.type,
241
238
  block: parser_1.Block.from(choices[0]),
@@ -249,10 +246,10 @@ var Controller = (function () {
249
246
  }
250
247
  }
251
248
  else if (sample.type == "CHOICE_AFTER_CALLED") {
252
- (0, assert_1.default)(sample.choices.DISCARD, "discard candidate tile is none: ".concat(JSON.stringify(sample, null, 2), " ").concat(this.hand(sample.wind).toString()));
249
+ (0, myassert_1.assert)(sample.choices.DISCARD, "discard candidate tile is none: ".concat(JSON.stringify(sample, null, 2), " ").concat(this.hand(sample.wind).toString()));
253
250
  var w = sample.wind;
254
251
  var t = parser_1.Tile.from(sample.choices.DISCARD[0]);
255
- (0, assert_1.default)(t != null, "undefined tile ".concat(this.hand(w).toString()));
252
+ (0, myassert_1.assert)(t != null, "undefined tile ".concat(this.hand(w).toString()));
256
253
  this.actor.send({ type: "DISCARD", tile: t, iam: w });
257
254
  }
258
255
  else if (sample.type == "CHOICE_FOR_CHAN_KAN") {
@@ -265,7 +262,7 @@ var Controller = (function () {
265
262
  return;
266
263
  }
267
264
  var e = selected[0];
268
- (0, assert_1.default)(e.choices.RON, "ron choice is none");
265
+ (0, myassert_1.assert)(e.choices.RON, "ron choice is none");
269
266
  this.actor.send({
270
267
  type: "RON",
271
268
  iam: e.wind,
@@ -336,7 +333,7 @@ var Controller = (function () {
336
333
  ? this.wall.blindDoraMarkers
337
334
  : undefined;
338
335
  var final = new calculator_1.DoubleCalculator(hand, __assign(__assign({}, ret.boardContext), { sticks: this.placeManager.sticks, blindDoraMarkers: blindDoraMarkers })).calc([ret.hand]);
339
- (0, assert_1.default)(final);
336
+ (0, myassert_1.assert)(final);
340
337
  return final;
341
338
  };
342
339
  Controller.prototype.doWin = function (w, t, params) {
@@ -526,7 +523,7 @@ var Controller = (function () {
526
523
  }
527
524
  var tiles = this.cannotDiscardTile(called);
528
525
  var ret = hand.filter(function (v) { return !tiles.some(function (t) { return v.equals(t, true); }); });
529
- (0, assert_1.default)(ret.length > 0, "no tiles to discard. hand: ".concat(this.hand(w), ", suji: ").concat(tiles, ", block-chi: ").concat(called));
526
+ (0, myassert_1.assert)(ret.length > 0, "no tiles to discard. hand: ".concat(this.hand(w), ", suji: ").concat(tiles, ", block-chi: ").concat(called));
530
527
  return ret;
531
528
  };
532
529
  Controller.prototype.cannotDiscardTile = function (called) {
@@ -568,7 +565,7 @@ var Controller = (function () {
568
565
  return false;
569
566
  for (var _b = 0, blocks_1 = blocks; _b < blocks_1.length; _b++) {
570
567
  var b = blocks_1[_b];
571
- (0, assert_1.default)(b.tiles.filter(function (t) { return t.has(core_1.OPERATOR.HORIZONTAL); }).length == 0, "h op ".concat(b.toString()));
568
+ (0, myassert_1.assert)(b.tiles.filter(function (t) { return t.has(core_1.OPERATOR.HORIZONTAL); }).length == 0, "h op ".concat(b.toString()));
572
569
  }
573
570
  return blocks;
574
571
  };
@@ -596,7 +593,7 @@ var Controller = (function () {
596
593
  return false;
597
594
  for (var _a = 0, blocks_2 = blocks; _a < blocks_2.length; _a++) {
598
595
  var b = blocks_2[_a];
599
- (0, assert_1.default)(b.tiles.filter(function (t) { return t.has(core_1.OPERATOR.HORIZONTAL); }).length == 2, "h op ".concat(b.toString()));
596
+ (0, myassert_1.assert)(b.tiles.filter(function (t) { return t.has(core_1.OPERATOR.HORIZONTAL); }).length == 2, "h op ".concat(b.toString()));
600
597
  }
601
598
  return blocks;
602
599
  };
@@ -625,7 +622,7 @@ var Controller = (function () {
625
622
  var rt = b.tiles[ridx].clone({ n: 0 });
626
623
  b = b.clone({ replace: { idx: ridx, tile: rt } });
627
624
  }
628
- (0, assert_1.default)(b.tiles.filter(function (t) { return t.has(core_1.OPERATOR.HORIZONTAL); }).length == 1, "h op ".concat(b.toString()));
625
+ (0, myassert_1.assert)(b.tiles.filter(function (t) { return t.has(core_1.OPERATOR.HORIZONTAL); }).length == 1, "h op ".concat(b.toString()));
629
626
  return b;
630
627
  };
631
628
  Controller.prototype.canDrawnGame = function (w) {
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.Counter = exports.prevWind = exports.nextWind = exports.prevRound = exports.nextRound = exports.PlaceManager = exports.ScoreManager = void 0;
7
4
  exports.shuffle = shuffle;
8
- var assert_1 = __importDefault(require("assert"));
5
+ var myassert_1 = require("../myassert");
9
6
  var constants_1 = require("../core/constants");
10
7
  var calculator_1 = require("../calculator");
11
8
  var parser_1 = require("../core/parser");
@@ -68,7 +65,7 @@ var PlaceManager = (function () {
68
65
  };
69
66
  PlaceManager.prototype.decrementReachStick = function () {
70
67
  this.sticks.reach--;
71
- (0, assert_1.default)(this.sticks.reach >= 0);
68
+ (0, myassert_1.assert)(this.sticks.reach >= 0);
72
69
  };
73
70
  PlaceManager.prototype.resetDeadStick = function () {
74
71
  this.sticks.dead = 0;
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.RiskRank = exports.PlayerEfficiency = void 0;
7
- var assert_1 = __importDefault(require("assert"));
4
+ var myassert_1 = require("../myassert");
8
5
  var constants_1 = require("../core/constants");
9
6
  var parser_1 = require("../core/parser");
10
7
  var weight = function (t, doras) {
@@ -44,7 +41,7 @@ var PlayerEfficiency = (function () {
44
41
  return playerCandidates;
45
42
  };
46
43
  PlayerEfficiency.selectMinPriority = function (c, playerCandidates, doras) {
47
- (0, assert_1.default)(playerCandidates.length > 0);
44
+ (0, myassert_1.assert)(playerCandidates.length > 0);
48
45
  var min = 0;
49
46
  var idx = 0;
50
47
  for (var i = 0; i < playerCandidates.length; i++) {
@@ -92,7 +89,7 @@ var RiskRank = (function () {
92
89
  function RiskRank() {
93
90
  }
94
91
  RiskRank.selectTile = function (c, targetUsers, tiles) {
95
- (0, assert_1.default)(targetUsers.length > 0 && tiles.length > 0);
92
+ (0, myassert_1.assert)(targetUsers.length > 0 && tiles.length > 0);
96
93
  var ret = tiles[0];
97
94
  var min = Number.POSITIVE_INFINITY;
98
95
  for (var _i = 0, tiles_1 = tiles; _i < tiles_1.length; _i++) {
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.Replayer = void 0;
7
- var assert_1 = __importDefault(require("assert"));
4
+ var myassert_1 = require("../myassert");
8
5
  var _1 = require("./");
9
6
  var Replayer = (function () {
10
7
  function Replayer(v) {
@@ -13,12 +10,12 @@ var Replayer = (function () {
13
10
  this.histories = JSON.parse(v);
14
11
  }
15
12
  Replayer.prototype.next = function () {
16
- (0, assert_1.default)(this.index < this.histories.length);
13
+ (0, myassert_1.assert)(this.index < this.histories.length);
17
14
  this.index++;
18
15
  };
19
16
  Replayer.prototype.prev = function () {
20
17
  this.index--;
21
- (0, assert_1.default)(this.index < 0);
18
+ (0, myassert_1.assert)(this.index < 0);
22
19
  };
23
20
  Replayer.prototype.start = function () {
24
21
  var c = _1.Controller.load(this.histories[this.index]);
@@ -8,12 +8,9 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
8
8
  }
9
9
  return to.concat(ar || Array.prototype.slice.call(from));
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
12
  exports.River = void 0;
16
- var assert_1 = __importDefault(require("assert"));
13
+ var myassert_1 = require("../myassert");
17
14
  var River = (function () {
18
15
  function River() {
19
16
  this.m = [];
@@ -24,7 +21,7 @@ var River = (function () {
24
21
  Object.defineProperty(River.prototype, "lastTile", {
25
22
  get: function () {
26
23
  var last = this.m.at(-1);
27
- (0, assert_1.default)(last != null, "lastTile is null(".concat(last, "). river: ").concat(JSON.stringify(this.m, null, 2)));
24
+ (0, myassert_1.assert)(last != null, "lastTile is null(".concat(last, "). river: ").concat(JSON.stringify(this.m, null, 2)));
28
25
  return last;
29
26
  },
30
27
  enumerable: false,
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MeasureText = void 0;
4
4
  var constants_1 = require("../core/constants");
5
+ var myassert_1 = require("../myassert");
5
6
  var MeasureText = (function () {
6
7
  function MeasureText(strText, numText) {
7
8
  if (strText === void 0) { strText = "東"; }
@@ -11,8 +12,7 @@ var MeasureText = (function () {
11
12
  this.measure = function (str, fontStr) {
12
13
  if (_this.ctx == null) {
13
14
  _this.ctx = document.createElement("canvas").getContext("2d");
14
- if (_this.ctx == null)
15
- throw new Error("[debug] context is null");
15
+ (0, myassert_1.assert)(_this.ctx, "context is null");
16
16
  }
17
17
  var ctx = _this.ctx;
18
18
  ctx.font = fontStr;
@@ -0,0 +1 @@
1
+ export declare function assert(condition: any, message?: string): asserts condition;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assert = assert;
4
+ function assert(condition, message) {
5
+ if (!condition) {
6
+ throw new Error(message);
7
+ }
8
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konoui/mjimage",
3
- "version": "0.0.30",
3
+ "version": "0.0.31",
4
4
  "description": "Generates Mahjong tiles in SVG format.",
5
5
  "author": "konoui",
6
6
  "license": "MIT",
@@ -30,14 +30,10 @@
30
30
  "./table": "./dist/mjs/lib/table/index.js",
31
31
  "./calculator": "./dist/mjs/lib/calculator/index.js"
32
32
  },
33
- "targets": {
34
- "module": {}
35
- },
36
33
  "devDependencies": {
37
34
  "@types/jest": "^29.5.5",
38
35
  "@types/js-yaml": "^4.0.9",
39
36
  "@types/svgdom": "^0.1.0",
40
- "assert": "^2.1.0",
41
37
  "buffer": "^6.0.3",
42
38
  "process": "^0.11.10",
43
39
  "svg-sprite": "^2.0.2",