From 5e36e8bf8532ba133d0fee171257875d8c482903 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tristan=20Dani=C3=ABl=20Maat?= Date: Sat, 29 Feb 2020 15:20:56 +0000 Subject: [PATCH] Fix javascript formatting --- src/index.js | 11 ++++---- src/music/player/audio_manager.js | 5 ++-- src/music/player/background.js | 8 ++---- src/music/player/backgrounds/Spectrum.js | 35 +++++++++++++++++------- src/music/player/controls.js | 16 ++++++----- src/music/player/display.js | 11 ++++---- src/music/player/player.js | 2 +- 7 files changed, 51 insertions(+), 37 deletions(-) diff --git a/src/index.js b/src/index.js index 71b8361..4f01543 100644 --- a/src/index.js +++ b/src/index.js @@ -22,7 +22,6 @@ class Typer { this._element.html(""); this._element.css("visibility", "visible"); - this._cursor = false; this._typed = 0; @@ -50,8 +49,9 @@ class Typer { _draw() { let text = this._text.slice(0, this._typed); - if (this._cursor) + if (this._cursor) { text += "\u2588"; + } window.requestAnimationFrame(() => this._element.html(text)); } @@ -67,8 +67,9 @@ class Typer { if (this._typed != this._text.length) setTimeout(this._type.bind(this), this._type_tick()); - else + else { this._end = Date.now(); + } } /** @@ -83,11 +84,9 @@ class Typer { // As long as we are typing, keep blinking if (this._typed != this._text.length) setTimeout(this._blink.bind(this), this._blink_tick); - // Once typing ends, keep going for a little bit else if (Date.now() - this._end < this._blink_timeout) setTimeout(this._blink.bind(this), this._blink_tick); - // Make sure we get rid of the cursor in the end else { this._cursor = true; @@ -107,4 +106,4 @@ class Typer { $(document).ready(() => { let typer = new Typer($(".head-line .typed").get(0), 500, 3000); typer.type(); -}) +}); diff --git a/src/music/player/audio_manager.js b/src/music/player/audio_manager.js index 34ea580..ca20973 100644 --- a/src/music/player/audio_manager.js +++ b/src/music/player/audio_manager.js @@ -43,10 +43,11 @@ class AudioManager { let context = this._context; let volume = this._volume; - if (this._muted) + if (this._muted) { volume.gain.setValueAtTime(1, context.currentTime); - else + } else { volume.gain.setValueAtTime(0, context.currentTime); + } this._muted = !this._muted; } diff --git a/src/music/player/background.js b/src/music/player/background.js index be9f131..031dfd2 100644 --- a/src/music/player/background.js +++ b/src/music/player/background.js @@ -4,13 +4,9 @@ class Background { throw new Error("Cannot instantiate abstract class!"); } - start() { + start() {} - } - - stop() { - - } + stop() {} } export default Background; diff --git a/src/music/player/backgrounds/Spectrum.js b/src/music/player/backgrounds/Spectrum.js index 0a6ae43..eec5efd 100644 --- a/src/music/player/backgrounds/Spectrum.js +++ b/src/music/player/backgrounds/Spectrum.js @@ -17,15 +17,24 @@ class Spectrum extends Background { } _get_canvas_height() { - return this._display.parent().height() - this._display.siblings().toArray().reduce((a, b) => { - return a + b.clientHeight; - }, 0); + return ( + this._display.parent().height() - + this._display + .siblings() + .toArray() + .reduce((a, b) => { + return a + b.clientHeight; + }, 0) + ); } _resize() { this._camera.aspect = this._display.width() / this._get_canvas_height(); this._camera.updateProjectionMatrix(); - this._renderer.setSize(this._display.width(), this._get_canvas_height()); + this._renderer.setSize( + this._display.width(), + this._get_canvas_height() + ); } _init_analyser() { @@ -33,7 +42,7 @@ class Spectrum extends Background { let analyser = audioManager.context.createAnalyser(); analyser.fftSize = 2048; - analyser.smoothingTimeConstant = .8; + analyser.smoothingTimeConstant = 0.8; let analyser_data = new Float32Array(analyser.frequencyBinCount); @@ -47,7 +56,12 @@ class Spectrum extends Background { _init_scene() { let scene = new three.Scene(); - let camera = new three.PerspectiveCamera(70, this._display.width() / this._get_canvas_height(), 0.01, 10); + let camera = new three.PerspectiveCamera( + 70, + this._display.width() / this._get_canvas_height(), + 0.01, + 10 + ); camera.position.z = 1; scene.add(camera); @@ -77,7 +91,7 @@ class Spectrum extends Background { for (let freq = 0; freq < analyser.frequencyBinCount; freq++) { let geometry = new three.BoxGeometry(1, 1, 1); - let material = new three.MeshBasicMaterial({color: 0x99d1ce}); + let material = new three.MeshBasicMaterial({ color: 0x99d1ce }); let cube = new three.Mesh(geometry, material); cube.scale.set(width, 1e-6, width); @@ -103,10 +117,11 @@ class Spectrum extends Background { for (let freq = 0; freq < analyser.frequencyBinCount; freq++) { let height = analyser.maxDecibels / this._analyser_data[freq]; - if (height > .3) - height -= .3; - else + if (height > 0.3) { + height -= 0.3; + } else { height = 1e-6; + } this._boxes[freq].scale.y = height; } diff --git a/src/music/player/controls.js b/src/music/player/controls.js index c2a97c5..4603df2 100644 --- a/src/music/player/controls.js +++ b/src/music/player/controls.js @@ -9,7 +9,7 @@ import $ from "jquery"; * @param {HTMLElement} div - The div of the text area. */ class _Text { - constructor (div) { + constructor(div) { this._element = div; this._text = ""; @@ -35,8 +35,9 @@ class _Text { let element = this._element; let flashing = this._flashing; - if (!flashing) + if (!flashing) { element.html(text); + } this._text = text; } @@ -61,7 +62,7 @@ class _Button { this._flash_timeout = null; } - click (callback) { + click(callback) { this._element.click(callback); } @@ -146,7 +147,7 @@ class Controls { text.setText(""); } - setLoading(reason="Loading") { + setLoading(reason = "Loading") { let button = this._button; let text = this._text; @@ -154,14 +155,15 @@ class Controls { text.setText(reason); } - setError(reason="") { + setError(reason = "") { let button = this._button; let text = this._text; - if (reason == "") + if (reason == "") { reason = "Error"; - else + } else { reason = `Error: ${reason}`; + } button.setIcon("fa-stop-circle"); text.setText(reason); diff --git a/src/music/player/display.js b/src/music/player/display.js index 908a189..2828909 100644 --- a/src/music/player/display.js +++ b/src/music/player/display.js @@ -2,7 +2,7 @@ import $ from "jquery"; import Spectrum from "./backgrounds/Spectrum.js"; let backgrounds = { - "Spectrum": Spectrum + Spectrum: Spectrum }; class Display { @@ -10,13 +10,14 @@ class Display { this._audioManager = audioManager; this._element = $("#playerContent"); - this._background = new backgrounds["Spectrum"](this._element, audioManager); + this._background = new backgrounds["Spectrum"]( + this._element, + audioManager + ); this._background.start(); } - set background(name) { - - } + set background(name) {} } export default Display; diff --git a/src/music/player/player.js b/src/music/player/player.js index cb844d6..749c8e1 100644 --- a/src/music/player/player.js +++ b/src/music/player/player.js @@ -4,7 +4,7 @@ import Controls from "./controls"; import Display from "./display"; class Player { - constructor(src="https://tlater.net/assets/Mseq_-_Journey.mp3") { + constructor(src = "https://tlater.net/assets/Mseq_-_Journey.mp3") { this._ui = $("#playerUI"); this._audioManager = new AudioManager(src); this._controls = new Controls(this._audioManager);