author | Xeli |
Fri, 26 Aug 2011 16:47:00 +0200 | |
branch | hedgeroid |
changeset 5657 | 4dad72a8f514 |
parent 5621 | ea796c83ea47 |
permissions | -rw-r--r-- |
5621 | 1 |
/* |
2 |
* Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game |
|
3 |
* Copyright (c) 2011 Richard Deurwaarder <xeli@xelification.com> |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*/ |
|
18 |
||
5463
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
19 |
package org.hedgewars.mobile.EngineProtocol; |
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 |
import java.io.File; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
22 |
import java.io.IOException; |
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 |
import android.content.Context; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
25 |
import android.graphics.drawable.Drawable; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
26 |
import android.os.Parcel; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
27 |
import android.os.Parcelable; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
28 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
29 |
public class Map implements Comparable<Map>, Parcelable{ |
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 |
private static final String MISSION_PREFIX = "Mission: "; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
32 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
33 |
private String name; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
34 |
private String path; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
35 |
private String previewPath; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
36 |
private MapType type; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
37 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
38 |
public Map(File mapDir, MapType _type, Context c){ |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
39 |
type = _type; |
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 |
name = mapDir.getName(); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
42 |
path = mapDir.getAbsolutePath(); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
43 |
previewPath = path + "/preview.png"; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
44 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
45 |
/*switch(type){ |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
46 |
case TYPE_DEFAULT: |
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 |
break; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
49 |
case TYPE_GENERATED: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
50 |
//TODO |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
51 |
break; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
52 |
case TYPE_MISSION: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
53 |
name = MISSION_PREFIX + mapDir.getName(); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
54 |
path = mapDir.getAbsolutePath(); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
55 |
break; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
56 |
}*/ |
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 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
61 |
public Map(Parcel in){ |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
62 |
readFromParcel(in); |
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 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
65 |
public String toString(){ |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
66 |
switch(type){ |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
67 |
default: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
68 |
case TYPE_DEFAULT: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
69 |
return name; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
70 |
case TYPE_GENERATED: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
71 |
return "bla"; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
72 |
case TYPE_MISSION: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
73 |
return MISSION_PREFIX + name; |
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 |
} |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
76 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
77 |
public void sendToEngine(EngineProtocolNetwork epn) throws IOException{ |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
78 |
epn.sendToEngine(String.format("emap %s",name)); |
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 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
81 |
public MapType getType(){ |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
82 |
return type; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
83 |
} |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
84 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
85 |
public Drawable getDrawable(){ |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
86 |
switch(type){ |
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 |
case TYPE_DEFAULT: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
89 |
return Drawable.createFromPath(previewPath); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
90 |
case TYPE_GENERATED: |
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 |
default: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
93 |
return null; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
94 |
} |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
95 |
} |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
96 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
97 |
public int compareTo(Map another) { |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
98 |
switch(type){ |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
99 |
case TYPE_GENERATED: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
100 |
switch(another.getType()){ |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
101 |
case TYPE_GENERATED: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
102 |
return name.compareTo(another.name); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
103 |
case TYPE_MISSION: |
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_DEFAULT: |
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 |
} |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
108 |
case TYPE_MISSION: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
109 |
switch(another.getType()){ |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
110 |
case TYPE_GENERATED: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
111 |
return 1; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
112 |
case TYPE_MISSION: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
113 |
return name.compareTo(another.name); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
114 |
case TYPE_DEFAULT: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
115 |
return -1; |
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 |
case TYPE_DEFAULT: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
118 |
switch(another.getType()){ |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
119 |
case TYPE_GENERATED: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
120 |
return 1; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
121 |
case TYPE_MISSION: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
122 |
return 1; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
123 |
case TYPE_DEFAULT: |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
124 |
return name.compareTo(another.name); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
125 |
} |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
126 |
} |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
127 |
return 0;//default case this should never happen |
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 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
130 |
public enum MapType{ |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
131 |
TYPE_DEFAULT, TYPE_MISSION, TYPE_GENERATED |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
132 |
} |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
133 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
134 |
public int describeContents() { |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
135 |
return 0; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
136 |
} |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
137 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
138 |
public void writeToParcel(Parcel dest, int flags) { |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
139 |
dest.writeString(name); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
140 |
dest.writeString(path); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
141 |
dest.writeString(previewPath); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
142 |
dest.writeString(type.name()); |
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 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
145 |
private void readFromParcel(Parcel src){ |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
146 |
name = src.readString(); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
147 |
path = src.readString(); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
148 |
previewPath = src.readString(); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
149 |
type = MapType.valueOf(src.readString()); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
150 |
} |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
151 |
public static final Parcelable.Creator<Map> CREATOR = new Parcelable.Creator<Map>() { |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
152 |
public Map createFromParcel(Parcel source) { |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
153 |
return new Map(source); |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
154 |
} |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
155 |
public Map[] newArray(int size) { |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
156 |
return new Map[size]; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
157 |
} |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
158 |
|
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
159 |
}; |
83c53a80f7ff
datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff
changeset
|
160 |
} |