OSDN Git Service

Added functionality to AssetManager.java:
authorRegiden <regiden@hotmail.de>
Thu, 27 Sep 2012 17:24:56 +0000 (19:24 +0200)
committerRegiden <regiden@hotmail.de>
Thu, 27 Sep 2012 17:24:56 +0000 (19:24 +0200)
 - method to get the type of an asset
 - method to get an asset without the type parameter

backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/assets/AssetManager.java
gdx/src/com/badlogic/gdx/assets/AssetManager.java

index c9bc5bc..20d5aeb 100644 (file)
@@ -73,6 +73,18 @@ public class AssetManager implements Disposable {
        }\r
 \r
        /** @param fileName the asset file name\r
+        * @return the asset */\r
+       public synchronized <T> T get (String fileName) {\r
+               Class<T> type = assetTypes.get(fileName);\r
+               ObjectMap<String, RefCountedContainer> assetsByType = assets.get(type);\r
+               if (assetsByType == null) throw new GdxRuntimeException("Asset not loaded: " + fileName);\r
+               RefCountedContainer assetContainer = assetsByType.get(fileName);\r
+               if (assetContainer == null) throw new GdxRuntimeException("Asset not loaded: " + fileName);\r
+               T asset = assetContainer.getObject(type);\r
+               if (asset == null) throw new GdxRuntimeException("Asset not loaded: " + fileName);\r
+               return asset;\r
+       }\r
+       /** @param fileName the asset file name\r
         * @param type the asset type\r
         * @return the asset */\r
        public synchronized <T> T get (String fileName, Class<T> type) {\r
@@ -566,5 +578,8 @@ public class AssetManager implements Disposable {
        public synchronized Array<String> getDependencies(String fileName) {\r
                return assetDependencies.get(fileName);\r
        }\r
-       \r
+       /** @return the type of a loaded asset. */\r
+       public synchronized Class getAssetType (String fileName) {\r
+               return assetTypes.get(fileName);\r
+       }\r
 }\r
index ecc0c70..fac8546 100644 (file)
@@ -97,6 +97,19 @@ public class AssetManager implements Disposable {
        }\r
 \r
        /** @param fileName the asset file name\r
+        * @return the asset */\r
+       public synchronized <T> T get (String fileName) {\r
+               Class<T> type = assetTypes.get(fileName);\r
+               ObjectMap<String, RefCountedContainer> assetsByType = assets.get(type);\r
+               if (assetsByType == null) throw new GdxRuntimeException("Asset not loaded: " + fileName);\r
+               RefCountedContainer assetContainer = assetsByType.get(fileName);\r
+               if (assetContainer == null) throw new GdxRuntimeException("Asset not loaded: " + fileName);\r
+               T asset = assetContainer.getObject(type);\r
+               if (asset == null) throw new GdxRuntimeException("Asset not loaded: " + fileName);\r
+               return asset;\r
+       }\r
+\r
+       /** @param fileName the asset file name\r
         * @param type the asset type\r
         * @return the asset */\r
        public synchronized <T> T get (String fileName, Class<T> type) {\r
@@ -596,12 +609,18 @@ public class AssetManager implements Disposable {
        }\r
 \r
        /** @return the file names of all loaded assets. */\r
-       public synchronized Array<String> getAssetNames() {\r
+       public synchronized Array<String> getAssetNames () {\r
                return assetTypes.keys().toArray();\r
        }\r
+\r
        /** @return the dependencies of an asset or null if the asset has no dependencies. */\r
-       public synchronized Array<String> getDependencies(String fileName) {\r
+       public synchronized Array<String> getDependencies (String fileName) {\r
                return assetDependencies.get(fileName);\r
        }\r
 \r
+       /** @return the type of a loaded asset. */\r
+       public synchronized Class getAssetType (String fileName) {\r
+               return assetTypes.get(fileName);\r
+       }\r
+\r
 }\r