g2o-player
Version:
46 lines (42 loc) • 1.54 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('g2o-reactive')) :
typeof define === 'function' && define.amd ? define(['exports', 'g2o-reactive'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MYLIB = {}, global.g2oReactive));
})(this, (function (exports, g2oReactive) { 'use strict';
class Player {
#board;
#frameCount;
/**
* The handle of the last frame requested.
*/
#handle = null;
constructor(board, callback) {
this.#board = board;
this.#frameCount = g2oReactive.effect(() => {
callback(board.frameCount);
});
}
dispose() {
if (this.#frameCount) {
this.#frameCount.dispose();
}
}
play() {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const animate = (timestamp) => {
this.#handle = null;
this.#board.update();
this.#handle = window.requestAnimationFrame(animate);
};
this.#handle = window.requestAnimationFrame(animate);
}
pause() {
if (typeof this.#handle === 'number') {
window.cancelAnimationFrame(this.#handle);
this.#handle = null;
}
}
}
exports.Player = Player;
}));
//# sourceMappingURL=index.js.map