frontispiece / apps / frontispiece-editor / src / commands / sfx-command.ts
sfx-command.ts
Raw
/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
 */

import { Command } from '@a-morphous/frontispiece-ink-processor'
import { SOUND_TYPE } from '../audio/audio-engine'
import { AudioHookStateController } from '../state/audio-state'

export const SFXCommand: Command = (engine, params) => {
	let audioFile = params._[0].trim()

	if (!audioFile.includes('/')) {
		audioFile = 'assets/audio/' + audioFile
	}

	if (!AudioHookStateController.exists(audioFile)) {
		AudioHookStateController.addSound([audioFile], audioFile, SOUND_TYPE.SFX)
	}

	AudioHookStateController.play(audioFile)

	// play it
	return null
}