#include "Utils/Audio/Manager.hpp"

using namespace cocos2d;
using namespace cocos2d::experimental;

namespace Audio
{
    CManager* CManager::m_instance = 0;
    
    CManager::CManager()
    {
        /* set initial values */
        
        setMusicVolume(1.0f);
        setSoundVolume(1.0f);
        
        /* Init audio engine */
        
        AudioEngine::lazyInit();
        
        /* set initial values */
        
        setMusicVolume(1.0f);
        setSoundVolume(1.0f);
    }
    
    CManager::~CManager()
    {
        AudioEngine::end();
    }
    
    CManager* CManager::getInstance()
    {
        if (!m_instance)
        {
            m_instance = new Audio::CManager();
        }
        return m_instance;
    }
    
    void CManager::playMusicEffect(const std::string& krName)
    {
        int musicID = AudioEngine::play2d(krName, false, m_fMusicVolume);
    }
    
    void CManager::playSoundEffect(const std::string& krName)
    {
        int soundID = AudioEngine::play2d(krName, false, m_fSoundVolume);
    }
    
    void CManager::setSoundVolume(const float kfValue)
    {
        m_fSoundVolume = kfValue;
        AudioEngine::setVolume(EType::Sound, m_fSoundVolume);
    }
    
    void CManager::setMusicVolume(const float kfValue)
    {
        m_fMusicVolume = kfValue;
        AudioEngine::setVolume(EType::Music, m_fMusicVolume);
    }
}
