Fix manually set songs not clearing random buffer

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

@ -342,13 +342,11 @@ HuesCore.prototype.blurUpdated = function(x, y) {
}; };
HuesCore.prototype.nextSong = function() { HuesCore.prototype.nextSong = function() {
this.lastSongArray = [];
let index = (this.songIndex + 1) % this.resourceManager.enabledSongs.length; let index = (this.songIndex + 1) % this.resourceManager.enabledSongs.length;
this.setSong(index); this.setSong(index);
}; };
HuesCore.prototype.previousSong = function() { HuesCore.prototype.previousSong = function() {
this.lastSongArray = [];
let index = ((this.songIndex - 1) + this.resourceManager.enabledSongs.length) % this.resourceManager.enabledSongs.length; let index = ((this.songIndex - 1) + this.resourceManager.enabledSongs.length) % this.resourceManager.enabledSongs.length;
this.setSong(index); this.setSong(index);
}; };
@ -372,10 +370,14 @@ HuesCore.prototype.setSongOject = function(song) {
} }
}; };
HuesCore.prototype.setSong = function(index) { HuesCore.prototype.setSong = function(index, leaveArray) {
if(this.currentSong == this.resourceManager.enabledSongs[index]) { if(this.currentSong == this.resourceManager.enabledSongs[index]) {
return; return;
} }
// When not randoming, clear this
if(!leaveArray) {
this.lastSongArray = [];
}
this.lastSongArray.push(index); this.lastSongArray.push(index);
this.songIndex = index; this.songIndex = index;
this.currentSong = this.resourceManager.enabledSongs[this.songIndex]; this.currentSong = this.resourceManager.enabledSongs[this.songIndex];
@ -461,7 +463,7 @@ HuesCore.prototype.randomSong = function() {
this.randomSong(); this.randomSong();
} else { } else {
console.log("Randoming a song!"); console.log("Randoming a song!");
this.setSong(index); this.setSong(index, true);
let noRepeat = Math.min(5, Math.floor(songCount / 2)); let noRepeat = Math.min(5, Math.floor(songCount / 2));
while (this.lastSongArray.length > noRepeat && noRepeat >= 0) { while (this.lastSongArray.length > noRepeat && noRepeat >= 0) {
this.lastSongArray.shift(); this.lastSongArray.shift();

Loading…
Cancel
Save