/**
* Original author of HeadlinerNPCFilter: Mat Groves http://matgroves.com/ @Doormat23
* adapted for Phaser.js
*/

/**
* This filter applies a HeadlinerNPC effect making display objects appear 'blocky'.
* @class HeadlinerNPCFilter
* @constructor
*/
Phaser.Filter.HeadlinerNPC = function(game) {

    Phaser.Filter.call(this, game);

    this.uniforms.invert = { type: '1f', value: 0 };
    this.uniforms.pixelSize = { type: '2f', value: { x: 10.0, y: 10.0 } };
    this.uniforms.dimensions = { type: '2f', value: { x: 1000.0, y: 1000.0 } };

    this.fragmentSrc = [

        "precision mediump float;",
        "varying vec2 vTextureCoord;",
        "uniform vec2 dimensions;",
        "uniform vec2 pixelSize;",
        "uniform sampler2D uSampler;",

        "void main(void)",
        "{",

            //"vec2 coord = vTextureCoord;",
            //"vec2 size = dimensions.xy/pixelSize;",
            //"vec2 color = floor( ( vTextureCoord * size ) ) / size + pixelSize/dimensions.xy * 0.5;",
            "gl_FragColor = texture2D(uSampler, vTextureCoord);",
        "}"
    ];
};

Phaser.Filter.HeadlinerNPC.prototype = Object.create(Phaser.Filter.prototype);
Phaser.Filter.HeadlinerNPC.prototype.constructor = Phaser.Filter.HeadlinerNPC;

/**
* An object with visible x and y properties that are used to define the size of the filter effect per pixel.
* 
* @property size
* @type Phaser.Point
*/
Object.defineProperty(Phaser.Filter.HeadlinerNPC.prototype, 'size', {

    get: function() {

        return this.uniforms.pixelSize.value;

    },

    set: function(value) {

        this.dirty = true;
        this.uniforms.pixelSize.value = value;

    }

});

/**
* A value that defines the horizontal size of the filter effect per pixel.
* 
* @property sizeX
* @type number
*/
Object.defineProperty(Phaser.Filter.HeadlinerNPC.prototype, 'sizeX', {

    get: function() {

        return this.uniforms.pixelSize.value.x;

    },

    set: function(value) {

        this.dirty = true;
        this.uniforms.pixelSize.value.x = value;

    }

});

/**
* A value that defines the vertical size of the filter effect per pixel.
* 
* @property sizeY
* @type number
*/
Object.defineProperty(Phaser.Filter.HeadlinerNPC.prototype, 'sizeY', {

    get: function() {

        return this.uniforms.pixelSize.value.y;

    },

    set: function(value) {

        this.dirty = true;
        this.uniforms.pixelSize.value.y = value;

    }

});