List of usage examples for com.badlogic.gdx.utils ObjectMap containsKey
public boolean containsKey(K key)
From source file:com.ahsgaming.starbattle.json.Utils.java
License:Apache License
public static String getStringProperty(ObjectMap<String, Object> json, String id) { if (json.containsKey(id)) return json.get(id).toString(); return ""; }
From source file:com.ahsgaming.starbattle.json.Utils.java
License:Apache License
public static float getFloatProperty(ObjectMap<String, Object> json, String id) { if (json.containsKey(id)) return Float.parseFloat(json.get(id).toString()); return 0;//from w w w .jav a 2s. c o m }
From source file:com.ahsgaming.superrummy.json.Utils.java
License:Apache License
public static String getStringProperty(ObjectMap<String, Object> json, String id, String defaultValue) { if (json.containsKey(id)) return json.get(id).toString(); return defaultValue; }
From source file:com.ahsgaming.superrummy.json.Utils.java
License:Apache License
public static float getFloatProperty(ObjectMap<String, Object> json, String id, float defaultValue) { if (json.containsKey(id)) return Float.parseFloat(json.get(id).toString()); return defaultValue; }
From source file:com.ahsgaming.superrummy.json.Utils.java
License:Apache License
public static int getIntProperty(ObjectMap<String, Object> json, String id, int defaultValue) { if (json.containsKey(id)) return (int) Float.parseFloat(json.get(id).toString()); return defaultValue; }
From source file:com.ahsgaming.valleyofbones.TextureManager.java
License:Apache License
public void loadTexturePackage(String name) { map.clear();// w w w. j a va 2 s . c o m JsonReader jsonReader = new JsonReader(); Object rObj = jsonReader.parse(Gdx.files.internal(name + "/package.json")); ObjectMap<String, Object> mapObjs = (ObjectMap<String, Object>) rObj; for (String key : mapObjs.keys()) { ObjectMap<String, Object> createObj = (ObjectMap<String, Object>) mapObjs.get(key); String file = ""; int x = 0, y = 0, w = 0, h = 0; if (createObj.containsKey("file")) { file = name + "/" + createObj.get("file").toString(); } if (createObj.containsKey("x")) { x = (int) Float.parseFloat(createObj.get("x").toString()); } if (createObj.containsKey("y")) { y = (int) Float.parseFloat(createObj.get("y").toString()); } if (createObj.containsKey("w")) { w = (int) Float.parseFloat(createObj.get("w").toString()); } if (createObj.containsKey("h")) { h = (int) Float.parseFloat(createObj.get("h").toString()); } Gdx.app.log(LOG, String.format("Loading %s from %s", key, file)); map.put(key, loadTextureRegion(file, x, y, w, h)); } }
From source file:com.stercore.code.net.dermetfan.utils.libgdx.box2d.Box2DMapObjectParser.java
License:Apache License
/** @return the desiredName if it was available, otherwise desiredName with a number appended */ public static String findAvailableName(String desiredName, ObjectMap<String, ?> map) { if (desiredName == null) desiredName = String.valueOf(map.size); if (map.containsKey(desiredName)) { int duplicate = 1; while (map.containsKey(desiredName + duplicate)) duplicate++;//from ww w . ja v a2s.c om desiredName += duplicate; } return desiredName; }
From source file:com.stercore.code.net.dermetfan.utils.libgdx.maps.TileAnimator.java
License:Apache License
/** filters the tiles that are frames * @param tiles all tiles//from w w w. ja va2 s. com * @param animationKey the key used to tell if a tile is a frame * @return an {@link ObjectMap} which values are tiles that are frames and which keys are their animation names */ public static ObjectMap<String, Array<StaticTiledMapTile>> filterFrames(TiledMapTile[] tiles, String animationKey) { ObjectMap<String, Array<StaticTiledMapTile>> animations = new ObjectMap<>(); MapProperties tileProperties; String animationName; for (TiledMapTile tile : tiles) { if (!(tile instanceof StaticTiledMapTile)) continue; tileProperties = tile.getProperties(); if (tileProperties.containsKey(animationKey)) { animationName = tileProperties.get(animationKey, String.class); if (!animations.containsKey(animationName)) animations.put(animationName, new Array<StaticTiledMapTile>(3)); animations.get(animationName).add((StaticTiledMapTile) tile); } } return animations; }
From source file:de.bitowl.advent.game2.MyTiledMapPacker.java
License:Apache License
/** You can either run the {@link MyTiledMapPacker#main(String[])} method or reference this class in your own project and call * this method.//from ww w.j a v a 2 s . c o m * * Keep in mind that this preprocessor will need to load the maps by using the {@link TmxMapLoader} loader and this in turn * will need a valid OpenGL context to work: this is probably subject to change in the future, where loading both maps metadata * and graphics resources should be made conditional. * * Process a directory containing TMX map files representing Tiled maps and produce a single TextureAtlas as well as new * processed TMX map files, correctly referencing the generated {@link TextureAtlas} by using the "atlas" custom map property. * * Typically, your maps will lie in a directory, such as "maps/" and your tilesets in a subdirectory such as "maps/city": this * layout will ensure that MapEditor will reference your tileset with a very simple relative path and no parent directory * names, such as "..", will ever happen in your TMX file definition avoiding much of the confusion caused by the preprocessor * working with relative paths. * * <strong>WARNING!</strong> Use caution if you have a "../" in the path of your tile sets! The output for these tile sets will * be relative to the output directory. For example, if your output directory is "C:\mydir\maps" and you have a tileset with * the path "../tileset.png", the tileset will be output to "C:\mydir\" and the maps will be in "C:\mydir\maps". * * @param inputDir the input directory containing the tmx files (and tile sets, relative to the path listed in the tmx file) * @param outputDir The output directory for the TMX files, <strong>should be empty before running</strong>. * @param settings the settings used in the TexturePacker */ public void processMaps(File inputDir, File outputDir, Settings settings) throws IOException { FileHandle inputDirHandle = new FileHandle(inputDir.getAbsolutePath()); File[] files = inputDir.listFiles(new TmxFilter()); ObjectMap<String, TiledMapTileSet> tilesetsToPack = new ObjectMap<String, TiledMapTileSet>(); for (File file : files) { map = mapLoader.load(file.getAbsolutePath()); // if enabled, build a list of used tileids for the tileset used by this map if (this.settings.stripUnusedTiles) { int mapWidth = map.getProperties().get("width", Integer.class); int mapHeight = map.getProperties().get("height", Integer.class); int numlayers = map.getLayers().getCount(); int bucketSize = mapWidth * mapHeight * numlayers; Iterator<MapLayer> it = map.getLayers().iterator(); while (it.hasNext()) { MapLayer layer = it.next(); // some layers can be plain MapLayer instances (ie. object groups), just ignore them if (layer instanceof TiledMapTileLayer) { TiledMapTileLayer tlayer = (TiledMapTileLayer) layer; for (int y = 0; y < mapHeight; ++y) { for (int x = 0; x < mapWidth; ++x) { if (tlayer.getCell(x, y) != null) { int tileid = tlayer.getCell(x, y).getTile().getId() & ~0xE0000000; String tilesetName = tilesetNameFromTileId(map, tileid); IntArray usedIds = getUsedIdsBucket(tilesetName, bucketSize); usedIds.add(tileid); // track this tileset to be packed if not already tracked if (!tilesetsToPack.containsKey(tilesetName)) { tilesetsToPack.put(tilesetName, map.getTileSets().getTileSet(tilesetName)); } } } } } } } else { for (TiledMapTileSet tileset : map.getTileSets()) { String tilesetName = tileset.getName(); if (!tilesetsToPack.containsKey(tilesetName)) { tilesetsToPack.put(tilesetName, tileset); } } } FileHandle tmxFile = new FileHandle(file.getAbsolutePath()); writeUpdatedTMX(map, outputDir, tmxFile); } packTilesets(tilesetsToPack, inputDirHandle, outputDir, settings); }
From source file:me.scarlet.undertailor.audio.AudioManager.java
License:Open Source License
/** * Internal method./*w ww .j a va 2 s . co m*/ * * <p>Handles loading both music and sounds from * directories.</p> */ private void load(File rootDirectory, Class<? extends Audio> audioClass) { String resourceName = audioClass == Music.class ? "Music" : "Sound"; String resourceNamePlural = audioClass == Music.class ? "Music" : "Sound(s)"; log.info("Loading " + resourceNamePlural.toLowerCase() + " from directory " + rootDirectory.getAbsolutePath()); ObjectMap<String, File> files = FileUtil.loadWithIdentifiers(rootDirectory, file -> { String fileName = file.getName(); return fileName.endsWith(".ogg") || fileName.endsWith(".wav") || fileName.endsWith(".mp3"); }); ObjectMap<String, Audio> targetMap; if (audioClass == Music.class) { targetMap = this.music; } else { targetMap = this.sounds; } for (String key : files.keys()) { File audioFile = files.get(key); try { if (targetMap.containsKey(key)) { log.warn(resourceName + " file " + audioFile.getAbsolutePath() + " is replacing a previous entry under the key " + key); } targetMap.put(key, audioClass == Music.class ? new MusicFactory(key, this, audioFile) : new SoundFactory(key, this, audioFile)); log.info("Loaded " + resourceName.toLowerCase() + " " + audioFile.getName() + " under key " + key); } catch (UnsupportedAudioFileException e) { log.error("Failed to load " + resourceName.toLowerCase() + " file " + audioFile.getAbsolutePath() + " (unsupported filetype, .ogg/.wav/.mp3 only)"); } } log.info(targetMap.size + " " + resourceNamePlural.toLowerCase() + (audioClass == Music.class ? " tracks(s)" : "") + " loaded."); }