UNPKG

marga

Version:
59 lines (58 loc) 1.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * The streak in the Big Road. */ class Streak { _firstEntity; _lastEntity; _next; _prev; _length = 0; getFirstEntity() { return this._firstEntity; } getLastEntity() { return this._lastEntity; } getNextStreak() { return this._next; } getPreviousStreak() { return this._prev; } setNextStreak(streak) { this._next = streak; } setPreviousStreak(streak) { this._prev = streak; streak.setNextStreak(this); } /** * How many entities are in this streak. * @return {number} The length of the streak */ getLength() { return this._length; } /** * Add an entity to the streak. The entity will be added to the end of the streak. If the entity is not the same(banco or punto) as the last entity in the streak, it will not be added. * @param {BigEntity} entity * @return {boolean} True if the entity was added, false if it was not */ addEntity(entity) { if (!this._lastEntity) { this._firstEntity = this._lastEntity = entity; this._length++; return true; } if (this.getLastEntity()?.isBanco != entity.isBanco) { return false; } entity.setPreviousEntity(this._lastEntity); this._lastEntity = entity; this._length++; return true; } } exports.default = Streak;