project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Datastructures/MapFile.java
author Medo <smaxein@googlemail.com>
Sun, 12 Aug 2012 23:51:36 +0200
changeset 7494 e65adfc99f15
parent 7485 0481bd74267c
child 7508 763d3961400b
permissions -rw-r--r--
frontlib/Hedgeroid: Modified frontlib build in Hedgeroid so it works without having to copy the source dir.

package org.hedgewars.hedgeroid.Datastructures;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Comparator;

import org.hedgewars.hedgeroid.Utils;

import android.content.Context;
import android.widget.AdapterView.OnItemSelectedListener;

/**
 * Represents a map from the data directory
 */
public final class MapFile {
	public static final String MISSION_PREFIX = "Mission: "; // TODO move text generation to UI to allow translation
	public static final String MAP_DIRECTORY = "Maps";
	
	public final String name;
	public final boolean isMission;
	
	public MapFile(String name, boolean isMission) {
		this.name = name;
		this.isMission = isMission;
	}
	
	/**
	 * @throws FileNotFoundException if the sdcard is not available. Does NOT throw if the requested map file does not exist.
	 */
	public static File getFileForMapname(Context ctx, String mapname) throws FileNotFoundException {
		return new File(new File(Utils.getDataPathFile(ctx), MAP_DIRECTORY), mapname);
	}
	
	public static final Comparator<MapFile> MISSIONS_FIRST_NAME_ORDER = new Comparator<MapFile>() {
		public int compare(MapFile lhs, MapFile rhs) {
			if(lhs.isMission != rhs.isMission) {
				return lhs.isMission && !rhs.isMission ? -1 : 1;
			} else {
				return lhs.name.compareToIgnoreCase(rhs.name);
			}
		}
	};
	
	@Override
	public String toString() {
		return (isMission ? MISSION_PREFIX : "") + name;
	}

	public File getPreviewFile(Context c) throws FileNotFoundException {
		return new File(new File(new File(Utils.getDataPathFile(c), MAP_DIRECTORY), name), "preview.png");
	};
}