package de.frajul.endlessroll.levels.worlds;

import android.support.annotation.DrawableRes;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import de.frajul.endlessroll.R;
import de.frajul.endlessroll.entities.textures.Texture;
import de.frajul.endlessroll.entities.textures.TexturePack;

/**
 * Created by Julian on 14.11.2016.
 */

public enum World {

    GRASSLANDS(R.drawable.world_previews_grasslands, R.drawable.terrain_t_grass,
            R.drawable.terrain_c_grass, R.drawable.juri_obstacles_grass,
            R.drawable.backgrounds_game_grass),
    ICY_MOUNTAINS(R.drawable.world_previews_icymountains, R.drawable.terrain_t_ice,
            R.drawable.terrain_c_ice, R.drawable.obstacles_snow, R.drawable.backgrounds_game_snow),
    TEST_WORLD_GRASS(R.drawable.world_previews_grasslands, R.drawable.terrain_t_grass,
            R.drawable.terrain_c_grass, R.drawable.juri_obstacles_grass,
            R.drawable.backgrounds_game_grass, R.drawable.juri_background_game_grass_2, R.drawable.juri_background_game_grass_3),
    TEST_WORLD_SNOW(R.drawable.world_previews_icymountains, R.drawable.terrain_t_ice,
            R.drawable.terrain_c_ice, R.drawable.obstacles_snow, R.drawable.backgrounds_game_snow, R.drawable.juri_background_game_snow_2, R.drawable.juri_background_game_snow_3);

    @DrawableRes
    private int previewId;
    @DrawableRes
    private int terrainId;
    @DrawableRes
    private int ceilingId;
    @DrawableRes
    private int obstacleId;
    private List<Integer> backgroundIds;

    private List<Texture> backgroundTextures = new ArrayList<>();
    private Texture terrain;
    private Texture ceiling;
    private Texture obstacle;

    World(@DrawableRes int previewId, @DrawableRes int terrainId, @DrawableRes int ceilingId, @DrawableRes int obstacleId, @DrawableRes Integer... backgroundIds) {
        this.previewId = previewId;
        this.terrainId = terrainId;
        this.ceilingId = ceilingId;
        this.obstacleId = obstacleId;
        this.backgroundIds = Arrays.asList(backgroundIds);
    }

    public static void loadAllSpecificTextures(TexturePack texturePack) {
        for (World world : values())
            world.loadSpecificTextures(texturePack);
    }

    private void loadSpecificTextures(TexturePack texturePack) {
        for (int backgroundId : backgroundIds)
            backgroundTextures.add(texturePack.loadTexture(backgroundId));
        terrain = texturePack.loadTexture(terrainId);
        ceiling = texturePack.loadTexture(ceilingId);
        obstacle = texturePack.loadAtlas(obstacleId, 8, 8);
    }

    public int getPreviewId() {
        return previewId;
    }

    public List<Texture> getBackgroundTextures() {
        return backgroundTextures;
    }

    public Texture getTerrainTexture() {
        return terrain;
    }

    public Texture getCeilingTexture() {
        return ceiling;
    }

    public Texture getObstacleTexture() {
        return obstacle;
    }
}
