class GarlandEmitter
{
    constructor (config)
    {
        this.scene = config.scene;

        this.emitting = false;

        this.emitters = [];

        this.xpos = config.x;
        this.ypos = config.y;

        let emitter = this.scene.add.particles(config.x, config.y, config.key,
        {
            active: true,

            frame: "0",

            x: { min: -100, max: 100 },
            y: { min: -10, max: 10 },
            lifespan: 700,
            speedY: { min: 750, max: 1000 },
            scale: { min: 0.6, max: 0.8 },
            alpha: { min:1.0, max: 1.0 },
            rotate: { min:0, max: 0 },
            quantity: 2,
            maxParticles: -1,
            frequency: 240,
            blendMode: "NORMAL"
        });
        
        emitter.setDepth(config.depth);
        
        this.emitters.push(emitter);

        emitter = this.scene.add.particles(config.x, config.y, config.key,
        {
            active: true,

            frame: ["0"],

            x: { min: -100, max: 100 },
            y: { min: -10, max: 10 },
            lifespan: 700,
            speedY: { min: 750, max: 1000 },
            scale: { min: 0.7, max: 0.9 },
            alpha: { min:1.0, max: 1.0 },
            rotate: { min:0, max: 0 },
            quantity: 3,
            maxParticles: -1,
            frequency: 120,
            blendMode: "NORMAL"
        });
        
        emitter.setDepth(config.depth);
        
        this.emitters.push(emitter);

        this.position = 0;
        
        this.stop();
    }

    start (v)
    {
        this.stop();

        this.position = v;
        
        for (let i = 0; i < this.emitters.length; ++i)
        {
            for (let j = 0; j < this.emitters[i].dead.length; ++j)
            {
                this.emitters[i].dead[j].destroy();
            }

		    this.emitters[i].dead.length = 0;
            this.emitters[i].start(500);
        }

        this.setPosition();

        this.emitting = true;
    }

    stop()
    {
        for (let i = 0; i < this.emitters.length; ++i)
        {
            this.emitters[i].killAll();
            this.emitters[i].stop(true);
        }

        this.emitting = false;
    }

    setPosition ()
    {
        let dx = 0;
        let dy = 0;

        if (this.scene.isPortraitMode())
        {
            dx = -420;
            dy = 358;
        }

        for (let i = 0; i < this.emitters.length; ++i)
        {
            this.emitters[i].setPosition(this.xpos + dx + this.position * REEL_RECT_WIDTH, this.ypos + dy);
        }
    }
}
