@gamepark/odin 1.0.0 → 1.1.0

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.
@@ -1,286 +1,153 @@
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 __read = (this && this.__read) || function (o, n) {
18
- var m = typeof Symbol === "function" && o[Symbol.iterator];
19
- if (!m) return o;
20
- var i = m.call(o), r, ar = [], e;
21
- try {
22
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
23
- }
24
- catch (error) { e = { error: error }; }
25
- finally {
26
- try {
27
- if (r && !r.done && (m = i["return"])) m.call(i);
28
- }
29
- finally { if (e) throw e.error; }
30
- }
31
- return ar;
32
- };
33
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
34
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
35
- if (ar || !(i in from)) {
36
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
37
- ar[i] = from[i];
38
- }
39
- }
40
- return to.concat(ar || Array.prototype.slice.call(from));
41
- };
42
- var __values = (this && this.__values) || function(o) {
43
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
44
- if (m) return m.call(o);
45
- if (o && typeof o.length === "number") return {
46
- next: function () {
47
- if (o && i >= o.length) o = void 0;
48
- return { value: o && o[i++], done: !o };
49
- }
50
- };
51
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
52
- };
53
- var __importDefault = (this && this.__importDefault) || function (mod) {
54
- return (mod && mod.__esModule) ? mod : { "default": mod };
55
- };
56
- Object.defineProperty(exports, "__esModule", { value: true });
57
- exports.PlayCardsRule = void 0;
58
- var rules_api_1 = require("@gamepark/rules-api");
59
- var groupBy_1 = __importDefault(require("lodash/groupBy"));
60
- var isEqual_1 = __importDefault(require("lodash/isEqual"));
61
- var orderBy_1 = __importDefault(require("lodash/orderBy"));
62
- var uniqWith_1 = __importDefault(require("lodash/uniqWith"));
63
- var Card_1 = require("../material/Card");
64
- var LocationType_1 = require("../material/LocationType");
65
- var MaterialType_1 = require("../material/MaterialType");
66
- var BasePlayerTurn_1 = require("./BasePlayerTurn");
67
- var CustomMoveType_1 = require("./CustomMoveType");
68
- var SortHelper_1 = require("./helper/SortHelper");
69
- var Memory_1 = require("./Memory");
70
- var RuleId_1 = require("./RuleId");
71
- var PlayCardsRule = (function (_super) {
72
- __extends(PlayCardsRule, _super);
73
- function PlayCardsRule() {
74
- return _super !== null && _super.apply(this, arguments) || this;
75
- }
76
- PlayCardsRule.prototype.onRuleStart = function () {
77
- var table = this.table;
78
- var tableSize = table.length;
79
- var hand = this.playableCards;
1
+ import { isCustomMoveType, isMoveItemTypeAtOnce } from '@gamepark/rules-api';
2
+ import groupBy from 'lodash/groupBy';
3
+ import isEqual from 'lodash/isEqual';
4
+ import orderBy from 'lodash/orderBy';
5
+ import uniqWith from 'lodash/uniqWith';
6
+ import { getCardValue } from '../material/Card';
7
+ import { LocationType, MiddleOfTable } from '../material/LocationType';
8
+ import { MaterialType } from '../material/MaterialType';
9
+ import { BasePlayerTurn } from './BasePlayerTurn';
10
+ import { CustomMoveType } from './CustomMoveType';
11
+ import { SortHelper } from './helper/SortHelper';
12
+ import { Memory } from './Memory';
13
+ import { RuleId } from './RuleId';
14
+ export class PlayCardsRule extends BasePlayerTurn {
15
+ onRuleStart() {
16
+ const table = this.table;
17
+ const tableSize = table.length;
18
+ const hand = this.playableCards;
80
19
  if (hand.length < tableSize) {
81
- return [this.customMove(CustomMoveType_1.CustomMoveType.Pass)];
20
+ return [this.customMove(CustomMoveType.Pass)];
82
21
  }
83
22
  return [];
84
- };
85
- PlayCardsRule.prototype.getPlayerMoves = function () {
23
+ }
24
+ getPlayerMoves() {
86
25
  return this.getAvailableMoves();
87
- };
88
- PlayCardsRule.prototype.getAvailableMoves = function () {
89
- var playableCards = this.playableCards;
90
- var table = this.table;
91
- var tableSize = table.length;
92
- var moves = [];
93
- var combinations = this.getPlayableCombinations(playableCards.getItems().map(function (item) { return item.id; }), tableSize, this.tableValue);
94
- var allHandCombination = this.getPlayableCombinations(playableCards.getItems().map(function (item) { return item.id; }), playableCards.length, this.tableValue);
95
- var sortHelper = new SortHelper_1.SortHelper(this.game);
26
+ }
27
+ getAvailableMoves() {
28
+ const playableCards = this.playableCards;
29
+ const table = this.table;
30
+ const tableSize = table.length;
31
+ const moves = [];
32
+ const combinations = this.getPlayableCombinations(playableCards.getItems().map((item) => item.id), tableSize, this.tableValue);
33
+ const allHandCombination = this.getPlayableCombinations(playableCards.getItems().map((item) => item.id), playableCards.length, this.tableValue);
34
+ const sortHelper = new SortHelper(this.game);
96
35
  if (allHandCombination.length) {
97
- moves.push.apply(moves, __spreadArray([], __read(allHandCombination.map(function (c) {
98
- var _a;
99
- return (_a = playableCards
100
- .id(function (id) { return c.includes(id); }))
101
- .sort.apply(_a, __spreadArray([], __read(sortHelper.sortByValue), false)).moveItemsAtOnce({
102
- type: LocationType_1.LocationType.MiddleOfTable,
103
- id: LocationType_1.MiddleOfTable.Next
104
- });
105
- })), false));
36
+ moves.push(...allHandCombination.map((c) => playableCards
37
+ .id((id) => c.includes(id))
38
+ .sort(...sortHelper.sortByValue)
39
+ .moveItemsAtOnce({
40
+ type: LocationType.MiddleOfTable,
41
+ id: MiddleOfTable.Next
42
+ })));
106
43
  }
107
- moves.push.apply(moves, __spreadArray([], __read(combinations.map(function (c) {
108
- var _a;
109
- return (_a = playableCards
110
- .id(function (id) { return c.includes(id); }))
111
- .sort.apply(_a, __spreadArray([], __read(sortHelper.sortByValue), false)).moveItemsAtOnce({
112
- type: LocationType_1.LocationType.MiddleOfTable,
113
- id: LocationType_1.MiddleOfTable.Next
114
- });
115
- })), false));
44
+ moves.push(...combinations.map((c) => playableCards
45
+ .id((id) => c.includes(id))
46
+ .sort(...sortHelper.sortByValue)
47
+ .moveItemsAtOnce({
48
+ type: LocationType.MiddleOfTable,
49
+ id: MiddleOfTable.Next
50
+ })));
116
51
  if (table.length) {
117
- moves.push(this.customMove(CustomMoveType_1.CustomMoveType.Pass));
52
+ moves.push(this.customMove(CustomMoveType.Pass));
118
53
  }
119
54
  return moves;
120
- };
121
- Object.defineProperty(PlayCardsRule.prototype, "tableValue", {
122
- get: function () {
123
- var table = this.table;
124
- return !table.length ? 0 : this.concatCardValue(table.getItems().map(function (item) { return item.id; }));
125
- },
126
- enumerable: false,
127
- configurable: true
128
- });
129
- PlayCardsRule.prototype.onCustomMove = function (move) {
130
- if (!(0, rules_api_1.isCustomMoveType)(CustomMoveType_1.CustomMoveType.Pass)(move))
55
+ }
56
+ get tableValue() {
57
+ const table = this.table;
58
+ return !table.length ? 0 : this.concatCardValue(table.getItems().map((item) => item.id));
59
+ }
60
+ onCustomMove(move) {
61
+ if (!isCustomMoveType(CustomMoveType.Pass)(move))
131
62
  return [];
132
- var moves = [];
133
- var nextTable = this.nextTable;
63
+ const moves = [];
64
+ const nextTable = this.nextTable;
134
65
  if (nextTable.length) {
135
66
  moves.push(nextTable.moveItemsAtOnce({
136
- type: LocationType_1.LocationType.Hand,
67
+ type: LocationType.Hand,
137
68
  player: this.player
138
69
  }));
139
70
  }
140
- moves.push.apply(moves, __spreadArray([], __read(this.goToNextPlayer()), false));
71
+ moves.push(...this.goToNextPlayer());
141
72
  return moves;
142
- };
143
- PlayCardsRule.prototype.afterItemMove = function (move) {
144
- if (!(0, rules_api_1.isMoveItemTypeAtOnce)(MaterialType_1.MaterialType.Card)(move) || move.location.type !== LocationType_1.LocationType.MiddleOfTable)
73
+ }
74
+ afterItemMove(move) {
75
+ if (!isMoveItemTypeAtOnce(MaterialType.Card)(move) || move.location.type !== LocationType.MiddleOfTable)
145
76
  return [];
146
- var moves = [];
147
- this.memorize(Memory_1.Memory.LastPlayerThatPlay, this.player);
77
+ const moves = [];
78
+ this.memorize(Memory.LastPlayerThatPlay, this.player);
148
79
  if (this.hand.length > 0) {
149
- moves.push(this.customMove(CustomMoveType_1.CustomMoveType.TurnTempo));
80
+ moves.push(this.customMove(CustomMoveType.TurnTempo));
150
81
  }
151
- moves.push(this.startRule(RuleId_1.RuleId.PickCard));
82
+ moves.push(this.startRule(RuleId.PickCard));
152
83
  return moves;
153
- };
154
- PlayCardsRule.prototype.goToNextPlayer = function () {
155
- var next = this.nextPlayer;
156
- var moves = [];
157
- var lastPlayerThatPlay = this.remind(Memory_1.Memory.LastPlayerThatPlay);
84
+ }
85
+ goToNextPlayer() {
86
+ const next = this.nextPlayer;
87
+ const moves = [];
88
+ const lastPlayerThatPlay = this.remind(Memory.LastPlayerThatPlay);
158
89
  if (lastPlayerThatPlay && next === lastPlayerThatPlay) {
159
- this.forget(Memory_1.Memory.LastPlayerThatPlay);
160
- var table = this.table;
90
+ this.forget(Memory.LastPlayerThatPlay);
91
+ const table = this.table;
161
92
  if (table.length) {
162
93
  moves.push(this.table.moveItemsAtOnce({
163
- type: LocationType_1.LocationType.Discard
94
+ type: LocationType.Discard
164
95
  }));
165
96
  }
166
- moves.push(this.startRule(RuleId_1.RuleId.ChangePlayer));
97
+ moves.push(this.startRule(RuleId.ChangePlayer));
167
98
  }
168
99
  else {
169
- moves.push(this.startPlayerTurn(RuleId_1.RuleId.PlayCards, this.nextPlayer));
100
+ moves.push(this.startPlayerTurn(RuleId.PlayCards, this.nextPlayer));
170
101
  }
171
102
  return moves;
172
- };
173
- Object.defineProperty(PlayCardsRule.prototype, "firstPlayer", {
174
- get: function () {
175
- return this.remind(Memory_1.Memory.FirstPlayer);
176
- },
177
- enumerable: false,
178
- configurable: true
179
- });
180
- Object.defineProperty(PlayCardsRule.prototype, "table", {
181
- get: function () {
182
- return this.material(MaterialType_1.MaterialType.Card).location(LocationType_1.LocationType.MiddleOfTable).locationId(LocationType_1.MiddleOfTable.Current);
183
- },
184
- enumerable: false,
185
- configurable: true
186
- });
187
- Object.defineProperty(PlayCardsRule.prototype, "nextTable", {
188
- get: function () {
189
- return this.material(MaterialType_1.MaterialType.Card).location(LocationType_1.LocationType.MiddleOfTable).locationId(LocationType_1.MiddleOfTable.Next);
190
- },
191
- enumerable: false,
192
- configurable: true
193
- });
194
- Object.defineProperty(PlayCardsRule.prototype, "playableCards", {
195
- get: function () {
196
- var _this = this;
197
- return this.material(MaterialType_1.MaterialType.Card).location(function (l) { return (l.type === LocationType_1.LocationType.Hand && l.player === _this.player) || (l.type === LocationType_1.LocationType.MiddleOfTable && l.id === LocationType_1.MiddleOfTable.Next); });
198
- },
199
- enumerable: false,
200
- configurable: true
201
- });
202
- Object.defineProperty(PlayCardsRule.prototype, "hand", {
203
- get: function () {
204
- return this.material(MaterialType_1.MaterialType.Card).location(LocationType_1.LocationType.Hand).player(this.player);
205
- },
206
- enumerable: false,
207
- configurable: true
208
- });
209
- PlayCardsRule.prototype.kCombinations = function (arr, k) {
103
+ }
104
+ get firstPlayer() {
105
+ return this.remind(Memory.FirstPlayer);
106
+ }
107
+ get table() {
108
+ return this.material(MaterialType.Card).location(LocationType.MiddleOfTable).locationId(MiddleOfTable.Current);
109
+ }
110
+ get nextTable() {
111
+ return this.material(MaterialType.Card).location(LocationType.MiddleOfTable).locationId(MiddleOfTable.Next);
112
+ }
113
+ get playableCards() {
114
+ return this.material(MaterialType.Card).location((l) => (l.type === LocationType.Hand && l.player === this.player) || (l.type === LocationType.MiddleOfTable && l.id === MiddleOfTable.Next));
115
+ }
116
+ get hand() {
117
+ return this.material(MaterialType.Card).location(LocationType.Hand).player(this.player);
118
+ }
119
+ kCombinations(arr, k) {
210
120
  if (k === 0)
211
121
  return [[]];
212
122
  if (arr.length < k)
213
123
  return [];
214
124
  if (arr.length === k)
215
125
  return [arr];
216
- var _a = __read(arr), first = _a[0], rest = _a.slice(1);
217
- return __spreadArray(__spreadArray([], __read(this.kCombinations(rest, k)), false), __read(this.kCombinations(rest, k - 1).map(function (comb) { return __spreadArray([first], __read(comb), false); })), false);
218
- };
219
- PlayCardsRule.prototype.concatCardValue = function (cards) {
220
- var values = cards.map(function (card) { return (0, Card_1.getCardValue)(card); }).sort(function (a, b) { return (0, Card_1.getCardValue)(b) - (0, Card_1.getCardValue)(a); });
126
+ const [first, ...rest] = arr;
127
+ return [...this.kCombinations(rest, k), ...this.kCombinations(rest, k - 1).map((comb) => [first, ...comb])];
128
+ }
129
+ concatCardValue(cards) {
130
+ const values = cards.map((card) => getCardValue(card)).sort((a, b) => getCardValue(b) - getCardValue(a));
221
131
  return parseInt(values.join(''), 10);
222
- };
223
- PlayCardsRule.prototype.getPlayableCombinations = function (hand, tableCount, tableValue) {
224
- var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
225
- var results = [];
226
- var byColor = (0, groupBy_1.default)(hand, function (card) { return card % 10; });
227
- var byValue = (0, groupBy_1.default)(hand, function (card) { return Math.floor(card / 10); });
228
- try {
229
- for (var _e = __values([byColor, byValue]), _f = _e.next(); !_f.done; _f = _e.next()) {
230
- var group = _f.value;
231
- try {
232
- for (var _g = (e_2 = void 0, __values(Object.values(group))), _h = _g.next(); !_h.done; _h = _g.next()) {
233
- var cards = _h.value;
234
- try {
235
- for (var _j = (e_3 = void 0, __values([tableCount, tableCount + 1])), _k = _j.next(); !_k.done; _k = _j.next()) {
236
- var count = _k.value;
237
- if (cards.length >= count) {
238
- try {
239
- for (var _l = (e_4 = void 0, __values(this.kCombinations(cards, count))), _m = _l.next(); !_m.done; _m = _l.next()) {
240
- var comb = _m.value;
241
- if (this.concatCardValue(comb) > tableValue) {
242
- results.push(comb);
243
- }
244
- }
245
- }
246
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
247
- finally {
248
- try {
249
- if (_m && !_m.done && (_d = _l.return)) _d.call(_l);
250
- }
251
- finally { if (e_4) throw e_4.error; }
252
- }
253
- }
254
- }
255
- }
256
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
257
- finally {
258
- try {
259
- if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
132
+ }
133
+ getPlayableCombinations(hand, tableCount, tableValue) {
134
+ const results = [];
135
+ const byColor = groupBy(hand, (card) => card % 10);
136
+ const byValue = groupBy(hand, (card) => Math.floor(card / 10));
137
+ for (const group of [byColor, byValue]) {
138
+ for (const cards of Object.values(group)) {
139
+ for (const count of [tableCount, tableCount + 1]) {
140
+ if (cards.length >= count) {
141
+ for (const comb of this.kCombinations(cards, count)) {
142
+ if (this.concatCardValue(comb) > tableValue) {
143
+ results.push(comb);
260
144
  }
261
- finally { if (e_3) throw e_3.error; }
262
145
  }
263
146
  }
264
147
  }
265
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
266
- finally {
267
- try {
268
- if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
269
- }
270
- finally { if (e_2) throw e_2.error; }
271
- }
272
148
  }
273
149
  }
274
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
275
- finally {
276
- try {
277
- if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
278
- }
279
- finally { if (e_1) throw e_1.error; }
280
- }
281
- var unique = (0, uniqWith_1.default)(results, function (a, b) { return (0, isEqual_1.default)((0, orderBy_1.default)(a), (0, orderBy_1.default)(b)); });
150
+ const unique = uniqWith(results, (a, b) => isEqual(orderBy(a), orderBy(b)));
282
151
  return unique;
283
- };
284
- return PlayCardsRule;
285
- }(BasePlayerTurn_1.BasePlayerTurn));
286
- exports.PlayCardsRule = PlayCardsRule;
152
+ }
153
+ }
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RuleId = void 0;
4
- var RuleId;
1
+ export var RuleId;
5
2
  (function (RuleId) {
6
3
  RuleId[RuleId["PlayCards"] = 1] = "PlayCards";
7
4
  RuleId[RuleId["PickCard"] = 2] = "PickCard";
8
5
  RuleId[RuleId["EndOfRound"] = 3] = "EndOfRound";
9
6
  RuleId[RuleId["DealCards"] = 4] = "DealCards";
10
7
  RuleId[RuleId["ChangePlayer"] = 5] = "ChangePlayer";
11
- })(RuleId = exports.RuleId || (exports.RuleId = {}));
8
+ })(RuleId || (RuleId = {}));
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Sort = void 0;
4
- var Sort;
1
+ export var Sort;
5
2
  (function (Sort) {
6
3
  Sort[Sort["Color"] = 1] = "Color";
7
4
  Sort[Sort["ValueAsc"] = 2] = "ValueAsc";
8
5
  Sort[Sort["ValueDesc"] = 3] = "ValueDesc";
9
- })(Sort = exports.Sort || (exports.Sort = {}));
6
+ })(Sort || (Sort = {}));
@@ -1,36 +1,7 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.EndHelper = void 0;
19
- var rules_api_1 = require("@gamepark/rules-api");
20
- var ScoreHelper_1 = require("./ScoreHelper");
21
- var EndHelper = (function (_super) {
22
- __extends(EndHelper, _super);
23
- function EndHelper() {
24
- return _super !== null && _super.apply(this, arguments) || this;
1
+ import { MaterialRulesPart } from '@gamepark/rules-api';
2
+ import { ScoreHelper } from './ScoreHelper';
3
+ export class EndHelper extends MaterialRulesPart {
4
+ get isEnded() {
5
+ return this.game.players.some((p) => new ScoreHelper(this.game, p).score >= 15);
25
6
  }
26
- Object.defineProperty(EndHelper.prototype, "isEnded", {
27
- get: function () {
28
- var _this = this;
29
- return this.game.players.some(function (p) { return new ScoreHelper_1.ScoreHelper(_this.game, p).score >= 15; });
30
- },
31
- enumerable: false,
32
- configurable: true
33
- });
34
- return EndHelper;
35
- }(rules_api_1.MaterialRulesPart));
36
- exports.EndHelper = EndHelper;
7
+ }
@@ -1,48 +1,19 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
18
- return (mod && mod.__esModule) ? mod : { "default": mod };
19
- };
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.ScoreHelper = void 0;
22
- var rules_api_1 = require("@gamepark/rules-api");
23
- var sum_1 = __importDefault(require("lodash/sum"));
24
- var Memory_1 = require("../Memory");
25
- var ScoreHelper = (function (_super) {
26
- __extends(ScoreHelper, _super);
27
- function ScoreHelper(game, player) {
28
- var _this = _super.call(this, game) || this;
29
- _this.player = player;
30
- return _this;
1
+ import { MaterialRulesPart } from '@gamepark/rules-api';
2
+ import sum from 'lodash/sum';
3
+ import { Memory } from '../Memory';
4
+ export class ScoreHelper extends MaterialRulesPart {
5
+ player;
6
+ constructor(game, player) {
7
+ super(game);
8
+ this.player = player;
31
9
  }
32
- ScoreHelper.prototype.isWinningRound = function (round) {
10
+ isWinningRound(round) {
33
11
  return this.getRoundScore(round) === 0;
34
- };
35
- Object.defineProperty(ScoreHelper.prototype, "score", {
36
- get: function () {
37
- return (0, sum_1.default)(this.remind(Memory_1.Memory.PlayerScore, this.player));
38
- },
39
- enumerable: false,
40
- configurable: true
41
- });
42
- ScoreHelper.prototype.getRoundScore = function (round) {
43
- var _a;
44
- return (_a = this.remind(Memory_1.Memory.PlayerScore, this.player)) === null || _a === void 0 ? void 0 : _a[round - 1];
45
- };
46
- return ScoreHelper;
47
- }(rules_api_1.MaterialRulesPart));
48
- exports.ScoreHelper = ScoreHelper;
12
+ }
13
+ get score() {
14
+ return sum(this.remind(Memory.PlayerScore, this.player));
15
+ }
16
+ getRoundScore(round) {
17
+ return this.remind(Memory.PlayerScore, this.player)?.[round - 1];
18
+ }
19
+ }
@@ -1,35 +1,7 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.SortHelper = void 0;
19
- var rules_api_1 = require("@gamepark/rules-api");
20
- var Card_1 = require("../../material/Card");
21
- var SortHelper = (function (_super) {
22
- __extends(SortHelper, _super);
23
- function SortHelper() {
24
- return _super !== null && _super.apply(this, arguments) || this;
1
+ import { MaterialRulesPart } from '@gamepark/rules-api';
2
+ import { getCardColor, getCardValue } from '../../material/Card';
3
+ export class SortHelper extends MaterialRulesPart {
4
+ get sortByValue() {
5
+ return [(item) => -getCardValue(item.id), (item) => getCardColor(item.id)];
25
6
  }
26
- Object.defineProperty(SortHelper.prototype, "sortByValue", {
27
- get: function () {
28
- return [function (item) { return -(0, Card_1.getCardValue)(item.id); }, function (item) { return (0, Card_1.getCardColor)(item.id); }];
29
- },
30
- enumerable: false,
31
- configurable: true
32
- });
33
- return SortHelper;
34
- }(rules_api_1.MaterialRulesPart));
35
- exports.SortHelper = SortHelper;
7
+ }
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@gamepark/odin",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "The rules of Odin adapted for Game Park",
5
+ "type": "module",
5
6
  "sideEffects": false,
6
7
  "main": "dist/index.js",
7
8
  "types": "dist/index.d.ts",
@@ -29,5 +30,5 @@
29
30
  "i18next": "^22.0.3",
30
31
  "lodash": "^4.17.21"
31
32
  },
32
- "gitHead": "d2d8272afb68c2035b154c54a38265bdabf4ad50"
33
+ "gitHead": "37b0ac0aa872e97847bbee028a8843f8bbc8591f"
33
34
  }