List of usage examples for com.badlogic.gdx.maps MapProperties get
public Object get(String key)
From source file:com.agateau.pixelwheels.map.MapUtils.java
License:Open Source License
@SuppressWarnings("unused") public static float getFloatProperty(MapProperties properties, String key, float defaultValue) { Object value = properties.get(key); if (value == null) { return defaultValue; }/* w ww . j a va 2 s . c o m*/ return Float.valueOf(value.toString()); }
From source file:com.agateau.pixelwheels.map.MapUtils.java
License:Open Source License
public static boolean getBooleanProperty(MapProperties properties, String key, boolean defaultValue) { Object value = properties.get(key); if (value == null) { return defaultValue; }/* w w w. ja va 2 s.co m*/ String v = value.toString(); if (v.equals("true")) { return true; } else if (v.equals("false")) { return false; } NLog.e("invalid boolean value: %s", v); return defaultValue; }
From source file:com.indignado.games.smariano.utils.dermetfan.box2d.Box2DMapObjectParser.java
License:Apache License
/** * internal method for easier access of {@link com.badlogic.gdx.maps.MapProperties} * * @param properties the {@link com.badlogic.gdx.maps.MapProperties} from which to get a property * @param property the key of the desired property * @param defaultValue the default value to return in case the value of the given key cannot be returned * @return the property value associated with the given property key *///from w w w.j a v a 2 s . c o m @SuppressWarnings("unchecked") private <T> T getProperty(MapProperties properties, String property, T defaultValue) { if (properties.get(property) == null) return defaultValue; if (defaultValue.getClass() == Float.class) if (properties.get(property).getClass() == Integer.class) return (T) new Float(properties.get(property, Integer.class)); else if (properties.get(property).getClass() == Float.class) return (T) new Float(properties.get(property, Float.class)); else return (T) new Float(Float.parseFloat(properties.get(property, String.class))); else if (defaultValue.getClass() == Short.class) return (T) new Short(Short.parseShort(properties.get(property, String.class))); else if (defaultValue.getClass() == Boolean.class) return (T) new Boolean(Boolean.parseBoolean(properties.get(property, String.class))); else return (T) properties.get(property, defaultValue.getClass()); }
From source file:com.rubentxu.juegos.core.utils.dermetfan.box2d.Box2DMapObjectParser.java
License:Apache License
/** * internal method for easier access of {@link MapProperties} * * @param properties the {@link MapProperties} from which to get a property * @param property the key of the desired property * @param defaultValue the default value to return in case the value of the given key cannot be returned * @return the property value associated with the given property key *///from w ww .j ava 2s.com @SuppressWarnings("unchecked") private <T> T getProperty(MapProperties properties, String property, T defaultValue) { if (properties.get(property) == null) return defaultValue; if (defaultValue.getClass() == Float.class) if (properties.get(property).getClass() == Integer.class) return (T) new Float(properties.get(property, Integer.class)); else return (T) new Float(Float.parseFloat(properties.get(property, String.class))); else if (defaultValue.getClass() == Short.class) return (T) new Short(Short.parseShort(properties.get(property, String.class))); else if (defaultValue.getClass() == Boolean.class) return (T) new Boolean(Boolean.parseBoolean(properties.get(property, String.class))); else return (T) properties.get(property, defaultValue.getClass()); }
From source file:com.stercore.code.net.dermetfan.utils.libgdx.maps.MapUtils.java
License:Apache License
/** Makes sure the return value is of the desired type (null-safe). If the value of the property is not of the desired type, it will be parsed. * @param properties the {@link MapProperties} to get the value from * @param key the key of the property//from w w w . ja v a2 s. c o m * @param defaultValue the value to return in case the value was null or an empty String or couldn't be returned * @return the key's value as the type of defaultValue */ @SuppressWarnings("unchecked") public static <T> T getProperty(MapProperties properties, String key, T defaultValue) { if (properties == null || key == null) return defaultValue; Object value = properties.get(key); if (value == null || value instanceof String && ((String) value).isEmpty()) return defaultValue; if (defaultValue != null) { if (defaultValue.getClass() == Boolean.class && !(value instanceof Boolean)) return (T) Boolean.valueOf(value.toString()); if (defaultValue.getClass() == Integer.class && !(value instanceof Integer)) return (T) Integer.valueOf(Float.valueOf(value.toString()).intValue()); if (defaultValue.getClass() == Float.class && !(value instanceof Float)) return (T) Float.valueOf(value.toString()); if (defaultValue.getClass() == Double.class && !(value instanceof Double)) return (T) Double.valueOf(value.toString()); if (defaultValue.getClass() == Long.class && !(value instanceof Long)) return (T) Long.valueOf(value.toString()); if (defaultValue.getClass() == Short.class && !(value instanceof Short)) return (T) Short.valueOf(value.toString()); if (defaultValue.getClass() == Byte.class && !(value instanceof Byte)) return (T) Byte.valueOf(value.toString()); } return (T) value; }
From source file:com.stercore.code.net.dermetfan.utils.libgdx.maps.MapUtils.java
License:Apache License
/** @see #readableHierarchy(com.badlogic.gdx.maps.Map, int) */ public static String readableHierarchy(MapProperties properties, int indent) { String hierarchy = ""; Iterator<String> keys = properties.getKeys(); while (keys.hasNext()) { String key = keys.next(); for (int i = 0; i < indent; i++) hierarchy += '\t'; hierarchy += key + ": " + properties.get(key).toString() + '\n'; }/* w ww .j ava 2 s .c o m*/ return hierarchy; }
From source file:com.stercore.code.net.dermetfan.utils.libgdx.maps.TmxMapWriter.java
License:Apache License
/** writes nothing if the given {@link MapProperties} are empty or every key is excluded * @param properties the {@link MapProperties} to write in TMX format * @param exclude the keys not to write * @return this {@link TmxMapWriter} */ public TmxMapWriter tmx(MapProperties properties, Array<String> exclude) throws IOException { Iterator<String> keys = properties.getKeys(); if (!keys.hasNext()) return this; boolean elementEmitted = false; while (keys.hasNext()) { String key = keys.next(); if (exclude != null && exclude.contains(key, false)) continue; if (!elementEmitted) { element("properties"); elementEmitted = true;/*w w w .j av a2s.c o m*/ } element("property").attribute("name", key).attribute("value", properties.get(key)).pop(); } if (elementEmitted) pop(); return this; }
From source file:com.stercore.code.net.dermetfan.utils.libgdx.maps.TmxMapWriter.java
License:Apache License
/** @param set the {@link TiledMapTileSet} to write in TMX format * @return this {@link TmxMapWriter} */ public TmxMapWriter tmx(TiledMapTileSet set) throws IOException { MapProperties props = set.getProperties(); element("tileset"); attribute("firstgid", getProperty(props, "firstgid", 1)); attribute("name", set.getName()); attribute("tilewidth", getProperty(props, "tilewidth", 0)); attribute("tileheight", getProperty(props, "tileheight", 0)); float spacing = getProperty(props, "spacing", Float.NaN), margin = getProperty(props, "margin", Float.NaN); if (!Float.isNaN(spacing)) attribute("spacing", round(spacing)); if (!Float.isNaN(margin)) attribute("margin", round(margin)); Iterator<TiledMapTile> iter = set.iterator(); if (iter.hasNext()) { TiledMapTile tile = iter.next(); element("tileoffset"); attribute("x", round(tile.getOffsetX())); attribute("y", round(-tile.getOffsetY())); pop();/*from www.ja v a 2 s . co m*/ } element("image"); attribute("source", getProperty(props, "imagesource", "")); attribute("imagewidth", getProperty(props, "imagewidth", 0)); attribute("imageheight", getProperty(props, "imageheight", 0)); pop(); iter = set.iterator(); if (iter.hasNext()) { @SuppressWarnings("unchecked") Array<String> asAttributes = Pools.obtain(Array.class); asAttributes.clear(); boolean elementEmitted = false; for (TiledMapTile tile = iter.next(); iter.hasNext(); tile = iter.next()) { MapProperties tileProps = tile.getProperties(); for (String attribute : asAttributes) if (tileProps.containsKey(attribute)) { if (!elementEmitted) { element("tile"); elementEmitted = true; } attribute(attribute, tileProps.get(attribute)); } tmx(tileProps, asAttributes); } asAttributes.clear(); Pools.free(asAttributes); if (elementEmitted) pop(); } pop(); return this; }
From source file:net.dermetfan.gdx.maps.MapUtils.java
License:Apache License
/** Makes sure the return value is of the desired type (null-safe). If the value of the property is not of the desired type, it will be parsed. * @param properties the {@link MapProperties} to get the value from * @param key the key of the property/*from w w w . j a va2 s .c o m*/ * @param defaultValue the value to return in case the value was null or an empty String or couldn't be returned * @return the key's value as the type of defaultValue */ @SuppressWarnings("unchecked") public static <T> T getProperty(MapProperties properties, String key, T defaultValue) { if (properties == null || key == null) return defaultValue; Object value = properties.get(key); if (value == null || value instanceof String && ((String) value).length() == 0) return defaultValue; if (defaultValue != null) { if (defaultValue.getClass() == Boolean.class && !(value instanceof Boolean)) return (T) Boolean.valueOf(value.toString()); if (defaultValue.getClass() == Integer.class && !(value instanceof Integer)) return (T) Integer.valueOf(Float.valueOf(value.toString()).intValue()); if (defaultValue.getClass() == Float.class && !(value instanceof Float)) return (T) Float.valueOf(value.toString()); if (defaultValue.getClass() == Double.class && !(value instanceof Double)) return (T) Double.valueOf(value.toString()); if (defaultValue.getClass() == Long.class && !(value instanceof Long)) return (T) Long.valueOf(value.toString()); if (defaultValue.getClass() == Short.class && !(value instanceof Short)) return (T) Short.valueOf(value.toString()); if (defaultValue.getClass() == Byte.class && !(value instanceof Byte)) return (T) Byte.valueOf(value.toString()); } return (T) value; }
From source file:net.dermetfan.gdx.maps.MapUtils.java
License:Apache License
/** @see #readableHierarchy(com.badlogic.gdx.maps.Map, int) */ public static String readableHierarchy(MapProperties properties, int indent) { StringBuilder hierarchy = new StringBuilder(); Iterator<String> keys = properties.getKeys(); while (keys.hasNext()) { String key = keys.next(); for (int i = 0; i < indent; i++) hierarchy.append('\t'); hierarchy.append(key).append(": ").append(properties.get(key).toString()).append('\n'); }/* ww w . j a v a 2 s . c o m*/ return hierarchy.toString(); }