From 51f306d1c766d0858dbfc99e6d74a6ee9d7614ac Mon Sep 17 00:00:00 2001 From: LoveEevee Date: Tue, 4 Dec 2018 01:23:11 +0300 Subject: [PATCH] About: Descriptive errors --- public/src/js/canvasdraw.js | 13 ++++++++++--- public/src/js/loader.js | 3 ++- public/src/js/loadsong.js | 14 ++++++++------ public/src/js/main.js | 6 +++++- public/src/js/pageevents.js | 10 +++++++--- public/src/js/soundbuffer.js | 2 ++ 6 files changed, 34 insertions(+), 14 deletions(-) diff --git a/public/src/js/canvasdraw.js b/public/src/js/canvasdraw.js index a1752e1..56fb806 100644 --- a/public/src/js/canvasdraw.js +++ b/public/src/js/canvasdraw.js @@ -295,9 +295,11 @@ drawn.push({text: symbol, x: 0, y: 0, h: 39, rotate: true}) }else if(symbol === "↓"){ drawn.push({text: symbol, x: 0, y: 12, h: 45}) + }else if(symbol === "."){ + drawn.push({realText: symbol, text: ".", x: 13, y: -7, h: 15, scale: [1.2, 0.7]}) }else if(r.comma.test(symbol)){ // Comma, full stop - drawn.push({text: symbol, x: 13, y: -9, h: 13, scale: [1.2, 0.7]}) + drawn.push({text: symbol, x: 13, y: -7, h: 15, scale: [1.2, 0.7]}) }else if(r.ideographicComma.test(symbol)){ // Ideographic comma, full stop drawn.push({text: symbol, x: 16, y: -16, h: 18}) @@ -538,7 +540,7 @@ let symbol = string[i] if(symbol === "-"){ - drawn.push({text: symbol, x: -2, y: 0, w: 28, scale: [0.8, 1]}) + drawn.push({text: symbol, x: -2, y: 0, w: 28}) }else if(symbol === "™"){ drawn.push({text: symbol, x: -2, y: 0, w: 20, scale: [0.6, 0.5]}) }else if(symbol === " "){ @@ -547,9 +549,11 @@ drawn.push({text: ",", x: 0, y: -15, w: 7, scale: [1, 0.7]}) }else if(symbol === "∀"){ drawn.push({text: symbol, x: -3, y: 0, w: 55}) + }else if(symbol === "."){ + drawn.push({text: symbol, x: -9, y: 0, w: 37}) }else if(r.comma.test(symbol)){ // Comma, full stop - drawn.push({text: symbol, x: 0, y: 0, w: 13}) + drawn.push({text: symbol, x: -3, y: 13, w: 13, scale: [1.2, 0.7]}) }else if(r.en.test(symbol)){ // n-width drawn.push({text: symbol, x: 0, y: 0, w: 28}) @@ -671,6 +675,9 @@ ctx.save() ctx.translate(currentX, currentY) if(symbol.scale){ + if(config.baseline === "middle"){ + ctx.translate(0, -ctx.lineWidth * (2 / symbol.scale[1])) + } ctx.scale(symbol.scale[0], symbol.scale[1]) ctx.lineWidth /= symbol.scale[0] } diff --git a/public/src/js/loader.js b/public/src/js/loader.js index fd2b52e..ac0e7d1 100644 --- a/public/src/js/loader.js +++ b/public/src/js/loader.js @@ -151,7 +151,8 @@ class Loader{ getFilename(name){ return name.slice(0, name.lastIndexOf(".")) } - errorMsg(){ + errorMsg(error){ + console.error(error) this.error = true this.loaderPercentage.appendChild(document.createElement("br")) this.loaderPercentage.appendChild(document.createTextNode("An error occurred, please refresh")) diff --git a/public/src/js/loadsong.js b/public/src/js/loadsong.js index 546659a..6b0eae2 100644 --- a/public/src/js/loadsong.js +++ b/public/src/js/loadsong.js @@ -90,6 +90,10 @@ class loadSong{ this.setupMultiplayer() }, error => { console.error(error) + if(Array.isArray(error) && error[1] instanceof HTMLElement){ + error = error[0] + ": " + error[1].outerHTML + } + errorMessage(new Error(error).stack) alert("An error occurred, please refresh") }) } @@ -194,13 +198,11 @@ class loadSong{ if(event.value === song.difficulty){ this.startMultiplayer() }else{ - this.selectedSong2 = { - title: song.title, - folder: song.folder, - difficulty: event.value, - type: song.type, - offset: song.offset + this.selectedSong2 = {} + for(var i in this.selectedSong){ + this.selectedSong2[i] = this.selectedSong[i] } + this.selectedSong2.difficulty = event.value if(song.type === "tja"){ this.startMultiplayer() }else{ diff --git a/public/src/js/main.js b/public/src/js/main.js index 6d9b00d..af9f25f 100644 --- a/public/src/js/main.js +++ b/public/src/js/main.js @@ -5,11 +5,15 @@ addEventListener("error", function(err){ }else{ stack = err.message + "\n at " + err.filename + ":" + err.lineno + ":" + err.colno } + errorMessage(stack) +}) + +function errorMessage(stack){ localStorage["lastError"] = JSON.stringify({ timestamp: +new Date, stack: stack }) -}) +} function toggleFullscreen(){ if("requestFullscreen" in root){ diff --git a/public/src/js/pageevents.js b/public/src/js/pageevents.js index aa16104..4577851 100644 --- a/public/src/js/pageevents.js +++ b/public/src/js/pageevents.js @@ -68,10 +68,14 @@ class PageEvents{ load(target){ return new Promise((resolve, reject) => { this.race(target, "load", "error", "abort").then(response => { - if(response.type === "load"){ - return resolve(response.event) + switch(response.type){ + case "load": + return resolve(response.event) + case "error": + return reject(["Loading error", target]) + case "abort": + return reject("Loading aborted") } - return reject() }) }) } diff --git a/public/src/js/soundbuffer.js b/public/src/js/soundbuffer.js index df906c8..50b6106 100644 --- a/public/src/js/soundbuffer.js +++ b/public/src/js/soundbuffer.js @@ -10,6 +10,8 @@ }).then(response => { return new Promise((resolve, reject) => { return this.context.decodeAudioData(response, resolve, reject) + }).catch(error => { + throw [error, url] }) }).then(buffer => { return new Sound(gain || {soundBuffer: this}, buffer)