no audio warning

This commit is contained in:
Daniel Bulant 2022-08-22 14:59:47 +02:00
parent ce8d590785
commit 33c5e2dc78
2 changed files with 31 additions and 2 deletions

View file

@ -7,7 +7,8 @@
import { gameActive, menuActive, page } from "./stores/gameActive";
import Menu from "./pages/menu.svelte";
import CrashHandler from "./pages/crashHandler.svelte";
import { startPlaying } from "./stores/music";
import { startPlaying, isPlaying } from "./stores/music";
import { fade } from "svelte/transition";
var preloads = new Map;
function preload(url) {
@ -69,6 +70,12 @@
</div>
{/if}
{#if !$isPlaying}
<div class="play-notif" transition:fade={{ duration: 300 }}>
Click anywhere for sound.
</div>
{/if}
{#if dialog[$page].map}
<Game bind:current={$page} />
{/if}
@ -99,4 +106,14 @@
vertical-align: middle;
line-height: normal;
}
.play-notif {
position: fixed;
top: 0;
left: 0;
width: 100vw;
text-align: center;
background-image: linear-gradient(to bottom, rgba(0,0,0,0.7), rgba(0,0,0,0.0));
z-index: 98;
font-size: x-large;
}
</style>

View file

@ -1,4 +1,5 @@
import { Howl } from "howler";
import { writable } from "svelte/store";
export const musicStore = {
departure: {
@ -13,6 +14,8 @@ export const musicStore = {
export class Music {
static current = musicStore.departure;
static isPlaying = writable(false);
/**
* @param {keyof musicStore} key
*/
@ -21,6 +24,11 @@ export class Music {
this.current = musicStore[key];
if(!this.current.howl) this.prepare();
this.current.howl.play();
if(this.current.howl.playing()) {
this.isPlaying.set(true);
}
this.current.howl.on("play", () => this.isPlaying.set(true));
this.current.howl.on("pause", () => this.isPlaying.set(false));
}
static prepare() {
@ -32,13 +40,17 @@ export class Music {
}
static startPlaying() {
if(!this.current.howl.playing())
if(!this.current.howl.playing()) {
this.current.howl.play();
this.isPlaying.set(true);
}
}
}
Music.prepare();
Music.startPlaying();
export const isPlaying = Music.isPlaying;
export function startPlaying(e) {
Music.startPlaying();
}