diff --git a/js/HuesCore.js b/js/HuesCore.js index 19d3889..06d7b5f 100644 --- a/js/HuesCore.js +++ b/js/HuesCore.js @@ -80,8 +80,7 @@ function HuesCore(defaults) { * * Called on every new beat. * beatString is a 256 char long array of current and upcoming beat chars - * beatIndex is a "safe to display" beat index. 0 during buildups, - * index % beatmap length otherwise. + * beatIndex is the beat index. Negative during buildups */ beat : [], /* callback invert(isInverted) @@ -172,13 +171,16 @@ function HuesCore(defaults) { document.onkeydown = function(e){ e = e || window.event; + if(e.defaultPrevented) { + return true; + } // Ignore modifiers so we don't steal other events if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) { return true; } // If we've focused a text input, let the input go through! - if(document.activeElement.tagName.toLowerCase() == "input" && - document.activeElement.type == "text") { + if((e.target.tagName.toLowerCase() == "input" && e.target.type == "text") + || e.target.contentEditable === "true") { return true; } var key = e.keyCode || e.which; @@ -281,14 +283,22 @@ HuesCore.prototype.animationLoop = function() { this.callEventListeners("frame"); }; -HuesCore.prototype.getSafeBeatIndex = function() { +HuesCore.prototype.getBeatIndex = function() { if(!this.soundManager.playing) { return 0; + } else if(this.beatIndex < 0) { + return this.beatIndex; + } else { + return this.beatIndex % this.currentSong.rhythm.length; } - if(this.beatIndex < 0) { +} + +HuesCore.prototype.getSafeBeatIndex = function() { + var index = this.getBeatIndex(); + if(index < 0) { return 0; } else { - return this.beatIndex % this.currentSong.rhythm.length; + return index; } }; @@ -549,7 +559,7 @@ HuesCore.prototype.getBeat = function(index) { }; HuesCore.prototype.beater = function(beat) { - this.callEventListeners("beat", this.getBeatString(), this.getSafeBeatIndex()); + this.callEventListeners("beat", this.getBeatString(), this.getBeatIndex()); switch(beat) { case 'X': case 'x': diff --git a/js/HuesUI.js b/js/HuesUI.js index 9544350..146d617 100644 --- a/js/HuesUI.js +++ b/js/HuesUI.js @@ -419,6 +419,9 @@ RetroUI.prototype.newColour = function(colour) { RetroUI.prototype.beat = function(beats, index) { var rest = beats.slice(1); this.beatBar.textContent = ">>" + rest; + if(index < 0) { + index = 0; + } this.beatCount.textContent = "B=" + this.intToHex4(index); }; @@ -480,7 +483,10 @@ WeedUI.prototype.beat = function(beats, index) { this.beatLeft.textContent = rest; this.beatRight.textContent = rest; - + + if(index < 0) { + index = 0; + } this.beatCount.textContent = "B=" + this.intToHex4(index); if(["x", "o", "X", "O"].indexOf(beats[0]) != -1) { @@ -744,6 +750,9 @@ ModernUI.prototype.beat = function(beats, index) { span.textContent = this.currentBeat; this.beatCenter.appendChild(span); } + if(index < 0) { + index = 0; + } this.beatCount.textContent = "B=" + this.intToHex4(index); };