From 6f5218cd66b15ab97a965cb0053644940d6b8a13 Mon Sep 17 00:00:00 2001 From: William Toohey Date: Tue, 2 Feb 2016 22:33:57 +1000 Subject: [PATCH] Right click to seek, XML saves filename --- src/js/HuesEditor.js | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/js/HuesEditor.js b/src/js/HuesEditor.js index 18a1883..142e49c 100644 --- a/src/js/HuesEditor.js +++ b/src/js/HuesEditor.js @@ -248,10 +248,17 @@ HuesEditor.prototype.loadAudio = function(editor) { // load audio this.blobToArrayBuffer(file) .then(buffer => { - // First load, go fresh, get the core synced up + // If first load, this makes fresh, gets the core synced up this.newSong(this.song); this.song[editor._sound] = buffer; + // Save filename for XML export + var noExt = file.name.replace(/\.[^/.]+$/, ""); + if(editor._sound == "sound") { + this.song.name = noExt; + } else { + this.song.buildupName = noExt; + } // make empty map if needed if(!this.getText(editor)) { this.setText(editor, "x...o...x...o..."); @@ -267,7 +274,8 @@ HuesEditor.prototype.loadAudio = function(editor) { this.core.updateBeatLength(); // We may have to go backwards in time this.core.recalcBeatIndex(); - }).catch(() => { + }).catch(error => { + console.log(error); alert("Couldn't load song! Is it a LAME encoded MP3?"); }); } @@ -602,6 +610,7 @@ HuesEditor.prototype.uiCreateSingleEditor = function(title, soundName, rhythmNam beatmap.contentEditable = true; beatmap.spellcheck = false; beatmap.oninput = this.textUpdated.bind(this, container); + beatmap.oncontextmenu = this.rightClick.bind(this, container); var beatHilight = document.createElement("div"); beatHilight.className = "beat-hilight"; @@ -626,6 +635,27 @@ HuesEditor.prototype.uiCreateSingleEditor = function(title, soundName, rhythmNam return container; } +HuesEditor.prototype.rightClick = function(editor, event) { + // We abuse the fact that right clicking moves the caret. Hooray! + var caret = this.getCaret(editor._beatmap); + var totalLen = this.getText(editor).length; + var percent = caret / totalLen; + if(caret <= totalLen) { + var seekTime = 0; + if(editor._rhythm == "rhythm") { // loop + seekTime = this.core.soundManager.loopLength * percent; + } else { // build + var bLen = this.core.soundManager.buildLength; + seekTime = -bLen + bLen * percent; + } + this.core.soundManager.seek(seekTime); + event.preventDefault(); + return false; + } else { + return true; + } +} + HuesEditor.prototype.textUpdated = function(editor) { if(!this.song || !this.song[editor._sound]) { this.reflow(editor, "");