diff --git a/public/blobs/snr/audio/ding.mp3 b/public/blobs/snr/audio/ding.mp3 new file mode 100644 index 0000000..8c81acf Binary files /dev/null and b/public/blobs/snr/audio/ding.mp3 differ diff --git a/src/lib/resources.ts b/src/lib/resources.ts index 2a8c2cb..8ebfdfd 100644 --- a/src/lib/resources.ts +++ b/src/lib/resources.ts @@ -41,7 +41,7 @@ export class ResourceManager { ) { const identifier = parseNamespacedId(name); if (typeof (value as EventSource).addEventListener === "function") { - if (value instanceof Image) { + if (value instanceof Image || value instanceof Audio) { // During development, we can use the local file system value.src = `/blobs/${identifier.namespace}/${identifier.type}/${identifier.name}${ @@ -55,8 +55,10 @@ export class ResourceManager { const onload = () => { this.resources.set(name, value); resolve(true); + (value as EventSource).removeEventListener("loadeddata", onload); (value as EventSource).removeEventListener("load", onload); }; + (value as EventSource).addEventListener("loadeddata", onload); (value as EventSource).addEventListener("load", onload); }), ); diff --git a/src/math/angle.ts b/src/math/angle.ts new file mode 100644 index 0000000..c9d272f --- /dev/null +++ b/src/math/angle.ts @@ -0,0 +1,7 @@ +export function angleToRadians(angle: number) { + return angle / 180 * Math.PI; +} + +export function angleToDegrees(angle: number) { + return angle * 180 / Math.PI; +} diff --git a/src/state/states/LoadState.ts b/src/state/states/LoadState.ts index 363b853..27424b6 100644 --- a/src/state/states/LoadState.ts +++ b/src/state/states/LoadState.ts @@ -39,9 +39,11 @@ export class LoadState extends State { resources.set("snr:sprite/LargeLady", new Image()); // resources.get("snr:sprite/engine")!.src = // "/sprites/EngineSprites.png"; + + resources.set("snr:audio/ding", new Audio()); resources.ready().then(() => { this.stateMachine.transitionTo(States.RUNNING); - }); + }).catch((e) => console.error(e)); const doodler = getContextItem("doodler"); // this.layers.push(doodler.createLayer((_, __, dTime) => {