/**
 * Created by Largoyle on 12/04/2014.
 */

/// <reference path="H:/Webpages/LudumDare/LD30/_assets/phaser/build/phaser.d.ts" />

module LEesLD30 {

    export class Preloader extends Phaser.State {

        preloadBar: Phaser.Sprite;
        myLogo: Phaser.Sprite;

        preload() {

            //  Set-up our preloader sprite
            this.preloadBar = this.add.sprite(200, this.world.centerY+80, 'preloadBar');
            this.load.setPreloadSprite(this.preloadBar);

            // add logo
            this.myLogo = this.add.sprite(this.world.centerX-145, 150, 'logo');

        //  IMAGES
            this.load.image('titletext', 'assets/img/title-big.png');

            //this.load.image('sirwalter', 'assets/SirWalterGrundlingTheThird.png');
            //this.load.image('sirwalter_boat', 'assets/SirWalterGrundlingTheThird_boat.sh.png');

            // ORANGE BLOCK
            this.game.load.spritesheet('anim_orangeblock', 'assets/img/orange-block.png', 40, 62, 20);

            // TILES
            this.game.load.spritesheet('lvl1_tiles', 'assets/img/color-palette.png', 40, 40, 140);

        // BACKGROUNDS
            this.load.image('bkgr0', 'assets/img/bts_lr_bkgr_sm.png');
            this.load.image('bkgr1', 'assets/img/bkgr1.png');
            this.load.image('scanlines', 'assets/img/scanlines2.png');


            // TODO
            //this.load.image('scorearrow', 'assets/score_arrow.png');
            //this.load.image('scoreboard', 'assets/scoreboard.png');
            //this.game.load.spritesheet('leftright_waves', 'assets/waves_sm.png', 800, 20, 4);

        // FILTERS
            this.game.load.script('filter-vignette', './assets/js/filters/Vignette.js');
            this.game.load.script('filter-film',     './assets/js/filters/FilmGrain.js');
            //this.game.load.script('filter-pixelate', './assets/js/filters/Pixelate.js');
            this.game.load.script('pixi-filter-abstract', './assets/js/filters/AbstractFilter.js');
            this.game.load.script('pixi-filter-sepia',    './assets/js/filters/SepiaFilter.js');


        // SOUNDS
            this.game.load.audio('snd_walk', [
                 'assets/audio/walk3.mp3',
                 'assets/audio/walk3.ogg']);
            this.game.load.audio('snd_jump', [
                'assets/audio/jump.mp3',
                'assets/audio/jump.ogg']);
            this.game.load.audio('snd_collect', [
                'assets/audio/collect.mp3',
                'assets/audio/collect.ogg']);
        // OBJECTS
        //    this.game.load.spritesheet('tiles_collectables', 'assets/obj_duck.png', 40, 40, 2);

//            this.load.image('logo', 'assets/logo.png');
//            this.load.audio('music', 'assets/title.mp3', true);
//            this.load.spritesheet('simon', 'assets/simon.png', 58, 96, 5);
//            this.load.image('level1', 'assets/level1.png');

        }

        create() {

            var tween = this.add.tween(this.preloadBar).to({ alpha: 0 }, 1000, Phaser.Easing.Linear.None, true);
            tween.onComplete.add(this.startMainMenu, this);

        }

        startMainMenu() {

            this.game.state.start('MainMenu', true, false);
            //this.game.state.start('Level1', true, false);

        }

    }

}

