frontispiece / apps / frontispiece-editor / src / commands / music-command.ts
music-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 MusicCommand: Command = (engine, params) => {
	// TODO: actually trim the params in the command.
	let audioFile = params._[0].trim()

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

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

	AudioHookStateController.play(audioFile)
	
	// play it
	return null
}