0
在基于LibGDX的项目中,编译HTML项目时(使用GWT),您的资产文件夹中隐藏的'.DT_Store'文件将不会部署但仍然会被引用。这会导致:当使用GWT为HTML编译时,LibGDX“.DT_Store”文件未找到错误消息
“.DT_Store文件” 找不到
当你打开页面。
在基于LibGDX的项目中,编译HTML项目时(使用GWT),您的资产文件夹中隐藏的'.DT_Store'文件将不会部署但仍然会被引用。这会导致:当使用GWT为HTML编译时,LibGDX“.DT_Store”文件未找到错误消息
“.DT_Store文件” 找不到
当你打开页面。
您需要过滤掉您不希望包含在您的部署中的文件。
此解决方案可以应用于任何其他您要排除的文件。
在.gwt.xml文件,添加以下标签:
<set-configuration-property name="gdx.assetfilterclass" value="com.my.Package.DefaultAssetFilter" />
<set-configuration-property name="gdx.assetpath" value="../android/assets" />
在你的HTML项目
,添加一个类:
package com.my.Package;
import com.badlogic.gdx.backends.gwt.preloader.AssetFilter;
/*******************************************************************************
* Copyright 2011 See AUTHORS file.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
public class DefaultAssetFilter implements AssetFilter {
private String extension (String file) {
String name = file;
int dotIndex = name.lastIndexOf('.');
if (dotIndex == -1) return "";
return name.substring(dotIndex + 1);
}
@Override
public boolean accept (String file, boolean isDirectory) {
if (isDirectory && file.endsWith(".svn")) return false;
if (isDirectory && file.endsWith(".bundle")) return false;
if (file.endsWith(".DS_Store")) return false;
return true;
}
@Override
public AssetType getType (String file) {
String extension = extension(file).toLowerCase();
if (isImage(extension)) return AssetType.Image;
if (isAudio(extension)) return AssetType.Audio;
if (isText(extension)) return AssetType.Text;
return AssetType.Binary;
}
private boolean isImage (String extension) {
return extension.toLowerCase().equals("jpg") || extension.toLowerCase().equals("jpeg") || extension.toLowerCase().equals("png") || extension.toLowerCase().equals("bmp") || extension.toLowerCase().equals("gif");
}
private boolean isText (String extension) {
return extension.toLowerCase().equals("json") || extension.toLowerCase().equals("xml") || extension.equals("txt") || extension.equals("glsl")
|| extension.equals("fnt") || extension.equals("pack") || extension.equals("obj") || extension.equals("atlas")
|| extension.equals("g3dj");
}
private boolean isAudio (String extension) {
return extension.toLowerCase().equals("mp3") || extension.toLowerCase().equals("ogg") || extension.toLowerCase().equals("wav");
}
@Override
public String getBundleName (String file) {
return "assets";
}
}