20 package org.hedgewars.hedgeroid.Datastructures; |
20 package org.hedgewars.hedgeroid.Datastructures; |
21 |
21 |
22 import java.io.File; |
22 import java.io.File; |
23 import java.io.FileNotFoundException; |
23 import java.io.FileNotFoundException; |
24 import java.util.ArrayList; |
24 import java.util.ArrayList; |
25 import java.util.Collections; |
|
26 import java.util.HashMap; |
25 import java.util.HashMap; |
27 import java.util.List; |
26 import java.util.List; |
28 |
27 |
29 import org.hedgewars.hedgeroid.R; |
28 import org.hedgewars.hedgeroid.R; |
30 import org.hedgewars.hedgeroid.Utils; |
29 import org.hedgewars.hedgeroid.util.FileUtils; |
31 |
30 |
32 import android.content.Context; |
31 import android.content.Context; |
33 import android.graphics.Bitmap; |
32 import android.graphics.Bitmap; |
34 import android.graphics.BitmapFactory; |
33 import android.graphics.BitmapFactory; |
35 |
34 |
37 |
36 |
38 /** |
37 /** |
39 * @throws FileNotFoundException if the sdcard isn't available or the Maps directory doesn't exist |
38 * @throws FileNotFoundException if the sdcard isn't available or the Maps directory doesn't exist |
40 */ |
39 */ |
41 public static ArrayList<MapFile> getMaps(Context c) throws FileNotFoundException { |
40 public static ArrayList<MapFile> getMaps(Context c) throws FileNotFoundException { |
42 File[] files = Utils.getFilesFromRelativeDir(c,"Maps"); |
41 File[] files = FileUtils.getFilesFromRelativeDir(c,"Maps"); |
43 ArrayList<MapFile> ret = new ArrayList<MapFile>(); |
42 ArrayList<MapFile> ret = new ArrayList<MapFile>(); |
44 |
43 |
45 for(File f : files) { |
44 for(File f : files) { |
46 boolean isMission = Utils.hasFileWithSuffix(f, ".lua"); |
45 boolean isMission = FileUtils.hasFileWithSuffix(f, ".lua"); |
47 ret.add(new MapFile(f.getName(), isMission)); |
46 ret.add(new MapFile(f.getName(), isMission)); |
48 } |
47 } |
49 Collections.sort(ret, MapFile.MISSIONS_FIRST_NAME_ORDER); |
|
50 |
48 |
51 return ret; |
49 return ret; |
52 } |
50 } |
53 |
51 |
54 /** |
52 /** |
55 * Returns a list of all multiplayer scripts (game styles) |
53 * Returns a list of all multiplayer scripts (game styles) |
56 * @throws FileNotFoundException if the sdcard isn't available or the Scripts/Multiplayer directory doesn't exist |
54 * @throws FileNotFoundException if the sdcard isn't available or the Scripts/Multiplayer directory doesn't exist |
57 */ |
55 */ |
58 public static List<String> getGameStyles(Context c) throws FileNotFoundException { |
56 public static List<String> getGameStyles(Context c) throws FileNotFoundException { |
59 File[] files = Utils.getFilesFromRelativeDir(c, "Scripts/Multiplayer"); |
57 File[] files = FileUtils.getFilesFromRelativeDir(c, "Scripts/Multiplayer"); |
60 ArrayList<String> ret = new ArrayList<String>(); |
58 ArrayList<String> ret = new ArrayList<String>(); |
61 /* |
59 /* |
62 * Caution: It is important that the "empty" style has this exact name, because |
60 * Caution: It is important that the "empty" style has this exact name, because |
63 * it will be interpreted as "don't load a script" by the frontlib, and also by |
61 * it will be interpreted as "don't load a script" by the frontlib, and also by |
64 * the QtFrontend in a netgame. This should probably be improved some time |
62 * the QtFrontend in a netgame. This should probably be improved some time |
70 if(name.endsWith(".lua")){ |
68 if(name.endsWith(".lua")){ |
71 //replace _ by a space and removed the last four characters (.lua) |
69 //replace _ by a space and removed the last four characters (.lua) |
72 ret.add(name.replace('_', ' ').substring(0, name.length()-4)); |
70 ret.add(name.replace('_', ' ').substring(0, name.length()-4)); |
73 } |
71 } |
74 } |
72 } |
75 Collections.sort(ret, String.CASE_INSENSITIVE_ORDER); |
|
76 return ret; |
73 return ret; |
77 } |
74 } |
78 |
75 |
79 /** |
76 /** |
80 * @throws FileNotFoundException if the sdcard isn't available or the Themes directory doesn't exist |
77 * @throws FileNotFoundException if the sdcard isn't available or the Themes directory doesn't exist |
81 */ |
78 */ |
82 public static List<String> getThemes(Context c) throws FileNotFoundException { |
79 public static List<String> getThemes(Context c) throws FileNotFoundException { |
83 List<String> list = Utils.getDirsWithFileSuffix(c, "Themes", "icon.png"); |
80 return FileUtils.getDirsWithFileSuffix(c, "Themes", "icon.png"); |
84 Collections.sort(list, String.CASE_INSENSITIVE_ORDER); |
|
85 return list; |
|
86 } |
|
87 |
|
88 public static List<Weaponset> getWeaponsets(Context c) { |
|
89 // TODO stub, re-implement |
|
90 /*List<Weapon> list = Weapon.getWeapons(c); |
|
91 Collections.sort(list);*/ |
|
92 return Collections.emptyList(); |
|
93 } |
81 } |
94 |
82 |
95 /** |
83 /** |
96 * @throws FileNotFoundException if the sdcard isn't available or the Graphics/Graves directory doesn't exist |
84 * @throws FileNotFoundException if the sdcard isn't available or the Graphics/Graves directory doesn't exist |
97 */ |
85 */ |
98 public static ArrayList<HashMap<String, ?>> getGraves(Context c) throws FileNotFoundException { |
86 public static ArrayList<HashMap<String, ?>> getGraves(Context c) throws FileNotFoundException { |
99 File gravePath = new File(new File(Utils.getDataPathFile(c), "Graphics"), "Graves"); |
87 File gravePath = new File(new File(FileUtils.getDataPathFile(c), "Graphics"), "Graves"); |
100 ArrayList<String> names = Utils.getFileNamesFromDirWithSuffix(c,"Graphics/Graves", ".png", true); |
88 ArrayList<String> names = FileUtils.getFileNamesFromDirWithSuffix(c,"Graphics/Graves", ".png", true); |
101 ArrayList<HashMap<String, ?>> data = new ArrayList<HashMap<String, ?>>(names.size()); |
89 ArrayList<HashMap<String, ?>> data = new ArrayList<HashMap<String, ?>>(names.size()); |
102 |
90 |
103 for(String s : names){ |
91 for(String s : names){ |
104 HashMap<String, Object> map = new HashMap<String, Object>(); |
92 HashMap<String, Object> map = new HashMap<String, Object>(); |
105 map.put("txt", s); |
93 map.put("txt", s); |
121 |
109 |
122 /** |
110 /** |
123 * @throws FileNotFoundException if the sdcard isn't available or the Graphics/Graves directory doesn't exist |
111 * @throws FileNotFoundException if the sdcard isn't available or the Graphics/Graves directory doesn't exist |
124 */ |
112 */ |
125 public static ArrayList<HashMap<String, ?>> getFlags(Context c) throws FileNotFoundException { |
113 public static ArrayList<HashMap<String, ?>> getFlags(Context c) throws FileNotFoundException { |
126 File flagsPath = new File(new File(Utils.getDataPathFile(c), "Graphics"), "Flags"); |
114 File flagsPath = new File(new File(FileUtils.getDataPathFile(c), "Graphics"), "Flags"); |
127 ArrayList<String> names = Utils.getFileNamesFromDirWithSuffix(c, "Graphics/Flags", ".png", true); |
115 ArrayList<String> names = FileUtils.getFileNamesFromDirWithSuffix(c, "Graphics/Flags", ".png", true); |
128 ArrayList<HashMap<String, ?>> data = new ArrayList<HashMap<String, ?>>(names.size()); |
116 ArrayList<HashMap<String, ?>> data = new ArrayList<HashMap<String, ?>>(names.size()); |
129 |
117 |
130 for(String s : names){ |
118 for(String s : names){ |
131 HashMap<String, Object> map = new HashMap<String, Object>(); |
119 HashMap<String, Object> map = new HashMap<String, Object>(); |
132 map.put("txt", s); |
120 map.put("txt", s); |
152 |
140 |
153 /** |
141 /** |
154 * @throws FileNotFoundException if the sdcard isn't available or the Forts directory doesn't exist |
142 * @throws FileNotFoundException if the sdcard isn't available or the Forts directory doesn't exist |
155 */ |
143 */ |
156 public static ArrayList<String> getForts(Context c) throws FileNotFoundException { |
144 public static ArrayList<String> getForts(Context c) throws FileNotFoundException { |
157 return Utils.getFileNamesFromDirWithSuffix(c,"Forts", "L.png", true); |
145 return FileUtils.getFileNamesFromDirWithSuffix(c,"Forts", "L.png", true); |
158 } |
146 } |
159 |
147 |
160 // TODO wat |
|
161 public static ArrayList<HashMap<String, ?>> getTypes(Context c){ |
148 public static ArrayList<HashMap<String, ?>> getTypes(Context c){ |
162 ArrayList<HashMap<String, ?>> data = new ArrayList<HashMap<String, ?>>(6); |
149 ArrayList<HashMap<String, ?>> data = new ArrayList<HashMap<String, ?>>(6); |
163 String[] levels = {c.getString(R.string.human), c.getString(R.string.bot5), c.getString(R.string.bot4), c.getString(R.string.bot3), c.getString(R.string.bot2), c.getString(R.string.bot1)}; |
150 String[] levels = {c.getString(R.string.human), c.getString(R.string.bot5), c.getString(R.string.bot4), c.getString(R.string.bot3), c.getString(R.string.bot2), c.getString(R.string.bot1)}; |
164 int[] images = {R.drawable.human, R.drawable.bot5, R.drawable.bot4, R.drawable.bot3, R.drawable.bot2, R.drawable.bot1}; |
151 int[] images = {R.drawable.human, R.drawable.bot5, R.drawable.bot4, R.drawable.bot3, R.drawable.bot2, R.drawable.bot1}; |
165 |
152 |
166 for(int i = 0; i < levels.length; i++){ |
153 for(int i = 0; i < levels.length; i++){ |
167 HashMap<String, Object> map = new HashMap<String, Object>(); |
154 HashMap<String, Object> map = new HashMap<String, Object>(); |
168 map.put("txt", levels[i]); |
155 map.put("txt", levels[i]); |
169 map.put("img", images[i]); |
156 map.put("img", images[i]); |
|
157 map.put("level", i); |
|
158 |
170 data.add(map); |
159 data.add(map); |
171 } |
160 } |
172 |
161 |
173 return data; |
162 return data; |
174 } |
163 } |
175 |
164 |
176 /** |
165 /** |
177 * @throws FileNotFoundException if the sdcard isn't available or the Graphics/Hats directory doesn't exist |
166 * @throws FileNotFoundException if the sdcard isn't available or the Graphics/Hats directory doesn't exist |
178 */ |
167 */ |
179 public static ArrayList<HashMap<String, ?>> getHats(Context c) throws FileNotFoundException { |
168 public static ArrayList<HashMap<String, ?>> getHats(Context c) throws FileNotFoundException { |
180 ArrayList<String> files = Utils.getFileNamesFromDirWithSuffix(c,"Graphics/Hats", ".png", true); |
169 ArrayList<String> files = FileUtils.getFileNamesFromDirWithSuffix(c,"Graphics/Hats", ".png", true); |
181 File hatsPath = new File(new File(Utils.getDataPathFile(c), "Graphics"), "Hats"); |
170 File hatsPath = new File(new File(FileUtils.getDataPathFile(c), "Graphics"), "Hats"); |
182 int size = files.size(); |
171 int size = files.size(); |
183 ArrayList<HashMap<String, ?>> data = new ArrayList<HashMap<String, ?>>(size); |
172 ArrayList<HashMap<String, ?>> data = new ArrayList<HashMap<String, ?>>(size); |
184 |
173 |
185 HashMap<String, Object> hashmap; |
174 HashMap<String, Object> hashmap; |
186 for(String s : files){ |
175 for(String s : files){ |