@antha/audio 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +39 -3
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,11 +1,47 @@
1
1
  # @antha/audio
2
2
 
3
- A pre-built [Antha](https://www.npmjs.com/package/antha) mod for handling audio.
4
-
5
- Demo: https://electrovir.github.io/antha/demo/audio
3
+ This package provides a pre-built [Antha game engine](https://www.npmjs.com/package/@antha/engine) mod for loading and playing audio in the browser.
6
4
 
7
5
  ## Install
8
6
 
9
7
  ```sh
10
8
  npm i @antha/audio
11
9
  ```
10
+
11
+ ## Usage
12
+
13
+ <!-- example-link: src/readme-examples/playing-audio.example.ts -->
14
+
15
+ ```TypeScript
16
+ import {AnthaEngine, defineAnthaMod} from '@antha/engine';
17
+ import {type AnthaAudioState, createAnthaAudioMod} from '@antha/audio';
18
+
19
+ type GameState = AnthaAudioState & {
20
+ shouldPlayJumpSound: boolean;
21
+ };
22
+
23
+ const engine = new AnthaEngine<GameState>({
24
+ initState: {
25
+ shouldPlayJumpSound: true,
26
+ },
27
+ mods: [
28
+ createAnthaAudioMod(),
29
+ defineAnthaMod<GameState>({
30
+ modName: 'game-logic',
31
+ execute({state}) {
32
+ if (state.audioPlayer && state.shouldPlayJumpSound) {
33
+ state.shouldPlayJumpSound = false;
34
+ void state.audioPlayer.play({
35
+ sources: [
36
+ '/audio/jump.ogg',
37
+ '/audio/jump.mp3',
38
+ ],
39
+ });
40
+ }
41
+ },
42
+ }),
43
+ ],
44
+ });
45
+
46
+ engine.startLoop();
47
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antha/audio",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "An Antha mod for handling audio.",
5
5
  "keywords": [
6
6
  "vir",
@@ -37,7 +37,7 @@
37
37
  "@augment-vir/common": "^32.2.2"
38
38
  },
39
39
  "devDependencies": {
40
- "@antha/engine": "^0.1.0",
40
+ "@antha/engine": "^0.1.1",
41
41
  "@augment-vir/test": "^32.2.2",
42
42
  "@web/dev-server-esbuild": "^2.0.0",
43
43
  "@web/test-runner": "^1.0.0",