OSDN Git Service

[changed] Internal files check classpath first on desktop.
authornathan.sweet <nathan.sweet@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Tue, 2 Nov 2010 05:05:57 +0000 (05:05 +0000)
committernathan.sweet <nathan.sweet@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Tue, 2 Nov 2010 05:05:57 +0000 (05:05 +0000)
[changed] FileHandle getFileName -> getPath, getInputStream -> readFile.

13 files changed:
backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidAudio.java
backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidFileHandle.java
backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGraphics.java
backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglFileHandle.java
backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglFiles.java
backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglGraphicsBase.java
backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/desktop/LwjglFileHandle.java
backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/desktop/LwjglFiles.java
backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/desktop/LwjglGraphics.java
gdx/src/com/badlogic/gdx/Files.java
gdx/src/com/badlogic/gdx/files/FileHandle.java
gdx/src/com/badlogic/gdx/graphics/BitmapFont.java
gdx/src/com/badlogic/gdx/graphics/particles/ParticleEffect.java

index de882cb..2514e0b 100644 (file)
@@ -84,7 +84,7 @@ final class AndroidAudio implements Audio {
 \r
                if (aHandle.isAsset()) {\r
                        try {\r
-                               AssetFileDescriptor descriptor = aHandle.getAssetManager().openFd(aHandle.getFileName());\r
+                               AssetFileDescriptor descriptor = aHandle.getAssetManager().openFd(aHandle.getPath());\r
                                mediaPlayer.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength());\r
                                descriptor.close();\r
                                mediaPlayer.prepare();\r
@@ -96,7 +96,7 @@ final class AndroidAudio implements Audio {
                        }\r
                } else {\r
                        try {\r
-                               mediaPlayer.setDataSource(aHandle.getFileName());\r
+                               mediaPlayer.setDataSource(aHandle.getPath());\r
                                mediaPlayer.prepare();\r
                                AndroidMusic music = new AndroidMusic(this, mediaPlayer);\r
                                musics.add(music);\r
@@ -115,7 +115,7 @@ final class AndroidAudio implements Audio {
                AndroidFileHandle aHandle = (AndroidFileHandle)file;\r
                if (aHandle.isAsset()) {\r
                        try {\r
-                               AssetFileDescriptor descriptor = aHandle.getAssetManager().openFd(aHandle.getFileName());\r
+                               AssetFileDescriptor descriptor = aHandle.getAssetManager().openFd(aHandle.getPath());\r
                                AndroidSound sound = new AndroidSound(soundPool, manager, soundPool.load(descriptor, 1));\r
                                descriptor.close();\r
                                return sound;\r
@@ -124,7 +124,7 @@ final class AndroidAudio implements Audio {
                        }\r
                } else {\r
                        try {\r
-                               return new AndroidSound(soundPool, manager, soundPool.load(aHandle.getFileName(), 1));\r
+                               return new AndroidSound(soundPool, manager, soundPool.load(aHandle.getPath(), 1));\r
                        } catch (Exception e) {\r
                                throw new GdxRuntimeException("Couldn't load Sound from file '" + file + "'", e);\r
                        }\r
index 0bc01f0..8d5c26d 100644 (file)
@@ -56,11 +56,11 @@ public class AndroidFileHandle implements FileHandle {
        /**\r
         * @return the filename\r
         */\r
-       public String getFileName () {\r
+       public String getPath () {\r
                return filename;\r
        }\r
 \r
-       public InputStream getInputStream () {\r
+       public InputStream readFile () {\r
                try {\r
                        return manager.open(filename);\r
                } catch (IOException ex) {\r
index 02b6916..0bfdb1c 100644 (file)
@@ -192,7 +192,7 @@ final class AndroidGraphics implements Graphics, Renderer {
         * {@inheritDoc}\r
         */\r
        @Override public Pixmap newPixmap (FileHandle file) {\r
-               return newPixmap(file.getInputStream());\r
+               return newPixmap(file.readFile());\r
        }\r
 \r
        /**\r
index ebd7ea9..e0b6022 100644 (file)
@@ -18,6 +18,7 @@ import java.io.FileInputStream;
 import java.io.FileNotFoundException;\r
 import java.io.InputStream;\r
 \r
+import com.badlogic.gdx.Files.FileType;\r
 import com.badlogic.gdx.files.FileHandle;\r
 import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
@@ -30,9 +31,11 @@ import com.badlogic.gdx.utils.GdxRuntimeException;
 public class JoglFileHandle implements FileHandle {\r
        /** the file **/\r
        private final File file;\r
+       private final FileType type;\r
 \r
-       JoglFileHandle (File file) {\r
+       JoglFileHandle (File file, FileType type) {\r
                this.file = file;\r
+               this.type = type;\r
        }\r
 \r
        /**\r
@@ -42,11 +45,15 @@ public class JoglFileHandle implements FileHandle {
                return file;\r
        }\r
 \r
-       public InputStream getInputStream () {\r
+       public InputStream readFile () {\r
+               if (type == FileType.Internal) {\r
+                       InputStream input = JoglFileHandle.class.getResourceAsStream("/" + file);\r
+                       if (input != null) return input;\r
+               }\r
                try {\r
                        return new FileInputStream(file);\r
                } catch (FileNotFoundException ex) {\r
-                       throw new GdxRuntimeException("Error reading file: " + file);\r
+                       throw new GdxRuntimeException("Error reading file: " + file, ex);\r
                }\r
        }\r
 \r
@@ -54,7 +61,7 @@ public class JoglFileHandle implements FileHandle {
                return file.toString();\r
        }\r
 \r
-       @Override public String getFileName() {\r
+       @Override public String getPath () {\r
                return file.toString();\r
        }\r
 }\r
index 6f007e3..68fb111 100644 (file)
@@ -47,7 +47,7 @@ final class JoglFiles implements Files {
                if (file.exists() == false)\r
                        throw new GdxRuntimeException("File '" + filename + "' doesn't exist");\r
                else\r
-                       return new JoglFileHandle(file);\r
+                       return new JoglFileHandle(file, type);\r
        }\r
 \r
        /**\r
index 303dcb1..0c2a424 100644 (file)
@@ -205,7 +205,7 @@ public abstract class JoglGraphicsBase implements Graphics, GLEventListener {
 \r
        @Override\r
        public Pixmap newPixmap(FileHandle file) {\r
-               return newPixmap(file.getInputStream());\r
+               return newPixmap(file.readFile());\r
        }\r
 \r
        @Override\r
index a6b5505..a4aca3f 100644 (file)
@@ -18,6 +18,7 @@ import java.io.FileInputStream;
 import java.io.FileNotFoundException;\r
 import java.io.InputStream;\r
 \r
+import com.badlogic.gdx.Files.FileType;\r
 import com.badlogic.gdx.files.FileHandle;\r
 import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
@@ -30,9 +31,11 @@ import com.badlogic.gdx.utils.GdxRuntimeException;
 public class LwjglFileHandle implements FileHandle {\r
        /** the file **/\r
        private final File file;\r
+       private final FileType type;\r
 \r
-       LwjglFileHandle (File file) {\r
+       LwjglFileHandle (File file, FileType type) {\r
                this.file = file;\r
+               this.type = type;\r
        }\r
 \r
        /**\r
@@ -42,7 +45,11 @@ public class LwjglFileHandle implements FileHandle {
                return file;\r
        }\r
 \r
-       public InputStream getInputStream () {\r
+       public InputStream readFile () {\r
+               if (type == FileType.Internal) {\r
+                       InputStream input = LwjglFileHandle.class.getResourceAsStream("/" + file);\r
+                       if (input != null) return input;\r
+               }\r
                try {\r
                        return new FileInputStream(file);\r
                } catch (FileNotFoundException ex) {\r
@@ -54,7 +61,7 @@ public class LwjglFileHandle implements FileHandle {
                return file.toString();\r
        }\r
        \r
-       @Override public String getFileName() {\r
+       @Override public String getPath() {\r
                return file.toString();\r
        }\r
 }\r
index 1f4657a..01c8752 100644 (file)
@@ -47,7 +47,7 @@ final class LwjglFiles implements Files {
                if (file.exists() == false)\r
                        throw new GdxRuntimeException("File '" + filename + "' doesn't exist");\r
                else\r
-                       return new LwjglFileHandle(file);\r
+                       return new LwjglFileHandle(file, type);\r
        }\r
 \r
        public String[] listDirectory (String directory, FileType type) {\r
index 4d5f025..8e3ce1d 100644 (file)
@@ -121,7 +121,7 @@ public final class LwjglGraphics implements Graphics{
        }\r
 \r
        public Pixmap newPixmap (FileHandle file) {\r
-               return newPixmap(file.getInputStream());\r
+               return newPixmap(file.readFile());\r
        }\r
 \r
        public Pixmap newPixmap (Object nativePixmap) {\r
index 0e5563f..0bb9206 100644 (file)
@@ -33,7 +33,7 @@ import com.badlogic.gdx.utils.GdxRuntimeException;
 public interface Files {\r
        /**\r
         * Enum describing the three file types, internal, external and absolute. Internal files are located in the asset directory on\r
-        * Android and are relative to the applications root directory on the desktop. External files are relative to the SD-card on\r
+        * Android and are relative to the root of the classpath or application's root directory on the desktop. External files are relative to the SD-card on\r
         * Android and relative to the home directory of the current user on the Desktop. Absolute files are just that, absolute files\r
         * that can point anywhere.\r
         * @author mzechner\r
index 9275ec3..90e2e0d 100644 (file)
@@ -16,6 +16,7 @@ package com.badlogic.gdx.files;
 import java.io.InputStream;\r
 \r
 import com.badlogic.gdx.Files;\r
+import com.badlogic.gdx.Files.FileType;\r
 \r
 /**\r
  * A file handle represents a system dependant representation of an internal or external file. FileHandles can only be created via\r
@@ -28,10 +29,10 @@ public interface FileHandle {
        /**\r
         * @return a new {@link InputStream} to the underlying file.\r
         */\r
-       public InputStream getInputStream ();\r
+       public InputStream readFile ();\r
        \r
        /**\r
-        * @return the file name.\r
+        * @return the path to the file.\r
         */\r
-       public String getFileName ();\r
+       public String getPath ();\r
 }\r
index 0d94791..a1f48a5 100644 (file)
@@ -82,23 +82,23 @@ public class BitmapFont {
                \r
                this(new FileHandle() {\r
                        @Override\r
-                       public String getFileName() {\r
+                       public String getPath() {\r
                                return "/com/badlogic/gdx/utils/arial-15.fnt";\r
                        }\r
 \r
                        @Override\r
-                       public InputStream getInputStream() {\r
-                               return BitmapFont.class.getResourceAsStream(getFileName());\r
+                       public InputStream readFile() {\r
+                               return BitmapFont.class.getResourceAsStream(getPath());\r
                        }\r
                }, new FileHandle() {\r
                        @Override\r
-                       public String getFileName() {\r
+                       public String getPath() {\r
                                return "/com/badlogic/gdx/utils/arial-15.png";\r
                        }\r
 \r
                        @Override\r
-                       public InputStream getInputStream() {\r
-                               return BitmapFont.class.getResourceAsStream(getFileName());\r
+                       public InputStream readFile() {\r
+                               return BitmapFont.class.getResourceAsStream(getPath());\r
                        }\r
                }, false);\r
        }\r
@@ -124,7 +124,7 @@ public class BitmapFont {
                float invTexHeight = 1.0f / texture.getHeight();\r
 \r
                BufferedReader reader = new BufferedReader(new InputStreamReader(\r
-                               fontFile.getInputStream()), 512);\r
+                               fontFile.readFile()), 512);\r
                try {\r
                        reader.readLine(); // info\r
 \r
index 44b3ebb..ce6436a 100644 (file)
@@ -95,7 +95,7 @@ public class ParticleEffect {
        }\r
 \r
        void loadEmitters (FileHandle file) {\r
-               InputStream input = file.getInputStream();\r
+               InputStream input = file.readFile();\r
                if (input == null) throw new GdxRuntimeException("Effect file not found: " + file);\r
                emitters.clear();\r
                BufferedReader reader = null;\r