UNPKG

@dcl/ecs

Version:
31 lines (30 loc) 1.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.defineAudioSourceComponent = void 0; const index_gen_1 = require("../generated/index.gen"); function defineAudioSourceComponent(engine) { const theComponent = (0, index_gen_1.AudioSource)(engine); return { ...theComponent, playSound(entity, src, resetCursor = true) { // Get the mutable to modify const audioSource = theComponent.getMutableOrNull(entity); if (!audioSource) return false; audioSource.audioClipUrl = src; audioSource.playing = true; audioSource.currentTime = resetCursor ? 0 : audioSource.currentTime; return true; }, stopSound(entity, resetCursor = true) { // Get the mutable to modify const audioSource = theComponent.getMutableOrNull(entity); if (!audioSource) return false; audioSource.playing = false; audioSource.currentTime = resetCursor ? 0 : audioSource.currentTime; return true; } }; } exports.defineAudioSourceComponent = defineAudioSourceComponent;