package de.samdev.colorrunner.game.world.map;

import com.badlogic.gdx.Gdx;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

public class CRMapStorage {
	public static final List<CRTiledMap> maps = new ArrayList<CRTiledMap>();

	public static final CRTiledMap map_start = internalload("map_pieces", "p00_start.tmx", false);

	public static final CRTiledMap map_01 = register("map_pieces", "p01.tmx");
	public static final CRTiledMap map_02 = register("map_pieces", "p02.tmx");
	public static final CRTiledMap map_03 = register("map_pieces", "p03.tmx");
	public static final CRTiledMap map_04 = register("map_pieces", "p04.tmx");
	public static final CRTiledMap map_05 = register("map_pieces", "p05.tmx");
	public static final CRTiledMap map_06 = register("map_pieces", "p06.tmx");
	public static final CRTiledMap map_07 = register("map_pieces", "p07.tmx");
	public static final CRTiledMap map_08 = register("map_pieces", "p08.tmx");
	public static final CRTiledMap map_09 = register("map_pieces", "p09.tmx");
	public static final CRTiledMap map_10 = register("map_pieces", "p10.tmx");
	public static final CRTiledMap map_11 = register("map_pieces", "p11.tmx");
	public static final CRTiledMap map_12 = register("map_pieces", "p12.tmx");
	public static final CRTiledMap map_13 = register("map_pieces", "p13.tmx");
	public static final CRTiledMap map_14 = register("map_pieces", "p14.tmx");
	public static final CRTiledMap map_15 = register("map_pieces", "p15.tmx");
	public static final CRTiledMap map_16 = register("map_pieces", "p16.tmx");
	public static final CRTiledMap map_17 = register("map_pieces", "p17.tmx");
	public static final CRTiledMap map_18 = register("map_pieces", "p18.tmx");
	public static final CRTiledMap map_19 = register("map_pieces", "p19.tmx");
	public static final CRTiledMap map_20 = register("map_pieces", "p20.tmx");
	public static final CRTiledMap map_21 = register("map_pieces", "p21.tmx");
	public static final CRTiledMap map_22 = register("map_pieces", "p22.tmx");
	public static final CRTiledMap map_23 = register("map_pieces", "p23.tmx");
	public static final CRTiledMap map_24 = register("map_pieces", "p24.tmx");
	public static final CRTiledMap map_25 = register("map_pieces", "p25.tmx");
	public static final CRTiledMap map_26 = register("map_pieces", "p26.tmx");

	public static final CRTiledMap lvl_01 = load("levels", 1, "plevel001.tmx");
	public static final CRTiledMap lvl_02 = load("levels", 2, "plevel002.tmx");
	public static final CRTiledMap lvl_03 = load("levels", 3, "plevel003.tmx");
	public static final CRTiledMap lvl_04 = load("levels", 4, "plevel004.tmx");

	public static Map<Integer, CRTiledMap> map_map;

	private static CRTiledMap load(String folder, int mid, String path) {
		if (map_map == null) map_map = new HashMap<Integer, CRTiledMap>();

		CRTiledMap m = internalload(folder, path, false);
		map_map.put(mid, m);
		return m;
	}

	private static CRTiledMap register(String folder, String path) {
		return internalload(folder, path, true);
	}

	private static CRTiledMap internalload(String folder, String path, boolean doRegister) {
		CRTiledMap m = CRTiledMap.load(path, Gdx.files.internal(folder + "/" + path).readString());

		if (doRegister)
			maps.add(m);

		return m;
	}

	public static CRTiledMap getMap(Random r) {
		return maps.get(r.nextInt(maps.size()));
	}
}
