Use arrow functions over .bind

master
William Toohey 10 years ago
parent 7b77d5c320
commit 9772999605
  1. 28
      src/js/HuesCore.js
  2. 4
      src/js/HuesSettings.js
  3. 52
      src/js/HuesUI.js
  4. 49
      src/js/ResourceManager.js
  5. 48
      src/js/ResourcePack.js
  6. 40
      src/js/SoundManager.js

@ -112,11 +112,11 @@ function HuesCore(defaults) {
settingsupdated : [] settingsupdated : []
}; };
window.onerror = function(msg, url, line, col, error) { window.onerror = (msg, url, line, col, error) => {
this.error(msg); this.error(msg);
// Get more info in console // Get more info in console
return false; return false;
}.bind(this); };
var versionString = "v" + (parseInt(this.version)/10).toFixed(1); var versionString = "v" + (parseInt(this.version)/10).toFixed(1);
console.log("0x40 Hues " + versionString + " - start your engines!"); console.log("0x40 Hues " + versionString + " - start your engines!");
@ -140,10 +140,8 @@ function HuesCore(defaults) {
this.vCtx = this.visualiser.getContext("2d"); this.vCtx = this.visualiser.getContext("2d");
this.soundManager = new SoundManager(this); this.soundManager = new SoundManager(this);
this.soundManager.init().then(function(response) { this.soundManager.init().then(response => {
setInterval(function() { setInterval(this.loopCheck.bind(this), 1000);
this.loopCheck();
}.bind(this), 1000);
this.renderer = new HuesCanvas("waifu", this.soundManager.context, this); this.renderer = new HuesCanvas("waifu", this.soundManager.context, this);
this.settings.connectCore(this); this.settings.connectCore(this);
// Update with merged // Update with merged
@ -162,7 +160,7 @@ function HuesCore(defaults) {
document.getElementById("preloadHelper").style.display = "none"; document.getElementById("preloadHelper").style.display = "none";
return; return;
} }
}.bind(this)).then(function(response) { }).then(response => {
document.getElementById("preloadHelper").classList.add("loaded"); document.getElementById("preloadHelper").classList.add("loaded");
if(defaults.firstImage) { if(defaults.firstImage) {
this.setImageByName(defaults.firstImage); this.setImageByName(defaults.firstImage);
@ -176,11 +174,11 @@ function HuesCore(defaults) {
this.setSong(0); this.setSong(0);
} }
} }
}.bind(this))["catch"](function(error) { }).catch(error => {
this.error(error); this.error(error);
}.bind(this)); });
document.onkeydown = function(e){ document.onkeydown = (e) => {
e = e || window.event; e = e || window.event;
if(e.defaultPrevented) { if(e.defaultPrevented) {
return true; return true;
@ -196,7 +194,7 @@ function HuesCore(defaults) {
} }
var key = e.keyCode || e.which; var key = e.keyCode || e.which;
return this.keyHandler(key); return this.keyHandler(key);
}.bind(this); };
} }
HuesCore.prototype.callEventListeners = function(ev) { HuesCore.prototype.callEventListeners = function(ev) {
@ -377,11 +375,11 @@ HuesCore.prototype.setSong = function(index) {
} }
} }
this.setInvert(false); this.setInvert(false);
this.soundManager.playSong(this.currentSong, this.doBuildup, function() { this.soundManager.playSong(this.currentSong, this.doBuildup, () => {
this.resetAudio(); this.resetAudio();
this.fillBuildup(); this.fillBuildup();
this.callEventListeners("songstarted"); this.callEventListeners("songstarted");
}.bind(this)); });
}; };
HuesCore.prototype.updateBeatLength = function() { HuesCore.prototype.updateBeatLength = function() {
@ -470,9 +468,9 @@ HuesCore.prototype.doAutoSong = function() {
func = this.nextSong; func = this.nextSong;
} }
if(localStorage["autoSongFadeout"] == "on") { if(localStorage["autoSongFadeout"] == "on") {
this.soundManager.fadeOut(function() { this.soundManager.fadeOut(() => {
func.call(this); func.call(this);
}.bind(this)); });
} else { } else {
func.call(this); func.call(this);
} }

@ -240,9 +240,7 @@ function HuesSettings(defaults) {
} }
// because we still care about the main window // because we still care about the main window
document.getElementById("closeButton").onclick = function() { document.getElementById("closeButton").onclick = this.hide.bind(this);
this.hide();
}.bind(this);
if(!this.defaults.noUI) { if(!this.defaults.noUI) {
this.initUI(); this.initUI();
} }

