Skip to content

Instantly share code, notes, and snippets.

@ProZhar
Created November 2, 2017 18:08
Show Gist options
  • Select an option

  • Save ProZhar/7c6cd0daf3535827b441558fb4ee4e63 to your computer and use it in GitHub Desktop.

Select an option

Save ProZhar/7c6cd0daf3535827b441558fb4ee4e63 to your computer and use it in GitHub Desktop.
import com.badlogic.gdx.assets.AssetDescriptor;
import com.badlogic.gdx.assets.AssetLoaderParameters;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.assets.loaders.AsynchronousAssetLoader;
import com.badlogic.gdx.assets.loaders.FileHandleResolver;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ObjectMap;
import com.badlogic.gdx.utils.ObjectMap.Entry;
public class Skin2Loader extends AsynchronousAssetLoader<Skin2, Skin2Loader.Skin2Parameter> {
public Skin2Loader(FileHandleResolver resolver) {
super(resolver);
}
@Override
public Array<AssetDescriptor> getDependencies(String fileName, FileHandle file, Skin2Parameter parameter) {
Array<AssetDescriptor> deps = new Array<>();
if (parameter == null || parameter.textureAtlasPath == null)
deps.add(new AssetDescriptor<>(file.pathWithoutExtension() + ".atlas", TextureAtlas.class));
else if (parameter.textureAtlasPath != null) deps.add(new AssetDescriptor<>(parameter.textureAtlasPath, TextureAtlas.class));
return deps;
}
@Override
public void loadAsync(AssetManager manager, String fileName, FileHandle file, Skin2Parameter parameter) {
}
@Override
public Skin2 loadSync(AssetManager manager, String fileName, FileHandle file, Skin2Parameter parameter) {
String textureAtlasPath = file.pathWithoutExtension() + ".atlas";
ObjectMap<String, Object> resources = null;
if (parameter != null) {
if (parameter.textureAtlasPath != null){
textureAtlasPath = parameter.textureAtlasPath;
}
if (parameter.resources != null){
resources = parameter.resources;
}
}
TextureAtlas atlas = manager.get(textureAtlasPath, TextureAtlas.class);
Skin2 skin2 = new Skin2(atlas);
if (resources != null) {
for (Entry<String, Object> entry : resources.entries()) {
skin2.add(entry.key, entry.value);
}
}
skin2.load(file);
return skin2;
}
static public class Skin2Parameter extends AssetLoaderParameters<Skin2> {
public final String textureAtlasPath;
public final ObjectMap<String, Object> resources;
public Skin2Parameter () {
this(null, null);
}
public Skin2Parameter(ObjectMap<String, Object> resources){
this(null, resources);
}
public Skin2Parameter (String textureAtlasPath) {
this(textureAtlasPath, null);
}
public Skin2Parameter (String textureAtlasPath, ObjectMap<String, Object> resources) {
this.textureAtlasPath = textureAtlasPath;
this.resources = resources;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment