Add comments for hiddenFrames feature

This commit is contained in:
Julian Descottes 2018-10-07 14:02:18 +02:00
parent af9095b934
commit 0a64d62b84
3 changed files with 21 additions and 8 deletions

View File

@ -116,7 +116,7 @@
this.previewList.insertBefore(newtile, this.addFrameTile); this.previewList.insertBefore(newtile, this.addFrameTile);
this.updateScrollerOverflows(); this.updateScrollerOverflows();
} else if (action == ACTION.TOGGLE) { } else if (action == ACTION.TOGGLE) {
this.piskelController.toggleFrameAt(index); this.piskelController.toggleFrameVisibilityAt(index);
} }
this.flagForRedraw_(); this.flagForRedraw_();

View File

@ -146,6 +146,7 @@
l.removeFrameAt(index); l.removeFrameAt(index);
}); });
// Update the array of hidden frames since some hidden indexes might have shifted.
this.piskel.hiddenFrames = this.piskel.hiddenFrames.map(function (hiddenIndex) { this.piskel.hiddenFrames = this.piskel.hiddenFrames.map(function (hiddenIndex) {
if (hiddenIndex > index) { if (hiddenIndex > index) {
return hiddenIndex - 1; return hiddenIndex - 1;
@ -169,7 +170,11 @@
this.onFrameAddedAt_(index + 1); this.onFrameAddedAt_(index + 1);
}; };
ns.PiskelController.prototype.toggleFrameAt = function (index) { /**
* Toggle frame visibility for the frame at the provided index.
* A visible frame will be included in the animated preview.
*/
ns.PiskelController.prototype.toggleFrameVisibilityAt = function (index) {
var hiddenFrames = this.piskel.hiddenFrames; var hiddenFrames = this.piskel.hiddenFrames;
if (hiddenFrames.indexOf(index) === -1) { if (hiddenFrames.indexOf(index) === -1) {
hiddenFrames.push(index); hiddenFrames.push(index);
@ -188,16 +193,24 @@
l.moveFrame(fromIndex, toIndex); l.moveFrame(fromIndex, toIndex);
}); });
// Update the array of hidden frames since some hidden indexes might have shifted.
this.piskel.hiddenFrames = this.piskel.hiddenFrames.map(function (index) { this.piskel.hiddenFrames = this.piskel.hiddenFrames.map(function (index) {
if (index === fromIndex) { if (index === fromIndex) {
return toIndex; return toIndex;
} }
var direction = fromIndex < toIndex ? 1 : -1; // All the frames between fromIndex and toIndex changed their index.
var max = Math.max(fromIndex, toIndex); var isImpacted = index >= Math.min(fromIndex, toIndex) &&
var min = Math.min(fromIndex, toIndex); index <= Math.max(fromIndex, toIndex);
if (index >= min && index <= max) { if (isImpacted) {
return index - direction; if (fromIndex < toIndex) {
// If the frame moved to a higher index, all impacted frames had their index
// reduced by 1.
return index - 1;
} else {
// Otherwise, they had their index increased by 1.
return index + 1;
}
} }
}); });
}; };

View File

@ -37,7 +37,7 @@
this.saveWrap_('moveLayerDown', true); this.saveWrap_('moveLayerDown', true);
this.saveWrap_('removeCurrentLayer', true); this.saveWrap_('removeCurrentLayer', true);
this.saveWrap_('setLayerOpacityAt', true); this.saveWrap_('setLayerOpacityAt', true);
this.saveWrap_('toggleFrameAt', true); this.saveWrap_('toggleFrameVisibilityAt', true);
var shortcuts = pskl.service.keyboard.Shortcuts; var shortcuts = pskl.service.keyboard.Shortcuts;
pskl.app.shortcutService.registerShortcut(shortcuts.MISC.PREVIOUS_FRAME, this.selectPreviousFrame.bind(this)); pskl.app.shortcutService.registerShortcut(shortcuts.MISC.PREVIOUS_FRAME, this.selectPreviousFrame.bind(this));