project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/EngineProtocol/Map.java
author Xeli
Tue, 09 Aug 2011 20:54:56 +0200
branchhedgeroid
changeset 5508 dcf1b3645af6
parent 5463 83c53a80f7ff
child 5621 ea796c83ea47
permissions -rw-r--r--
Fixed IPC provide gameconfig
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
     6
import android.content.Context;
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
     7
import android.graphics.drawable.Drawable;
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
     8
import android.os.Parcel;
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
     9
import android.os.Parcelable;
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    10
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    11
public class Map implements Comparable<Map>, Parcelable{
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    12
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    13
	private static final String MISSION_PREFIX = "Mission: ";
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    14
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    15
	private String name;
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    16
	private String path;
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    17
	private String previewPath;
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    18
	private MapType type;
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    19
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    20
	public Map(File mapDir, MapType _type, Context c){
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    21
		type = _type;
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    22
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    23
		name = mapDir.getName();
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    24
		path = mapDir.getAbsolutePath();
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    25
		previewPath = path + "/preview.png";
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    26
		
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    27
		/*switch(type){
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    28
		case TYPE_DEFAULT:
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    29
			
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    30
			break;
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    31
		case TYPE_GENERATED:
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    32
			//TODO
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    33
			break;
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    34
		case TYPE_MISSION:
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    35
			name = MISSION_PREFIX + mapDir.getName();
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    36
			path = mapDir.getAbsolutePath();
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    37
			break;
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    38
		}*/
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
	public Map(Parcel in){
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    44
		readFromParcel(in);
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    45
	}
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
	public String toString(){
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    48
		switch(type){
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    49
		default:
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    50
		case TYPE_DEFAULT:
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    51
			return name;
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    52
		case TYPE_GENERATED:
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    53
			return "bla";
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    54
		case TYPE_MISSION:
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    55
			return MISSION_PREFIX + name;
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
	public void sendToEngine(EngineProtocolNetwork epn) throws IOException{
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    60
		epn.sendToEngine(String.format("emap %s",name));
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    61
	}
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
	public MapType getType(){
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    64
		return type;
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    65
	}
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
	public Drawable getDrawable(){
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    68
		switch(type){
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    69
		case TYPE_MISSION:
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    70
		case TYPE_DEFAULT:
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    71
			return Drawable.createFromPath(previewPath);
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    72
		case TYPE_GENERATED:
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    73
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    74
		default:
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    75
			return null;
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
	}
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
	@Override
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    80
	public int compareTo(Map another) {
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    81
		switch(type){
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    82
		case TYPE_GENERATED:
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    83
			switch(another.getType()){
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    84
			case TYPE_GENERATED:
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    85
				return name.compareTo(another.name);
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    86
			case TYPE_MISSION:
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    87
				return -1;
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 -1;
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    90
			}
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    91
		case TYPE_MISSION:
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    92
			switch(another.getType()){
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    93
			case TYPE_GENERATED:
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    94
				return 1;
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    95
			case TYPE_MISSION:
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    96
				return name.compareTo(another.name);
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    97
			case TYPE_DEFAULT:
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    98
				return -1;
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
    99
			}
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
   100
		case TYPE_DEFAULT:
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
   101
			switch(another.getType()){
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
   102
			case TYPE_GENERATED:
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
   103
				return 1;
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
   104
			case TYPE_MISSION:
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
   105
				return 1;
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
   106
			case TYPE_DEFAULT:
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
   107
				return name.compareTo(another.name);
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
   108
			}
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
		return 0;//default case this should never happen
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
   111
	}
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
	public enum MapType{
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
   114
		TYPE_DEFAULT, TYPE_MISSION, TYPE_GENERATED
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
   115
	}
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
	public int describeContents() {
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
   118
		return 0;
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
   119
	}
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
	public void writeToParcel(Parcel dest, int flags) {
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
   122
		dest.writeString(name);
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
   123
		dest.writeString(path);
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
   124
		dest.writeString(previewPath);
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
   125
		dest.writeString(type.name());
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
	
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
   128
	private void readFromParcel(Parcel src){
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
   129
		name = src.readString();
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
   130
		path = src.readString();
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
   131
		previewPath = src.readString();
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
   132
		type = MapType.valueOf(src.readString());
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 static final Parcelable.Creator<Map> CREATOR = new Parcelable.Creator<Map>() {
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
   135
		public Map createFromParcel(Parcel source) {
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
   136
			return new Map(source);
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 Map[] newArray(int size) {
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
   139
			return new Map[size];
83c53a80f7ff datastructures for the different aspects of a gameconfiguration
Xeli
parents:
diff changeset
   140
		}
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
}