project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Datastructures/Map.java
changeset 7485 0481bd74267c
parent 7482 d70a5b0d1190
child 7488 7e09947b6aa5
equal deleted inserted replaced
7482:d70a5b0d1190 7485:0481bd74267c
     1 /*
       
     2  * Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game
       
     3  * Copyright (c) 2011-2012 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 
       
    19 package org.hedgewars.hedgeroid.Datastructures;
       
    20 
       
    21 import java.io.File;
       
    22 
       
    23 import android.content.Context;
       
    24 import android.graphics.drawable.Drawable;
       
    25 
       
    26 public class Map implements Comparable<Map> {
       
    27 
       
    28 	private static final String MISSION_PREFIX = "Mission: ";
       
    29 
       
    30 	private String name;
       
    31 	private String path;
       
    32 	private String previewPath;
       
    33 	private MapType type;
       
    34 
       
    35 	public Map(File mapDir, MapType _type, Context c){
       
    36 		type = _type;
       
    37 
       
    38 		name = mapDir.getName();
       
    39 		path = mapDir.getAbsolutePath();
       
    40 		previewPath = path + "/preview.png";
       
    41 		
       
    42 		/*switch(type){
       
    43 		case TYPE_DEFAULT:
       
    44 			
       
    45 			break;
       
    46 		case TYPE_GENERATED:
       
    47 			//TODO
       
    48 			break;
       
    49 		case TYPE_MISSION:
       
    50 			name = MISSION_PREFIX + mapDir.getName();
       
    51 			path = mapDir.getAbsolutePath();
       
    52 			break;
       
    53 		}*/
       
    54 
       
    55 		
       
    56 	}
       
    57 
       
    58 	public String toString(){
       
    59 		switch(type){
       
    60 		default:
       
    61 		case TYPE_DEFAULT:
       
    62 			return name;
       
    63 		case TYPE_GENERATED:
       
    64 			return "bla";
       
    65 		case TYPE_MISSION:
       
    66 			return MISSION_PREFIX + name;
       
    67 		}
       
    68 	}
       
    69 	
       
    70 	public MapType getType(){
       
    71 		return type;
       
    72 	}
       
    73 
       
    74 	public Drawable getDrawable(){
       
    75 		switch(type){
       
    76 		case TYPE_MISSION:
       
    77 		case TYPE_DEFAULT:
       
    78 			return Drawable.createFromPath(previewPath);
       
    79 		case TYPE_GENERATED:
       
    80 
       
    81 		default:
       
    82 			return null;
       
    83 		}
       
    84 	}
       
    85 
       
    86 	public int compareTo(Map another) {
       
    87 		switch(type){
       
    88 		case TYPE_GENERATED:
       
    89 			switch(another.getType()){
       
    90 			case TYPE_GENERATED:
       
    91 				return name.compareTo(another.name);
       
    92 			case TYPE_MISSION:
       
    93 				return -1;
       
    94 			case TYPE_DEFAULT:
       
    95 				return -1;
       
    96 			}
       
    97 		case TYPE_MISSION:
       
    98 			switch(another.getType()){
       
    99 			case TYPE_GENERATED:
       
   100 				return 1;
       
   101 			case TYPE_MISSION:
       
   102 				return name.compareTo(another.name);
       
   103 			case TYPE_DEFAULT:
       
   104 				return -1;
       
   105 			}
       
   106 		case TYPE_DEFAULT:
       
   107 			switch(another.getType()){
       
   108 			case TYPE_GENERATED:
       
   109 				return 1;
       
   110 			case TYPE_MISSION:
       
   111 				return 1;
       
   112 			case TYPE_DEFAULT:
       
   113 				return name.compareTo(another.name);
       
   114 			}
       
   115 		}
       
   116 		return 0;//default case this should never happen
       
   117 	}
       
   118 
       
   119 	public enum MapType{
       
   120 		TYPE_DEFAULT, TYPE_MISSION, TYPE_GENERATED
       
   121 	}
       
   122 }