From 18fff4db844c1a7a7c2ec32314d31af92902c88e Mon Sep 17 00:00:00 2001 From: William Toohey Date: Sat, 6 Feb 2016 16:38:04 +1000 Subject: [PATCH] Fix same bug for images --- src/js/HuesCore.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/js/HuesCore.js b/src/js/HuesCore.js index 7c19273..e0a0c2d 100644 --- a/src/js/HuesCore.js +++ b/src/js/HuesCore.js @@ -537,7 +537,7 @@ HuesCore.prototype.randomImage = function() { if ((index == this.imageIndex || this.lastImageArray.indexOf(index) != -1) && len > 1) { this.randomImage(); } else { - this.setImage(index); + this.setImage(index, true); this.lastImageArray.push(index); let cull = Math.min(20, Math.floor((len / 2))); while (this.lastImageArray.length > cull && cull >= 0) { @@ -550,13 +550,17 @@ HuesCore.prototype.randomImage = function() { } }; -HuesCore.prototype.setImage = function(index) { +HuesCore.prototype.setImage = function(index, leaveArray) { // If there are no images, this corrects NaN to 0 this.imageIndex = index ? index : 0; let img=this.resourceManager.enabledImages[this.imageIndex]; if (img == this.currentImage && img !== null) { return; } + // When not randoming, clear this + if(!leaveArray) { + this.lastImageArray = []; + } if (img) { this.currentImage = img; } else { @@ -582,14 +586,12 @@ HuesCore.prototype.nextImage = function() { this.setIsFullAuto(false); let img=(this.imageIndex + 1) % this.resourceManager.enabledImages.length; this.setImage(img); - this.lastImageArray = []; }; HuesCore.prototype.previousImage = function() { this.setIsFullAuto(false); let img=((this.imageIndex - 1) + this.resourceManager.enabledImages.length) % this.resourceManager.enabledImages.length; this.setImage(img); - this.lastImageArray = []; }; HuesCore.prototype.randomColourIndex = function() {