/*
 * Copyright (C) 2013 Darth Affe <http://wyrez.org> and contributors
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.wyrez.shootingstars.sound;

import com.jme3.asset.AssetManager;
import com.jme3.audio.AudioNode;
import org.wyrez.shootingstars.states.util.OptionSettings;

/**
 *
 * @author Darth Affe
 */
public class BackgroundMusic extends AudioNode {

    private OptionSettings settings;
    private boolean isRunning = false;

    public BackgroundMusic(AssetManager assetManager, OptionSettings settings) {
        super(assetManager, "Sound/menu_loop1.wav", false);
        this.settings = settings;
        this.setLooping(true);
        this.setPositional(false);

        update();
    }

    public final void update() {
        this.setVolume((settings.getMenuVolume() * (float) settings.getMasterVolume() / 100f) / 100f);
    }

    @Override
    public void play() {
        if (!isRunning) {
            isRunning = true;
            super.play();
        }
    }

    @Override
    public void stop() {
        if (isRunning) {
            isRunning = false;
            super.stop();
        }
    }

    @Override
    public void pause() {
        if (isRunning) {
            isRunning = false;
            super.pause();
        }
    }
}
