2023-01-19 22:32:04 +01:00
|
|
|
/**
|
|
|
|
* @param {number} duration
|
|
|
|
*/
|
2023-01-13 00:25:05 +01:00
|
|
|
const Frame = function (duration) {
|
|
|
|
this.layers = [];
|
|
|
|
this.duration = duration;
|
|
|
|
}
|
|
|
|
|
2023-01-14 00:04:38 +01:00
|
|
|
const LED_COLOR = {
|
|
|
|
WHITE: 0,
|
|
|
|
RED: 1,
|
|
|
|
GREEN: 2,
|
|
|
|
BLUE: 3,
|
|
|
|
}
|
|
|
|
|
|
|
|
const ANIMATION_FRAME_QUEUE = [];
|
|
|
|
|
|
|
|
const COLOR_CLASS = [];
|
|
|
|
COLOR_CLASS[LED_COLOR.WHITE] = 'led-white';
|
|
|
|
COLOR_CLASS[LED_COLOR.RED] = 'led-red';
|
|
|
|
COLOR_CLASS[LED_COLOR.GREEN] = 'led-green';
|
|
|
|
COLOR_CLASS[LED_COLOR.BLUE] = 'led-blue';
|
|
|
|
|
2023-01-19 22:32:04 +01:00
|
|
|
/**
|
|
|
|
* @param {string} id
|
|
|
|
*/
|
2023-01-14 00:04:38 +01:00
|
|
|
const Selector = function (id) {
|
|
|
|
this.items = [];
|
|
|
|
this.currentItem = 0;
|
|
|
|
this.html = document.getElementById(id);
|
|
|
|
this.htmlDisplay = this.html.querySelector('.selector-display');
|
|
|
|
this.htmlItems = this.html.querySelector('.selector-items');
|
|
|
|
|
|
|
|
this.htmlItems.hidden = true;
|
|
|
|
|
|
|
|
this.htmlDisplay.addEventListener(
|
|
|
|
'click',
|
|
|
|
() => {
|
|
|
|
this.htmlItems.hidden = !this.htmlItems.hidden;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
for (const i in this.htmlItems.children) {
|
|
|
|
this.htmlItems.children.item(i).addEventListener(
|
|
|
|
'click',
|
|
|
|
() => {
|
|
|
|
this.selectItem(i);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.onSelect = function () {};
|
|
|
|
|
2023-01-19 22:32:04 +01:00
|
|
|
/**
|
|
|
|
* @param {number} index
|
|
|
|
*/
|
2023-01-14 00:04:38 +01:00
|
|
|
this.selectItem = function (index) {
|
|
|
|
this.htmlItems.hidden = true;
|
|
|
|
|
|
|
|
if (index !== this.currentItem) {
|
|
|
|
this.currentItem = index;
|
|
|
|
|
|
|
|
this.htmlDisplay.innerHTML = this.htmlItems.children.item(index).innerHTML;
|
|
|
|
|
|
|
|
this.onSelect(index);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-01-19 22:32:04 +01:00
|
|
|
/**
|
|
|
|
* @param {number} width
|
|
|
|
* @param {number} depth
|
|
|
|
* @param {number} height
|
|
|
|
*/
|
2023-01-13 00:25:05 +01:00
|
|
|
const FrameFactory = function (width, depth, height) {
|
|
|
|
this.width = width;
|
|
|
|
this.depth = depth;
|
|
|
|
this.height = height;
|
|
|
|
|
2023-01-19 22:32:04 +01:00
|
|
|
/**
|
|
|
|
* @param {number} duration
|
|
|
|
* @returns Frame
|
|
|
|
*/
|
2023-01-13 00:25:05 +01:00
|
|
|
this.getFrame = function (duration) {
|
|
|
|
const frame = new Frame(duration);
|
|
|
|
|
|
|
|
for (let z = 0; z < this.height; z++) {
|
|
|
|
const layer = [];
|
|
|
|
|
|
|
|
for (let led = 0; led < this.width * this.depth; led++) {
|
|
|
|
layer.push(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
frame.layers.push(layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-19 22:32:04 +01:00
|
|
|
/**
|
|
|
|
* @param {number} width
|
|
|
|
* @param {number} depth
|
|
|
|
* @param {number} height
|
|
|
|
*/
|
2023-01-13 00:25:05 +01:00
|
|
|
const Cube = function (width, depth, height) {
|
|
|
|
this.width = width;
|
|
|
|
this.depth = depth;
|
|
|
|
this.height = height;
|
|
|
|
this.html = document.getElementById('cube');
|
|
|
|
this.frames = [];
|
|
|
|
this.currentFrame = 0;
|
|
|
|
|
|
|
|
this.setup = function () {
|
|
|
|
this._setupHtml();
|
|
|
|
}
|
|
|
|
|
2023-01-19 22:32:04 +01:00
|
|
|
/**
|
|
|
|
* @param {number} frameIndex
|
|
|
|
*/
|
2023-01-13 00:25:05 +01:00
|
|
|
this.setCurrentFrame = function (frameIndex) {
|
|
|
|
this.currentFrame = frameIndex;
|
|
|
|
|
|
|
|
this._loadFrame(frameIndex);
|
|
|
|
}
|
|
|
|
|
2023-01-19 22:32:04 +01:00
|
|
|
/**
|
|
|
|
* @param {Frame} frame
|
|
|
|
*/
|
2023-01-14 00:04:38 +01:00
|
|
|
this.addFrame = function (frame) {
|
|
|
|
this.frames.push(frame);
|
|
|
|
}
|
|
|
|
|
2023-01-19 22:32:04 +01:00
|
|
|
/**
|
|
|
|
* @param {number} frameIndex
|
|
|
|
*/
|
2023-01-17 23:13:34 +01:00
|
|
|
this.deleteFrame = function (frameIndex) {
|
|
|
|
this.frames = this.frames.slice(0, frameIndex).concat(
|
|
|
|
this.frames.slice(frameIndex + 1)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-01-19 22:32:04 +01:00
|
|
|
/**
|
|
|
|
* @param {number} layerIndex
|
|
|
|
* @param {number} ledIndex
|
|
|
|
*/
|
2023-01-13 00:25:05 +01:00
|
|
|
this.switchLed = function (layerIndex, ledIndex) {
|
|
|
|
this.frames[this.currentFrame].layers[layerIndex][ledIndex] = !this.frames[this.currentFrame].layers[layerIndex][ledIndex];
|
|
|
|
}
|
|
|
|
|
2023-01-19 22:32:04 +01:00
|
|
|
/**
|
|
|
|
* @param {number} layerIndex
|
|
|
|
* @param {boolean} state
|
|
|
|
*/
|
2023-01-13 00:25:05 +01:00
|
|
|
this.setLayer = function (layerIndex, state) {
|
|
|
|
for (let index = 0; index < this.width * this.depth; index++) {
|
|
|
|
this.frames[this.currentFrame].layers[layerIndex][index] = state;
|
|
|
|
}
|
|
|
|
|
2023-01-14 00:04:38 +01:00
|
|
|
for (const row of this.html.children.item(this.height - layerIndex - 1).children) {
|
2023-01-13 00:25:05 +01:00
|
|
|
for (const led of row.children) {
|
|
|
|
this._setLed(led, state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-19 22:32:04 +01:00
|
|
|
/**
|
|
|
|
* @param {LED_COLOR} color
|
|
|
|
*/
|
2023-01-14 00:04:38 +01:00
|
|
|
this.setLedColor = function (color) {
|
|
|
|
for (const layer of this.html.children) {
|
|
|
|
for (const row of layer.children) {
|
|
|
|
for (const led of row.children) {
|
|
|
|
for (const cssClass of COLOR_CLASS) {
|
|
|
|
led.classList.remove(cssClass);
|
|
|
|
}
|
|
|
|
|
|
|
|
led.classList.add(COLOR_CLASS[color]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-19 22:32:04 +01:00
|
|
|
/**
|
|
|
|
* @param {number} frameIndex
|
|
|
|
*/
|
2023-01-13 00:25:05 +01:00
|
|
|
this._loadFrame = function (frameIndex) {
|
|
|
|
for (let layer = 0; layer < this.frames[frameIndex].layers.length; layer++) {
|
|
|
|
for (let row = 0; row < this.depth; row++) {
|
|
|
|
for (let led = 0; led < this.width; led++) {
|
|
|
|
const state = this.frames[frameIndex].layers[layer][row * this.depth + led];
|
|
|
|
|
2023-01-14 00:04:38 +01:00
|
|
|
this._setLed(this.html.children.item(this.height - layer - 1).children.item(row).children.item(led), state);
|
2023-01-13 00:25:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this._setupHtml = function () {
|
|
|
|
for (let z = 0; z < this.height; z++) {
|
|
|
|
const layerElement = document.createElement('div');
|
|
|
|
layerElement.classList.add('layer');
|
|
|
|
|
|
|
|
for (let y = 0; y < this.depth; y++) {
|
|
|
|
const row = document.createElement('div');
|
|
|
|
row.classList.add('row');
|
|
|
|
|
|
|
|
for (let x = 0; x < this.width; x++) {
|
|
|
|
const led = document.createElement('div');
|
|
|
|
led.classList.add('led', 'led-off');
|
|
|
|
|
|
|
|
led.addEventListener(
|
2023-01-17 23:13:34 +01:00
|
|
|
'mousedown',
|
2023-01-13 00:25:05 +01:00
|
|
|
(event) => {
|
|
|
|
const index = y * this.depth + x;
|
|
|
|
const layer = this.height - z - 1;
|
|
|
|
|
|
|
|
this.switchLed(layer, index);
|
|
|
|
this._setLed(event.target, this.frames[this.currentFrame].layers[layer][index]);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2023-01-14 00:04:38 +01:00
|
|
|
led.addEventListener(
|
|
|
|
'mouseover',
|
|
|
|
(event) => {
|
|
|
|
if (event.buttons === 1) {
|
|
|
|
const index = y * this.depth + x;
|
|
|
|
const layer = this.height - z - 1;
|
|
|
|
|
|
|
|
this.switchLed(layer, index);
|
|
|
|
this._setLed(event.target, this.frames[this.currentFrame].layers[layer][index]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2023-01-13 00:25:05 +01:00
|
|
|
row.appendChild(led);
|
|
|
|
}
|
|
|
|
|
|
|
|
layerElement.appendChild(row);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.html.appendChild(layerElement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-19 22:32:04 +01:00
|
|
|
/**
|
|
|
|
* @param {HTMLElement} ledHtml
|
|
|
|
* @param {boolean} state
|
|
|
|
*/
|
2023-01-13 00:25:05 +01:00
|
|
|
this._setLed = function (ledHtml, state) {
|
|
|
|
if (state) {
|
|
|
|
ledHtml.classList.remove('led-off');
|
|
|
|
} else {
|
|
|
|
ledHtml.classList.add('led-off');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-19 22:32:04 +01:00
|
|
|
/**
|
|
|
|
* @param {string} id
|
|
|
|
*/
|
2023-01-14 00:04:38 +01:00
|
|
|
const FrameMenu = function (id) {
|
|
|
|
this.html = document.getElementById(id);
|
|
|
|
this.htmlSlider = this.html.querySelector('#frame-slider');
|
|
|
|
this.htmlDisplayCurrentFrame = this.html.querySelector('#current-frame');
|
|
|
|
this.htmlDisplayFrames = this.html.querySelector('#frame-number');
|
|
|
|
this.htmlButtonAddFrameBefore = this.html.querySelector('#button-add-frame-before');
|
|
|
|
this.htmlButtonAddFrameAfter = this.html.querySelector('#button-add-frame-after');
|
|
|
|
this.htmlButtonToggleAnimation = this.html.querySelector('#button-toggle-animation');
|
2023-01-17 23:13:34 +01:00
|
|
|
this.htmlButtonDeleteFrame = this.html.querySelector('#button-delete-frame');
|
2023-01-14 00:04:38 +01:00
|
|
|
this.htmlInputDuration = this.html.querySelector('#frame-duration');
|
2023-01-19 00:03:33 +01:00
|
|
|
this.htmlMenuGlobalDuration = this.html.querySelector('#global-duration-popup');
|
|
|
|
this.htmlButtonGlobalDuration = this.html.querySelector('#button-scale-duration');
|
|
|
|
this.htmlGlobalDurationSlider = this.html.querySelector('#global-duration-slider');
|
|
|
|
this.htmlGlobalDurationValue = this.html.querySelector('#global-duration-value');
|
|
|
|
this.htmlButtonChangeGlobalDuration = this.html.querySelector('#button-change-global-duration');
|
|
|
|
this.htmlButtonCloseGlobalDurationPopup = this.html.querySelector('#button-close-menu');
|
|
|
|
|
2023-01-14 00:04:38 +01:00
|
|
|
|
|
|
|
this.isAnimationPlaying = false;
|
|
|
|
|
|
|
|
this.htmlSlider.addEventListener(
|
|
|
|
'input',
|
|
|
|
() => {
|
|
|
|
this._updateFramePosition();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
this.htmlButtonAddFrameBefore.addEventListener(
|
|
|
|
'click',
|
|
|
|
() => {
|
|
|
|
this._increaseSliderMax();
|
|
|
|
this.onFramePrepend();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
this.htmlButtonAddFrameAfter.addEventListener(
|
|
|
|
'click',
|
|
|
|
() => {
|
|
|
|
this._increaseSliderMax();
|
|
|
|
this.onFrameAppend();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
this.htmlInputDuration.addEventListener(
|
|
|
|
'input',
|
|
|
|
() => {
|
|
|
|
this.onInputDuration(this.htmlInputDuration.value);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
this.htmlButtonToggleAnimation.addEventListener(
|
|
|
|
'click',
|
|
|
|
() => {
|
|
|
|
this.isAnimationPlaying = !this.isAnimationPlaying;
|
|
|
|
|
|
|
|
this._updateToggleButton();
|
|
|
|
this.onToggleAnimation(this.isAnimationPlaying);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2023-01-17 23:13:34 +01:00
|
|
|
this.htmlButtonDeleteFrame.addEventListener(
|
|
|
|
'click',
|
|
|
|
() => {
|
|
|
|
this._decreaseSliderMax();
|
|
|
|
this.onFrameDelete();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2023-01-19 00:03:33 +01:00
|
|
|
this.htmlButtonGlobalDuration.addEventListener(
|
|
|
|
'click',
|
|
|
|
() => {
|
|
|
|
this.htmlMenuGlobalDuration.style.display = 'inherit';
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
this.htmlGlobalDurationSlider.addEventListener(
|
|
|
|
'input',
|
|
|
|
() => {
|
|
|
|
this.htmlGlobalDurationValue.innerText = this.htmlGlobalDurationSlider.value;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
this.htmlButtonChangeGlobalDuration.addEventListener(
|
|
|
|
'click',
|
|
|
|
() => {
|
|
|
|
this.onChangeGlobalDuration();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
this.htmlButtonCloseGlobalDurationPopup.addEventListener(
|
|
|
|
'click',
|
|
|
|
() => {
|
|
|
|
this.htmlMenuGlobalDuration.style.display = 'none';
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2023-01-19 22:32:04 +01:00
|
|
|
/**
|
|
|
|
* @param {number} frameIndex
|
|
|
|
*/
|
2023-01-14 00:04:38 +01:00
|
|
|
this.slideToFrame = function (frameIndex) {
|
|
|
|
this.htmlSlider.value = frameIndex + 1;
|
|
|
|
this._updateFramePosition();
|
|
|
|
}
|
|
|
|
|
2023-01-19 22:32:04 +01:00
|
|
|
/**
|
|
|
|
* @param {number} frameIndex
|
|
|
|
*/
|
2023-01-14 00:04:38 +01:00
|
|
|
this.setDuration = function (duration) {
|
|
|
|
this.htmlInputDuration.value = duration;
|
|
|
|
}
|
|
|
|
|
2023-01-17 23:13:34 +01:00
|
|
|
this.startAnimation = function () {
|
|
|
|
this.isAnimationPlaying = false;
|
|
|
|
|
|
|
|
this._updateToggleButton();
|
|
|
|
}
|
|
|
|
|
2023-01-14 00:04:38 +01:00
|
|
|
this.stopAnimation = function () {
|
|
|
|
this.isAnimationPlaying = false;
|
|
|
|
|
|
|
|
this._updateToggleButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.onFramePrepend = function () {}
|
|
|
|
|
|
|
|
this.onFrameAppend = function () {}
|
|
|
|
|
2023-01-17 23:13:34 +01:00
|
|
|
this.onFrameDelete = function () {}
|
|
|
|
|
2023-01-14 00:04:38 +01:00
|
|
|
this.onSlide = function () {}
|
|
|
|
|
|
|
|
this.onInputDuration = function () {}
|
|
|
|
|
|
|
|
this.onToggleAnimation = function () {}
|
|
|
|
|
2023-01-19 00:03:33 +01:00
|
|
|
this.onChangeGlobalDuration = function () {}
|
|
|
|
|
2023-01-14 00:04:38 +01:00
|
|
|
this._increaseSliderMax = function () {
|
|
|
|
const frameNumber = parseInt(this.htmlSlider.max) + 1;
|
|
|
|
|
|
|
|
this.htmlSlider.max = frameNumber;
|
|
|
|
this.htmlDisplayFrames.innerText = frameNumber;
|
|
|
|
|
|
|
|
if (frameNumber > 1) {
|
|
|
|
this.htmlButtonToggleAnimation.disabled = false;
|
|
|
|
}
|
2023-01-17 23:13:34 +01:00
|
|
|
|
|
|
|
this.htmlButtonDeleteFrame.disabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._decreaseSliderMax = function () {
|
|
|
|
const frameNumber = parseInt(this.htmlSlider.max) - 1;
|
|
|
|
|
|
|
|
this.htmlSlider.max = frameNumber;
|
|
|
|
this.htmlDisplayFrames.innerText = frameNumber;
|
|
|
|
|
|
|
|
if (frameNumber < 2) {
|
|
|
|
this.htmlButtonToggleAnimation.disabled = true;
|
|
|
|
this.htmlButtonDeleteFrame.disabled = true;
|
|
|
|
}
|
2023-01-14 00:04:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
this._updateFramePosition = function () {
|
|
|
|
this.htmlDisplayCurrentFrame.innerText = this.htmlSlider.value;
|
|
|
|
this.onSlide(this.htmlSlider.value - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
this._updateToggleButton = function () {
|
|
|
|
if (this.isAnimationPlaying) {
|
|
|
|
this.htmlButtonToggleAnimation.classList.add('icon-button-stop');
|
|
|
|
this.htmlButtonToggleAnimation.classList.remove('icon-button-play');
|
|
|
|
} else {
|
|
|
|
this.htmlButtonToggleAnimation.classList.add('icon-button-play');
|
|
|
|
this.htmlButtonToggleAnimation.classList.remove('icon-button-stop');
|
|
|
|
}
|
2023-01-17 23:13:34 +01:00
|
|
|
|
|
|
|
const elements = [
|
|
|
|
this.htmlSlider,
|
|
|
|
this.htmlButtonAddFrameAfter,
|
|
|
|
this.htmlButtonAddFrameBefore,
|
|
|
|
this.htmlInputDuration,
|
|
|
|
this.htmlButtonDeleteFrame,
|
|
|
|
];
|
|
|
|
|
|
|
|
for (const element of elements) {
|
|
|
|
element.disabled = this.isAnimationPlaying;
|
|
|
|
}
|
2023-01-14 00:04:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-13 00:25:05 +01:00
|
|
|
const WIDTH = 4;
|
|
|
|
const DEPTH = 4;
|
|
|
|
const HEIGHT = 4;
|
|
|
|
|
|
|
|
const cube = new Cube(WIDTH, DEPTH, HEIGHT);
|
|
|
|
cube.setup();
|
|
|
|
|
|
|
|
const frameFactory = new FrameFactory(WIDTH, DEPTH, HEIGHT);
|
|
|
|
|
2023-01-14 00:04:38 +01:00
|
|
|
cube.frames.push(frameFactory.getFrame(500));
|
2023-01-13 00:25:05 +01:00
|
|
|
cube.setCurrentFrame(0);
|
2023-01-14 00:04:38 +01:00
|
|
|
cube.setLedColor(LED_COLOR.RED);
|
|
|
|
|
|
|
|
const colorSelector = new Selector('color-selector');
|
|
|
|
colorSelector.onSelect = (index) => {
|
|
|
|
cube.setLedColor(index);
|
|
|
|
};
|
|
|
|
colorSelector.selectItem(LED_COLOR.RED);
|
|
|
|
|
|
|
|
const frameMenu = new FrameMenu('frame-menu');
|
|
|
|
frameMenu.onSlide = (frameIndex) => {
|
|
|
|
cube.setCurrentFrame(frameIndex);
|
|
|
|
frameMenu.setDuration(cube.frames[cube.currentFrame].duration);
|
|
|
|
}
|
|
|
|
frameMenu.onFramePrepend = () => {
|
|
|
|
cube.frames = cube.frames.slice(0, cube.currentFrame).concat(
|
|
|
|
[frameFactory.getFrame(cube.frames[cube.currentFrame].duration)].concat(
|
|
|
|
cube.frames.slice(cube.currentFrame)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
frameMenu.slideToFrame(cube.currentFrame - 1);
|
|
|
|
}
|
|
|
|
frameMenu.onFrameAppend = () => {
|
|
|
|
cube.frames = cube.frames.slice(0, cube.currentFrame + 1).concat(
|
|
|
|
[frameFactory.getFrame(cube.frames[cube.currentFrame].duration)].concat(
|
|
|
|
cube.frames.slice(cube.currentFrame + 1)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
frameMenu.slideToFrame(cube.currentFrame + 1);
|
|
|
|
}
|
|
|
|
frameMenu.onInputDuration = (duration) => {
|
|
|
|
if (+duration <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cube.frames[cube.currentFrame].duration = +duration;
|
|
|
|
}
|
|
|
|
frameMenu.onToggleAnimation = (isPlaying) => {
|
|
|
|
if (isPlaying) {
|
|
|
|
let duration = 0;
|
|
|
|
|
|
|
|
for (let frame = cube.currentFrame; frame < cube.frames.length; frame++) {
|
|
|
|
duration += cube.frames[frame].duration;
|
|
|
|
|
|
|
|
if (frame === cube.frames.length - 1) {
|
|
|
|
setTimeout(
|
|
|
|
() => {
|
|
|
|
frameMenu.stopAnimation();
|
|
|
|
},
|
|
|
|
duration
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
ANIMATION_FRAME_QUEUE.push(
|
|
|
|
setTimeout(
|
|
|
|
() => {
|
|
|
|
frameMenu.slideToFrame(frame + 1);
|
|
|
|
},
|
|
|
|
duration
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (const frame of ANIMATION_FRAME_QUEUE) {
|
|
|
|
clearTimeout(frame);
|
|
|
|
}
|
2023-01-17 23:13:34 +01:00
|
|
|
|
|
|
|
frameMenu.stopAnimation();
|
2023-01-14 00:04:38 +01:00
|
|
|
}
|
2023-01-17 23:13:34 +01:00
|
|
|
}
|
|
|
|
frameMenu.onFrameDelete = () => {
|
|
|
|
if (cube.frames.length < 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cube.deleteFrame(cube.currentFrame);
|
|
|
|
cube.currentFrame--;
|
|
|
|
cube.currentFrame = cube.currentFrame < 0 ? 0 : cube.currentFrame;
|
|
|
|
|
|
|
|
frameMenu.slideToFrame(cube.currentFrame);
|
2023-01-19 00:03:33 +01:00
|
|
|
}
|
|
|
|
frameMenu.onChangeGlobalDuration = () => {
|
|
|
|
const factor = frameMenu.htmlGlobalDurationSlider.value / 100;
|
|
|
|
|
|
|
|
for (const frame of cube.frames) {
|
|
|
|
frame.duration *= factor;
|
|
|
|
}
|
|
|
|
|
|
|
|
frameMenu.htmlInputDuration.value = cube.frames[cube.currentFrame].duration;
|
|
|
|
frameMenu.htmlMenuGlobalDuration.style.display = 'none';
|
|
|
|
frameMenu,htmlGlobalDurationSlider.value = 100;
|
2023-01-14 00:04:38 +01:00
|
|
|
}
|