@konoui/mjimage 0.0.24 → 0.0.25

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.
@@ -12,7 +12,7 @@ export interface HandData {
12
12
  reached: boolean;
13
13
  }
14
14
  export declare class Hand {
15
- private data;
15
+ protected data: HandData;
16
16
  constructor(input: string, allowBackBlock?: boolean);
17
17
  private init;
18
18
  get hands(): Tile[];
@@ -77,8 +77,9 @@ var Hand = (function () {
77
77
  var drawn_1 = this.drawn;
78
78
  var idx = tiles.findIndex(function (t) { return t.equals(drawn_1); });
79
79
  if (idx < 0)
80
- throw new Error("[debug] hand has drawn: ".concat(this.drawn, " but no tile in hands"));
81
- tiles[idx] = tiles[idx].clone({ add: constants_1.OPERATOR.TSUMO });
80
+ throw new Error("[debug] hand has drawn: ".concat(this.drawn, " but no tile in hands: ").concat(tiles.join("")));
81
+ else
82
+ tiles[idx] = tiles[idx].clone({ add: constants_1.OPERATOR.TSUMO });
82
83
  }
83
84
  if (tiles.length < 1)
84
85
  throw new Error("[debug] no tiles in hand ".concat(tiles.length, ", called: ").concat(this.called, ", data: ").concat(JSON.stringify(this.data, null, 2)));
@@ -164,11 +165,6 @@ var Hand = (function () {
164
165
  return backup;
165
166
  };
166
167
  Hand.prototype.dec = function (tiles) {
167
- if (this.hands.every(function (t) { return t.t == constants_1.TYPE.BACK; })) {
168
- var toRemove = tiles.map(function (v) { return new parser_1.Tile(constants_1.TYPE.BACK, 0); });
169
- this.data[constants_1.TYPE.BACK][1] -= tiles.length;
170
- return toRemove;
171
- }
172
168
  var backup = [];
173
169
  for (var _i = 0, tiles_2 = tiles; _i < tiles_2.length; _i++) {
174
170
  var t = tiles_2[_i];
@@ -225,8 +221,8 @@ var Hand = (function () {
225
221
  };
226
222
  Hand.prototype.kan = function (b) {
227
223
  if (b instanceof parser_1.BlockAnKan) {
228
- var t = b.tiles.filter(function (v) { return v.t != constants_1.TYPE.BACK && v.n != 0; });
229
- this.dec([t[0], t[0], t[0], t[0]]);
224
+ var t = b.tiles[0];
225
+ this.dec([t, t, t, t]);
230
226
  this.data.called.push(b);
231
227
  this.data.tsumo = null;
232
228
  return;
@@ -82,56 +82,7 @@ export declare class Controller {
82
82
  } | {
83
83
  type: "DRAWN_GAME_BY_NINE_TILES";
84
84
  iam: Wind;
85
- }, Record<string, import("xstate").AnyActorRef>, import("xstate").ProvidedActor, import("xstate").ParameterizedObject, import("xstate").ParameterizedObject, string, import("xstate").StateValue, string, unknown, import("xstate").NonReducibleUnknown, import("xstate").ResolveTypegenMeta<import("xstate").TypegenDisabled, {
86
- type: "";
87
- } | {
88
- type: "NEXT";
89
- } | {
90
- type: "CHI";
91
- block: BlockChi;
92
- iam: Wind;
93
- } | {
94
- type: "PON";
95
- block: BlockPon;
96
- iam: Wind;
97
- } | {
98
- type: "RON";
99
- ret: WinResult;
100
- iam: Wind;
101
- targetInfo: {
102
- wind: Wind;
103
- tile: Tile;
104
- };
105
- quadWin?: boolean;
106
- } | {
107
- type: "TSUMO";
108
- ret: WinResult;
109
- iam: Wind;
110
- lastTile: Tile;
111
- } | {
112
- type: "REACH";
113
- tile: Tile;
114
- iam: Wind;
115
- } | {
116
- type: "DISCARD";
117
- tile: Tile;
118
- iam: Wind;
119
- } | {
120
- type: "AN_KAN";
121
- block: BlockAnKan;
122
- iam: Wind;
123
- } | {
124
- type: "SHO_KAN";
125
- block: BlockShoKan;
126
- iam: Wind;
127
- } | {
128
- type: "DAI_KAN";
129
- block: BlockDaiKan;
130
- iam: Wind;
131
- } | {
132
- type: "DRAWN_GAME_BY_NINE_TILES";
133
- iam: Wind;
134
- }, import("xstate").ProvidedActor, import("xstate").ParameterizedObject, import("xstate").ParameterizedObject, string, string>>>;
85
+ }, Record<string, import("xstate").AnyActorRef>, import("xstate").ProvidedActor, import("xstate").ParameterizedObject, import("xstate").ParameterizedObject, never, import("xstate").StateValue, string, unknown, import("xstate").NonReducibleUnknown, import("xstate").EventObject, import("xstate").MetaObject, any>>;
135
86
  observer: Observer;
136
87
  handlers: {
137
88
  [id: string]: EventHandler;
@@ -146,7 +97,7 @@ export declare class Controller {
146
97
  debug?: boolean;
147
98
  });
148
99
  boardParams(w: Wind): BoardParams;
149
- hand(w: Wind): Hand;
100
+ hand(w: Wind): ActorHand;
150
101
  get placeManager(): PlaceManager;
151
102
  get scoreManager(): ScoreManager;
152
103
  get river(): River;
@@ -183,22 +134,27 @@ export declare class Controller {
183
134
  "4w": string;
184
135
  };
185
136
  }
137
+ export declare class ActorHand extends Hand {
138
+ isBackHand(): boolean;
139
+ clone(): ActorHand;
140
+ dec(tiles: Tile[]): Tile[];
141
+ }
186
142
  export declare abstract class BaseActor {
187
143
  id: string;
188
144
  river: River;
189
145
  placeManager: PlaceManager;
190
146
  scoreManager: ScoreManager;
191
147
  hands: {
192
- "1w": Hand;
193
- "2w": Hand;
194
- "3w": Hand;
195
- "4w": Hand;
148
+ "1w": ActorHand;
149
+ "2w": ActorHand;
150
+ "3w": ActorHand;
151
+ "4w": ActorHand;
196
152
  };
197
153
  counter: Counter;
198
154
  doraMarkers: Tile[];
199
155
  eventHandler: EventHandler;
200
156
  constructor(id: string, eventHandler: EventHandler);
201
- hand(w: Wind): Hand;
157
+ hand(w: Wind): ActorHand;
202
158
  protected abstract setHands(e: DistributeEvent): void;
203
159
  handleEvent(e: PlayerEvent): void;
204
160
  }
@@ -210,4 +166,3 @@ export declare class Observer extends BaseActor {
210
166
  setHands(e: DistributeEvent): void;
211
167
  handleEvent(e: PlayerEvent): void;
212
168
  }
213
- export declare function replaceTileBlock(obj: any): void;
@@ -38,8 +38,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
38
38
  return (mod && mod.__esModule) ? mod : { "default": mod };
39
39
  };
40
40
  Object.defineProperty(exports, "__esModule", { value: true });
41
- exports.Observer = exports.BaseActor = exports.Controller = void 0;
42
- exports.replaceTileBlock = replaceTileBlock;
41
+ exports.Observer = exports.BaseActor = exports.ActorHand = exports.Controller = void 0;
43
42
  var assert_1 = __importDefault(require("assert"));
44
43
  var xstate_1 = require("xstate");
45
44
  var core_1 = require("../core/");
@@ -278,7 +277,6 @@ var Controller = (function () {
278
277
  };
279
278
  Controller.load = function (h) {
280
279
  var events = h.choiceEvents;
281
- replaceTileBlock(events);
282
280
  var playerIDs = Object.keys(h.players);
283
281
  var empty = {
284
282
  emit: function (_) { },
@@ -657,12 +655,43 @@ var Controller = (function () {
657
655
  return Controller;
658
656
  }());
659
657
  exports.Controller = Controller;
658
+ var ActorHand = (function (_super) {
659
+ __extends(ActorHand, _super);
660
+ function ActorHand() {
661
+ return _super !== null && _super.apply(this, arguments) || this;
662
+ }
663
+ ActorHand.prototype.isBackHand = function () {
664
+ for (var _i = 0, _a = Object.values(core_1.TYPE); _i < _a.length; _i++) {
665
+ var t = _a[_i];
666
+ if (t == core_1.TYPE.BACK)
667
+ continue;
668
+ if (this.sum(t) > 0)
669
+ return false;
670
+ }
671
+ return this.sum(core_1.TYPE.BACK) > 0;
672
+ };
673
+ ActorHand.prototype.clone = function () {
674
+ var c = new ActorHand(this.toString());
675
+ c.data.called = this.called.map(function (b) { return b.clone(); });
676
+ c.data.reached = this.data.reached;
677
+ c.data.tsumo = this.data.tsumo == null ? null : this.data.tsumo;
678
+ return c;
679
+ };
680
+ ActorHand.prototype.dec = function (tiles) {
681
+ if (!this.isBackHand())
682
+ return _super.prototype.dec.call(this, tiles);
683
+ _super.prototype.dec.call(this, tiles.map(function () { return new parser_1.Tile(core_1.TYPE.BACK, 0); }));
684
+ return tiles;
685
+ };
686
+ return ActorHand;
687
+ }(calculator_1.Hand));
688
+ exports.ActorHand = ActorHand;
660
689
  var BaseActor = (function () {
661
690
  function BaseActor(id, eventHandler) {
662
691
  this.river = new _1.River();
663
692
  this.placeManager = new _1.PlaceManager({});
664
693
  this.scoreManager = new _1.ScoreManager({});
665
- this.hands = (0, _1.createWindMap)(new calculator_1.Hand(""));
694
+ this.hands = (0, _1.createWindMap)(new ActorHand(""));
666
695
  this.counter = new _1.Counter();
667
696
  this.doraMarkers = [];
668
697
  this.id = id;
@@ -798,11 +827,11 @@ var Observer = (function (_super) {
798
827
  var _this = _super.call(this, "observer", eventHandler) || this;
799
828
  _this.applied = {};
800
829
  _this.counter.disable = true;
801
- _this.hands = (0, _1.createWindMap)(new calculator_1.Hand("_____________"));
830
+ _this.hands = (0, _1.createWindMap)(new ActorHand("_____________"));
802
831
  return _this;
803
832
  }
804
833
  Observer.prototype.setHands = function (e) {
805
- this.hands[e.wind] = new calculator_1.Hand(e.hands[e.wind]);
834
+ this.hands[e.wind] = new ActorHand(e.hands[e.wind]);
806
835
  };
807
836
  Observer.prototype.handleEvent = function (e) {
808
837
  _super.prototype.handleEvent.call(this, e);
@@ -852,44 +881,3 @@ var Observer = (function (_super) {
852
881
  return Observer;
853
882
  }(BaseActor));
854
883
  exports.Observer = Observer;
855
- function replaceTileBlock(obj) {
856
- for (var key in obj) {
857
- if (obj.hasOwnProperty(key)) {
858
- var propValue = obj[key];
859
- if (typeof propValue === "object" &&
860
- propValue !== null &&
861
- "k" in propValue &&
862
- "n" in propValue &&
863
- "ops" in propValue) {
864
- obj[key] = new parser_1.Tile(propValue.k, propValue.n, propValue.ops);
865
- }
866
- else if (typeof propValue === "object" &&
867
- propValue != null &&
868
- "tiles" in propValue &&
869
- "type" in propValue) {
870
- obj[key] = (0, parser_1.blockWrapper)(propValue.tiles.map(function (t) { return new parser_1.Tile(t.t, t.n, t.ops); }), propValue.type);
871
- }
872
- else if (Array.isArray(propValue)) {
873
- for (var i = 0; i < propValue.length; i++) {
874
- var v = propValue[i];
875
- if (typeof v === "object" &&
876
- v !== null &&
877
- "k" in v &&
878
- "n" in v &&
879
- "ops" in v)
880
- propValue[i] = new parser_1.Tile(v.k, v.n, v.ops);
881
- else if (typeof v === "object" &&
882
- v != null &&
883
- "tiles" in v &&
884
- "type" in v)
885
- propValue[i] = (0, parser_1.blockWrapper)(v.tiles.map(function (t) { return new parser_1.Tile(t.t, t.n, t.ops); }), v.type);
886
- else
887
- replaceTileBlock(propValue[i]);
888
- }
889
- }
890
- else if (typeof propValue === "object") {
891
- replaceTileBlock(propValue);
892
- }
893
- }
894
- }
895
- }
@@ -40,7 +40,7 @@ var Player = (function (_super) {
40
40
  Player.prototype.setHands = function (e) {
41
41
  for (var _i = 0, _a = Object.values(core_1.WIND); _i < _a.length; _i++) {
42
42
  var w = _a[_i];
43
- this.hands[w] = new calculator_1.Hand(e.hands[w]);
43
+ this.hands[w] = new _1.ActorHand(e.hands[w]);
44
44
  }
45
45
  };
46
46
  Player.prototype.handleDiscard = function (tiles) {
@@ -62,55 +62,6 @@ export declare const createControllerMachine: (c: Controller) => import("xstate"
62
62
  } | {
63
63
  type: "DRAWN_GAME_BY_NINE_TILES";
64
64
  iam: Wind;
65
- }, Record<string, import("xstate").AnyActorRef>, import("xstate").ProvidedActor, import("xstate").ParameterizedObject, import("xstate").ParameterizedObject, string, import("xstate").StateValue, string, unknown, import("xstate").NonReducibleUnknown, import("xstate").ResolveTypegenMeta<import("xstate").TypegenDisabled, {
66
- type: "";
67
- } | {
68
- type: "NEXT";
69
- } | {
70
- type: "CHI";
71
- block: BlockChi;
72
- iam: Wind;
73
- } | {
74
- type: "PON";
75
- block: BlockPon;
76
- iam: Wind;
77
- } | {
78
- type: "RON";
79
- ret: WinResult;
80
- iam: Wind;
81
- targetInfo: {
82
- wind: Wind;
83
- tile: Tile;
84
- };
85
- quadWin?: boolean;
86
- } | {
87
- type: "TSUMO";
88
- ret: WinResult;
89
- iam: Wind;
90
- lastTile: Tile;
91
- } | {
92
- type: "REACH";
93
- tile: Tile;
94
- iam: Wind;
95
- } | {
96
- type: "DISCARD";
97
- tile: Tile;
98
- iam: Wind;
99
- } | {
100
- type: "AN_KAN";
101
- block: BlockAnKan;
102
- iam: Wind;
103
- } | {
104
- type: "SHO_KAN";
105
- block: BlockShoKan;
106
- iam: Wind;
107
- } | {
108
- type: "DAI_KAN";
109
- block: BlockDaiKan;
110
- iam: Wind;
111
- } | {
112
- type: "DRAWN_GAME_BY_NINE_TILES";
113
- iam: Wind;
114
- }, import("xstate").ProvidedActor, import("xstate").ParameterizedObject, import("xstate").ParameterizedObject, string, string>>;
65
+ }, Record<string, import("xstate").AnyActorRef>, import("xstate").ProvidedActor, import("xstate").ParameterizedObject, import("xstate").ParameterizedObject, never, import("xstate").StateValue, string, unknown, import("xstate").NonReducibleUnknown, import("xstate").EventObject, import("xstate").MetaObject, any>;
115
66
  export declare function incrementalIDGenerator(start?: number): () => string;
116
67
  export {};
@@ -470,7 +470,7 @@ var createControllerMachine = function (c) {
470
470
  context.missingMap[iam] = false;
471
471
  for (var _i = 0, _b = Object.values(constants_1.WIND); _i < _b.length; _i++) {
472
472
  var w = _b[_i];
473
- var t = new parser_1.Tile(constants_1.TYPE.BACK, 0);
473
+ var t = new parser_1.Tile(constants_1.TYPE.BACK, 0, [constants_1.OPERATOR.TSUMO]);
474
474
  if (w == iam)
475
475
  t = drawn;
476
476
  var e = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konoui/mjimage",
3
- "version": "0.0.24",
3
+ "version": "0.0.25",
4
4
  "description": "Generates Mahjong tiles in SVG format.",
5
5
  "author": "konoui",
6
6
  "license": "MIT",