List of usage examples for com.badlogic.gdx.assets AssetDescriptor AssetDescriptor
public AssetDescriptor(FileHandle file, Class<T> assetType)
From source file:com.badlogic.gdx.spriter.demo.SpriterDemoApp.java
private void changeSpriterFile(SpriterDemoFileHandle file) { AssetManager manager = file.manager; AssetDescriptor<SpriterData> desc = new AssetDescriptor<SpriterData>(file, SpriterData.class); try {/*from www .ja v a 2 s. com*/ manager.load(desc); manager.finishLoading(); } catch (GdxRuntimeException ex) { popup("Loading error", ex.getLocalizedMessage()); return; } SpriterData data = manager.get(desc); animators.clear(); for (SpriterEntity entity : data.entities) { // Change toString method for charmaps Array<SpriterCharacterMap> replacements = new Array<SpriterCharacterMap>(); for (SpriterCharacterMap map : entity.characterMaps) { SpriterCharacterMap newMap = new SpriterCharacterMap() { @Override public String toString() { return id + ": " + name; } }; newMap.id = map.id; newMap.name = map.name; newMap.maps = map.maps; replacements.add(newMap); } entity.characterMaps = replacements; SpriterAnimator animator = new SpriterAnimator(entity) { @Override public String toString() { SpriterEntity entity = getEntity(); return entity.id + ": " + entity.name; } }; animator.addAnimationListener(new SpriterAnimationAdapter() { @Override public void onEventTriggered(SpriterAnimator animator, String eventName) { popup("SpriterEvent", eventName); } @Override public void onAnimationFinished(SpriterAnimator animator, SpriterAnimation animation) { if (!animation.looping) animator.play(animation); } }); animators.add(animator); } fileChooser.setSelected(file); entityChooser.setItems(animators); if (animators.size > 0) changeAnimator(animators.first()); }
From source file:com.disc.jammers.boxsprite.Disc.java
public Disc(World world, EventQueue queue, AssetManager manager) { super(queue, manager); this.world = world; assetDesc = new AssetDescriptor(picFileName, Texture.class); }
From source file:com.forerunnergames.peril.client.ui.screens.game.play.modes.classic.playmap.io.loaders.DefaultCountryAtlasMetadataLoader.java
License:Open Source License
@Override public ImmutableSet<CountryAtlasMetadata> load(final PlayMapMetadata playMapMetadata) { Arguments.checkIsNotNull(playMapMetadata, "playMapMetadata"); // @formatter:off final PlayMapGraphicsPathParser absolutePlayMapGraphicsPathParser = new AbsolutePlayMapGraphicsPathParser( playMapMetadata.getMode());/*from w ww .j a v a 2 s.co m*/ final PlayMapGraphicsPathParser relativePlayMapGraphicsPathParser = new RelativePlayMapGraphicsPathParser( playMapMetadata.getMode()); final File externalCountryAtlasesDirectory = new File( absolutePlayMapGraphicsPathParser.parseCountryAtlasesPath(playMapMetadata)); final Set<CountryAtlasMetadata> countryAtlasMetadatas = new HashSet<>(); // @formatter:on try { final File[] childPathFiles = externalCountryAtlasesDirectory.listFiles(); int expectedAtlasIndex = 1; if (childPathFiles == null) { generalCountryAtlasError("Cannot find any country atlases", externalCountryAtlasesDirectory, playMapMetadata, expectedAtlasIndex); } Arrays.sort(childPathFiles); final String relativeCountryAtlasesPath = relativePlayMapGraphicsPathParser .parseCountryAtlasesPath(playMapMetadata); for (final File childPathFile : childPathFiles) { log.trace("Processing potential country atlas file [{}].", childPathFile.getAbsolutePath()); if (childPathFile.isDirectory()) { log.trace( "Ignoring potential country atlas file [{}] for play map [{}] because it is a directory", childPathFile, playMapMetadata); continue; } if (childPathFile.isHidden()) { log.trace("Ignoring potential country atlas file [{}] for play map [{}] because it is hidden.", childPathFile, playMapMetadata); continue; } // Each country atlas pack file, e.g., countries1.atlas, // must be accompanied by a country atlas image file with matching atlas index, e.g., countries1.png. // The following two guard clauses skip valid, matching .png country atlas image files. // Covers the case where countries1.png is found BEFORE countries1.atlas, for example, // so expectedAtlasIndex is still 1. if (AssetSettings.isValidCountryAtlasImageFileName(childPathFile.getName(), expectedAtlasIndex)) { log.trace( "Ignoring potential country atlas file [{}] for play map [{}] because although it's a valid country " + "atlas *image* file, we're looking for the country atlas *pack* file for atlas index [{}].", childPathFile, playMapMetadata, expectedAtlasIndex); continue; } // Covers the case where countries1.png is found AFTER countries1.atlas, for example, // so expectedAtlasIndex is already incremented to 2. // In the first iteration, this will result in checking for countries0.png, // but in that corner case it will always return false, so it's not a problem. if (AssetSettings.isValidCountryAtlasImageFileName(childPathFile.getName(), expectedAtlasIndex - 1)) { log.trace( "Ignoring child path file [{}] for play map [{}] because although it's a valid country atlas " + "*image* file, we're looking for the country atlas *pack* file for atlas index [{}].", childPathFile, playMapMetadata, expectedAtlasIndex); continue; } final String rawCountryAtlasFileName = childPathFile.getName(); if (!AssetSettings.isAtlasPackFileType(rawCountryAtlasFileName)) { invalidCountryAtlasError("Found invalid file in country atlas directory", rawCountryAtlasFileName, externalCountryAtlasesDirectory, playMapMetadata, expectedAtlasIndex); } if (!AssetSettings.isValidCountryAtlasPackFileName(rawCountryAtlasFileName, expectedAtlasIndex)) { invalidCountryAtlasError("Found invalid country atlas filename", rawCountryAtlasFileName, externalCountryAtlasesDirectory, playMapMetadata, expectedAtlasIndex); } final CountryAtlasMetadata countryAtlasMetadata = new DefaultCountryAtlasMetadata( new AssetDescriptor<>(relativeCountryAtlasesPath + rawCountryAtlasFileName, TextureAtlas.class), playMapMetadata); if (!countryAtlasMetadatas.add(countryAtlasMetadata)) { invalidCountryAtlasError("Found duplicate country atlas filename", rawCountryAtlasFileName, externalCountryAtlasesDirectory, playMapMetadata, expectedAtlasIndex); } log.debug("Successfully loaded country atlas metadata [{}].", countryAtlasMetadata); ++expectedAtlasIndex; } if (countryAtlasMetadatas.isEmpty()) { generalCountryAtlasError("Cannot find any country atlases", externalCountryAtlasesDirectory, playMapMetadata, 1); } return ImmutableSet.copyOf(countryAtlasMetadatas); } catch (final SecurityException e) { // @formatter:off throw new PlayMapLoadingException(Strings.format("Could not load country atlases for {} map: \'{}\'", playMapMetadata.getType().name().toLowerCase(), playMapMetadata.getName()), e); // @formatter:on } }
From source file:com.github.fauu.helix.core.GeometrySetLoader.java
License:Open Source License
@Override public Array<AssetDescriptor> getDependencies(String fileName, FileHandle hgsFile, Parameters parameters) { final Array<AssetDescriptor> dependencies = new Array(); try {//from w w w . j av a 2s . c o m root = xml.parse(hgsFile); // FIXME: Not DRY at all final int geometrySetId = root.getIntAttribute("id"); final Array<XmlReader.Element> geometryElements = root.getChildrenByName("geometry"); for (XmlReader.Element geometryElement : geometryElements) { dependencies.add(new AssetDescriptor<Model>( "assets/geometrysets/" + geometrySetId + "/" + geometryElement.getAttribute("id") + ".obj", Model.class)); } return dependencies; } catch (IOException e) { throw new GdxRuntimeException("Couldn't load geometry set '" + fileName + "'", e); } }
From source file:com.github.fauu.helix.editor.World.java
License:Open Source License
private void paintObject(Tile tile) { final Sidebar editorSidebar = editorFrame.getSidebar(); final ObjectWrapper newObjectWrapper = editorSidebar.getObjectPicker().getSelectedObject(); final int selectedElevation = (Integer) editorSidebar.getElevationPicker().getValue(); final Direction selectedFacing = ((FacingWrapper) editorSidebar.getFacingPicker().getSelectedItem()) .getFacing();// w w w.j a v a2s.com final String modelPath = "assets/objects/" + newObjectWrapper.getModelName() + ".g3db"; if (!assets.isLoaded(modelPath)) { assets.load(new AssetDescriptor(modelPath, Model.class)); assets.finishLoading(); } final Model newObjectModel = assets.get(modelPath); final Object newObject = new Object(tile.getPosition(), newObjectWrapper.getModelName(), newObjectModel, selectedElevation, selectedFacing); mapRegion.getObjects().add(newObject); }
From source file:com.kotcrab.vis.plugin.spine.runtime.SkeletonDataLoader.java
License:Open Source License
@Override public Array<AssetDescriptor> getDependencies(String fileName, FileHandle file, SkeletonDataLoaderParameter parameter) { Array<AssetDescriptor> deps = new Array<AssetDescriptor>(); deps.add(new AssetDescriptor(parameter.atlasPath, TextureAtlas.class)); return deps;// w w w. ja va 2 s .c o m }
From source file:com.kotcrab.vis.plugin.spriter.runtime.SpriterSupport.java
License:Apache License
@Override public void resolveDependencies(Array<AssetDescriptor> dependencies, EntityData entityData, Component component) {/*from w ww . j av a 2 s.c o m*/ if (component instanceof AssetReference) { VisAssetDescriptor asset = ((AssetReference) component).asset; if (asset instanceof SpriterAsset) { SpriterAsset spriterAsset = (SpriterAsset) asset; dependencies.add(new AssetDescriptor<SpriterData>(spriterAsset.getPath(), SpriterData.class)); } } }
From source file:com.kotcrab.vis.runtime.scene.SceneLoader.java
License:Apache License
private void loadDependencies(Array<AssetDescriptor> dependencies, Array<EntityData> entities) { for (EntityData entityData : entities) { for (Component component : entityData.components) { if (component instanceof AssetReference) { VisAssetDescriptor asset = ((AssetReference) component).asset; //TODO refactor if (asset instanceof TextureRegionAsset) { dependencies//from ww w.j a va2 s . c o m .add(new AssetDescriptor<TextureAtlas>(data.textureAtlasPath, TextureAtlas.class)); } else if (asset instanceof AtlasRegionAsset) { AtlasRegionAsset regionAsset = (AtlasRegionAsset) asset; dependencies .add(new AssetDescriptor<TextureAtlas>(regionAsset.getPath(), TextureAtlas.class)); } else if (asset instanceof BmpFontAsset) { checkShader(dependencies); bmpFontProvider.load(dependencies, asset); } else if (asset instanceof TtfFontAsset) { if (ttfFontProvider == null) { throw new IllegalStateException( "TTF fonts are not enabled, ensure that gdx-freetype was " + "added to your project and call `manager.enableFreeType(new FreeTypeFontProvider())` " + "before scene loading!"); } ttfFontProvider.load(dependencies, asset); } else if (asset instanceof ParticleAsset) { PathAsset particleAsset = (ParticleAsset) asset; dependencies.add( new AssetDescriptor<ParticleEffect>(particleAsset.getPath(), ParticleEffect.class)); } else if (asset instanceof SoundAsset) { SoundAsset soundAsset = (SoundAsset) asset; dependencies.add(new AssetDescriptor<Sound>(soundAsset.getPath(), Sound.class)); } else if (asset instanceof MusicAsset) { MusicAsset musicAsset = (MusicAsset) asset; dependencies.add(new AssetDescriptor<Music>(musicAsset.getPath(), Music.class)); } } if (component instanceof ProtoShader) { ProtoShader shaderComponent = (ProtoShader) component; ShaderAsset asset = shaderComponent.asset; if (asset != null) { String path = asset.getFragPath().substring(0, asset.getFragPath().length() - 5); dependencies.add(new AssetDescriptor<ShaderProgram>(path, ShaderProgram.class)); } } for (EntitySupport support : supports) support.resolveDependencies(dependencies, entityData, component); } } }
From source file:com.kotcrab.vis.runtime.scene.SceneLoader.java
License:Apache License
private void checkShader(Array<AssetDescriptor> dependencies) { if (distanceFieldShaderLoaded == false) dependencies.add(new AssetDescriptor<ShaderProgram>(Gdx.files.classpath(DISTANCE_FIELD_SHADER), ShaderProgram.class)); distanceFieldShaderLoaded = true;/*w ww. jav a 2 s. c om*/ }
From source file:com.nebula2d.assets.AssetManager.java
License:Open Source License
public static void installAssets(FileHandle assetsFile) throws IOException { XmlReader reader = new XmlReader(); XmlReader.Element root = reader.parse(assetsFile); Array<XmlReader.Element> assets = root.getChildrenByName("asset"); for (XmlReader.Element assetElement : assets) { String path = assetElement.getAttribute("path"); String type = assetElement.getAttribute("assetType"); String sceneName = assetElement.getAttribute("sceneName"); List<AssetDescriptor> assetList = assetMap.getOrDefault(sceneName, new ArrayList<AssetDescriptor>()); if (type.equalsIgnoreCase("SPRITE")) { assetList.add(new AssetDescriptor<Sprite>(path, Sprite.class)); } else if (type.equalsIgnoreCase("MUSIC")) { assetList.add(new AssetDescriptor<MusicTrack>(path, MusicTrack.class)); } else if (type.equalsIgnoreCase("SFX")) { assetList.add(new AssetDescriptor<SoundEffect>(path, SoundEffect.class)); } else if (type.equalsIgnoreCase("SCRIPT")) { assetList.add(new AssetDescriptor<Script>(path, Script.class)); } else if (type.equalsIgnoreCase("TILED_TILE_SHEET")) { assetList.add(new AssetDescriptor<TiledTileSheet>(path, TiledTileSheet.class)); }//from ww w . j a va2s. c om assetMap.put(sceneName, assetList); } }