project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Datastructures/MapRecipe.java
changeset 7508 763d3961400b
parent 7485 0481bd74267c
child 7584 7831c84cc644
equal deleted inserted replaced
7504:ed1d52c5aa94 7508:763d3961400b
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    17  */
    17  */
    18 
    18 
    19 package org.hedgewars.hedgeroid.Datastructures;
    19 package org.hedgewars.hedgeroid.Datastructures;
    20 
    20 
       
    21 import java.util.Arrays;
       
    22 import java.util.UUID;
       
    23 
    21 import org.hedgewars.hedgeroid.R;
    24 import org.hedgewars.hedgeroid.R;
    22 import org.hedgewars.hedgeroid.frontlib.Frontlib;
    25 import org.hedgewars.hedgeroid.frontlib.Frontlib;
    23 
    26 
    24 import android.content.res.Resources;
    27 import android.content.res.Resources;
    25 
    28 
    61 		return new MapRecipe(Frontlib.MAPGEN_DRAWN, 0, 0, MAPNAME_DRAWN, seed, theme, drawData);
    64 		return new MapRecipe(Frontlib.MAPGEN_DRAWN, 0, 0, MAPNAME_DRAWN, seed, theme, drawData);
    62 	}
    65 	}
    63 	
    66 	
    64 	public byte[] getDrawData() {
    67 	public byte[] getDrawData() {
    65 		return drawData==null ? null : drawData.clone();
    68 		return drawData==null ? null : drawData.clone();
       
    69 	}
       
    70 	
       
    71 	public MapRecipe withMapgen(int mapgen) {
       
    72 		return new MapRecipe(mapgen, templateFilter, mazeSize, name, seed, theme, drawData);
       
    73 	}
       
    74 	
       
    75 	public MapRecipe withTemplateFilter(int templateFilter) {
       
    76 		return new MapRecipe(mapgen, templateFilter, mazeSize, name, seed, theme, drawData);
       
    77 	}
       
    78 	
       
    79 	public MapRecipe withMazeSize(int mazeSize) {
       
    80 		return new MapRecipe(mapgen, templateFilter, mazeSize, name, seed, theme, drawData);
       
    81 	}
       
    82 	
       
    83 	public MapRecipe withName(String name) {
       
    84 		return new MapRecipe(mapgen, templateFilter, mazeSize, name, seed, theme, drawData);
       
    85 	}
       
    86 	
       
    87 	public MapRecipe withSeed(String seed) {
       
    88 		return new MapRecipe(mapgen, templateFilter, mazeSize, name, seed, theme, drawData);
       
    89 	}
       
    90 	
       
    91 	public MapRecipe withTheme(String theme) {
       
    92 		return new MapRecipe(mapgen, templateFilter, mazeSize, name, seed, theme, drawData);
       
    93 	}
       
    94 	
       
    95 	public MapRecipe withDrawData(byte[] drawData) {
       
    96 		return new MapRecipe(mapgen, templateFilter, mazeSize, name, seed, theme, drawData);
    66 	}
    97 	}
    67 	
    98 	
    68 	public static String formatMapName(Resources res, String map) {
    99 	public static String formatMapName(Resources res, String map) {
    69 		if(map.charAt(0)=='+') {
   100 		if(map.charAt(0)=='+') {
    70 			if(map.equals(MAPNAME_REGULAR)) {
   101 			if(map.equals(MAPNAME_REGULAR)) {
    75 				return res.getString(R.string.map_drawn);
   106 				return res.getString(R.string.map_drawn);
    76 			}
   107 			}
    77 		}
   108 		}
    78 		return map;
   109 		return map;
    79 	}
   110 	}
       
   111 
       
   112 	/**
       
   113 	 * Returns the mapname corresponding to the map generator (e.g. "+rnd+" for regular maps)
       
   114 	 * If the mapgen does not have a unique name (MAPGEN_NAMED) or is not known, the def
       
   115 	 * value is returned.
       
   116 	 */
       
   117 	public static String mapnameForGenerator(int mapgen, String def) {
       
   118 		switch(mapgen) {
       
   119 		case Frontlib.MAPGEN_REGULAR: return MAPNAME_REGULAR;
       
   120 		case Frontlib.MAPGEN_MAZE: return MAPNAME_MAZE;
       
   121 		case Frontlib.MAPGEN_DRAWN: return MAPNAME_DRAWN;
       
   122 		default: return def;
       
   123 		}
       
   124 	}
       
   125 	
       
   126 	/**
       
   127 	 * In a sense this is the inverse of mapnameForGenerator. Returns the mapgen that uses
       
   128 	 * mapName as special identifier, or MAPGEN_NAMED if there is none.
       
   129 	 */
       
   130 	public static int generatorForMapname(String mapName) {
       
   131 		if(MapRecipe.MAPNAME_REGULAR.equals(mapName)) {
       
   132 			return Frontlib.MAPGEN_REGULAR;
       
   133 		} else if(MapRecipe.MAPNAME_MAZE.equals(mapName)) {
       
   134 			return Frontlib.MAPGEN_MAZE;
       
   135 		} else if(MapRecipe.MAPNAME_DRAWN.equals(mapName)) {
       
   136 			return Frontlib.MAPGEN_DRAWN;
       
   137 		} else {
       
   138 			return Frontlib.MAPGEN_NAMED;
       
   139 		}
       
   140 	}
       
   141 	
       
   142 	@Override
       
   143 	public String toString() {
       
   144 		return "MapRecipe [mapgen=" + mapgen + ", templateFilter="
       
   145 				+ templateFilter + ", mazeSize=" + mazeSize + ", name=" + name
       
   146 				+ ", seed=" + seed + ", theme=" + theme + ", drawData="
       
   147 				+ Arrays.toString(drawData) + "]";
       
   148 	}
       
   149 
       
   150 	@Override
       
   151 	public int hashCode() {
       
   152 		final int prime = 31;
       
   153 		int result = 1;
       
   154 		result = prime * result + Arrays.hashCode(drawData);
       
   155 		result = prime * result + mapgen;
       
   156 		result = prime * result + mazeSize;
       
   157 		result = prime * result + ((name == null) ? 0 : name.hashCode());
       
   158 		result = prime * result + ((seed == null) ? 0 : seed.hashCode());
       
   159 		result = prime * result + templateFilter;
       
   160 		result = prime * result + ((theme == null) ? 0 : theme.hashCode());
       
   161 		return result;
       
   162 	}
       
   163 
       
   164 	@Override
       
   165 	public boolean equals(Object obj) {
       
   166 		if (this == obj)
       
   167 			return true;
       
   168 		if (obj == null)
       
   169 			return false;
       
   170 		if (getClass() != obj.getClass())
       
   171 			return false;
       
   172 		MapRecipe other = (MapRecipe) obj;
       
   173 		if (!Arrays.equals(drawData, other.drawData))
       
   174 			return false;
       
   175 		if (mapgen != other.mapgen)
       
   176 			return false;
       
   177 		if (mazeSize != other.mazeSize)
       
   178 			return false;
       
   179 		if (name == null) {
       
   180 			if (other.name != null)
       
   181 				return false;
       
   182 		} else if (!name.equals(other.name))
       
   183 			return false;
       
   184 		if (seed == null) {
       
   185 			if (other.seed != null)
       
   186 				return false;
       
   187 		} else if (!seed.equals(other.seed))
       
   188 			return false;
       
   189 		if (templateFilter != other.templateFilter)
       
   190 			return false;
       
   191 		if (theme == null) {
       
   192 			if (other.theme != null)
       
   193 				return false;
       
   194 		} else if (!theme.equals(other.theme))
       
   195 			return false;
       
   196 		return true;
       
   197 	}
       
   198 
       
   199 	public static String makeRandomSeed() {
       
   200 		return "{"+UUID.randomUUID().toString()+"}";
       
   201 	}
    80 }
   202 }