public MapRepository() { mMapInfos = new ArrayList<>(); mMapInfos.add(new MapInfo("original", R.string.map_original_name, R.raw.map_original)); mMapInfos.add(new MapInfo("waiting_line", R.string.map_waiting_line_name, R.raw.map_waiting_line)); mMapInfos.add(new MapInfo("turn_round", R.string.map_turn_round_name, R.raw.map_turn_round)); mMapInfos.add(new MapInfo("hurry", R.string.map_hurry_name, R.raw.map_hurry)); mMapInfos.add(new MapInfo("civyshk_yard", R.string.map_civyshk_yard_name, R.raw.map_civyshk_yard)); mMapInfos.add(new MapInfo("civyshk_2y", R.string.map_civyshk_2y_name, R.raw.map_civyshk_2y)); mMapInfos.add(new MapInfo("civyshk_line5", R.string.map_civyshk_line5_name, R.raw.map_civyshk_line5)); mMapInfos.add(new MapInfo("civyshk_labyrinth", R.string.map_civyshk_labyrinth_name, R.raw.map_civyshk_labyrinth)); }
public MapInfo getMapById(String mapId) { for (MapInfo mapInfo : mMapInfos) { if (mapInfo.getMapId().equals(mapId)) { return mapInfo; } } throw new RuntimeException("Map not found!"); }
ViewHolder viewHolder = new ViewHolder(mapItemView); viewHolder.txt_name.setText(resources.getString(mapInfo.getMapNameResId())); String highScore = fmt.format(mHighScores.getHighScore(mapInfo.getMapId())); viewHolder.txt_highscore.setText(resources.getString(R.string.score) + ": " + highScore); if (!sThumbCache.containsKey(mapInfo.getMapId())) { MapThumbGenerator generator = new MapThumbGenerator(); Bitmap thumb = generator.generateThumb(resources, mapInfo.getMapDataResId()); sThumbCache.put(mapInfo.getMapId(), thumb); viewHolder.img_thumb.setImageBitmap(sThumbCache.get(mapInfo.getMapId()));
private KeyValueStore createGameConfig(String mapId) { Log.d(TAG, "Loading configuration..."); KeyValueStore gameConfig = KeyValueStore.fromResources(mContext.getResources(), R.raw.game_settings); KeyValueStore entityConfig = new KeyValueStore(); entityConfig.extend(KeyValueStore.fromResources(mContext.getResources(), R.raw.enemy_settings)); entityConfig.extend(KeyValueStore.fromResources(mContext.getResources(), R.raw.tower_settings)); gameConfig.putStore("entities", entityConfig); MapInfo mapInfo = mMapRepository.getMapById(mapId); gameConfig.putStore("map", KeyValueStore.fromResources(mContext.getResources(), mapInfo.getMapDataResId())); gameConfig.extend(KeyValueStore.fromResources(mContext.getResources(), R.raw.waves)); return gameConfig; }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { mGameLoader.loadMap(mMapRepository.getMapInfos().get(position).getMapId()); finish(); }