import {Pad} from "../input/Pad";
export class Player {
    speed = 2;
    enabled = true;

    constructor(public sprite:Phaser.Sprite, public pad:Pad) {
        sprite.smoothed = false;
        this.setupPlayerAnimations(sprite);

        this.pad.onRight = ()=> {
            if (this.enabled) {
                this.sprite.play('right');
            }
        };
        this.pad.onLeft = ()=> {
            if (this.enabled) {
                this.sprite.play('left');
            }
        };
        this.pad.onUp = ()=> {
            if (this.enabled) {
                this.sprite.play('up');
            }
        };
        this.pad.onDown = ()=> {
            if (this.enabled) {
                this.sprite.play('down');
            }
        };

        this.pad.onStopHold = ()=> {
            if (this.enabled) {
                this.sprite.animations.stop();
            }
        };

        this.pad.onRightHold = ()=> {
            if (this.enabled) {
                this.sprite.position.add(this.speed, 0);
            }
        };
        this.pad.onLeftHold = ()=> {
            if (this.enabled) {
                this.sprite.position.add(-this.speed, 0);
            }
        };
        this.pad.onUpHold = ()=> {
            if (this.enabled) {
                this.sprite.position.add(0, -this.speed);
            }
        };
        this.pad.onDownHold = ()=> {
            if (this.enabled) {
                this.sprite.position.add(0, this.speed);
            }
        };
    }

    setupPlayerAnimations = (sprite:Phaser.Sprite) => {
        sprite.scale.setTo(1.5, 1.5);
        sprite.animations.add('up', ['01.png', '02.png', '03.png', '04.png'], 6, true, false);
        sprite.animations.add('down', ['05.png', '06.png', '07.png', '08.png'], 6, true, false);
        sprite.animations.add('left', ['09.png', '10.png'], 6, true, false);
        sprite.animations.add('right', ['11.png', '12.png'], 6, true, false);
        sprite.animations.add('hammer', ['13.png', '14.png', '15.png', '16.png'], 6, false, false);
        this.sprite = sprite;
    };

    setupPlayerRobeAnimations = (sprite:Phaser.Sprite) => {
        sprite.scale.setTo(1.5, 1.5);
        sprite.animations.add('up', ['05.png', '06.png', '07.png', '08.png'], 6, true, false);
        sprite.animations.add('down', ['01.png', '02.png', '03.png', '04.png'], 6, true, false);
        sprite.animations.add('left', ['09.png', '10.png', '11.png', '12.png'], 6, true, false);
        sprite.animations.add('right', ['13.png', '14.png', '15.png', '16.png'], 6, true, false);
        sprite.animations.add('dance', ['17.png', '18.png', '19.png'], 6, false, false);
        this.sprite = sprite;
    };

    setupRobeAnimations = (sprite:Phaser.Sprite)=> {
        sprite.scale.setTo(1.5, 1.5);
        sprite.animations.add('down', ['01.png', '02.png', '03.png', '04.png'], 6, true, false);
        sprite.animations.add('up', ['05.png', '06.png', '07.png', '08.png'], 6, true, false);
        sprite.animations.add('left', ['09.png', '10.png', '11.png', '12.png'], 6, true, false);
        sprite.animations.add('right', ['13.png', '14.png', '15.png', '16.png'], 6, true, false);
        sprite.animations.add('hands_up_down', ['17.png', '18.png', '19.png'], 4, true, false);
        sprite.animations.add('fall', ['24.png', '25.png'], 2, false, false);
        sprite.animations.add('naked', ['26.png'], 1, false, false);
        this.sprite = sprite;
    };
}