Fix same bug for images

master
William Toohey 10 years ago
parent 764a2330d9
commit 18fff4db84
  1. 10
      src/js/HuesCore.js

@ -537,7 +537,7 @@ HuesCore.prototype.randomImage = function() {
if ((index == this.imageIndex || this.lastImageArray.indexOf(index) != -1) && len > 1) { if ((index == this.imageIndex || this.lastImageArray.indexOf(index) != -1) && len > 1) {
this.randomImage(); this.randomImage();
} else { } else {
this.setImage(index); this.setImage(index, true);
this.lastImageArray.push(index); this.lastImageArray.push(index);
let cull = Math.min(20, Math.floor((len / 2))); let cull = Math.min(20, Math.floor((len / 2)));
while (this.lastImageArray.length > cull && cull >= 0) { 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 // If there are no images, this corrects NaN to 0
this.imageIndex = index ? index : 0; this.imageIndex = index ? index : 0;
let img=this.resourceManager.enabledImages[this.imageIndex]; let img=this.resourceManager.enabledImages[this.imageIndex];
if (img == this.currentImage && img !== null) { if (img == this.currentImage && img !== null) {
return; return;
} }
// When not randoming, clear this
if(!leaveArray) {
this.lastImageArray = [];
}
if (img) { if (img) {
this.currentImage = img; this.currentImage = img;
} else { } else {
@ -582,14 +586,12 @@ HuesCore.prototype.nextImage = function() {
this.setIsFullAuto(false); this.setIsFullAuto(false);
let img=(this.imageIndex + 1) % this.resourceManager.enabledImages.length; let img=(this.imageIndex + 1) % this.resourceManager.enabledImages.length;
this.setImage(img); this.setImage(img);
this.lastImageArray = [];
}; };
HuesCore.prototype.previousImage = function() { HuesCore.prototype.previousImage = function() {
this.setIsFullAuto(false); this.setIsFullAuto(false);
let img=((this.imageIndex - 1) + this.resourceManager.enabledImages.length) % this.resourceManager.enabledImages.length; let img=((this.imageIndex - 1) + this.resourceManager.enabledImages.length) % this.resourceManager.enabledImages.length;
this.setImage(img); this.setImage(img);
this.lastImageArray = [];
}; };
HuesCore.prototype.randomColourIndex = function() { HuesCore.prototype.randomColourIndex = function() {

Loading…
Cancel
Save