//
// Created by sebastian on 04.08.26.
//

#include "AudioLayer.h"

#include "GLFW/glfw3.h"

void ludo::AudioLayer::onUpdate(float deltaTime) {
    Layer::onUpdate(deltaTime);
    if (getKeyboard().keyPressEvent(GLFW_KEY_P)) {
        for (auto& soundSource : soundSources) {
            soundSource.play();
        }
    }
}

void ludo::AudioLayer::onAttachImpl() {
    Layer::onAttachImpl();
    auto rollingDiceSoundBufffer = m_assetManager.getSound("rolling_dice");

    auto rollingDiceSoundSource = engine::audio::SoundSource();
    rollingDiceSoundSource.setBuffer(*rollingDiceSoundBufffer);
    rollingDiceSoundSource.setPosition(0.0f, 0.0f, 0.0f);
    rollingDiceSoundSource.setGain(1.0f);

    soundSources.push_back(std::move(rollingDiceSoundSource));
}
