Skip to content

Commit

Permalink
Audio docs (#20)
Browse files Browse the repository at this point in the history
* Added docs for existing state

* Renamed audio manager to SoundEffectPlayer.

---------
  • Loading branch information
benpollarduk authored Feb 18, 2024
1 parent d53e051 commit 9e36dc8
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 13 deletions.
32 changes: 32 additions & 0 deletions docs/mkdocs/docs/audio.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Audio
Ktvn supports audio to allow rich visual novels to be created. Audio is roughly broken in to two categories -
background music and sound effects.

## Background Music
In Ktvn background music is specified as part of the **Scene**. This is documented on the [Customising Scenes](customising-scenes.md)
page.

## Sound Effects
Sounds effects can be played during any **Step**. All sound effects require an **AudioManager** to play.

### Sound Effect Player
The **SoundEffectPlayer** is a class that invokes sound effects in Ktvn. It depends on an **AudioAdapter**. The
**DynamicGameConfiguration** provides an instance of **AudioAdapter** that is suitable for nearly all use cases.

```kotlin
val configuration = DynamicGameConfiguration()
val audio = SoundEffectPlayer(configuration.gameAdapter.audioAdapter)
```

The **SoundEffectPlayer** can then be used to play sound effects with the **sfx** function. Here a **next** step is
used to play *sfxWoosh*.

```kotlin
next { audio sfx sfxWoosh }
```

In this case *sfxWoosh** is a **ResourceSoundEffect**, but a **FileSoundEffect** could also be used.

```kotlin
val sfxWoosh = soundEffectFromResource("shuttleLaunch/audio/woosh.wav")
```
1 change: 1 addition & 0 deletions docs/mkdocs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ nav:
- 'Clear': 'dsl/clear.md'
- 'End': 'dsl/end.md'
- Customising Scenes: 'customising-scenes.md'
- Audio: 'audio.md'
- Game Engine: 'game-engine.md'
- Using Resources: 'using-resources.md'
- Api documentation: 'api-documentation.md'
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.github.benpollarduk.ktvn.examples.shuttleLaunch.assets

import com.github.benpollarduk.ktvn.audio.AudioManager
import com.github.benpollarduk.ktvn.audio.ResourceSoundEffect.Companion.soundEffectFromResource
import com.github.benpollarduk.ktvn.audio.ResourceTrack.Companion.trackFromResource
import com.github.benpollarduk.ktvn.audio.SoundEffect
import com.github.benpollarduk.ktvn.audio.SoundEffectPlayer
import com.github.benpollarduk.ktvn.audio.Track
import com.github.benpollarduk.ktvn.backgrounds.Background
import com.github.benpollarduk.ktvn.backgrounds.ResourceBackground.Companion.backgroundFromResource
Expand Down Expand Up @@ -50,9 +50,9 @@ public object AssetStore {
public val narrator: Narrator = Narrator(configuration.gameAdapter.narratorAdapter)

/**
* The audio manager, responsible for all audio.
* The sound effect player, responsible invoking sound effects.
*/
public val audio: AudioManager = AudioManager(configuration.gameAdapter.audioAdapter)
public val audio: SoundEffectPlayer = SoundEffectPlayer(configuration.gameAdapter.audioAdapter)

/**
* Toki, a cosmonaut.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.benpollarduk.ktvn.examples.theFateOfMorgana.assets

import com.github.benpollarduk.ktvn.audio.AudioManager
import com.github.benpollarduk.ktvn.audio.SoundEffectPlayer
import com.github.benpollarduk.ktvn.characters.Character
import com.github.benpollarduk.ktvn.characters.Narrator
import com.github.benpollarduk.ktvn.characters.animations.Animation
Expand All @@ -23,9 +23,9 @@ public object AssetStore {
public val narrator: Narrator = Narrator(configuration.gameAdapter.narratorAdapter)

/**
* The audio manager, responsible for all audio.
* The sound effect player, responsible invoking sound effects.
*/
public val audio: AudioManager = AudioManager(configuration.gameAdapter.audioAdapter)
public val audio: SoundEffectPlayer = SoundEffectPlayer(configuration.gameAdapter.audioAdapter)

/**
* Morgana, a witch. The antagonist of the story.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import com.github.benpollarduk.ktvn.audio.ResourceSoundEffect.Companion.soundEff
import com.github.benpollarduk.ktvn.logic.adapters.AudioAdapter

/**
* Provides a class for managing audio playback and control. An [adapter] must be specified.
* Provides a class for playing sound effects. An [adapter] must be specified.
*/
public class AudioManager(private val adapter: AudioAdapter) {
public class SoundEffectPlayer(private val adapter: AudioAdapter) {
/**
* Play a specified [soundEffect].
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.github.benpollarduk.ktvn.logic.adapters.AudioAdapter
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test

class AudioManagerTest {
class SoundEffectPlayerTest {
@Test
fun `given sfx from object when calling sfx then listener invoked`() {
// Given
Expand All @@ -14,10 +14,10 @@ class AudioManagerTest {
called = true
}
}
val manager = AudioManager(adapter)
val player = SoundEffectPlayer(adapter)

// When
manager.sfx(ResourceSoundEffect(""))
player.sfx(ResourceSoundEffect(""))

// Then
Assertions.assertTrue(called)
Expand All @@ -32,10 +32,10 @@ class AudioManagerTest {
called = true
}
}
val manager = AudioManager(adapter)
val player = SoundEffectPlayer(adapter)

// When
manager.sfx("")
player.sfx("")

// Then
Assertions.assertTrue(called)
Expand Down
Binary file modified ktvn/src/test/resources/test.jar
Binary file not shown.

0 comments on commit 9e36dc8

Please sign in to comment.