author | Medo <smaxein@googlemail.com> |
Mon, 20 Aug 2012 20:19:35 +0200 | |
changeset 7582 | 714310efad8f |
parent 7508 | 763d3961400b |
child 7584 | 7831c84cc644 |
permissions | -rw-r--r-- |
7485 | 1 |
package org.hedgewars.hedgeroid.Datastructures; |
2 |
||
3 |
import java.io.File; |
|
4 |
import java.io.FileNotFoundException; |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
5 |
import java.util.ArrayList; |
7485 | 6 |
import java.util.Comparator; |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
7 |
import java.util.List; |
7485 | 8 |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
9 |
import org.hedgewars.hedgeroid.R; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
10 |
import org.hedgewars.hedgeroid.util.FileUtils; |
7485 | 11 |
|
12 |
import android.content.Context; |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
13 |
import android.content.res.Resources; |
7485 | 14 |
|
15 |
/** |
|
16 |
* Represents a map from the data directory |
|
17 |
*/ |
|
18 |
public final class MapFile { |
|
19 |
public static final String MAP_DIRECTORY = "Maps"; |
|
20 |
||
21 |
public final String name; |
|
22 |
public final boolean isMission; |
|
23 |
||
24 |
public MapFile(String name, boolean isMission) { |
|
25 |
this.name = name; |
|
26 |
this.isMission = isMission; |
|
27 |
} |
|
28 |
||
29 |
/** |
|
30 |
* @throws FileNotFoundException if the sdcard is not available. Does NOT throw if the requested map file does not exist. |
|
31 |
*/ |
|
32 |
public static File getFileForMapname(Context ctx, String mapname) throws FileNotFoundException { |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
33 |
return new File(new File(FileUtils.getDataPathFile(ctx), MAP_DIRECTORY), mapname); |
7485 | 34 |
} |
35 |
||
36 |
public static final Comparator<MapFile> MISSIONS_FIRST_NAME_ORDER = new Comparator<MapFile>() { |
|
37 |
public int compare(MapFile lhs, MapFile rhs) { |
|
38 |
if(lhs.isMission != rhs.isMission) { |
|
39 |
return lhs.isMission && !rhs.isMission ? -1 : 1; |
|
40 |
} else { |
|
41 |
return lhs.name.compareToIgnoreCase(rhs.name); |
|
42 |
} |
|
43 |
} |
|
44 |
}; |
|
45 |
||
46 |
@Override |
|
47 |
public String toString() { |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
48 |
return "MapFile [name=" + name + ", isMission=" + isMission + "]"; |
7485 | 49 |
} |
50 |
||
51 |
public File getPreviewFile(Context c) throws FileNotFoundException { |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
52 |
return getPreviewFile(c, name); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
53 |
} |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
54 |
|
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
55 |
public static File getPreviewFile(Context c, String mapName) throws FileNotFoundException { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
56 |
return new File(FileUtils.getDataPathFile(c), MAP_DIRECTORY + "/" + mapName + "/" + "preview.png"); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
57 |
} |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
58 |
|
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
59 |
public static List<String> toDisplayNameList(List<MapFile> mapFiles, Resources res) { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
60 |
String missionPrefix = res.getString(R.string.map_mission_prefix); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
61 |
List<String> result = new ArrayList<String>(); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
62 |
for(MapFile mapFile : mapFiles) { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
63 |
result.add((mapFile.isMission ? missionPrefix : "") + mapFile.name); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
64 |
} |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
65 |
return result; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
66 |
} |
7485 | 67 |
} |