|
1 package org.hedgewars.mobile; |
|
2 |
|
3 import java.io.File; |
|
4 import java.util.Arrays; |
|
5 |
|
6 import android.content.Context; |
|
7 |
|
8 public class FrontendDataUtil { |
|
9 |
|
10 private static final String MISSION_PREFIX = "Mission: "; |
|
11 |
|
12 public static String[] getMaps(Context c){ |
|
13 File[] files = Utils.getFilesFromRelativeDir(c,"Maps"); |
|
14 String[] maps = new String[files.length]; |
|
15 String[] missions = new String[maps.length]; |
|
16 int mapsCounter = 0, missionsCounter = 0; |
|
17 |
|
18 for(File f : files){ |
|
19 if(Utils.hasFileWithSuffix(f, ".lua")){ |
|
20 missions[missionsCounter++] = MISSION_PREFIX + f.getName(); |
|
21 }else{ |
|
22 maps[mapsCounter++] = f.getName(); |
|
23 } |
|
24 } |
|
25 String[] ret = new String[maps.length]; |
|
26 System.arraycopy(missions, 0, ret, 0, missionsCounter); |
|
27 System.arraycopy(maps, 0, ret, missionsCounter, mapsCounter); |
|
28 Arrays.sort(ret, 0, missionsCounter); |
|
29 Arrays.sort(ret, missionsCounter, ret.length); |
|
30 return ret; |
|
31 } |
|
32 |
|
33 public static String[] getGameplay(Context c){ |
|
34 String[] files = Utils.getFileNamesFromRelativeDir(c, "Scripts/Multiplayer"); |
|
35 int retCounter = 0; |
|
36 |
|
37 for(int i = 0; i < files.length; i++){ |
|
38 if(files[i].endsWith(".lua")){ |
|
39 files[i] = files[i].replace('_', ' ').substring(0, files[i].length()-4); //replace _ by a space and removed the last four characters (.lua) |
|
40 retCounter++; |
|
41 }else files[i] = null; |
|
42 } |
|
43 String[] ret = new String[retCounter]; |
|
44 retCounter = 0; |
|
45 for(String s : files){ |
|
46 if(s != null) ret[retCounter++] = s; |
|
47 } |
|
48 Arrays.sort(ret); |
|
49 |
|
50 return ret; |
|
51 } |
|
52 |
|
53 public static String[] getThemes(Context c){ |
|
54 return Utils.getDirsWithFileSuffix(c, "Themes", "icon.png"); |
|
55 } |
|
56 |
|
57 public static Scheme[] getSchemes(Context c){ |
|
58 return Scheme.getSchemes(c); |
|
59 } |
|
60 |
|
61 public static Weapon[] getWeapons(Context c){ |
|
62 return Weapon.getWeapons(c); |
|
63 } |
|
64 } |