Lint & Prettier fixes on Svelte files

This commit is contained in:
Alexis Faizeau
2021-12-06 16:12:37 +01:00
parent 6cd76b9c1b
commit c95e20c677
46 changed files with 1852 additions and 1695 deletions
@@ -1,7 +1,7 @@
<script lang="typescript">
import { AudioContext } from 'standardized-audio-context';
import {SoundMeter} from "../../Phaser/Components/SoundMeter";
import {onDestroy} from "svelte";
import { AudioContext } from "standardized-audio-context";
import { SoundMeter } from "../../Phaser/Components/SoundMeter";
import { onDestroy } from "svelte";
export let stream: MediaStream | null;
let volume = 0;
@@ -11,6 +11,7 @@
let timeout: ReturnType<typeof setTimeout>;
const soundMeter = new SoundMeter();
let display = false;
let error = false;
$: {
if (stream && stream.getAudioTracks().length > 0) {
@@ -19,17 +20,19 @@
if (timeout) {
clearInterval(timeout);
error = false;
}
timeout = setInterval(() => {
try{
volume = parseInt((soundMeter.getVolume() / 100 * NB_BARS).toFixed(0));
//console.log(volume);
}catch(err){
try {
volume = parseInt(((soundMeter.getVolume() / 100) * NB_BARS).toFixed(0));
} catch (err) {
if (!error) {
console.error(err);
error = true;
}
}
}, 100);
} else {
display = false;
}
@@ -40,11 +43,10 @@
if (timeout) {
clearInterval(timeout);
}
})
});
function color(i: number, volume: number) {
const red = 255 * i / NB_BARS;
const red = (255 * i) / NB_BARS;
const green = 255 * (1 - i / NB_BARS);
let alpha = 1;
@@ -52,31 +54,29 @@
alpha = 0.5;
}
return 'background-color:rgba('+red+', '+green+', 0, '+alpha+')';
return "background-color:rgba(" + red + ", " + green + ", 0, " + alpha + ")";
}
</script>
<div class="horizontal-sound-meter" class:active={display}>
{#each [...Array(NB_BARS).keys()] as i (i)}
<div style={color(i, volume)}></div>
<div style={color(i, volume)} />
{/each}
</div>
<style lang="scss">
.horizontal-sound-meter {
display: flex;
flex-direction: row;
width: 50%;
height: 30px;
margin-left: auto;
margin-right: auto;
margin-top: 1vh;
display: flex;
flex-direction: row;
width: 50%;
height: 30px;
margin-left: auto;
margin-right: auto;
margin-top: 1vh;
}
.horizontal-sound-meter div {
margin-left: 5px;
flex-grow: 1;
margin-left: 5px;
flex-grow: 1;
}
</style>