From ed78cf6e954912310ebe89324eb2aa0cfecd0f72 Mon Sep 17 00:00:00 2001 From: William Toohey Date: Sun, 1 Nov 2015 00:29:24 +1000 Subject: [PATCH] Lint pass --- js/HuesCanvas.js | 56 +++++++-------- js/HuesCore.js | 91 ++++++++++++------------ js/HuesSettings.js | 137 ++++++++++++++++++------------------ js/HuesUI.js | 158 +++++++++++++++++++++--------------------- js/ResourceManager.js | 121 ++++++++++++++++---------------- js/ResourcePack.js | 68 +++++++++--------- js/SoundManager.js | 32 ++++----- 7 files changed, 338 insertions(+), 325 deletions(-) diff --git a/js/HuesCanvas.js b/js/HuesCanvas.js index 8875832..3cae374 100644 --- a/js/HuesCanvas.js +++ b/js/HuesCanvas.js @@ -79,7 +79,7 @@ function HuesCanvas(element, aContext, core) { HuesCanvas.prototype.resizeHandler = function(that) { return function() {that.resize();}; -} +}; HuesCanvas.prototype.resize = function() { // height is constant 720px, we expand width to suit @@ -88,7 +88,7 @@ HuesCanvas.prototype.resize = function() { var snow = document.getElementById("snow").getContext("2d"); snow.canvas.width = Math.ceil(720 * ratio); this.needsRedraw = true; -} +}; HuesCanvas.prototype.redraw = function() { var offset; // for centering/right/left align @@ -159,19 +159,19 @@ HuesCanvas.prototype.redraw = function() { } else { this.needsRedraw = false; } -} +}; /* Second fastest method from http://stackoverflow.com/questions/10073699/pad-a-number-with-leading-zeros-in-javascript It stil does millions of ops per second, and isn't ugly like the integer if/else */ HuesCanvas.prototype.intToHex = function(num) { return '#' + ("00000"+num.toString(16)).slice(-6); -} +}; HuesCanvas.prototype.getAnimLoop = function() { var that = this; - return function() {that.animationLoop()}; -} + return function() {that.animationLoop();}; +}; HuesCanvas.prototype.animationLoop = function() { if (this.colourFade) { @@ -234,7 +234,7 @@ HuesCanvas.prototype.animationLoop = function() { if(this.animating) { requestAnimationFrame(this.getAnimLoop()); } -} +}; HuesCanvas.prototype.setImage = function(image) { this.needsRedraw = true; @@ -251,11 +251,11 @@ HuesCanvas.prototype.setImage = function(image) { this.syncAnim(); } } -} +}; HuesCanvas.prototype.beat = function() { this.lastBeat = this.aContext.currentTime; -} +}; HuesCanvas.prototype.syncAnim = function() { var song = this.core.currentSong; @@ -275,7 +275,7 @@ HuesCanvas.prototype.syncAnim = function() { this.animFrame = Math.floor(aLen * (beatLoc / this.image.beatsPerAnim)); // Because negative mods are different in JS this.animFrame = ((this.animFrame % aLen) + aLen) % aLen; -} +}; HuesCanvas.prototype.setColour = function(colour, isFade) { if(isFade) { @@ -285,7 +285,7 @@ HuesCanvas.prototype.setColour = function(colour, isFade) { this.colour = colour; } this.needsRedraw = true; -} +}; HuesCanvas.prototype.doBlackout = function(whiteout) { if (typeof(whiteout)==='undefined') whiteout = false; @@ -301,7 +301,7 @@ HuesCanvas.prototype.doBlackout = function(whiteout) { if(localStorage["blackoutUI"] == "on") { this.core.userInterface.hide(); } -} +}; // for song changes HuesCanvas.prototype.clearBlackout = function() { @@ -311,27 +311,27 @@ HuesCanvas.prototype.clearBlackout = function() { if(localStorage["blackoutUI"] == "on") { this.core.userInterface.show(); } -} +}; HuesCanvas.prototype.doShortBlackout = function(beatTime) { this.doBlackout(); this.blackoutTimeout = this.aContext.currentTime + beatTime / 1.7; // looks better if we go right to black this.blackoutStart = 0; -} +}; HuesCanvas.prototype.doColourFade = function(length) { this.colourFade = true; this.colourFadeLength = length; this.colourFadeStart = this.aContext.currentTime; this.oldColour = this.colour; -} +}; HuesCanvas.prototype.stopFade = function() { this.colourFade = false; this.colourFadeStart = 0; this.colourFadeLength = 0; -} +}; HuesCanvas.prototype.mixColours = function(percent) { percent = Math.min(1, percent); @@ -345,7 +345,7 @@ HuesCanvas.prototype.mixColours = function(percent) { var mixG = oldG * (1 - percent) + newG * percent; var mixB = oldB * (1 - percent) + newB * percent; this.colour = mixR << 16 | mixG << 8 | mixB; -} +}; HuesCanvas.prototype.doXBlur = function() { this.blurStart = this.aContext.currentTime; @@ -353,7 +353,7 @@ HuesCanvas.prototype.doXBlur = function() { this.xBlur = true; this.yBlur = false; this.needsRedraw = true; -} +}; HuesCanvas.prototype.doYBlur = function() { this.blurStart = this.aContext.currentTime; @@ -361,32 +361,32 @@ HuesCanvas.prototype.doYBlur = function() { this.xBlur = false; this.yBlur = true; this.needsRedraw = true; -} +}; HuesCanvas.prototype.setBlurDecay = function(decay) { this.blurDecay = {"slow" : 7.8, "medium" : 14.1, "fast" : 20.8, "faster!" : 28.7}[decay]; -} +}; HuesCanvas.prototype.setBlurQuality = function(quality) { this.blurIterations = {"low" : 3, "medium" : 11, "high" : 19, "extreme" : 35}[quality]; this.blurDelta = 1 / (this.blurIterations/2); this.blurAlpha = 1 / (this.blurIterations/2); -} +}; HuesCanvas.prototype.setBlurAmount = function(amount) { this.blurAmount = {"low" : 48, "medium" : 96, "high" : 384}[amount]; -} +}; HuesCanvas.prototype.setSmartAlign = function(align) { this.smartAlign = align == "on"; -} +}; HuesCanvas.prototype.setAnimating = function(anim) { if(!this.animating && anim) { requestAnimationFrame(this.animationLoop); } this.animating = anim; -} +}; // From http://thecodeplayer.com/walkthrough/html5-canvas-snow-effect @@ -403,15 +403,15 @@ HuesCanvas.prototype.startSnow = function() { y: Math.random()*height, //y-coordinate r: Math.random()*4+1, //radius d: Math.random()*25 //density - }) + }); } this.lastSnow = this.aContext.currentTime; -} +}; HuesCanvas.prototype.stopSnow = function() { this.snowing = false; document.getElementById("snow").style.display = "none"; -} +}; HuesCanvas.prototype.drawSnow = function() { var ctx = document.getElementById("snow").getContext("2d"); @@ -459,4 +459,4 @@ HuesCanvas.prototype.drawSnow = function() { } } this.lastSnow = this.aContext.currentTime; -} \ No newline at end of file +}; \ No newline at end of file diff --git a/js/HuesCore.js b/js/HuesCore.js index f2bc3db..30719c2 100644 --- a/js/HuesCore.js +++ b/js/HuesCore.js @@ -19,6 +19,9 @@ * THE SOFTWARE. */ +/* We don't want localstorage variables optimised to different identifiers*/ +/*jshint -W069 */ + HuesCore = function(defaults) { // Bunch-o-initialisers this.version = "0x01"; @@ -98,12 +101,12 @@ HuesCore = function(defaults) { }; this.animationLoop(); -} +}; HuesCore.prototype.animationLoop = function() { var that = this; if(!this.soundManager.playing) { - requestAnimationFrame(function() {that.animationLoop()}); + requestAnimationFrame(function() {that.animationLoop();}); return; } var now = this.soundManager.currentTime(); @@ -120,12 +123,12 @@ HuesCore.prototype.animationLoop = function() { var beat = this.getBeat(this.beatIndex); this.beater(beat); } - requestAnimationFrame(function() {that.animationLoop()}); -} + requestAnimationFrame(function() {that.animationLoop();}); +}; HuesCore.prototype.getCurrentMode = function() { return this.isFullAuto ? "FULL AUTO" : "NORMAL"; -} +}; HuesCore.prototype.getSafeBeatIndex = function() { if(!this.soundManager.playing) { @@ -136,23 +139,23 @@ HuesCore.prototype.getSafeBeatIndex = function() { } else { return this.beatIndex % this.currentSong.rhythm.length; } -} +}; HuesCore.prototype.blurUpdated = function(x, y) { this.userInterface.blurUpdated(x, y); -} +}; HuesCore.prototype.nextSong = function() { this.lastSongArray = []; var index = (this.songIndex + 1) % this.resourceManager.enabledSongs.length; this.setSong(index); -} +}; HuesCore.prototype.previousSong = function() { this.lastSongArray = []; var index = ((this.songIndex - 1) + this.resourceManager.enabledSongs.length) % this.resourceManager.enabledSongs.length; this.setSong(index); -} +}; HuesCore.prototype.setSongByName = function(name) { var songs = this.resourceManager.enabledSongs; @@ -163,7 +166,7 @@ HuesCore.prototype.setSongByName = function(name) { } } this.setSong(0); // fallback -} +}; HuesCore.prototype.setSong = function(index) { if(this.currentSong == this.resourceManager.enabledSongs[index]) { @@ -171,7 +174,7 @@ HuesCore.prototype.setSong = function(index) { } this.songIndex = index; this.currentSong = this.resourceManager.enabledSongs[this.songIndex]; - if (this.currentSong == undefined) { + if (this.currentSong === undefined) { this.currentSong = {"name":"None", "title":"None", "rhythm":".", "source":null, "crc":"none", "sound":null, "enabled":true, "filename":"none"}; } console.log("Next song:", this.songIndex, this.currentSong); @@ -197,12 +200,12 @@ HuesCore.prototype.setSong = function(index) { that.resetAudio(); that.fillBuildup(); }); -} +}; HuesCore.prototype.fillBuildup = function() { this.beatLength = this.soundManager.loopLength / this.currentSong.rhythm.length; var buildBeats = Math.floor(this.soundManager.loopStart / this.beatLength) + 1; - if (this.currentSong.buildupRhythm == null) { + if (this.currentSong.buildupRhythm === null) { this.currentSong.buildupRhythm = ""; } if (this.currentSong.buildupRhythm.length < buildBeats) { @@ -213,22 +216,22 @@ HuesCore.prototype.fillBuildup = function() { } console.log("Buildup length:", buildBeats); this.beatIndex = this.doBuildup ? -this.currentSong.buildupRhythm.length : 0; -} +}; HuesCore.prototype.randomSong = function() { var index=Math.floor((Math.random() * this.resourceManager.enabledSongs.length)); - if (index == this.songIndex && this.resourceManager.enabledSongs.length > 1 || !(this.lastSongArray.indexOf(index) == -1)) { + if (index == this.songIndex && this.resourceManager.enabledSongs.length > 1 || this.lastSongArray.indexOf(index) != -1) { this.randomSong(); } else { console.log("Randoming a song!"); this.setSong(index); this.lastSongArray.push(index); - noRepeat = Math.min(5, Math.floor((this.resourceManager.enabledSongs.length / 2))); + var noRepeat = Math.min(5, Math.floor((this.resourceManager.enabledSongs.length / 2))); while (this.lastSongArray.length > noRepeat && noRepeat >= 0) { this.lastSongArray.shift(); } } -} +}; /* HuesCore.prototype.onLoop = function() { this.loopCount = this.loopCount + 1; @@ -261,12 +264,12 @@ HuesCore.prototype.songDataUpdated = function() { } else { this.beatLength = -1; } -} +}; HuesCore.prototype.resetAudio = function() { this.beatIndex = 0; this.songDataUpdated(); -} +}; HuesCore.prototype.randomImage = function() { var len = this.resourceManager.enabledImages.length; @@ -281,13 +284,13 @@ HuesCore.prototype.randomImage = function() { this.lastImageArray.shift(); } } -} +}; HuesCore.prototype.setImage = function(index) { // If there are no images, this corrects NaN to 0 this.imageIndex = index ? index : 0; var img=this.resourceManager.enabledImages[this.imageIndex]; - if (img == this.currentImage && !(img == null)) { + if (img == this.currentImage && img !== null) { return; } if (img) { @@ -299,21 +302,21 @@ HuesCore.prototype.setImage = function(index) { } this.renderer.setImage(this.currentImage); this.userInterface.setImageText(); -} +}; HuesCore.prototype.nextImage = function() { this.setIsFullAuto(false); var img=(this.imageIndex + 1) % this.resourceManager.enabledImages.length; this.setImage(img); this.lastImageArray = []; -} +}; HuesCore.prototype.previousImage = function() { this.setIsFullAuto(false); var img=((this.imageIndex - 1) + this.resourceManager.enabledImages.length) % this.resourceManager.enabledImages.length; this.setImage(img); this.lastImageArray = []; -} +}; HuesCore.prototype.randomColourIndex = function() { var index=Math.floor((Math.random() * 64)); @@ -321,18 +324,18 @@ HuesCore.prototype.randomColourIndex = function() { return this.randomColourIndex(); } return index; -} +}; HuesCore.prototype.randomColour = function(isFade) { var index=this.randomColourIndex(); this.setColour(index, isFade); -} +}; HuesCore.prototype.setColour = function(index, isFade) { this.colourIndex = index; this.renderer.setColour(this.colours[this.colourIndex].c, isFade); this.userInterface.setColourText(); -} +}; HuesCore.prototype.getBeat = function(index) { if(index < 0) { @@ -340,7 +343,7 @@ HuesCore.prototype.getBeat = function(index) { } else { return this.currentSong.rhythm[index % this.currentSong.rhythm.length]; } -} +}; HuesCore.prototype.beater = function(beat) { this.userInterface.beat(); @@ -404,7 +407,7 @@ HuesCore.prototype.beater = function(beat) { this.randomImage(); } } -} +}; HuesCore.prototype.getBeatString = function(length) { length = length ? length : 256; @@ -424,18 +427,18 @@ HuesCore.prototype.getBeatString = function(length) { } return beatString; -} +}; HuesCore.prototype.setIsFullAuto = function(auto) { this.isFullAuto = auto; if (this.userInterface) { this.userInterface.modeUpdated(); } -} +}; HuesCore.prototype.toggleFullAuto = function() { this.setIsFullAuto(!this.isFullAuto); -} +}; /*HuesCore.prototype.enterFrame = function() { this.setTexts(); @@ -460,7 +463,7 @@ HuesCore.prototype.toggleFullAuto = function() { HuesCore.prototype.respackLoaded = function() { this.init(); -} +}; /*HuesCore.prototype.rightClickListener = function(event) { switch (event) { @@ -478,7 +481,7 @@ HuesCore.prototype.respackLoaded = function() { }*/ HuesCore.prototype.changeUI = function(index) { - if (index >= 0 && this.uiArray.length > index && !(this.userInterface == this.uiArray[index])) { + if (index >= 0 && this.uiArray.length > index && this.userInterface != this.uiArray[index]) { this.hideLists(); if(this.userInterface) this.userInterface.disconnect(); @@ -490,7 +493,7 @@ HuesCore.prototype.changeUI = function(index) { this.userInterface.beat(); this.userInterface.modeUpdated(); } -} +}; HuesCore.prototype.settingsUpdated = function() { this.renderer.setSmartAlign(localStorage["smartAlign"]); @@ -537,37 +540,37 @@ HuesCore.prototype.settingsUpdated = function() { this.loopCount = 0; this.autoSong = this.settings.autosong; }*/ -} +}; HuesCore.prototype.enabledChanged = function() { this.resourceManager.rebuildEnabled(); -} +}; HuesCore.prototype.hideLists = function() { this.resourceManager.hideLists(); -} +}; HuesCore.prototype.toggleSongList = function() { this.settings.hide(); this.resourceManager.toggleSongList(); -} +}; HuesCore.prototype.toggleImageList = function() { this.settings.hide(); this.resourceManager.toggleImageList(); -} +}; HuesCore.prototype.openSongSource = function() { if (this.currentSong && this.currentSong.source) { window.open(this.currentSong.source,'_blank'); } -} +}; HuesCore.prototype.openImageSource = function() { if (this.currentImage && this.currentImage.source) { window.open(this.currentImage.source,'_blank'); } -} +}; HuesCore.prototype.keyHandler = function(key) { switch (key) { @@ -642,12 +645,12 @@ HuesCore.prototype.keyHandler = function(key) { return true; } return false; -} +}; HuesCore.prototype.error = function(message) { document.getElementById("preSub").textContent = "Error: " + message; document.getElementById("preMain").style.color = "#F00"; -} +}; HuesCore.prototype.oldColours = [{'c': 0x000000, 'n': 'black'}, diff --git a/js/HuesSettings.js b/js/HuesSettings.js index 7aa10f1..40818b3 100644 --- a/js/HuesSettings.js +++ b/js/HuesSettings.js @@ -47,7 +47,7 @@ HuesSettings.prototype.defaultSettings = { blackoutUI: "off", playBuildups: "on", volume : 0.7 -} +}; // Don't get saved to localStorage HuesSettings.prototype.ephemeralSettings = [ @@ -78,7 +78,7 @@ HuesSettings.prototype.settingsCategories = { "Audio Settings" : [ "playBuildups" ] -} +}; HuesSettings.prototype.settingsOptions = { smartAlign : { @@ -114,7 +114,7 @@ HuesSettings.prototype.settingsOptions = { options : ["off", "once", "on"] } -} +}; function HuesSettings(defaults) { this.core = null; @@ -123,20 +123,22 @@ function HuesSettings(defaults) { this.hide(); for(var attr in this.defaultSettings) { - if(defaults[attr] == undefined) { - defaults[attr] = this.defaultSettings[attr]; - } - // don't write to local if it's a temp settings - if(this.ephemeralSettings.indexOf(attr) != -1) { - continue; - } - if(defaults.overwriteLocal) { - localStorage[attr] = defaults[attr]; - } - // populate defaults, ignoring current - if(localStorage[attr] == undefined) { - localStorage[attr] = defaults[attr]; - } + if(this.defaultSettings.hasOwnProperty(attr)) { + if(defaults[attr] === undefined) { + defaults[attr] = this.defaultSettings[attr]; + } + // don't write to local if it's a temp settings + if(this.ephemeralSettings.indexOf(attr) != -1) { + continue; + } + if(defaults.overwriteLocal) { + localStorage[attr] = defaults[attr]; + } + // populate defaults, ignoring current + if(localStorage[attr] === undefined) { + localStorage[attr] = defaults[attr]; + } + } } this.defaults = defaults; @@ -153,11 +155,11 @@ HuesSettings.prototype.show = function() { if(this.core) this.core.hideLists(); this.window.style.display = "block"; -} +}; HuesSettings.prototype.hide = function() { this.window.style.display = "none"; -} +}; HuesSettings.prototype.toggle = function() { if(this.window.style.display == "none") { @@ -167,22 +169,22 @@ HuesSettings.prototype.toggle = function() { } else { this.window.style.display = "none"; } -} +}; HuesSettings.prototype.showRespacks = function() { this.show(); document.getElementById("tab1").checked = true; -} +}; HuesSettings.prototype.showOptions = function() { this.show(); document.getElementById("tab2").checked = true; -} +}; HuesSettings.prototype.showInfo = function() { this.show(); document.getElementById("tab3").checked = true; -} +}; HuesSettings.prototype.initUI = function() { var doc = this.root.ownerDocument; @@ -191,48 +193,49 @@ HuesSettings.prototype.initUI = function() { document.getElementById("closeButton").onclick = function() {that.hide();}; // To order things nicely - for(cat in this.settingsCategories) { - var catContainer = doc.createElement("div"); - catContainer.textContent = cat; - catContainer.className = "settings-category"; - var cats = this.settingsCategories[cat]; - for(var i = 0; i < cats.length; i++) { - var setName = cats[i]; - var setContainer = doc.createElement("div"); - var setting = this.settingsOptions[setName]; - setContainer.textContent = setting.name; - setContainer.className = "settings-individual"; - var buttonContainer = doc.createElement("div"); - buttonContainer.className = "settings-buttons"; - for(var j = 0; j < setting.options.length; j++) { - var option = setting.options[j]; - var checkbox = doc.createElement("input"); - checkbox.className = "settings-checkbox"; - checkbox.type = "radio"; - checkbox.name = setName; - checkbox.value = option; - checkbox.id = setName + "-" + option; - if(localStorage[setName] == option) { - checkbox.checked = true; - } - var that = this; - checkbox.onclick = function() { - that.set(this.name, this.value); + for(var cat in this.settingsCategories) { + if(this.settingsCategories.hasOwnProperty(cat)) { + var catContainer = doc.createElement("div"); + catContainer.textContent = cat; + catContainer.className = "settings-category"; + var cats = this.settingsCategories[cat]; + for(var i = 0; i < cats.length; i++) { + var setName = cats[i]; + var setContainer = doc.createElement("div"); + var setting = this.settingsOptions[setName]; + setContainer.textContent = setting.name; + setContainer.className = "settings-individual"; + var buttonContainer = doc.createElement("div"); + buttonContainer.className = "settings-buttons"; + for(var j = 0; j < setting.options.length; j++) { + var option = setting.options[j]; + var checkbox = doc.createElement("input"); + checkbox.className = "settings-checkbox"; + checkbox.type = "radio"; + checkbox.name = setName; + checkbox.value = option; + checkbox.id = setName + "-" + option; + if(localStorage[setName] == option) { + checkbox.checked = true; + } + checkbox.onclick = function() { + that.set(this.name, this.value); + }; + buttonContainer.appendChild(checkbox); + // So we can style this nicely + var label = doc.createElement("label"); + label.className = "settings-label"; + label.htmlFor = checkbox.id; + label.textContent = option.toUpperCase(); + buttonContainer.appendChild(label); } - buttonContainer.appendChild(checkbox); - // So we can style this nicely - var label = doc.createElement("label"); - label.className = "settings-label"; - label.htmlFor = checkbox.id; - label.textContent = option.toUpperCase(); - buttonContainer.appendChild(label); + setContainer.appendChild(buttonContainer); + catContainer.appendChild(setContainer); } - setContainer.appendChild(buttonContainer); - catContainer.appendChild(setContainer); + this.root.appendChild(catContainer); } - this.root.appendChild(catContainer); } -} +}; // Set a named index to its named value, returns false if name doesn't exist HuesSettings.prototype.set = function(setting, value) { @@ -249,15 +252,17 @@ HuesSettings.prototype.set = function(setting, value) { localStorage[setting] = value; core.settingsUpdated(); return true; -} +}; // Note: This is not defaults as per defaultSettings, but those merged with // the defaults given in the initialiser HuesSettings.prototype.setDefaults = function() { for(var attr in this.defaults) { - if(this.ephemeralSettings.indexOf(attr) != -1) { - continue; + if(this.defaults.hasOwnProperty(attr)) { + if(this.ephemeralSettings.indexOf(attr) != -1) { + continue; + } + localStorage[attr] = this.defaults[attr]; } - localStorage[attr] = this.defaults[attr]; } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/js/HuesUI.js b/js/HuesUI.js index 07ab106..e27d1f2 100644 --- a/js/HuesUI.js +++ b/js/HuesUI.js @@ -105,11 +105,11 @@ HuesUI.prototype.initUI = function() { var songList = document.createElement("div"); songList.textContent = "SONGS"; - songList.onclick = function() {that.core.toggleSongList()}; + songList.onclick = function() {that.core.toggleSongList();}; this.songList = songList; var imageList = document.createElement("div"); imageList.textContent = "IMAGES"; - imageList.onclick = function() {that.core.toggleImageList()}; + imageList.onclick = function() {that.core.toggleImageList();}; this.imageList = imageList; // Beat timer, x and y blur, millis timer @@ -130,21 +130,20 @@ HuesUI.prototype.initUI = function() { this.settingsToggle.innerHTML = ''; this.settingsToggle.onclick = function() { that.core.settings.toggle(); - } + }; this.hideToggle = document.createElement("div"); this.hideToggle.innerHTML = "▼"; this.hideToggle.onclick = function() { that.toggleHide(); - } + }; this.listContainer = document.createElement("div"); - var that = this; this.resizeHandler = function() { that.resize(); - } -} + }; +}; HuesUI.prototype.connectCore = function(core) { this.core = core; @@ -153,7 +152,7 @@ HuesUI.prototype.connectCore = function(core) { window.addEventListener('resize', this.resizeHandler); this.resizeHandler(); -} +}; HuesUI.prototype.disconnect = function() { this.core = null; @@ -163,17 +162,17 @@ HuesUI.prototype.disconnect = function() { } window.removeEventListener('resize', this.resizeHandler); -} +}; // ONLY FOR CHANGING UI, NOT FOR "HIDE" FEATURE HuesUI.prototype.show = function() { this.root.style.display = "block"; -} +}; // ONLY FOR CHANGING UI, NOT FOR "HIDE" FEATURE HuesUI.prototype.hide = function() { this.root.style.display = "none"; -} +}; HuesUI.prototype.toggleHide = function() { this.hidden = !this.hidden; @@ -182,13 +181,13 @@ HuesUI.prototype.toggleHide = function() { } else { this.root.className = this.constructor.name; } -} +}; // May do nothing, may scale elements if needed etc etc -HuesUI.prototype.resize = function() {} -HuesUI.prototype.modeUpdated = function() {} -HuesUI.prototype.beat = function() {} -HuesUI.prototype.updateVolume = function(vol) {} +HuesUI.prototype.resize = function() {}; +HuesUI.prototype.modeUpdated = function() {}; +HuesUI.prototype.beat = function() {}; +HuesUI.prototype.updateVolume = function(vol) {}; HuesUI.prototype.setSongText = function() { var song = this.core.currentSong; @@ -198,7 +197,7 @@ HuesUI.prototype.setSongText = function() { this.songLink.textContent = song.title.toUpperCase(); this.songLink.href = song.source; -} +}; HuesUI.prototype.setImageText = function() { var image = this.core.currentImage; @@ -210,37 +209,37 @@ HuesUI.prototype.setImageText = function() { this.imageLink.textContent = name.toUpperCase(); this.imageLink.href = image.source ? image.source : ""; -} +}; -HuesUI.prototype.setColourText = function(colour) { +HuesUI.prototype.setColourText = function() { var colour = this.core.colours[this.core.colourIndex]; this.hueName.textContent = colour.n.toUpperCase(); -} +}; HuesUI.prototype.blurUpdated = function(x, y) { x = Math.floor(x * 0xFF); - y = Math.floor(y * 0xFF);; + y = Math.floor(y * 0xFF); this.xBlur.textContent = "X=" + this.intToHex2(x); this.yBlur.textContent = "Y=" + this.intToHex2(y); -} +}; HuesUI.prototype.updateTime = function(time) { time = Math.floor(time * 1000); this.timer.textContent = "T=" + this.intToHex4(time); -} +}; HuesUI.prototype.intToHex2 = function(num) { return '$0x' + ("00"+num.toString(16)).slice(-2); -} +}; HuesUI.prototype.intToHex3 = function(num) { return '$0x' + ("000"+num.toString(16)).slice(-3); -} +}; HuesUI.prototype.intToHex4 = function(num) { return '$0x' + ("0000"+num.toString(16)).slice(-4); -} +}; /* Individual UIs ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -258,6 +257,7 @@ function RetroUI() { HuesUI.call(this); } + RetroUI.prototype = Object.create(HuesUI.prototype); RetroUI.prototype.constructor = RetroUI; @@ -337,12 +337,12 @@ RetroUI.prototype.initUI = function() { this.hideRestore.innerHTML = "▲"; this.hideRestore.onclick = function() { that.toggleHide(); - } + }; this.root.appendChild(this.hideRestore); this.listContainer.className = "hues-r-listcontainer"; this.root.appendChild(this.listContainer); -} +}; RetroUI.prototype.toggleHide = function(stylename) { stylename = stylename ? stylename : 'r'; @@ -358,18 +358,18 @@ RetroUI.prototype.toggleHide = function(stylename) { this.hideRestore.className = "hues-r-hiderestore hidden"; } this.hidden = !this.hidden; -} +}; RetroUI.prototype.connectCore = function(core) { HuesUI.prototype.connectCore.call(this, core); this.version.textContent = "V=$" + core.version; this.modeUpdated(); -} +}; RetroUI.prototype.modeUpdated = function() { this.mode.textContent = "M=" + this.core.getCurrentMode(); -} +}; RetroUI.prototype.setImageText = function() { var image = this.core.currentImage; @@ -379,13 +379,13 @@ RetroUI.prototype.setImageText = function() { this.imageLink.textContent = "I=" + image.name.toUpperCase(); this.imageLink.href = image.source; -} +}; RetroUI.prototype.setColourText = function(colour) { HuesUI.prototype.setColourText.call(this, colour); this.colourIndex.textContent = "C=" + this.intToHex2(this.core.colourIndex); -} +}; RetroUI.prototype.beat = function() { var beats = this.core.getBeatString(); @@ -394,7 +394,7 @@ RetroUI.prototype.beat = function() { this.beatBar.textContent = ">>" + rest; this.beatCount.textContent = "B=" + this.intToHex3(this.core.getSafeBeatIndex()); -} +}; function WeedUI() { RetroUI.call(this); @@ -402,13 +402,14 @@ function WeedUI() { this.xVariance = 10; this.yVariance = 20; } + WeedUI.prototype = Object.create(RetroUI.prototype); WeedUI.prototype.constructor = WeedUI; WeedUI.prototype.initUI = function() { RetroUI.prototype.initUI.call(this); - this.container.removeChild(this.beatBar) + this.container.removeChild(this.beatBar); this.controls.className = "hues-w-controls"; this.subControls.className = "hues-w-subcontrols"; @@ -430,7 +431,7 @@ WeedUI.prototype.initUI = function() { this.imageModeManual.textContent = "ONE"; this.imageModeAuto.textContent = "MANY"; -} +}; WeedUI.prototype.toggleHide = function() { if(this.hidden) { @@ -439,7 +440,7 @@ WeedUI.prototype.toggleHide = function() { this.beatBar.className = "hues-w-beatbar hidden"; } RetroUI.prototype.toggleHide.call(this, 'w'); -} +}; WeedUI.prototype.beat = function() { var beats = this.core.getBeatString(); @@ -464,18 +465,18 @@ WeedUI.prototype.beat = function() { this.root.appendChild(beatCenter); window.setTimeout(this.getRemoveBeat(beatCenter), 1500); } -} +}; WeedUI.prototype.round10 = function(num) { return Math.round(num * 10) / 10; -} +}; WeedUI.prototype.getRemoveBeat = function(element) { var that = this; return function() { that.root.removeChild(element); }; -} +}; function ModernUI() { this.beatBar = null; @@ -497,6 +498,7 @@ function ModernUI() { this.hidden = 0; // we have a 3 stage hide } + ModernUI.prototype = Object.create(HuesUI.prototype); ModernUI.prototype.constructor = ModernUI; @@ -542,7 +544,7 @@ ModernUI.prototype.initUI = function() { label.textContent = "VOL"; label.className = "hues-m-vol-label"; label.onclick = function() { - that.core.soundManager.toggleMute() + that.core.soundManager.toggleMute(); }; volBar.appendChild(label); this.volLabel = label; @@ -552,7 +554,7 @@ ModernUI.prototype.initUI = function() { infoToggle.className = "hues-m-question"; infoToggle.onclick = function() { that.core.settings.showInfo(); - } + }; volCluster.appendChild(infoToggle); var input = document.createElement("input"); @@ -564,7 +566,7 @@ ModernUI.prototype.initUI = function() { this.volInput = input; input.oninput = function() { that.core.soundManager.setVolume(parseFloat(input.value)); - } + }; var rightBox = document.createElement("div"); rightBox.className = "hues-m-rightbox"; @@ -578,8 +580,8 @@ ModernUI.prototype.initUI = function() { var songControls = document.createElement("div"); songControls.className = "hues-m-controlbuttons"; - this.songPrev.className = "hues-m-prevbutton" - this.songNext.className = "hues-m-nextbutton" + this.songPrev.className = "hues-m-prevbutton"; + this.songNext.className = "hues-m-nextbutton"; var songShuffle = document.createElement("div"); songShuffle.innerHTML = ''; songShuffle.className = "hues-m-actbutton"; @@ -619,7 +621,7 @@ ModernUI.prototype.initUI = function() { leftInfo.appendChild(this.yBlur); rightInfo.appendChild(this.timer); rightInfo.appendChild(this.beatCount); - this.rightInfo = rightInfo + this.rightInfo = rightInfo; this.leftInfo = leftInfo; controls.appendChild(leftInfo); controls.appendChild(rightInfo); @@ -648,12 +650,12 @@ ModernUI.prototype.initUI = function() { this.hideRestore.className = "hues-m-hiderestore"; this.hideRestore.onclick = function() { that.toggleHide(); - } + }; this.root.appendChild(this.hideRestore); this.listContainer.className = "hues-m-listcontainer"; this.root.appendChild(this.listContainer); -} +}; ModernUI.prototype.toggleHide = function() { this.beatBar.className = "hues-m-beatbar"; @@ -669,16 +671,16 @@ ModernUI.prototype.toggleHide = function() { this.hideRestore.className = "hues-m-hiderestore hidden"; } this.hidden = (this.hidden+1) % 3; -} +}; ModernUI.prototype.updateVolume = function(vol) { this.volInput.value = vol; - if(vol == 0) { + if(vol === 0) { this.volLabel.textContent = "(VOL)"; } else { this.volLabel.textContent = "VOL"; - }; -} + } +}; ModernUI.prototype.modeUpdated = function() { if(this.core.isFullAuto) { @@ -686,7 +688,7 @@ ModernUI.prototype.modeUpdated = function() { } else { this.imageMode.innerHTML = "▶"; // PLAY } -} +}; ModernUI.prototype.beat = function() { var beats = this.core.getBeatString(); @@ -707,30 +709,30 @@ ModernUI.prototype.beat = function() { this.beatCenter.appendChild(span); } this.beatCount.textContent = "B=" + this.intToHex4(this.core.getSafeBeatIndex()); -} +}; ModernUI.prototype.resize = function() { this.resizeSong(); this.resizeImage(); -} +}; ModernUI.prototype.resizeElement = function(el, parent) { - el.className = "" + el.className = ""; if (el.offsetWidth > parent.clientWidth) { - el.className = "small" + el.className = "small"; } if (el.offsetWidth > parent.clientWidth) { - el.className = "x-small" + el.className = "x-small"; } -} +}; ModernUI.prototype.resizeSong = function() { this.resizeElement(this.songLink, this.songName); -} +}; ModernUI.prototype.resizeImage = function() { this.resizeElement(this.imageLink, this.imageName); -} +}; ModernUI.prototype.setSongText = function() { HuesUI.prototype.setSongText.call(this); @@ -739,7 +741,7 @@ ModernUI.prototype.setSongText = function() { return; this.resizeSong(); -} +}; ModernUI.prototype.setImageText = function() { HuesUI.prototype.setImageText.call(this); @@ -748,7 +750,7 @@ ModernUI.prototype.setImageText = function() { return; this.resizeImage(); -} +}; function XmasUI() { ModernUI.call(this); @@ -758,8 +760,7 @@ function XmasUI() { this.controls.removeChild(this.rightInfo); this.controls.removeChild(this.leftInfo); - this.leftBox = this.rightBox = this.hueName = this.xBlur = this.yBlur - = this.timer = null; + this.leftBox = this.rightBox = this.hueName = this.xBlur = this.yBlur = this.timer = null; this.controls.className = "hues-x-controls"; this.beatBar.className = "hues-x-beatbar"; @@ -810,39 +811,40 @@ function XmasUI() { wires.appendChild(bottomHelper); this.root.appendChild(wires); } + XmasUI.prototype = Object.create(ModernUI.prototype); XmasUI.prototype.constructor = XmasUI; XmasUI.prototype.connectCore = function(core) { HuesUI.prototype.connectCore.call(this, core); this.core.renderer.startSnow(); -} +}; XmasUI.prototype.disconnect = function() { this.core.renderer.stopSnow(); HuesUI.prototype.disconnect.call(this); -} +}; XmasUI.prototype.lightOn = function(light) { light.on.className = "hues-x-lighton"; light.off.className = "hues-x-lightoff"; -} +}; XmasUI.prototype.lightOff = function(light) { light.on.className = "hues-x-lighton off"; light.off.className = "hues-x-lightoff off"; -} +}; XmasUI.prototype.lightFadeOut = function(light) { light.on.className = "hues-x-lighton hues-x-fade off"; light.off.className = "hues-x-lightoff hues-x-fade off"; -} +}; XmasUI.prototype.lightRecolour = function(light) { var hue = Math.random() * 360; light.bulb.style.filter = "hue-rotate(" + hue + "deg)"; light.bulb.style.webkitFilter = "hue-rotate(" + hue + "deg)"; -} +}; XmasUI.prototype.randomLight = function(light) { if(Math.random() >= 0.5) { @@ -850,7 +852,7 @@ XmasUI.prototype.randomLight = function(light) { } else { this.lightOff(light); } -} +}; XmasUI.prototype.newLight = function(l, parent) { var light = document.createElement("div"); @@ -870,7 +872,7 @@ XmasUI.prototype.newLight = function(l, parent) { this.randomLight(light); this.lightRecolour(light); return light; -} +}; XmasUI.prototype.beat = function() { ModernUI.prototype.beat.call(this); @@ -890,7 +892,7 @@ XmasUI.prototype.beat = function() { } } } -} +}; XmasUI.prototype.toggleHide = function() { this.beatBar.className = "hues-x-beatbar"; @@ -904,7 +906,7 @@ XmasUI.prototype.toggleHide = function() { this.controls.className = "hues-x-controls hidden"; } this.hidden = (this.hidden+1) % 3; -} +}; XmasUI.prototype.setColourText = function(colour) {}; XmasUI.prototype.blurUpdated = function(x, y) {}; @@ -928,7 +930,7 @@ var xleft = [ {"angle":107.530202659,"x":50.45,"y":1068.75}, {"angle":74.9981580491,"x":45.75,"y":1158.5}, {"angle":88.3307935055,"x":35.85,"y":1238.55} -] +]; var xright = [ {"angle":120.001009518,"x":33.3,"y":-29.75}, {"angle":90.0026227926,"x":35.35,"y":53.65}, @@ -948,7 +950,7 @@ var xright = [ {"angle":76.1887724128,"x":11.95,"y":1062.25}, {"angle":87.4690563489,"x":40.45,"y":1119.9}, {"angle":102.46813454,"x":20.9,"y":1193.85} -] +]; var xbottom = [ {"angle":32.5804579323,"x":110.35,"y":-12.1}, {"angle":3.28979777069,"x":168.05,"y":-5.55}, @@ -984,4 +986,4 @@ var xbottom = [ {"angle":17.6989154099,"x":2540.2,"y":28.5}, {"angle":-18.378894807,"x":2627.55,"y":24.9}, {"angle":-4.561224264,"x":2710.4,"y":14.4} -] \ No newline at end of file +]; \ No newline at end of file diff --git a/js/ResourceManager.js b/js/ResourceManager.js index 2f8e7a9..0f4e0b7 100644 --- a/js/ResourceManager.js +++ b/js/ResourceManager.js @@ -34,7 +34,7 @@ function Resources(core) { this.toLoad = 0; this.progressState = []; - this.rToLoad = [] + this.rToLoad = []; this.loadFinishCallback = null; this.progressCallback = null; @@ -105,15 +105,15 @@ Resources.prototype.addAll = function(urls, callback, progressCallback) { } }, this.createProgCallback(i)); } -} +}; Resources.prototype.createProgCallback = function(i) { var that = this; return function(progress, pack) { that.progressState[i] = progress; that.updateProgress(pack); - } -} + }; +}; Resources.prototype.updateProgress = function(pack) { var total = 0; @@ -122,7 +122,7 @@ Resources.prototype.updateProgress = function(pack) { } total /= this.progressState.length; this.progressCallback(total, pack); -} +}; Resources.prototype.addPack = function(pack) { console.log("Added", pack.name, "to respacks"); @@ -140,12 +140,12 @@ Resources.prototype.addPack = function(pack) { }, this.selectPackCallback(id) ); -} +}; Resources.prototype.addResourcesToArrays = function(pack) { this.allImages = this.allImages.concat(pack.images); this.allSongs = this.allSongs.concat(pack.songs); -} +}; Resources.prototype.rebuildArrays = function() { this.allSongs = []; @@ -155,7 +155,7 @@ Resources.prototype.rebuildArrays = function() { for(var i = 0; i < this.resourcePacks.length; i++) { this.addResourcesToArrays(this.resourcePacks[i]); } -} +}; Resources.prototype.rebuildEnabled = function() { this.enabledSongs = []; @@ -163,7 +163,7 @@ Resources.prototype.rebuildEnabled = function() { for(var i = 0; i < this.resourcePacks.length; i++) { var pack = this.resourcePacks[i]; - if (pack["enabled"] != true) { + if (pack.enabled !== true) { continue; } for(var j = 0; j < pack.songs.length; j++) { @@ -182,11 +182,11 @@ Resources.prototype.rebuildEnabled = function() { var songList = this.enabledSongList; while(songList.firstElementChild) { - songList.removeChild(songList.firstElementChild) + songList.removeChild(songList.firstElementChild); } var imageList = this.enabledImageList; while(imageList.firstElementChild) { - imageList.removeChild(imageList.firstElementChild) + imageList.removeChild(imageList.firstElementChild); } for(var i = 0; i < this.enabledSongs.length; i++) { var song = this.enabledSongs[i]; @@ -197,14 +197,14 @@ Resources.prototype.rebuildEnabled = function() { this.appendSimpleListItem(image.name, imageList, this.selectImageCallback(i)); } this.updateTotals(); -} +}; Resources.prototype.playSongCallback = function(index) { var that = this; return function() { that.core.setSong(index); }; -} +}; Resources.prototype.selectImageCallback = function(index) { var that = this; @@ -212,7 +212,7 @@ Resources.prototype.selectImageCallback = function(index) { that.core.setImage(index); that.core.setIsFullAuto(false); }; -} +}; Resources.prototype.removePack = function(pack) { var index = this.resourcePacks.indexOf(pack); @@ -220,20 +220,20 @@ Resources.prototype.removePack = function(pack) { this.resourcePacks.splice(index, 1); this.rebuildArrays(); } -} +}; Resources.prototype.removeAllPacks = function() { this.resourcePacks = []; this.rebuildArrays(); -} +}; Resources.prototype.getSongNames = function() { - var names = [] + var names = []; for(var i = 0; i < this.allSongs.length; i++) { names.push(this.allSongs[i]); } return names; -} +}; Resources.prototype.loadLocal = function() { console.log("Loading local zip(s)"); @@ -242,7 +242,7 @@ Resources.prototype.loadLocal = function() { this.fileParseQueue.push(files[i]); } this.parseLocalQueue(); -} +}; Resources.prototype.parseLocalQueue = function(recursing) { var that = this; @@ -265,7 +265,7 @@ Resources.prototype.parseLocalQueue = function(recursing) { console.log("Local respack parsing complete"); this.currentlyParsing = false; } -} +}; Resources.prototype.localProgress = function(progress, respack) { this.packsView.progressStatus.textContent = "Processing..."; @@ -274,7 +274,7 @@ Resources.prototype.localProgress = function(progress, respack) { this.packsView.progressCurrent.textContent = respack.filesLoaded; this.packsView.progressTop.textContent = respack.filesToLoad; this.packsView.progressPercent.textContent = Math.round(progress * 100) + "%"; -} +}; Resources.prototype.localComplete = function(progress) { var progStat = this.packsView.progressStatus; @@ -285,7 +285,7 @@ Resources.prototype.localComplete = function(progress) { this.packsView.progressCurrent.textContent = "0b"; this.packsView.progressTop.textContent = "0b"; this.packsView.progressPercent.textContent = "0%"; -} +}; Resources.prototype.initUI = function() { this.root = document.getElementById("huesResources"); @@ -302,11 +302,14 @@ Resources.prototype.initUI = function() { packList.className = "res-list"; packList.id = "res-packlist"; this.packsView.respackList = packList; + // so we don't use it out of scope in the next if + var remoteHeader = null; + var remoteList = null; if(!this.core.settings.defaults.disableRemoteResources) { - var remoteHeader = document.createElement("div"); + remoteHeader = document.createElement("div"); remoteHeader.textContent = "Remote respacks"; remoteHeader.className = "res-header"; - var remoteList = document.createElement("div"); + remoteList = document.createElement("div"); remoteList.className = "res-list"; remoteList.id = "res-remotelist"; this.appendSimpleListItem("Click to load the list", remoteList, @@ -397,7 +400,7 @@ Resources.prototype.initUI = function() { packInfo.appendChild(packSize); var packDesc = document.createElement("div"); packDesc.id = "res-packdesc"; - packDesc.textContent = "" + packDesc.textContent = ""; var packTabs = document.createElement("div"); packTabs.id = "res-packtabs"; @@ -424,7 +427,7 @@ Resources.prototype.initUI = function() { imageCount.htmlFor = "res-imagetab"; packTabs.appendChild(imageCheck); packTabs.appendChild(imageCount); - ; + var songList = document.createElement("div"); songList.id = "res-songlist"; songList.className = "res-list"; @@ -507,12 +510,12 @@ Resources.prototype.initUI = function() { this.listView.appendChild(this.enabledSongList); this.listView.appendChild(this.enabledImageList); -} +}; Resources.prototype.hideLists = function() { this.enabledSongList.className = "hidden"; this.enabledImageList.className = "hidden"; -} +}; Resources.prototype.toggleSongList = function() { if(this.enabledSongList.className == "hidden") { @@ -521,7 +524,7 @@ Resources.prototype.toggleSongList = function() { this.enabledSongList.className = "hidden"; } this.enabledImageList.className = "hidden"; -} +}; Resources.prototype.toggleImageList = function() { if(this.enabledImageList.className == "hidden") { @@ -530,18 +533,18 @@ Resources.prototype.toggleImageList = function() { this.enabledImageList.className = "hidden"; } this.enabledSongList.className = "hidden"; -} +}; Resources.prototype.updateTotals = function() { this.packView.totalSongs.textContent = this.enabledSongs.length + "/" + this.allSongs.length; this.packView.totalImages.textContent = this.enabledImages.length + "/" + this.allImages.length; -} +}; Resources.prototype.truncateNum = function(num) { return Math.round(num * 100) / 100; -} +}; Resources.prototype.selectPack = function(id) { var pack = this.resourcePacks[id]; @@ -566,10 +569,10 @@ Resources.prototype.selectPack = function(id) { var songList = this.packView.songList; var imageList = this.packView.imageList; while (songList.firstElementChild) { - songList.removeChild(songList.firstElementChild) + songList.removeChild(songList.firstElementChild); } while (imageList.firstElementChild) { - imageList.removeChild(imageList.firstElementChild) + imageList.removeChild(imageList.firstElementChild); } for(var i = 0; i < pack.songs.length; i++) { @@ -587,12 +590,12 @@ Resources.prototype.selectPack = function(id) { this.clickResourceCallback(image, false), image.enabled); } -} +}; Resources.prototype.selectPackCallback = function(id) { var that = this; - return function() {that.selectPack(id)}; -} + return function() {that.selectPack(id);}; +}; Resources.prototype.selectResourceCallback = function(res) { var that = this; @@ -600,7 +603,7 @@ Resources.prototype.selectResourceCallback = function(res) { res.enabled = this.checked; that.rebuildEnabled(); }; -} +}; Resources.prototype.clickResourceCallback = function(res, isSong) { var that = this; @@ -618,7 +621,7 @@ Resources.prototype.clickResourceCallback = function(res, isSong) { that.core.setIsFullAuto(false); } }; -} +}; Resources.prototype.getEnabledTabContents = function() { var pack = this.packView.pack; @@ -632,7 +635,7 @@ Resources.prototype.getEnabledTabContents = function() { ret.elName = "song"; } return ret; -} +}; Resources.prototype.enableAll = function() { var tab = this.getEnabledTabContents(); @@ -643,7 +646,7 @@ Resources.prototype.enableAll = function() { document.getElementById(tab.elName + i).checked = true; } this.rebuildEnabled(); -} +}; Resources.prototype.disableAll = function() { var tab = this.getEnabledTabContents(); @@ -654,7 +657,7 @@ Resources.prototype.disableAll = function() { document.getElementById(tab.elName + i).checked = false; } this.rebuildEnabled(); -} +}; Resources.prototype.invert = function() { var tab = this.getEnabledTabContents(); @@ -665,10 +668,10 @@ Resources.prototype.invert = function() { document.getElementById(tab.elName + i).checked = tab.arr[i].enabled; } this.rebuildEnabled(); -} +}; Resources.prototype.appendListItem = function(name, value, id, root, oncheck, onclick, checked) { - if(checked == undefined) { + if(checked === undefined) { checked = true; } var div = document.createElement("div"); @@ -689,13 +692,13 @@ Resources.prototype.appendListItem = function(name, value, id, root, oncheck, on div.appendChild(checkStyler); div.appendChild(label); root.appendChild(div); -} +}; Resources.prototype.loadRemotes = function() { var that = this; var remoteList = this.packsView.remoteList; while(remoteList.firstElementChild) { - remoteList.removeChild(remoteList.firstElementChild) + remoteList.removeChild(remoteList.firstElementChild); } var item = this.appendSimpleListItem("Loading...", remoteList); @@ -712,26 +715,26 @@ Resources.prototype.loadRemotes = function() { req.onerror = function() { item.textContent = "Could not load list! Click to try again"; item.onclick = function() {that.loadRemotes();}; - } + }; req.send(); -} +}; Resources.prototype.populateRemotes = function() { var remoteList = this.packsView.remoteList; while(remoteList.firstElementChild) { - remoteList.removeChild(remoteList.firstElementChild) + remoteList.removeChild(remoteList.firstElementChild); } for(var i = 0; i < this.remotes.length; i++) { this.remotes[i].loaded = false; this.appendSimpleListItem(this.remotes[i].name, remoteList, this.getRemoteCallback(i)); } -} +}; Resources.prototype.getRemoteCallback = function(index) { var that = this; return function() {that.selectRemotePack(index);}; -} +}; Resources.prototype.selectRemotePack = function(id) { var pack = this.remotes[id]; @@ -762,10 +765,10 @@ Resources.prototype.selectRemotePack = function(id) { var songList = this.packView.songList; var imageList = this.packView.imageList; while (songList.firstElementChild) { - songList.removeChild(songList.firstElementChild) + songList.removeChild(songList.firstElementChild); } while (imageList.firstElementChild) { - imageList.removeChild(imageList.firstElementChild) + imageList.removeChild(imageList.firstElementChild); } for(var i = 0; i < pack.songs.length; i++) { @@ -777,14 +780,14 @@ Resources.prototype.selectRemotePack = function(id) { var image = pack.images[i]; this.appendSimpleListItem(image, imageList); } -} +}; Resources.prototype.loadCurrentRemote = function() { var pack = this.packView.pack; var that = this; // Not actually a remote, ignore. How did you press this :< - if(pack.loaded == undefined || pack.loaded) { + if(pack.loaded === undefined || pack.loaded) { return; } @@ -796,7 +799,7 @@ Resources.prototype.loadCurrentRemote = function() { that.remoteComplete(); }, function(progress, respack) {that.remoteProgress(progress, respack);} ); -} +}; Resources.prototype.remoteProgress = function(progress, respack) { if(progress < 0.5) { @@ -812,7 +815,7 @@ Resources.prototype.remoteProgress = function(progress, respack) { this.packsView.progressBar.style.width = ((progress - 0.5) * 2 * 100) + "%"; this.packsView.progressPercent.textContent = Math.round((progress - 0.5) * 2 * 100) + "%"; } -} +}; Resources.prototype.remoteComplete = function(progress) { var progStat = this.packsView.progressStatus; @@ -824,7 +827,7 @@ Resources.prototype.remoteComplete = function(progress) { this.packsView.progressCurrent.textContent = "0b"; this.packsView.progressTop.textContent = "0b"; this.packsView.progressPercent.textContent = "0%"; -} +}; Resources.prototype.appendSimpleListItem = function(value, root, onclick) { var div = document.createElement("div"); @@ -835,4 +838,4 @@ Resources.prototype.appendSimpleListItem = function(value, root, onclick) { div.appendChild(label); root.appendChild(div); return label; -} \ No newline at end of file +}; \ No newline at end of file diff --git a/js/ResourcePack.js b/js/ResourcePack.js index 257b779..b559ad4 100644 --- a/js/ResourcePack.js +++ b/js/ResourcePack.js @@ -72,7 +72,7 @@ Respack.prototype.updateProgress = function() { } this.progressCallback(percent, this); } -} +}; Respack.prototype.loadFromURL = function(url, callback, progress) { var that = this; @@ -87,7 +87,7 @@ Respack.prototype.loadFromURL = function(url, callback, progress) { }; req.onerror = function() { console.log("Could not load respack at URL", url); - } + }; req.onprogress = function(event) { if (event.lengthComputable) { that.size = event.total; @@ -99,9 +99,9 @@ Respack.prototype.loadFromURL = function(url, callback, progress) { } else { // Unable to compute progress information since the total size is unknown } - } + }; req.send(); -} +}; Respack.prototype.loadBlob = function(blob, callback, progress, errorCallback) { this._completionCallback = callback; @@ -121,7 +121,7 @@ Respack.prototype.loadBlob = function(blob, callback, progress, errorCallback) { } } ); -} +}; Respack.prototype.parseWholeZip = function() { // TODO might break on bad file @@ -143,10 +143,10 @@ Respack.prototype.parseWholeZip = function() { debug("ZIP loader: trying to finish"); this.tryFinish(); -} +}; Respack.prototype.parseFile = function(file) { - var name = file.name + var name = file.name; if (name.match(this.audioExtensions)) { this.parseSong(file); this.filesToLoad++; @@ -168,15 +168,15 @@ Respack.prototype.parseFile = function(file) { default: } } -} +}; Respack.prototype.parseSong = function(file) { this.songQueue.push(file); -} +}; Respack.prototype.parseImage = function(file) { this.imageQueue.push(file); -} +}; Respack.prototype.parseXML = function() { var that = this; @@ -227,13 +227,13 @@ Respack.prototype.parseXML = function() { if(this._completionCallback) { this._completionCallback(); } -} +}; // Save some chars Element.prototype.getTag = function(tag, def) { var t = this.getElementsByTagName(tag)[0]; return t ? t.textContent : (def ? def : null); -} +}; Respack.prototype.parseSongFile = function(text) { debug(" - Parsing songFile"); @@ -241,7 +241,7 @@ Respack.prototype.parseSongFile = function(text) { var oParser = new DOMParser(); var oDOM = oParser.parseFromString(text, "text/xml"); if(oDOM.documentElement.nodeName !== "songs"){ - console.log("songs.xml error, corrupt file?") + console.log("songs.xml error, corrupt file?"); return; } @@ -280,7 +280,7 @@ Respack.prototype.parseSongFile = function(text) { // get rid of the junk this.songs.splice(this.songs.indexOf(build), 1); } else { - debug(" WARNING!", "Didn't find a buildup '" + buildup + "'!"); + debug(" WARNING!", "Didn't find a buildup '" + song.buildup + "'!"); } } @@ -301,11 +301,11 @@ Respack.prototype.parseSongFile = function(text) { } for(var i = 0; i < this.songs.length; i++) { if(newSongs.indexOf(this.songs[i]) == -1) { - debug(" WARNING!", "We have a file for", song.name, "but no information for it"); + debug(" WARNING!", "We have a file for", this.songs[i].name, "but no information for it"); } } this.songs = newSongs; -} +}; Respack.prototype.parseInfoFile = function(text) { debug(" - Parsing infoFile"); @@ -314,7 +314,7 @@ Respack.prototype.parseInfoFile = function(text) { var oDOM = oParser.parseFromString(text, "text/xml"); var info = oDOM.documentElement; if(info.nodeName !== "info"){ - console.log("info.xml error, corrupt file?") + console.log("info.xml error, corrupt file?"); return; } @@ -323,7 +323,7 @@ Respack.prototype.parseInfoFile = function(text) { this.author = info.getTag("author", this.author); this.description = info.getTag("description", this.description); this.link = info.getTag("link", this.link); -} +}; Respack.prototype.parseImageFile = function(text) { debug(" - Parsing imagefile"); @@ -331,7 +331,7 @@ Respack.prototype.parseImageFile = function(text) { var oParser = new DOMParser(); var oDOM = oParser.parseFromString(text, "text/xml"); if(oDOM.documentElement.nodeName !== "images"){ - console.log("images.xml error, corrupt file?") + console.log("images.xml error, corrupt file?"); return; } @@ -352,7 +352,7 @@ Respack.prototype.parseImageFile = function(text) { image.beatsPerAnim = parseFloat(el.getTag("beatsPerAnim")); var frameDur = el.getTag("frameDuration"); if(frameDur) { - image.frameDurations = [] + image.frameDurations = []; var strSplit = frameDur.split(","); for(var j = 0; j < strSplit.length; j++) { image.frameDurations.push(parseInt(strSplit[j])); @@ -385,15 +385,15 @@ Respack.prototype.parseImageFile = function(text) { return a.name.localeCompare(b.name); }); this.images = newImages; -} +}; Respack.prototype.containsSong = function(name) { return this.getSong(name) !== null; -} +}; Respack.prototype.containsImage = function(name) { return this.getImage(name) !== null; -} +}; Respack.prototype.getSong = function(name) { for(var i = 0; i < this.songs.length; i++) { @@ -402,7 +402,7 @@ Respack.prototype.getSong = function(name) { } } return null; -} +}; Respack.prototype.getImage = function(name) { for(var i = 0; i < this.images.length; i++) { @@ -411,7 +411,7 @@ Respack.prototype.getImage = function(name) { } } return null; -} +}; Respack.prototype.parseSongQueue = function() { var that = this; @@ -458,14 +458,14 @@ Respack.prototype.parseSongQueue = function() { }); this.songs.push(newSong); } -} +}; Respack.prototype.parseImageQueue = function() { var imgFile = this.imageQueue.shift(); var name = imgFile.name.replace(this.imageExtensions, ""); - if (match = name.match(new RegExp("^(.*)_(\\d+)$"))) { - var anim = this.getImage(match[1]) + if((match = name.match(new RegExp("^(.*)_(\\d+)$")))) { + var anim = this.getImage(match[1]); if(!anim) { // make a fresh one anim = {"name":match[1], "fullname":match[1], @@ -493,10 +493,10 @@ Respack.prototype.parseImageQueue = function() { this.images.push(img); this.imageLoadStart(imgFile, img); } else { - existing = this.getImage(name); + var existing = this.getImage(name); debug("WARNING: Image", name, "already exists! Conflict with", imgFile.name, "and", existing.name); } -} +}; Respack.prototype.imageLoadStart = function(imgFile, imageObj) { var that = this; @@ -519,10 +519,10 @@ Respack.prototype.imageLoadStart = function(imgFile, imageObj) { imgFile.getData64URI(mime, function(image) { that.imageLoadComplete(image, imageObj); }); -} +}; Respack.prototype.imageLoadComplete = function(imageBmp, imageObj) { - newImg = new Image(); + var newImg = new Image(); newImg.src = imageBmp; if (imageObj.animated) { imageObj.bitmaps.push(newImg); @@ -533,7 +533,7 @@ Respack.prototype.imageLoadComplete = function(imageBmp, imageObj) { this.filesLoaded++; this.updateProgress(); this.tryFinish(); -} +}; Respack.prototype.tryFinish = function() { if (this.imageQueue.length > 0) { @@ -544,4 +544,4 @@ Respack.prototype.tryFinish = function() { debug("Finished parsing images/songs, parsing xml files..."); this.parseXML(); } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/js/SoundManager.js b/js/SoundManager.js index 0b4eea7..4b24c8c 100644 --- a/js/SoundManager.js +++ b/js/SoundManager.js @@ -144,7 +144,7 @@ SoundManager.prototype.playSong = function(song, playBuild, callback) { } } }); -} +}; SoundManager.prototype.stop = function() { if (this.playing) { @@ -157,7 +157,7 @@ SoundManager.prototype.stop = function() { this.loopStart = 0; this.loopLength = 0; } -} +}; // In seconds, relative to the loop start SoundManager.prototype.currentTime = function() { @@ -165,7 +165,7 @@ SoundManager.prototype.currentTime = function() { return 0; } return this.context.currentTime - this.startTime; -} +}; SoundManager.prototype.displayableTime = function() { if(!this.playing) { @@ -177,7 +177,7 @@ SoundManager.prototype.displayableTime = function() { } else { return time % this.loopLength; } -} +}; SoundManager.prototype.loadBuffer = function(song, callback) { if(callback) { @@ -187,7 +187,7 @@ SoundManager.prototype.loadBuffer = function(song, callback) { this.loadAudioFile(song, true); } this.loadAudioFile(song, false); -} +}; SoundManager.prototype.loadAudioFile = function(song, isBuild) { this.context.decodeAudioData( @@ -197,7 +197,7 @@ SoundManager.prototype.loadAudioFile = function(song, isBuild) { console.log('Error decoding audio "' + song.name + '".'); } ); -} +}; /* decodeAudioData nukes our original MP3 array, but we want to keep it around for memory saving purposes, so we must duplicate it locally here */ @@ -223,7 +223,7 @@ SoundManager.prototype.getAudioCallback = function(song, isBuild) { } that.onSongLoad(song); }; -} +}; SoundManager.prototype.onSongLoad = function(song) { // if this fails, we need to wait for the other part to load @@ -243,7 +243,7 @@ SoundManager.prototype.onSongLoad = function(song) { this.onLoadCallback = null; } } -} +}; // because MP3 is bad, we nuke silence SoundManager.prototype.trimMP3 = function(buffer, forceTrim, noTrim) { @@ -272,7 +272,7 @@ SoundManager.prototype.trimMP3 = function(buffer, forceTrim, noTrim) { } } return ret; -} +}; // This wouldn't be required if Web Audio could do gapless playback properly SoundManager.prototype.concatenateAudioBuffers = function(buffer1, buffer2) { @@ -312,27 +312,27 @@ SoundManager.prototype.setMute = function(mute) { this.core.userInterface.updateVolume(this.gainNode.gain.value); this.mute = mute; return mute; -} +}; SoundManager.prototype.toggleMute = function() { return this.setMute(!this.mute); -} +}; SoundManager.prototype.decreaseVolume = function() { this.setMute(false); - val = Math.max(this.gainNode.gain.value - 0.1, 0); + var val = Math.max(this.gainNode.gain.value - 0.1, 0); this.gainNode.gain.value = val; this.core.userInterface.updateVolume(val); -} +}; SoundManager.prototype.increaseVolume = function() { this.setMute(false); - val = Math.min(this.gainNode.gain.value + 0.1, 1); + var val = Math.min(this.gainNode.gain.value + 0.1, 1); this.gainNode.gain.value = val; this.core.userInterface.updateVolume(val); -} +}; SoundManager.prototype.setVolume = function(vol) { this.gainNode.gain.value = vol; this.core.userInterface.updateVolume(vol); -} \ No newline at end of file +}; \ No newline at end of file