@ -100,28 +100,28 @@ HuesUI.prototype.initUI = function() {
// Prev/next controls // Prev/next controls
var imagePrev = document.createElement("div"); var imagePrev = document.createElement("div");
imagePrev.textContent = "<"; imagePrev.textContent = "<";
imagePrev.onclick = function() {this.core.previousImage();}.bind(this); imagePrev.onclick = () => {this.core.previousImage();};
this.imagePrev = imagePrev; this.imagePrev = imagePrev;
var imageNext = document.createElement("div"); var imageNext = document.createElement("div");
imageNext.textContent = ">"; imageNext.textContent = ">";
imageNext.onclick = function() {this.core.nextImage();}.bind(this); imageNext.onclick = () =>{this.core.nextImage();};
this.imageNext = imageNext; this.imageNext = imageNext;
var songPrev = document.createElement("div"); var songPrev = document.createElement("div");
songPrev.textContent = "<"; songPrev.textContent = "<";
this.songPrev = songPrev; this.songPrev = songPrev;
songPrev.onclick = function() {this.core.previousSong();}.bind(this); songPrev.onclick = () =>{this.core.previousSong();};
var songNext = document.createElement("div"); var songNext = document.createElement("div");
songNext.textContent = ">"; songNext.textContent = ">";
songNext.onclick = function() {this.core.nextSong();}.bind(this); songNext.onclick = () =>{this.core.nextSong();};
this.songNext = songNext; this.songNext = songNext;
var songList = document.createElement("div"); var songList = document.createElement("div");
songList.textContent = "SONGS"; songList.textContent = "SONGS";
songList.onclick = function() {this.core.toggleSongList();}.bind(this); songList.onclick = () =>{this.core.toggleSongList();};
this.songList = songList; this.songList = songList;
var imageList = document.createElement("div"); var imageList = document.createElement("div");
imageList.textContent = "IMAGES"; imageList.textContent = "IMAGES";
imageList.onclick = function() {this.core.toggleImageList();}.bind(this); imageList.onclick = () =>{this.core.toggleImageList();};
this.imageList = imageList; this.imageList = imageList;
// Beat timer, x and y blur, millis timer // Beat timer, x and y blur, millis timer
@ -141,15 +141,15 @@ HuesUI.prototype.initUI = function() {
this.settingsToggle = document.createElement("div"); this.settingsToggle = document.createElement("div");
this.settingsToggle.innerHTML = '&#xe900;'; // COG this.settingsToggle.innerHTML = '&#xe900;'; // COG
this.settingsToggle.className = 'hues-icon'; this.settingsToggle.className = 'hues-icon';
this.settingsToggle.onclick = function() { this.settingsToggle.onclick = () => {
this.core.settings.toggle(); this.core.settings.toggle();
}.bind(this); };
this.hideToggle = document.createElement("div"); this.hideToggle = document.createElement("div");
this.hideToggle.innerHTML = "&#x25BC;"; this.hideToggle.innerHTML = "&#x25BC;";
this.hideToggle.onclick = function() { this.hideToggle.onclick = () => {
this.toggleHide(); this.toggleHide();
}.bind(this); };
this.listContainer = document.createElement("div"); this.listContainer = document.createElement("div");
this.visualiserContainer = document.createElement("div"); this.visualiserContainer = document.createElement("div");
@ -322,15 +322,15 @@ RetroUI.prototype.initUI = function() {
var imageMode = document.createElement("div"); var imageMode = document.createElement("div");
this.imageModeManual = document.createElement("div"); this.imageModeManual = document.createElement("div");
this.imageModeManual.textContent = "NORMAL"; this.imageModeManual.textContent = "NORMAL";
this.imageModeManual.onclick = function() { this.imageModeManual.onclick = () => {
this.core.setIsFullAuto(false); this.core.setIsFullAuto(false);
}.bind(this); };
this.imageModeManual.className = "hues-r-manualmode hues-r-button"; this.imageModeManual.className = "hues-r-manualmode hues-r-button";
this.imageModeAuto = document.createElement("div"); this.imageModeAuto = document.createElement("div");
this.imageModeAuto.textContent = "FULL AUTO"; this.imageModeAuto.textContent = "FULL AUTO";
this.imageModeAuto.onclick = function() { this.imageModeAuto.onclick = () => {
this.core.setIsFullAuto(true); this.core.setIsFullAuto(true);
}.bind(this); };
this.imageModeAuto.className = "hues-r-automode hues-r-button"; this.imageModeAuto.className = "hues-r-automode hues-r-button";
imageMode.appendChild(this.imageModeManual); imageMode.appendChild(this.imageModeManual);
imageMode.appendChild(this.imageModeAuto); imageMode.appendChild(this.imageModeAuto);
@ -363,9 +363,9 @@ RetroUI.prototype.initUI = function() {
this.hideRestore = document.createElement("div"); this.hideRestore = document.createElement("div");
this.hideRestore.className = "hues-r-hiderestore"; this.hideRestore.className = "hues-r-hiderestore";
this.hideRestore.innerHTML = "&#x25B2;"; this.hideRestore.innerHTML = "&#x25B2;";
this.hideRestore.onclick = function() { this.hideRestore.onclick = () => {
this.toggleHide(); this.toggleHide();
}.bind(this); };
this.root.appendChild(this.hideRestore); this.root.appendChild(this.hideRestore);
this.listContainer.className = "hues-r-listcontainer"; this.listContainer.className = "hues-r-listcontainer";
@ -580,18 +580,18 @@ ModernUI.prototype.initUI = function() {
var label = document.createElement("div"); var label = document.createElement("div");
label.textContent = "VOL"; label.textContent = "VOL";
label.className = "hues-m-vol-label"; label.className = "hues-m-vol-label";
label.onclick = function() { label.onclick = () => {
this.core.soundManager.toggleMute(); this.core.soundManager.toggleMute();
}.bind(this); };
volBar.appendChild(label); volBar.appendChild(label);
this.volLabel = label; this.volLabel = label;
this.infoToggle = document.createElement("div"); this.infoToggle = document.createElement("div");
this.infoToggle.innerHTML = '?'; this.infoToggle.innerHTML = '?';
this.infoToggle.className = "hues-m-question"; this.infoToggle.className = "hues-m-question";
this.infoToggle.onclick = function() { this.infoToggle.onclick = () => {
this.core.settings.showInfo(); this.core.settings.showInfo();
}.bind(this); };
volCluster.appendChild(this.infoToggle); volCluster.appendChild(this.infoToggle);
var input = document.createElement("input"); var input = document.createElement("input");
@ -601,9 +601,9 @@ ModernUI.prototype.initUI = function() {
input.step = 0.1; input.step = 0.1;
volBar.appendChild(input); volBar.appendChild(input);
this.volInput = input; this.volInput = input;
input.oninput = function() { input.oninput = () => {
this.core.soundManager.setVolume(parseFloat(input.value)); this.core.soundManager.setVolume(parseFloat(input.value));
}.bind(this); };
var rightBox = document.createElement("div"); var rightBox = document.createElement("div");
rightBox.className = "hues-m-rightbox"; rightBox.className = "hues-m-rightbox";
@ -623,7 +623,7 @@ ModernUI.prototype.initUI = function() {
this.songShuffle = document.createElement("div"); this.songShuffle = document.createElement("div");
this.songShuffle.innerHTML = '&#xe903;'; // SHUFFLE this.songShuffle.innerHTML = '&#xe903;'; // SHUFFLE
this.songShuffle.className = "hues-m-actbutton hues-icon"; this.songShuffle.className = "hues-m-actbutton hues-icon";
this.songShuffle.onclick = function() {this.core.randomSong();}.bind(this); this.songShuffle.onclick = () => {this.core.randomSong();};
songs.appendChild(this.songList); songs.appendChild(this.songList);
songControls.appendChild(this.songPrev); songControls.appendChild(this.songPrev);
songControls.appendChild(this.songShuffle); songControls.appendChild(this.songShuffle);
@ -642,7 +642,7 @@ ModernUI.prototype.initUI = function() {
this.imageMode = document.createElement("div"); this.imageMode = document.createElement("div");
this.imageMode.innerHTML = "&#xe901;"; // PLAY this.imageMode.innerHTML = "&#xe901;"; // PLAY
this.imageMode.className = "hues-m-actbutton hues-icon"; this.imageMode.className = "hues-m-actbutton hues-icon";
this.imageMode.onclick = function() {this.core.toggleFullAuto();}.bind(this); this.imageMode.onclick = () => {this.core.toggleFullAuto();};
this.imagePrev.className = "hues-m-prevbutton"; this.imagePrev.className = "hues-m-prevbutton";
this.imageNext.className = "hues-m-nextbutton"; this.imageNext.className = "hues-m-nextbutton";
images.appendChild(this.imageList); images.appendChild(this.imageList);
@ -690,9 +690,9 @@ ModernUI.prototype.initUI = function() {
this.hideRestore = document.createElement("div"); this.hideRestore = document.createElement("div");
this.hideRestore.className = "hues-m-hiderestore"; this.hideRestore.className = "hues-m-hiderestore";
this.hideRestore.onclick = function() { this.hideRestore.onclick = () => {
this.toggleHide(); this.toggleHide();
}.bind(this); };
this.root.appendChild(this.hideRestore); this.root.appendChild(this.hideRestore);
this.listContainer.className = "hues-m-listcontainer"; this.listContainer.className = "hues-m-listcontainer";

@ -82,7 +82,7 @@ function Resources(core) {
// Array of URLs to load, and a callback for when we're done // Array of URLs to load, and a callback for when we're done
// Preserves order of URLs being loaded // Preserves order of URLs being loaded
Resources.prototype.addAll = function(urls, progressCallback) { Resources.prototype.addAll = function(urls, progressCallback) {
return new Promise(function(resolve, reject) { return new Promise((resolve, reject) => {
this.toLoad += urls.length; this.toLoad += urls.length;
if(progressCallback) { if(progressCallback) {
this.progressCallback = progressCallback; this.progressCallback = progressCallback;
@ -91,7 +91,7 @@ Resources.prototype.addAll = function(urls, progressCallback) {
for(var i = 0; i < urls.length; i++) { for(var i = 0; i < urls.length; i++) {
var r = new Respack(); var r = new Respack();
this.rToLoad.push(r); this.rToLoad.push(r);
r.loadFromURL(urls[i], function() { r.loadFromURL(urls[i], () => {
this.toLoad--; this.toLoad--;
if(this.toLoad <= 0) { if(this.toLoad <= 0) {
for(var i = 0; i < this.rToLoad.length; i++) { for(var i = 0; i < this.rToLoad.length; i++) {
@ -101,12 +101,12 @@ Resources.prototype.addAll = function(urls, progressCallback) {
this.progressCallback = null; this.progressCallback = null;
resolve(); resolve();
} }
}.bind(this), function(index, progress, pack) { }, function(index, progress, pack) {
this.progressState[index] = progress; this.progressState[index] = progress;
this.updateProgress(pack); this.updateProgress(pack);
}.bind(this, i)); }.bind(this, i));
} }
}.bind(this)); });
}; };
Resources.prototype.updateProgress = function(pack) { Resources.prototype.updateProgress = function(pack) {
@ -239,13 +239,13 @@ Resources.prototype.parseLocalQueue = function(recursing) {
if(this.fileParseQueue.length) { if(this.fileParseQueue.length) {
var r = new Respack(); var r = new Respack();
r.loadBlob(this.fileParseQueue.shift(), r.loadBlob(this.fileParseQueue.shift(),
function() { () => {
this.addPack(r); this.addPack(r);
this.localComplete(); this.localComplete();
this.parseLocalQueue(true); this.parseLocalQueue(true);
}.bind(this), },
function(progress, respack) {this.localProgress(progress, respack);}.bind(this), (progress, respack) => {this.localProgress(progress, respack);},
function() {this.parseLocalQueue(true);}.bind(this)); () => {this.parseLocalQueue(true);});
} else { } else {
console.log("Local respack parsing complete"); console.log("Local respack parsing complete");
this.currentlyParsing = false; this.currentlyParsing = false;
@ -298,7 +298,7 @@ Resources.prototype.initUI = function() {
remoteList.className = "res-list"; remoteList.className = "res-list";
remoteList.id = "res-remotelist"; remoteList.id = "res-remotelist";
this.appendSimpleListItem("Click to load the list", remoteList, this.appendSimpleListItem("Click to load the list", remoteList,
function() {this.loadRemotes();}.bind(this)); this.loadRemotes.bind(this));
this.packsView.remoteList = remoteList; this.packsView.remoteList = remoteList;
} else { } else {
packList.className += " noremotes"; packList.className += " noremotes";
@ -309,11 +309,11 @@ Resources.prototype.initUI = function() {
var loadRemote = document.createElement("div"); var loadRemote = document.createElement("div");
loadRemote.className = "hues-button hidden"; loadRemote.className = "hues-button hidden";
loadRemote.textContent = "LOAD REMOTE"; loadRemote.textContent = "LOAD REMOTE";
loadRemote.onclick = function() {this.loadCurrentRemote();}.bind(this); loadRemote.onclick = this.loadCurrentRemote.bind(this);
var loadLocal = document.createElement("div"); var loadLocal = document.createElement("div");
loadLocal.className = "hues-button"; loadLocal.className = "hues-button";
loadLocal.textContent = "LOAD ZIPS"; loadLocal.textContent = "LOAD ZIPS";
loadLocal.onclick = function() {this.fileInput.click();}.bind(this); loadLocal.onclick = () => {this.fileInput.click};
buttons.appendChild(loadLocal); buttons.appendChild(loadLocal);
buttons.appendChild(loadRemote); buttons.appendChild(loadRemote);
this.packsView.loadRemote = loadRemote; this.packsView.loadRemote = loadRemote;
@ -322,7 +322,7 @@ Resources.prototype.initUI = function() {
this.fileInput.type ="file"; this.fileInput.type ="file";
this.fileInput.accept="application/zip"; this.fileInput.accept="application/zip";
this.fileInput.multiple = true; this.fileInput.multiple = true;
this.fileInput.onchange = function() {this.loadLocal();}.bind(this); this.fileInput.onchange = this.loadLocal.bind(this);
var progressContainer = document.createElement("div"); var progressContainer = document.createElement("div");
progressContainer.id = "res-progress-container"; progressContainer.id = "res-progress-container";
@ -428,15 +428,15 @@ Resources.prototype.initUI = function() {
var enableAll = document.createElement("div"); var enableAll = document.createElement("div");
enableAll.textContent = "ENABLE ALL"; enableAll.textContent = "ENABLE ALL";
enableAll.className = "hues-button"; enableAll.className = "hues-button";
enableAll.onclick = function() {this.enableAll();}.bind(this); enableAll.onclick = this.enableAll.bind(this);
var invert = document.createElement("div"); var invert = document.createElement("div");
invert.textContent = "INVERT"; invert.textContent = "INVERT";
invert.className = "hues-button"; invert.className = "hues-button";
invert.onclick = function() {this.invert();}.bind(this); invert.onclick = this.invert.bind(this);
var disableAll = document.createElement("div"); var disableAll = document.createElement("div");
disableAll.textContent = "DISABLE ALL"; disableAll.textContent = "DISABLE ALL";
disableAll.className = "hues-button"; disableAll.className = "hues-button";
disableAll.onclick = function() {this.disableAll();}.bind(this); disableAll.onclick = this.disableAll.bind(this);
packButtons.appendChild(enableAll); packButtons.appendChild(enableAll);
packButtons.appendChild(invert); packButtons.appendChild(invert);
packButtons.appendChild(disableAll); packButtons.appendChild(disableAll);
@ -688,17 +688,17 @@ Resources.prototype.loadRemotes = function() {
var req = new XMLHttpRequest(); var req = new XMLHttpRequest();
req.open('GET', packsURL, true); req.open('GET', packsURL, true);
req.responseType = 'json'; req.responseType = 'json';
req.onload = function() { req.onload = () => {
if(!req.response) { if(!req.response) {
req.onerror(); req.onerror();
} }
this.remotes = req.response; this.remotes = req.response;
this.populateRemotes(); this.populateRemotes();
}.bind(this); };
req.onerror = function() { req.onerror = () => {
item.textContent = "Could not load list! Click to try again"; item.textContent = "Could not load list! Click to try again";
item.onclick = function() {this.loadRemotes();}.bind(this); item.onclick = this.loadRemotes.bind(this);
}.bind(this); };
req.send(); req.send();
}; };
@ -792,13 +792,10 @@ Resources.prototype.loadCurrentRemote = function() {
pack.loaded = true; pack.loaded = true;
this.packsView.loadRemote.className = "hues-button loaded"; this.packsView.loadRemote.className = "hues-button loaded";
this.packsView.loadRemote.textContent = "LOADING"; this.packsView.loadRemote.textContent = "LOADING";
this.addAll([pack.url], function() { this.addAll([pack.url], (progress, respack) => {
this.remoteComplete();
}.bind(this),
function(progress, respack) {
this.remoteProgress(progress, respack); this.remoteProgress(progress, respack);
}.bind(this) }
); ).then(this.remoteComplete.bind(this));
}; };
Resources.prototype.remoteProgress = function(progress, respack) { Resources.prototype.remoteProgress = function(progress, respack) {

@ -83,13 +83,13 @@ Respack.prototype.loadFromURL = function(url, callback, progress) {
var req = new XMLHttpRequest(); var req = new XMLHttpRequest();
req.open('GET', url, true); req.open('GET', url, true);
req.responseType = 'blob'; req.responseType = 'blob';
req.onload = function() { req.onload = () => {
this.loadBlob(req.response, callback, progress); this.loadBlob(req.response, callback, progress);
}.bind(this); };
req.onerror = function() { req.onerror = function() {
console.log("Could not load respack at URL", url); console.log("Could not load respack at URL", url);
}; };
req.onprogress = function(event) { req.onprogress = event => {
if (event.lengthComputable) { if (event.lengthComputable) {
this.size = event.total; this.size = event.total;
this.downloaded = event.loaded; this.downloaded = event.loaded;
@ -100,7 +100,7 @@ Respack.prototype.loadFromURL = function(url, callback, progress) {
} else { } else {
// Unable to compute progress information since the total size is unknown // Unable to compute progress information since the total size is unknown
} }
}.bind(this); };
req.send(); req.send();
}; };
@ -110,16 +110,14 @@ Respack.prototype.loadBlob = function(blob, callback, progress, errorCallback) {
this.size = blob.size; this.size = blob.size;
this.file = new zip.fs.FS(); this.file = new zip.fs.FS();
this.file.importBlob(blob, this.file.importBlob(blob,
function() { // success this.parseWholeZip.bind(this),
this.parseWholeZip(); error => { // failure
}.bind(this),
function(error) { // failure
console.log("Error loading respack :", error.toString()); console.log("Error loading respack :", error.toString());
this.file = null; this.file = null;
if(errorCallback) { if(errorCallback) {
errorCallback(error.toString()); errorCallback(error.toString());
} }
}.bind(this) }
); );
}; };
@ -180,18 +178,18 @@ Respack.prototype.parseImage = function(file) {
Respack.prototype.parseXML = function() { Respack.prototype.parseXML = function() {
if (this._infoFile) { if (this._infoFile) {
this._infoFile.getText(function(text) { this._infoFile.getText(text => {
text = text.replace(/&amp;/g, '&'); text = text.replace(/&amp;/g, '&');
text = text.replace(/&/g, '&amp;'); text = text.replace(/&/g, '&amp;');
this.parseInfoFile(text); this.parseInfoFile(text);
this._infoFile = null; this._infoFile = null;
this.parseXML(); this.parseXML();
}.bind(this)); });
return; return;
} }
if (this.songs.length > 0) { if (this.songs.length > 0) {
if (this._songFile) { if (this._songFile) {
this._songFile.getText(function(text) { this._songFile.getText(text => {
//XML parser will complain about a bare '&', but some respacks use &amp //XML parser will complain about a bare '&', but some respacks use &amp
text = text.replace(/&amp;/g, '&'); text = text.replace(/&amp;/g, '&');
text = text.replace(/&/g, '&amp;'); text = text.replace(/&/g, '&amp;');
@ -200,7 +198,7 @@ Respack.prototype.parseXML = function() {
this._songFile = null; this._songFile = null;
this._songFileParsed = true; this._songFileParsed = true;
this.parseXML(); this.parseXML();
}.bind(this)); });
return; return;
} else if(!this._songFileParsed) { } else if(!this._songFileParsed) {
console.log("!!!", "Got songs but no songs.xml!"); console.log("!!!", "Got songs but no songs.xml!");
@ -208,13 +206,13 @@ Respack.prototype.parseXML = function() {
} }
} }
if (this.images.length > 0 && this._imageFile) { if (this.images.length > 0 && this._imageFile) {
this._imageFile.getText(function(text) { this._imageFile.getText(text => {
text = text.replace(/&amp;/g, '&'); text = text.replace(/&amp;/g, '&');
text = text.replace(/&/g, '&amp;'); text = text.replace(/&/g, '&amp;');
this.parseImageFile(text); this.parseImageFile(text);
this._imageFile = null; this._imageFile = null;
this.parseXML(); this.parseXML();
}.bind(this)); });
return; return;
} }
@ -443,17 +441,17 @@ Respack.prototype.parseSongQueue = function() {
default: default:
mime = "application/octet-stream"; mime = "application/octet-stream";
} }
songFile.getBlob(mime, function(sound) { songFile.getBlob(mime, sound => {
// Because blobs are crap // Because blobs are crap
var fr = new FileReader(); var fr = new FileReader();
fr.onload = function(self) { fr.onload = () => {
newSong.sound = this.result; newSong.sound = fr.result;
self.filesLoaded++; this.filesLoaded++;
self.updateProgress(); this.updateProgress();
self.tryFinish(); this.tryFinish();
}.bind(fr, this); };
fr.readAsArrayBuffer(sound); fr.readAsArrayBuffer(sound);
}.bind(this)); });
this.songs.push(newSong); this.songs.push(newSong);
} }
}; };
@ -514,9 +512,9 @@ Respack.prototype.imageLoadStart = function(imgFile, imageObj) {
default: default:
mime = "application/octet-stream"; mime = "application/octet-stream";
} }
imgFile.getData64URI(mime, function(image) { imgFile.getData64URI(mime, image => {
this.imageLoadComplete(image, imageObj); this.imageLoadComplete(image, imageObj);
}.bind(this)); });
}; };
Respack.prototype.imageLoadComplete = function(imageBmp, imageObj) { Respack.prototype.imageLoadComplete = function(imageBmp, imageObj) {

@ -66,7 +66,7 @@ function SoundManager(core) {
SoundManager.prototype.init = function() { SoundManager.prototype.init = function() {
if(!this.initPromise) { if(!this.initPromise) {
this.initPromise = new Promise(function(resolve, reject) { this.initPromise = new Promise((resolve, reject) => {
// Check Web Audio API Support // Check Web Audio API Support
try { try {
// More info at http://caniuse.com/#feat=audio-api // More info at http://caniuse.com/#feat=audio-api
@ -79,8 +79,8 @@ SoundManager.prototype.init = function() {
return; return;
} }
resolve(); resolve();
}.bind(this)).then(function(response) { }).then(response => {
return new Promise(function(resolve, reject) { return new Promise((resolve, reject) => {
// Get our MP3 decoder started // Get our MP3 decoder started
try { try {
this.mp3Worker = new Worker(this.core.settings.defaults.workersPath + 'mp3-worker.js'); this.mp3Worker = new Worker(this.core.settings.defaults.workersPath + 'mp3-worker.js');
@ -88,24 +88,24 @@ SoundManager.prototype.init = function() {
console.log(e); console.log(e);
reject(Error("MP3 Worker cannot be started - correct path set in defaults?")); reject(Error("MP3 Worker cannot be started - correct path set in defaults?"));
} }
var pingListener = function(event) { var pingListener = event => {
this.mp3Worker.removeEventListener('message', pingListener); this.mp3Worker.removeEventListener('message', pingListener);
this.mp3Worker.addEventListener('message', this.workerFinished.bind(this), false); this.mp3Worker.addEventListener('message', this.workerFinished.bind(this), false);
resolve(); resolve();
}.bind(this) };
this.mp3Worker.addEventListener('message', pingListener, false); this.mp3Worker.addEventListener('message', pingListener, false);
this.mp3Worker.addEventListener('error', function() { this.mp3Worker.addEventListener('error', () => {
reject(Error("MP3 Worker cannot be started - correct path set in defaults?")); reject(Error("MP3 Worker cannot be started - correct path set in defaults?"));
}.bind(this), false); }, false);
this.mp3Worker.postMessage({ping:true}); this.mp3Worker.postMessage({ping:true});
}.bind(this)) })
}.bind(this)).then(function(response) { }).then(response => {
return new Promise(function(resolve, reject) { return new Promise((resolve, reject) => {
// iOS and other some mobile browsers - unlock the context as // iOS and other some mobile browsers - unlock the context as
// it starts in a suspended state // it starts in a suspended state
if(this.context.state != "running") { if(this.context.state != "running") {
this.core.warning("We're about to load about 10MB of stuff. Tap to begin!"); this.core.warning("We're about to load about 10MB of stuff. Tap to begin!");
var unlocker = function() { var unlocker = () => {
// create empty buffer // create empty buffer
var buffer = this.context.createBuffer(1, 1, 22050); var buffer = this.context.createBuffer(1, 1, 22050);
var source = this.context.createBufferSource(); var source = this.context.createBufferSource();
@ -121,14 +121,14 @@ SoundManager.prototype.init = function() {
window.removeEventListener('click', unlocker); window.removeEventListener('click', unlocker);
this.core.clearMessage(); this.core.clearMessage();
resolve(); resolve();
}.bind(this); };
window.addEventListener('touchend', unlocker, false); window.addEventListener('touchend', unlocker, false);
window.addEventListener('click', unlocker, false); window.addEventListener('click', unlocker, false);
} else { } else {
resolve(); resolve();
} }
}.bind(this)) })
}.bind(this)); });
} }
return this.initPromise; return this.initPromise;
} }
@ -151,7 +151,7 @@ SoundManager.prototype.playSong = function(song, playBuild, callback) {
this.setMute(true); this.setMute(true);
} }
this.loadBuffer(song, function() { this.loadBuffer(song, () => {
// To prevent race condition if you press "next" twice fast // To prevent race condition if you press "next" twice fast
if(song == this.song) { if(song == this.song) {
// more racing than the Melbourne Cup // more racing than the Melbourne Cup
@ -167,7 +167,7 @@ SoundManager.prototype.playSong = function(song, playBuild, callback) {
// This fixes sync issues on Firefox and slow machines. // This fixes sync issues on Firefox and slow machines.
if(this.context.suspend && this.context.resume) { if(this.context.suspend && this.context.resume) {
this.context.suspend().then(function() { this.context.suspend().then(() => {
if(playBuild) { if(playBuild) {
// mobile webkit requires offset, even if 0 // mobile webkit requires offset, even if 0
this.bufSource.start(0); this.bufSource.start(0);
@ -176,12 +176,12 @@ SoundManager.prototype.playSong = function(song, playBuild, callback) {
this.bufSource.start(0, this.loopStart); this.bufSource.start(0, this.loopStart);
this.startTime = this.context.currentTime; this.startTime = this.context.currentTime;
} }
this.context.resume().then(function() { this.context.resume().then(() => {
this.playing = true; this.playing = true;
if(callback) if(callback)
callback(); callback();
}.bind(this)); });
}.bind(this)); });
} else { } else {
if(playBuild) { if(playBuild) {
// mobile webkit requires offset, even if 0 // mobile webkit requires offset, even if 0
@ -196,7 +196,7 @@ SoundManager.prototype.playSong = function(song, playBuild, callback) {
callback(); callback();
} }
} }
}.bind(this)); });
}; };
SoundManager.prototype.stop = function() { SoundManager.prototype.stop = function() {

Loading…
Cancel
Save