UNPKG

cardation

Version:

fundation of card games, card model

45 lines (44 loc) 1.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const Persistence_1 = require("../../tool/Persistence"); /** * * Abstract class for all collection which implements the serialize method. * */ class Collection { _cardArray = []; getCardArray() { return this._cardArray; } /** * Insert card(s) to the collection. * @param index where to insert * @param cards the cards to be inserted */ insertCard(index, ...cards) { this.getCardArray().splice(index, 0, ...cards); } getDuplicatedCardArray() { return [...this._cardArray]; } getLength() { return this.getCardArray().length; } /** * Push card(s) to the collection. * @param card card to be push in * @todo avoid duplicate card object in a collection */ pushCard(...card) { this._cardArray.push(...card); } includes(card) { const cardArray = this.getDuplicatedCardArray(); return cardArray.find(element => card.equals(element)) ? true : false; } serialize() { return Persistence_1.default.serialize(this); } } exports.default = Collection;