@Override public long getLong (String key) { Long v = (Long)values.get(key); return v == null ? 0 : v; }
@Override public boolean getBoolean (String key, boolean defValue) { Boolean res = (Boolean)values.get(key); return res == null ? defValue : res; }
/** Convenience method to lookup a color by {@code name}. The invocation of this method is equivalent to the expression * {@code Colors.getColors().get(name)} * * @param name the name of the color * @return the color to which the specified {@code name} is mapped, or {@code null} if there was no mapping for {@code name} * . */ public static Color get (String name) { return map.get(name); }
/** Returns a named resource of the specified type. * @return null if not found. */ public <T> T optional (String name, Class<T> type) { if (name == null) throw new IllegalArgumentException("name cannot be null."); if (type == null) throw new IllegalArgumentException("type cannot be null."); ObjectMap<String, Object> typeResources = resources.get(type); if (typeResources == null) return null; return (T)typeResources.get(name); }
/** Returns a named resource of the specified type. * @return null if not found. */ public <T> T optional (String name, Class<T> type) { if (name == null) throw new IllegalArgumentException("name cannot be null."); if (type == null) throw new IllegalArgumentException("type cannot be null."); ObjectMap<String, Object> typeResources = resources.get(type); if (typeResources == null) return null; return (T)typeResources.get(name); }
/** Sets the reference count of an asset. * @param fileName */ public synchronized void setReferenceCount (String fileName, int refCount) { Class type = assetTypes.get(fileName); if (type == null) throw new GdxRuntimeException("Asset not loaded: " + fileName); assets.get(type).get(fileName).setRefCount(refCount); }
/** Returns the name of the specified style object, or null if it is not in the skin. This compares potentially every style * object in the skin of the same type as the specified style, which may be a somewhat expensive operation. */ public String find (Object resource) { if (resource == null) throw new IllegalArgumentException("style cannot be null."); ObjectMap<String, Object> typeResources = resources.get(resource.getClass()); if (typeResources == null) return null; return typeResources.findKey(resource, true); }
public boolean has (String name, Class type) { ObjectMap<String, Object> typeResources = resources.get(type); if (typeResources == null) return false; return typeResources.containsKey(name); }
/** @param asset the asset * @return the filename of the asset or null */ public synchronized <T> String getAssetFileName (T asset) { for (Class assetType : assets.keys()) { ObjectMap<String, RefCountedContainer> assetsByType = assets.get(assetType); for (String fileName : assetsByType.keys()) { T otherAsset = (T)assetsByType.get(fileName).getObject(Object.class); if (otherAsset == asset || asset.equals(otherAsset)) return fileName; } } return null; }
public OpenALSound newSound (FileHandle file) { if (file == null) throw new IllegalArgumentException("file cannot be null."); Class<? extends OpenALSound> soundClass = extensionToSoundClass.get(file.extension().toLowerCase()); if (soundClass == null) throw new GdxRuntimeException("Unknown file extension for sound: " + file); try { return soundClass.getConstructor(new Class[] {OpenALAudio.class, FileHandle.class}).newInstance(this, file); } catch (Exception ex) { throw new GdxRuntimeException("Error creating sound " + soundClass.getName() + " for file: " + file, ex); } }
public OpenALSound newSound (FileHandle file) { if (file == null) throw new IllegalArgumentException("file cannot be null."); Class<? extends OpenALSound> soundClass = extensionToSoundClass.get(file.extension().toLowerCase()); if (soundClass == null) throw new GdxRuntimeException("Unknown file extension for sound: " + file); try { return soundClass.getConstructor(new Class[] {OpenALAudio.class, FileHandle.class}).newInstance(this, file); } catch (Exception ex) { throw new GdxRuntimeException("Error creating sound " + soundClass.getName() + " for file: " + file, ex); } }
/** Reads the entire file into a string using the specified charset. * @throw GdxRuntimeException if the file handle represents a directory, doesn't exist, or could not be read. */ public String readString (String charset) { if (preloader.isText(file)) return preloader.texts.get(file); try { return new String(readBytes(), "UTF-8"); } catch (UnsupportedEncodingException e) { return null; } }
/** Reads the entire file into a string using the specified charset. * @throw GdxRuntimeException if the file handle represents a directory, doesn't exist, or could not be read. */ public String readString (String charset) { if (preloader.isText(file)) return preloader.texts.get(file); try { return new String(readBytes(), "UTF-8"); } catch (UnsupportedEncodingException e) { return null; } }
public Entry next () { if (!hasNext) throw new NoSuchElementException(); if (!valid) throw new GdxRuntimeException("#iterator() cannot be used nested."); entry.key = keys.get(nextIndex); entry.value = map.get(entry.key); nextIndex++; hasNext = nextIndex < map.size; return entry; }
/** Sets the type of elements in a collection. When the element type is known, the class for each element in the collection * does not need to be written unless different from the element type. */ public void setElementType (Class type, String fieldName, Class elementType) { ObjectMap<String, FieldMetadata> fields = getFields(type); FieldMetadata metadata = fields.get(fieldName); if (metadata == null) throw new SerializationException("Field not found: " + fieldName + " (" + type.getName() + ")"); metadata.elementType = elementType; }
@Override public Preferences getPreferences (String name) { Preferences pref = prefs.get(name); if (pref == null) { pref = new GwtPreferences(name); prefs.put(name, pref); } return pref; }
/** Returns a new or existing pool for the specified type, stored in a Class to {@link Pool} map. Note the max size is ignored * if this is not the first time this pool has been requested. */ static public <T> Pool<T> get (Class<T> type, int max) { Pool pool = typePools.get(type); if (pool == null) { pool = new ReflectionPool(type, 4, max); typePools.put(type, pool); } return pool; }
/** Returns a new or existing pool for the specified type, stored in a Class to {@link Pool} map. Note the max size is ignored * if this is not the first time this pool has been requested. */ static public <T> Pool<T> get (Class<T> type, int max) { Pool pool = typePools.get(type); if (pool == null) { pool = new ReflectionPool(type, 4, max); typePools.put(type, pool); } return pool; }
/** Disposes all resources associated with this shader. Must be called when the shader is no longer used. */ public void dispose () { GL20 gl = Gdx.gl20; gl.glUseProgram(0); gl.glDeleteShader(vertexShaderHandle); gl.glDeleteShader(fragmentShaderHandle); gl.glDeleteProgram(program); if (shaders.get(Gdx.app) != null) shaders.get(Gdx.app).removeValue(this, true); }
@Override public Preferences getPreferences(String name) { if (preferences.containsKey(name)) { return preferences.get(name); } else { Preferences prefs = new HeadlessPreferences(name, this.preferencesdir); preferences.put(name, prefs); return prefs; } }