OSDN Git Service

Add classpath files support for gwt (limited)
authorJustin Shapcott <support@mobidevelop.com>
Wed, 22 May 2013 07:01:45 +0000 (00:01 -0700)
committerJustin Shapcott <support@mobidevelop.com>
Wed, 22 May 2013 07:01:45 +0000 (00:01 -0700)
Classpath files, such as the default bitmap font and the default shaders
for the new 3d api, are now available in gwt. This limited support
requires the classpath files to be specified in the gwt module definition
by setting the multi-valued property 'gdx.files.classpath'. Any file
specified will be copied to the assets folder at compile time.

CHANGES
backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtFileHandle.java
backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtFiles.java
backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/preloader/PreloaderBundleGenerator.java
gdx/src/com/badlogic/gdx.gwt.xml

diff --git a/CHANGES b/CHANGES
index c5cc8b4..eba484a 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,4 +1,5 @@
 [0.9.9]
+- added classpath files support for gwt backend (limited)
 - moved AndroidWallpaperListener to Android Backend
 - added new VertexAttribute Usage flags, bone weight, tangent, binormal. previously encoded as Usage.Generic. Also
   added field "unit" to VertexAttribute, used by texture coordinates and bone weights to specify index/unit.
index b96ead6..900f984 100644 (file)
@@ -39,7 +39,7 @@ public class GwtFileHandle extends FileHandle {
        private final FileType type;
 
        protected GwtFileHandle (Preloader preloader, String fileName, FileType type) {
-               if (type != FileType.Internal) throw new GdxRuntimeException("FileType '" + type + "' Not supported in GWT backend");
+               if (type != FileType.Internal && type != FileType.Classpath) throw new GdxRuntimeException("FileType '" + type + "' Not supported in GWT backend");
                this.preloader = preloader;
                this.file = fileName.replace('\\', '/');
                this.type = type;
index 62bed0e..0d5f154 100644 (file)
@@ -36,7 +36,8 @@ public class GwtFiles implements Files {
 \r
        @Override\r
        public FileHandle classpath (String path) {\r
-               throw new GdxRuntimeException("Not supported in GWT backend");\r
+               return new GwtFileHandle(preloader, path, FileType.Classpath);\r
+//             throw new GdxRuntimeException("Not supported in GWT backend");\r
        }\r
 \r
        @Override\r
index fe7f59e..bf903ef 100644 (file)
 package com.badlogic.gdx.backends.gwt.preloader;
 
 import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
 import java.io.PrintWriter;
 import java.net.URLConnection;
 import java.util.ArrayList;
+import java.util.List;
 
 import com.badlogic.gdx.backends.gwt.preloader.AssetFilter.AssetType;
 import com.badlogic.gdx.utils.GdxRuntimeException;
@@ -80,6 +83,22 @@ public class PreloaderBundleGenerator extends Generator {
                ArrayList<Asset> assets = new ArrayList<Asset>();
                copyDirectory(source, target, assetFilter, assets);
 
+               // Now collect classpath files and copy to assets
+               List<String> classpathFiles = getClasspathFiles(context);
+               for (String classpathFile : classpathFiles) {                   
+                       if (assetFilter.accept(classpathFile, false)) {
+                               try {
+                                       InputStream is = context.getClass().getClassLoader().getResourceAsStream(classpathFile);
+                                       FileWrapper dest = target.child(classpathFile);
+                                       dest.write(is, false);
+                                       assets.add(new Asset(dest, assetFilter.getType(dest.path())));
+                                       is.close();
+                               } catch (IOException e) {
+                                       e.printStackTrace();
+                               }                       
+                       }
+               }               
+               
                StringBuffer buffer = new StringBuffer();
                for (Asset asset : assets) {
                        String path = asset.file.path().replace('\\', '/').replace(assetOutputPath + "assets/", "").replaceFirst("assets", "");
@@ -202,6 +221,19 @@ public class PreloaderBundleGenerator extends Generator {
                }
        }
 
+       private List<String> getClasspathFiles(GeneratorContext context) {
+               List<String> classpathFiles = new ArrayList<String>();
+               try {
+                       ConfigurationProperty prop = context.getPropertyOracle().getConfigurationProperty("gdx.files.classpath");
+                       for (String value : prop.getValues()) {
+                               classpathFiles.add(value);
+                       }
+               } catch (BadPropertyValueException e) {
+                       // Ignore
+               }               
+               return classpathFiles;
+       }
+       
        private String createDummyClass (TreeLogger logger, GeneratorContext context) {
                String packageName = "com.badlogic.gdx.backends.gwt.preloader";
                String className = "PreloaderBundleImpl";
index 04211b5..f530a1d 100644 (file)
                <include name="utils/compression/rangecoder/Encoder.java"/>
 
        </source>
+       
+       <define-configuration-property name="gdx.files.classpath" is-multi-valued="true" />
+       <extend-configuration-property name="gdx.files.classpath" value="com/badlogic/gdx/graphics/g3d/shaders/default.fragment.glsl" />
+       <extend-configuration-property name="gdx.files.classpath" value="com/badlogic/gdx/graphics/g3d/shaders/default.vertex.glsl" />
+       <extend-configuration-property name="gdx.files.classpath" value="com/badlogic/gdx/utils/arial-15.fnt" />
+       <extend-configuration-property name="gdx.files.classpath" value="com/badlogic/gdx/utils/arial-15.png" />
 </module>
\ No newline at end of file