import SoundManager = Laya.SoundManager;
import { WXSdk } from "../game_module/WXSdk";
export class SettingController {
    private static instasnce: SettingController;
    public vibrate = true;
    public sound=true;
    public static get Instance(): SettingController {
        return this.instasnce || (this.instasnce = new SettingController());
    }
    public SettingSound(value?: number) {
           if(!this.sound)return;
            SoundManager.setSoundVolume(value);
            SoundManager.setMusicVolume(value);
    }

    private soundChannel: Laya.SoundChannel;
    public _playMusic(on) {
        if(!this.sound)return;
        if (on) {
            if (this.soundChannel == null) {
                this.soundChannel = SoundManager.playMusic(this.TrainLoop, 0);
                this.soundChannel.volume = 0.5
            }
            this.soundChannel.resume();
        } else {
            if (this.soundChannel) {
                this.soundChannel.pause();
            }
        }
    }

    public _playBadMove() {
       
        WXSdk.ShortVibrate();
        if(!this.sound)return;
        SoundManager.playSound(this.badMove);
    }

    public _Click() {
        if(!this.sound)return;
        SoundManager.playSound(this.click);
    }

    public _Continue(on) {
        if(!this.sound)return;
        if (on) {
            SoundManager.playSound(this.Continue);
        } else {
            SoundManager.stopSound(this.Continue);
        }

    }

    public _LevelComp() {
        if(!this.sound)return;
        SoundManager.playSound(this.LevelComp);
    }

    public _TrainCrash() {
        WXSdk.LongVibrate();
        if(!this.sound)return;
        SoundManager.playSound(this.TrainCrash);
    }
    public _TrainStop() {
        if(!this.sound)return;
        SoundManager.playSound(this.TrainStop);
    }
    public _Coin() {
        WXSdk.ShortVibrate();
        if(!this.sound)return;
        SoundManager.playSound(this.Coin);
    }


    private temp = 0;
    public _Jump() {
        WXSdk.ShortVibrate();
        if(!this.sound)return;
        SoundManager.playSound(this.Jump[this.temp]);
        this.temp++;
        if (this.temp == 8) this.temp = 0;
    }

    private badMove = "res/Sound/BadMove.mp3";
    private click = "res/Sound/click.mp3";
    private Continue = "res/Sound/Continue.mp3";
    private LevelComp = "res/Sound/LevelComp.mp3";
    private TrainCrash = "res/Sound/TrainCrash.mp3";
    private TrainLoop = "res/Sound/TrainLoop.mp3";
    private TrainStop = "res/Sound/TrainStop.mp3";
    private Coin="res/Sound/Coin1.mp3";
    private Jump =
        [
            "res/Sound/PassengerJumpIn1.mp3",
            "res/Sound/PassengerJumpIn2.mp3",
            "res/Sound/PassengerJumpIn3.mp3",
            "res/Sound/PassengerJumpIn4.mp3",
            "res/Sound/PassengerJumpIn5.mp3",
            "res/Sound/PassengerJumpIn6.mp3",
            "res/Sound/PassengerJumpIn7.mp3",
            "res/Sound/PassengerJumpIn8.mp3",
        ];

}