/*
 * Copyright (C) 2013 Darth Affe <http://wyrez.org> and contributors
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.wyrez.shootingstars.factories;

import com.jme3.asset.AssetManager;
import com.jme3.effect.ParticleEmitter;
import com.jme3.effect.ParticleMesh;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;

/**
 *
 * @author Darth Affe
 */
public enum Particles {

    SPARKLE(500, "Textures/star.png", ColorRGBA.White, new Vector3f(0f, 100f, 0f), 1f);
    private static AssetManager assetManager;
    private static int particleDensity;
    /**/
    private int particleCount;
    private String texture;
    private ColorRGBA color;
    private Vector3f initialVelocity;
    private float velocityVariation;

    Particles(int particleCount, String texture, ColorRGBA color,
            Vector3f initialVelocity, float velocityVariation) {
        this.particleCount = particleCount;
        this.texture = texture;
        this.color = color;
        this.initialVelocity = initialVelocity;
        this.velocityVariation = velocityVariation;
    }

    public ParticleEmitter create() {
        int particles = particleCount;
        for (int i = 0; i < 3 - particleDensity; i++) {
            particles *= 0.5;
        }
        ParticleEmitter particleEmitter = new ParticleEmitter("Emitter", ParticleMesh.Type.Triangle, particles);
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
        mat.setTexture("Texture", assetManager.loadTexture(texture));
        particleEmitter.setMaterial(mat);
        particleEmitter.setRotateSpeed(4);
        particleEmitter.getParticleInfluencer().setInitialVelocity(initialVelocity);
        particleEmitter.setStartColor(color);
        particleEmitter.getParticleInfluencer().setVelocityVariation(velocityVariation);
        return particleEmitter;
    }

    public static void initialize(AssetManager assetManager) {
        Particles.assetManager = assetManager;
    }

    public static void setParticleDensity(int particleDensity) {
        Particles.particleDensity = particleDensity;
    }
}
