author | Xeli |
Thu, 04 Aug 2011 17:41:07 +0200 | |
branch | hedgeroid |
changeset 5479 | b9aed3de7c27 |
parent 5463 | 83c53a80f7ff |
child 5508 | dcf1b3645af6 |
permissions | -rw-r--r-- |
5463
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
1 |
package org.hedgewars.mobile.EngineProtocol; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
2 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
3 |
import java.io.File; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
4 |
import java.io.IOException; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
5 |
import java.io.OutputStream; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
6 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
7 |
import android.content.Context; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
8 |
import android.graphics.drawable.Drawable; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
9 |
import android.os.Parcel; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
10 |
import android.os.Parcelable; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
11 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
12 |
public class Map implements Comparable<Map>, Parcelable{ |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
13 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
14 |
private static final String MISSION_PREFIX = "Mission: "; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
15 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
16 |
private String name; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
17 |
private String path; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
18 |
private String previewPath; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
19 |
private MapType type; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
20 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
21 |
public Map(File mapDir, MapType _type, Context c){ |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
22 |
type = _type; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
23 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
24 |
name = mapDir.getName(); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
25 |
path = mapDir.getAbsolutePath(); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
26 |
previewPath = path + "/preview.png"; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
27 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
28 |
/*switch(type){ |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
29 |
case TYPE_DEFAULT: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
30 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
31 |
break; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
32 |
case TYPE_GENERATED: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
33 |
//TODO |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
34 |
break; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
35 |
case TYPE_MISSION: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
36 |
name = MISSION_PREFIX + mapDir.getName(); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
37 |
path = mapDir.getAbsolutePath(); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
38 |
break; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
39 |
}*/ |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
40 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
41 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
42 |
} |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
43 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
44 |
public Map(Parcel in){ |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
45 |
readFromParcel(in); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
46 |
} |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
47 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
48 |
public String toString(){ |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
49 |
switch(type){ |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
50 |
default: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
51 |
case TYPE_DEFAULT: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
52 |
return name; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
53 |
case TYPE_GENERATED: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
54 |
return "bla"; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
55 |
case TYPE_MISSION: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
56 |
return MISSION_PREFIX + name; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
57 |
} |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
58 |
} |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
59 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
60 |
public void sendToEngine(EngineProtocolNetwork epn) throws IOException{ |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
61 |
epn.sendToEngine(String.format("emap %s",name)); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
62 |
} |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
63 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
64 |
public MapType getType(){ |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
65 |
return type; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
66 |
} |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
67 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
68 |
public Drawable getDrawable(){ |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
69 |
switch(type){ |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
70 |
case TYPE_MISSION: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
71 |
case TYPE_DEFAULT: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
72 |
return Drawable.createFromPath(previewPath); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
73 |
case TYPE_GENERATED: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
74 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
75 |
default: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
76 |
return null; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
77 |
} |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
78 |
} |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
79 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
80 |
@Override |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
81 |
public int compareTo(Map another) { |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
82 |
switch(type){ |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
83 |
case TYPE_GENERATED: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
84 |
switch(another.getType()){ |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
85 |
case TYPE_GENERATED: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
86 |
return name.compareTo(another.name); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
87 |
case TYPE_MISSION: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
88 |
return -1; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
89 |
case TYPE_DEFAULT: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
90 |
return -1; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
91 |
} |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
92 |
case TYPE_MISSION: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
93 |
switch(another.getType()){ |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
94 |
case TYPE_GENERATED: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
95 |
return 1; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
96 |
case TYPE_MISSION: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
97 |
return name.compareTo(another.name); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
98 |
case TYPE_DEFAULT: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
99 |
return -1; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
100 |
} |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
101 |
case TYPE_DEFAULT: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
102 |
switch(another.getType()){ |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
103 |
case TYPE_GENERATED: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
104 |
return 1; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
105 |
case TYPE_MISSION: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
106 |
return 1; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
107 |
case TYPE_DEFAULT: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
108 |
return name.compareTo(another.name); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
109 |
} |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
110 |
} |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
111 |
return 0;//default case this should never happen |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
112 |
} |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
113 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
114 |
public enum MapType{ |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
115 |
TYPE_DEFAULT, TYPE_MISSION, TYPE_GENERATED |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
116 |
} |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
117 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
118 |
public int describeContents() { |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
119 |
return 0; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
120 |
} |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
121 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
122 |
public void writeToParcel(Parcel dest, int flags) { |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
123 |
dest.writeString(name); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
124 |
dest.writeString(path); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
125 |
dest.writeString(previewPath); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
126 |
dest.writeString(type.name()); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
127 |
} |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
128 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
129 |
private void readFromParcel(Parcel src){ |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
130 |
name = src.readString(); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
131 |
path = src.readString(); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
132 |
previewPath = src.readString(); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
133 |
type = MapType.valueOf(src.readString()); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
134 |
} |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
135 |
public static final Parcelable.Creator<Map> CREATOR = new Parcelable.Creator<Map>() { |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
136 |
public Map createFromParcel(Parcel source) { |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
137 |
return new Map(source); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
138 |
} |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
139 |
public Map[] newArray(int size) { |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
140 |
return new Map[size]; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
141 |
} |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
142 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
143 |
}; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
144 |
} |