From: Justin Shapcott Date: Wed, 22 May 2013 07:01:45 +0000 (-0700) Subject: Add classpath files support for gwt (limited) X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=62a8ca93316e2d4656664838ff705e26c0433a34;p=mikumikustudio%2Flibgdx-mikumikustudio.git Add classpath files support for gwt (limited) 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. --- diff --git a/CHANGES b/CHANGES index c5cc8b424..eba484acf 100644 --- 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. diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtFileHandle.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtFileHandle.java index b96ead6d1..900f984a8 100644 --- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtFileHandle.java +++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtFileHandle.java @@ -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; diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtFiles.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtFiles.java index 62bed0e9d..0d5f15461 100644 --- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtFiles.java +++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtFiles.java @@ -36,7 +36,8 @@ public class GwtFiles implements Files { @Override public FileHandle classpath (String path) { - throw new GdxRuntimeException("Not supported in GWT backend"); + return new GwtFileHandle(preloader, path, FileType.Classpath); +// throw new GdxRuntimeException("Not supported in GWT backend"); } @Override diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/preloader/PreloaderBundleGenerator.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/preloader/PreloaderBundleGenerator.java index fe7f59ed3..bf903efb3 100644 --- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/preloader/PreloaderBundleGenerator.java +++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/preloader/PreloaderBundleGenerator.java @@ -17,9 +17,12 @@ 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 assets = new ArrayList(); copyDirectory(source, target, assetFilter, assets); + // Now collect classpath files and copy to assets + List 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 getClasspathFiles(GeneratorContext context) { + List classpathFiles = new ArrayList(); + 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"; diff --git a/gdx/src/com/badlogic/gdx.gwt.xml b/gdx/src/com/badlogic/gdx.gwt.xml index 04211b513..f530a1dab 100644 --- a/gdx/src/com/badlogic/gdx.gwt.xml +++ b/gdx/src/com/badlogic/gdx.gwt.xml @@ -469,4 +469,10 @@ + + + + + + \ No newline at end of file