UNPKG

step-sequence-generator

Version:

A step sequence generator for figure skating programs

60 lines (59 loc) 2.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DefaultStepSequenceGenerator = void 0; const AbstractSequenceGenerator_1 = require("./AbstractSequenceGenerator"); const custom_errors_1 = require("../../errors/custom-errors"); const filter_stategy_name_enum_1 = require("../../shared/enums/filter-stategy-name.enum"); class DefaultStepSequenceGenerator extends AbstractSequenceGenerator_1.AbstractSequenceGenerator { constructor(data) { const { library, context, counter, chanceRatioMapGenerator, roulette, tracker, filterStrategy, threeTurnsBlockGenerator, compassArc, } = data; super({ library, context, counter, chanceRatioMapGenerator, roulette, tracker, filterStrategy, compassArc, }); this.threeTurnsBlockGenerator = threeTurnsBlockGenerator; this.serviceMessage = { text: 'Генерация выполнена успешно', code: 'OK', }; } generate(stepAmountBySequenceLevel, distanceFactor) { this.reset(); this.threeTurnsBlockGenerator.reset(); try { while (this.counter.difficultTurnsOriginAmount < stepAmountBySequenceLevel) { if (this.isTimeToInsertThreeTurnsBlock()) { const movements = this.threeTurnsBlockGenerator.generate(this.context.currentStep || this.generateMovement(distanceFactor, this.getFilterStrategy(filter_stategy_name_enum_1.FilterStrategyName.DEFAULT)), distanceFactor); movements.forEach((movement) => { this.update(movement); }); } else { const movement = this.generateMovement(distanceFactor, this.getFilterStrategy(filter_stategy_name_enum_1.FilterStrategyName.DEFAULT)); this.update(movement); } } } catch (error) { if (error instanceof custom_errors_1.SequenceTrackerError) { this.serviceMessage = { text: 'Генерация прервана из-за внутренней ошибки', code: String(error.code), }; console.debug('from DefaultStepSequenceGenerator', this.serviceMessage.code); } } return this.stepSequence; } isTimeToInsertThreeTurnsBlock() { return this.threeTurnsBlockGenerator.blockAmount < 2 ? this.getRandomIndex(2) === 1 : false; } } exports.DefaultStepSequenceGenerator = DefaultStepSequenceGenerator;