Added frame toggling for preview

This commit is contained in:
Grzegorz 2018-09-02 22:51:02 +02:00 committed by Julian Descottes
parent 6e84f0a2b5
commit e5d89104a1
5 changed files with 53 additions and 6 deletions

View File

@ -135,6 +135,10 @@
cursor: default; cursor: default;
} }
.preview-tile .tile-overlay.tile-count.toggled {
background-color: rgba(111, 215, 0, 0.6);
}
.preview-tile .tile-overlay.delete-frame-action { .preview-tile .tile-overlay.delete-frame-action {
top: 0; top: 0;
right: 0; right: 0;

View File

@ -5,7 +5,8 @@
SELECT : 'select', SELECT : 'select',
CLONE : 'clone', CLONE : 'clone',
DELETE : 'delete', DELETE : 'delete',
NEW_FRAME : 'newframe' NEW_FRAME : 'newframe',
TOGGLE: 'toggle'
}; };
ns.FramesListController = function (piskelController, container) { ns.FramesListController = function (piskelController, container) {
@ -114,6 +115,9 @@
this.tiles.push(newtile); this.tiles.push(newtile);
this.previewList.insertBefore(newtile, this.addFrameTile); this.previewList.insertBefore(newtile, this.addFrameTile);
this.updateScrollerOverflows(); this.updateScrollerOverflows();
} else if (action == ACTION.TOGGLE) {
var frame = this.piskelController.getCurrentLayer().getFrameAt(index);
frame.toggled = !frame.toggled;
} }
this.flagForRedraw_(); this.flagForRedraw_();
@ -127,10 +131,19 @@
// Remove selected class // Remove selected class
this.tiles[i].classList.remove('selected'); this.tiles[i].classList.remove('selected');
// Remove toggle class
this.tiles[i].querySelector('.tile-count').classList.remove('toggled');
// Update tile numbers // Update tile numbers
this.tiles[i].setAttribute('data-tile-number', i); this.tiles[i].setAttribute('data-tile-number', i);
this.tiles[i].querySelector('.tile-count').innerHTML = (i + 1); this.tiles[i].querySelector('.tile-count').innerHTML = (i + 1);
// Update toggle
var frame = this.piskelController.getCurrentLayer().getFrameAt(i);
if (frame.toggled) {
this.tiles[i].querySelector('.tile-count').classList.add('toggled');
}
// Check if any tile is updated // Check if any tile is updated
var hash = this.piskelController.getCurrentLayer().getFrameAt(i).getHash(); var hash = this.piskelController.getCurrentLayer().getFrameAt(i).getHash();
if (this.tiles[i].getAttribute('data-tile-hash') !== hash) { if (this.tiles[i].getAttribute('data-tile-hash') !== hash) {
@ -290,8 +303,12 @@
previewTileRoot.appendChild(dndHandle); previewTileRoot.appendChild(dndHandle);
// Add tile count // Add tile count
var tileCount = document.createElement('div'); var tileCount = document.createElement('button');
tileCount.className = 'tile-overlay tile-count'; tileCount.setAttribute('rel', 'tooltip');
tileCount.setAttribute('title', 'Toggle for preview');
tileCount.setAttribute('data-tile-number', tileNumber);
tileCount.setAttribute('data-tile-action', ACTION.TOGGLE);
tileCount.className = 'tile-overlay tile-count toggle-frame-action';
tileCount.innerHTML = tileNumber + 1; tileCount.innerHTML = tileNumber + 1;
previewTileRoot.appendChild(tileCount); previewTileRoot.appendChild(tileCount);

View File

@ -158,6 +158,29 @@
}); });
}; };
ns.PiskelController.prototype.getFrames = function () {
var layer = this.getCurrentLayer();
return layer.getFrames();
};
ns.PiskelController.prototype.getToggledFrameIndexes = function () {
var frameIndexes = this.getFrames()
/* Replace each frame with its index
or -1 if it's not toggled */
.map(
function(frame, idx) {
var idx;
idx += 1;
return (frame.toggled) ? idx - 1 : -1;
})
/* Filter out untoggled frames */
.filter(
function(frame) {
return frame >= 0;
});
return frameIndexes;
};
ns.PiskelController.prototype.getFrameCount = function () { ns.PiskelController.prototype.getFrameCount = function () {
return this.piskel.getFrameCount(); return this.piskel.getFrameCount();
}; };

View File

@ -281,12 +281,14 @@
return this.piskelController.getCurrentFrameIndex(); return this.piskelController.getCurrentFrameIndex();
} else { } else {
var index = Math.floor(this.elapsedTime / (1000 / this.fps)); var index = Math.floor(this.elapsedTime / (1000 / this.fps));
if (!this.piskelController.hasFrameAt(index)) { var frameIndexes = this.piskelController.getToggledFrameIndexes();
if (frameIndexes.length <= index) {
this.elapsedTime = 0; this.elapsedTime = 0;
index = 0; index = (frameIndexes.length) ? frameIndexes[0] : this.piskelController.getCurrentFrameIndex();
}
return index; return index;
} }
return frameIndexes[index];
}
}; };
/** /**

View File

@ -9,6 +9,7 @@
this.version = 0; this.version = 0;
this.pixels = ns.Frame.createEmptyPixelGrid_(width, height); this.pixels = ns.Frame.createEmptyPixelGrid_(width, height);
this.stateIndex = 0; this.stateIndex = 0;
this.toggled = true;
} else { } else {
throw 'Bad arguments in pskl.model.Frame constructor : ' + width + ', ' + height; throw 'Bad arguments in pskl.model.Frame constructor : ' + width + ', ' + height;
} }