Strict

Import mojo

Const SOUND_SELECTION: Int = 0
Const SOUND_BACK: Int = 1
Const SOUND_DOOR: Int = 2
Const SOUND_STEP: Int = 3

Class SoundManager
Private
	Global soundSelection: Sound
	Global soundBack: Sound
	Global soundDoor: Sound
	Global soundStep: Sound

Public
	Function LoadSoundByID: Void(soundID: Int)
		Select soundID
			Case SOUND_SELECTION
				If soundSelection = Null Then soundSelection = LoadSound("selection.wav")
			Case SOUND_BACK
				If soundBack = Null Then soundBack = LoadSound("back.wav")
			Case SOUND_DOOR
				If soundDoor = Null Then soundDoor = LoadSound("door.wav")
			Case SOUND_STEP
				If soundStep = Null Then soundStep = LoadSound("step.wav")
		End
	End
	
	Function PlayFX:Void (soundID: Int, vol: Float = 0.5)
		Local snd: Sound = GetSound(soundID)
		If snd = Null Then Return

		StopChannel(0)
		SetChannelVolume(0, vol)
		PlaySound(snd, 0, 0)
	End
	
Private
	Function GetSound: Sound(soundID: Int)
		Select soundID
			Case SOUND_SELECTION
				If soundSelection = Null Then LoadSoundByID (SOUND_SELECTION)
				Return soundSelection
			Case SOUND_BACK
				If soundBack = Null Then LoadSoundByID (SOUND_BACK)
				Return soundBack
			Case SOUND_DOOR
				If soundDoor = Null Then LoadSoundByID (SOUND_DOOR)
				Return soundDoor 
			Case SOUND_STEP
				If soundStep = Null Then LoadSoundByID (SOUND_STEP)
				Return soundStep
		End
		Return Null
	End
End