7485
|
1 |
package org.hedgewars.hedgeroid.Datastructures;
|
|
2 |
|
|
3 |
import java.io.File;
|
|
4 |
import java.io.FileNotFoundException;
|
|
5 |
import java.util.Comparator;
|
|
6 |
|
|
7 |
import org.hedgewars.hedgeroid.Utils;
|
|
8 |
|
|
9 |
import android.content.Context;
|
|
10 |
import android.widget.AdapterView.OnItemSelectedListener;
|
|
11 |
|
|
12 |
/**
|
|
13 |
* Represents a map from the data directory
|
|
14 |
*/
|
|
15 |
public final class MapFile {
|
|
16 |
public static final String MISSION_PREFIX = "Mission: "; // TODO move text generation to UI to allow translation
|
|
17 |
public static final String MAP_DIRECTORY = "Maps";
|
|
18 |
|
|
19 |
public final String name;
|
|
20 |
public final boolean isMission;
|
|
21 |
|
|
22 |
public MapFile(String name, boolean isMission) {
|
|
23 |
this.name = name;
|
|
24 |
this.isMission = isMission;
|
|
25 |
}
|
|
26 |
|
|
27 |
/**
|
|
28 |
* @throws FileNotFoundException if the sdcard is not available. Does NOT throw if the requested map file does not exist.
|
|
29 |
*/
|
|
30 |
public static File getFileForMapname(Context ctx, String mapname) throws FileNotFoundException {
|
|
31 |
return new File(new File(Utils.getDataPathFile(ctx), MAP_DIRECTORY), mapname);
|
|
32 |
}
|
|
33 |
|
|
34 |
public static final Comparator<MapFile> MISSIONS_FIRST_NAME_ORDER = new Comparator<MapFile>() {
|
|
35 |
public int compare(MapFile lhs, MapFile rhs) {
|
|
36 |
if(lhs.isMission != rhs.isMission) {
|
|
37 |
return lhs.isMission && !rhs.isMission ? -1 : 1;
|
|
38 |
} else {
|
|
39 |
return lhs.name.compareToIgnoreCase(rhs.name);
|
|
40 |
}
|
|
41 |
}
|
|
42 |
};
|
|
43 |
|
|
44 |
@Override
|
|
45 |
public String toString() {
|
|
46 |
return (isMission ? MISSION_PREFIX : "") + name;
|
|
47 |
}
|
|
48 |
|
|
49 |
public File getPreviewFile(Context c) throws FileNotFoundException {
|
|
50 |
return new File(new File(new File(Utils.getDataPathFile(c), MAP_DIRECTORY), name), "preview.png");
|
|
51 |
};
|
|
52 |
}
|