intval3/lib/sequence/index.js

76 lines
2.3 KiB
JavaScript
Raw Normal View History

2019-10-11 21:53:41 +00:00
'use strict';
2019-10-16 14:58:46 +00:00
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
2019-10-16 14:58:46 +00:00
const v4_1 = __importDefault(require("uuid/v4"));
2019-10-11 21:53:41 +00:00
const log = require('../log')('seq');
2019-10-31 02:32:52 +00:00
const delay_1 = require("../delay");
const MAX_INTEGER = 2147483647;
2017-12-20 23:40:51 +00:00
/** Object sequence features */
class Sequence {
2019-10-31 02:32:52 +00:00
/**
* @constructor
*
* Create a sequencer object from class
**/
constructor(intval) {
2019-10-16 14:58:46 +00:00
this.active = false;
2019-10-31 02:32:52 +00:00
this.delay = 0;
2019-10-16 14:58:46 +00:00
this.count = 0;
2019-10-31 02:32:52 +00:00
/**
* Stop a running sequence and reset counter and delay
**/
this.stop = function () {
2019-10-16 14:58:46 +00:00
this.active = false;
this.count = 0;
2019-10-31 02:32:52 +00:00
this.delay = 0;
};
this.intval = intval;
this.intval.sequence = function () {
if (this.active) {
this.stop();
return false;
}
else {
this.start();
return true;
}
};
2019-10-11 21:53:41 +00:00
}
2019-10-16 14:58:46 +00:00
/**
* Start running a "sequence" of frames. Shoots a continuous sequence
* of single frames with a delay in between each one.
**/
2019-10-31 02:32:52 +00:00
async start(options) {
let len = typeof options.len !== 'undefined' ? options.len : MAX_INTEGER;
let multiple = typeof options.multiple !== 'undefined' ? options.multiple : 1;
2019-10-16 14:58:46 +00:00
this.id = v4_1.default();
2019-10-31 02:32:52 +00:00
this.delay = typeof options.delay !== 'undefined' ? options.delay : 0;
this.count = 0;
for (let i = 0; i < len; i++) {
if (multiple > 1) {
for (let x = 0; x < multiple; x++) {
await this.intval.frame();
log.info({ id: this.id, count: this.count });
2019-10-16 14:58:46 +00:00
this.count++;
}
2019-10-11 21:53:41 +00:00
}
else {
2019-10-31 02:32:52 +00:00
await this.intval.frame();
log.info({ id: this.id, count: this.count });
this.count++;
}
if (this.delay > 0) {
await delay_1.delay(this.delay);
}
if (!this.active) {
break;
2019-10-11 21:53:41 +00:00
}
}
2019-10-31 02:32:52 +00:00
this.stop();
2019-10-11 21:53:41 +00:00
}
}
2019-10-31 02:32:52 +00:00
exports.Sequence = Sequence;
module.exports = Sequence;
2019-10-11 21:53:41 +00:00
//# sourceMappingURL=index.js.map