Squashing to remove big audio files
parent
0a0e5334b5
commit
9b44cc6194
Binary file not shown.
Binary file not shown.
@ -1,7 +1,9 @@
|
||||
import com.last.commit.inventory.Inventory
|
||||
import com.last.commit.config.PlayerSettings
|
||||
import com.last.commit.config.GameSettings
|
||||
import com.last.commit.audio.SoundEngine
|
||||
|
||||
public data class GameState(
|
||||
public val inventory: Inventory,
|
||||
public val settings: PlayerSettings,
|
||||
data class GameState(
|
||||
val inventory: Inventory,
|
||||
val settings: GameSettings,
|
||||
public val soundEngine: SoundEngine,
|
||||
)
|
@ -0,0 +1,9 @@
|
||||
package com.last.commit.audio
|
||||
|
||||
import com.last.commit.audio.GameSound
|
||||
|
||||
class GameMusic(name: String): GameSound(name) {
|
||||
companion object {
|
||||
val WORLD_MUSIC = GameMusic("world_music.mp3")
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
|
||||
package com.last.commit.audio;
|
||||
|
||||
public abstract class GameSound(public val name: String) {
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.last.commit.audio;
|
||||
|
||||
import com.last.commit.audio.GameSound
|
||||
|
||||
public class GameSoundEffect(name: String): GameSound(name) {
|
||||
companion object {
|
||||
val STEPS_INDOOR = GameSoundEffect("steps_indoor.mp3");
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package com.last.commit.audio;
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.audio.Sound
|
||||
import com.badlogic.gdx.audio.Music
|
||||
import com.last.commit.audio.GameSound
|
||||
import com.last.commit.audio.GameMusic
|
||||
|
||||
|
||||
public class SoundEngine {
|
||||
|
||||
private val sounds: HashMap<String, Sound> = HashMap()
|
||||
private var playingMusic: Music? = null
|
||||
|
||||
public fun play(gameSound: GameSound, volume: Float = 1f) {
|
||||
if (gameSound is GameSoundEffect) {
|
||||
val sound = loadEffect(gameSound.name)
|
||||
sound.play(volume)
|
||||
println("Playing sound ${gameSound.name}")
|
||||
} else if (gameSound is GameMusic) {
|
||||
if (playingMusic != null && playingMusic!!.isPlaying()) {
|
||||
playingMusic!!.stop()
|
||||
}
|
||||
val music = loadMusic(gameSound.name)
|
||||
music.volume = volume
|
||||
music.setLooping(true)
|
||||
music.play()
|
||||
playingMusic = music
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadEffect(name: String): Sound {
|
||||
return loadSound("effects/$name")
|
||||
}
|
||||
|
||||
private fun loadMusic(name: String): Music {
|
||||
return Gdx.audio.newMusic(Gdx.files.internal("sounds/music/$name"))
|
||||
}
|
||||
|
||||
private fun loadSound(name: String): Sound {
|
||||
var sound = sounds.get(name)
|
||||
|
||||
if (sound == null) {
|
||||
println("Loading sound $name")
|
||||
sound = Gdx.audio.newSound(Gdx.files.internal("sounds/$name"))
|
||||
sounds[name] = sound
|
||||
}
|
||||
|
||||
return sound!!
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue