package de.heatup.mapengine;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

import javax.swing.JFileChooser;

import de.heatup.cfg.Config;
import de.heatup.logging.Logger;

public class MapLoader {
	protected File chooseMap() {
		JFileChooser chooser = new JFileChooser();
		chooser.showOpenDialog(null);
		File mapFile = null;
		
		try {
			Config.mapFilePath = chooser.getSelectedFile().getCanonicalPath().toString();
			mapFile = chooser.getSelectedFile();
			Logger.write("Map \""+ chooser.getSelectedFile().getCanonicalPath().toString() + "\" loaded");
		} catch (IOException e) {
			Logger.write("Could not load map file");
			e.printStackTrace();
		}
		return mapFile;
	}
	protected InputStream loadMap(int mapNumber) {
		ClassLoader cl = this.getClass().getClassLoader();
		InputStream is = cl.getResourceAsStream("de/heatup/resources/maps/map"+mapNumber+".txt");
		Logger.write("Map de/heatup/resources/maps/map"+mapNumber+".txt loaded");
		return is;
	}
}
