project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/EngineProtocol/Weapon.java
equal
deleted
inserted
replaced
22 import java.io.File; |
22 import java.io.File; |
23 import java.io.FileNotFoundException; |
23 import java.io.FileNotFoundException; |
24 import java.io.FileReader; |
24 import java.io.FileReader; |
25 import java.io.IOException; |
25 import java.io.IOException; |
26 import java.util.ArrayList; |
26 import java.util.ArrayList; |
27 import java.util.Arrays; |
|
28 |
27 |
29 import org.xmlpull.v1.XmlPullParser; |
28 import org.xmlpull.v1.XmlPullParser; |
30 import org.xmlpull.v1.XmlPullParserException; |
29 import org.xmlpull.v1.XmlPullParserException; |
31 import org.xmlpull.v1.XmlPullParserFactory; |
30 import org.xmlpull.v1.XmlPullParserFactory; |
32 |
31 |
33 import android.content.Context; |
32 import android.content.Context; |
34 import android.os.Parcel; |
33 import android.os.Parcel; |
35 import android.os.Parcelable; |
34 import android.os.Parcelable; |
36 |
35 import android.util.Log; |
37 public class Weapon implements Parcelable{ |
36 |
|
37 public class Weapon implements Parcelable, Comparable<Weapon>{ |
38 |
38 |
39 public static final String DIRECTORY_WEAPON = "weapons"; |
39 public static final String DIRECTORY_WEAPON = "weapons"; |
40 |
40 |
41 private String name; |
41 private String name; |
42 private String QT; |
42 private String QT; |
93 |
93 |
94 public static ArrayList<Weapon> getWeapons(Context c) throws IllegalArgumentException{ |
94 public static ArrayList<Weapon> getWeapons(Context c) throws IllegalArgumentException{ |
95 String dir = c.getFilesDir().getAbsolutePath() + '/' + DIRECTORY_WEAPON + '/'; |
95 String dir = c.getFilesDir().getAbsolutePath() + '/' + DIRECTORY_WEAPON + '/'; |
96 String[] files = new File(dir).list(); |
96 String[] files = new File(dir).list(); |
97 if(files == null) files = new String[]{}; |
97 if(files == null) files = new String[]{}; |
98 Arrays.sort(files); |
|
99 |
98 |
100 ArrayList<Weapon> weapons = new ArrayList<Weapon>(); |
99 ArrayList<Weapon> weapons = new ArrayList<Weapon>(); |
101 |
100 |
102 try { |
101 try { |
103 XmlPullParserFactory xmlPullFactory = XmlPullParserFactory.newInstance(); |
102 XmlPullParserFactory xmlPullFactory = XmlPullParserFactory.newInstance(); |
207 public Weapon[] newArray(int size) { |
206 public Weapon[] newArray(int size) { |
208 return new Weapon[size]; |
207 return new Weapon[size]; |
209 } |
208 } |
210 |
209 |
211 }; |
210 }; |
|
211 |
|
212 public int compareTo(Weapon another) { |
|
213 boolean equalsDefault = name.toLowerCase().equals("crazy"); |
|
214 boolean otherEqualsDefault = another.name.toLowerCase().equals("crazy"); |
|
215 if(equalsDefault && otherEqualsDefault) return 0; |
|
216 else if(equalsDefault && !otherEqualsDefault) return -1; |
|
217 else if((!equalsDefault) && otherEqualsDefault) return 1; |
|
218 else return name.compareTo(another.name); |
|
219 } |
|
220 |
|
221 |
212 } |
222 } |