@Override public void testWorker() { FileHandle directory = Gdx.files.external(""); dstFile = ProjectUtils.getNonExistentFile( directory, image.nameWithoutExtension() + "1", image.extension()); controller.action(ExecuteWorker.class, DownloadFile.class, false, this, URL, dstFile); dstFile2 = ProjectUtils.getNonExistentFile( directory, image.nameWithoutExtension() + "2", image.extension()); controller.action(ExecuteWorker.class, DownloadFile.class, false, this, image.read(), dstFile2); }
/** * If the PSH file contains a line starting with {@link PolygonRegionParameters#texturePrefix * params.texturePrefix}, an {@link AssetDescriptor} for the file referenced on that line will be * added to the returned Array. Otherwise a sibling of the given file with the same name and the * first found extension in {@link PolygonRegionParameters#textureExtensions * params.textureExtensions} will be used. If no suitable file is found, the returned Array will * be empty. */ @Override public Array<AssetDescriptor> getDependencies( String fileName, FileHandle file, PolygonRegionParameters params) { if (params == null) params = defaultParameters; String image = null; try { BufferedReader reader = file.reader(params.readerBuffer); for (String line = reader.readLine(); line != null; line = reader.readLine()) if (line.startsWith(params.texturePrefix)) { image = line.substring(params.texturePrefix.length()); break; } reader.close(); } catch (IOException e) { throw new GdxRuntimeException("Error reading " + fileName, e); } if (image == null && params.textureExtensions != null) for (String extension : params.textureExtensions) { FileHandle sibling = file.sibling(file.nameWithoutExtension().concat("." + extension)); if (sibling.exists()) image = sibling.name(); } if (image != null) { Array<AssetDescriptor> deps = new Array<AssetDescriptor>(1); deps.add(new AssetDescriptor<Texture>(file.sibling(image), Texture.class)); return deps; } return null; }
public void load(String loadingPath, boolean internal) { project = null; game = null; scenes.clear(); projectAssets.setLoadingPath(loadingPath, internal); projectAssets.loadGame(this); FileHandle scenesPath = projectAssets.resolve(ProjectAssets.SCENES_PATH); for (FileHandle sceneFile : scenesPath.list()) { projectAssets.loadScene(sceneFile.nameWithoutExtension(), this); } projectAssets.loadProject(this); }
/** * Loads a language from a {@link FileHandle} * * @param file The {@link FileHandle} of the language file to load * @return True on success, otherwise false */ protected static boolean loadFile(FileHandle file) { if (!file.isDirectory() && file.extension().equalsIgnoreCase("lang")) { try { LanguageEntry lang = languages.get(file.name()); if (lang == null) { lang = new LanguageEntry(new Properties()); languages.put(file.nameWithoutExtension(), lang); } lang.addProperties(file); } catch (Exception io) { Gdx.app.error( TAG, "Could not load language file with name " + file.nameWithoutExtension(), io); return false; } } else { Gdx.app.debug(TAG, "Ignored " + file.name() + " while loading language file"); } return true; }
public void pack(File outputDir, String packFileName) { outputDir.mkdirs(); // if (packFileName.indexOf('.') == -1 || packFileName.endsWith(".png") || // packFileName.endsWith(".jpg")) // packFileName += ".atlas"; int dotIndex = packFileName.indexOf('.'); if (dotIndex != -1) packFileName = packFileName.substring(0, dotIndex); for (float scale : settings.scale) { String scaledPackFileName = packFileName; if (scale != 1 || settings.scale.length != 1) { FileHandle file = new FileHandle(scaledPackFileName); String suffix = scale == (int) scale ? Integer.toString((int) scale) : Float.toString(scale); scaledPackFileName = file.nameWithoutExtension(); // + suffix ; //+ "." + file.extension(); } imageProcessor.setScale(scale); for (InputImage inputImage : inputImages) { if (inputImage.file != null) imageProcessor.addImage(inputImage.file); else imageProcessor.addImage(inputImage.image, inputImage.name); } Array<Page> pages = packer.pack(imageProcessor.getImages()); writeImages(outputDir, pages, scaledPackFileName); try { System.out.println("--Start writing pack file."); writePackFile(outputDir, pages, scaledPackFileName); writePlistFile(outputDir, pages, scaledPackFileName); } catch (IOException ex) { throw new RuntimeException("Error writing pack file.", ex); } imageProcessor.clear(); } }
void loadSkeleton(final FileHandle skeletonFile) { if (skeletonFile == null) return; try { // Setup a texture atlas that uses a white image for images not found in the atlas. Pixmap pixmap = new Pixmap(32, 32, Format.RGBA8888); pixmap.setColor(new Color(1, 1, 1, 0.33f)); pixmap.fill(); final AtlasRegion fake = new AtlasRegion(new Texture(pixmap), 0, 0, 32, 32); pixmap.dispose(); String atlasFileName = skeletonFile.nameWithoutExtension(); if (atlasFileName.endsWith(".json")) atlasFileName = new FileHandle(atlasFileName).nameWithoutExtension(); FileHandle atlasFile = skeletonFile.sibling(atlasFileName + ".atlas"); if (!atlasFile.exists()) atlasFile = skeletonFile.sibling(atlasFileName + ".atlas.txt"); TextureAtlasData data = !atlasFile.exists() ? null : new TextureAtlasData(atlasFile, atlasFile.parent(), false); TextureAtlas atlas = new TextureAtlas(data) { public AtlasRegion findRegion(String name) { AtlasRegion region = super.findRegion(name); if (region == null) { // Look for separate image file. FileHandle file = skeletonFile.sibling(name + ".png"); if (file.exists()) { Texture texture = new Texture(file); texture.setFilter(TextureFilter.Linear, TextureFilter.Linear); region = new AtlasRegion(texture, 0, 0, texture.getWidth(), texture.getHeight()); region.name = name; } } return region != null ? region : fake; } }; // Load skeleton data. String extension = skeletonFile.extension(); if (extension.equalsIgnoreCase("json") || extension.equalsIgnoreCase("txt")) { SkeletonJson json = new SkeletonJson(atlas); json.setScale(ui.scaleSlider.getValue()); skeletonData = json.readSkeletonData(skeletonFile); } else { SkeletonBinary binary = new SkeletonBinary(atlas); binary.setScale(ui.scaleSlider.getValue()); skeletonData = binary.readSkeletonData(skeletonFile); if (skeletonData.getBones().size == 0) throw new Exception("No bones in skeleton data."); } } catch (Exception ex) { ex.printStackTrace(); ui.toast("Error loading skeleton: " + skeletonFile.name()); lastModifiedCheck = 5; return; } skeleton = new Skeleton(skeletonData); skeleton.setToSetupPose(); skeleton = new Skeleton(skeleton); // Tests copy constructors. skeleton.updateWorldTransform(); state = new AnimationState(new AnimationStateData(skeletonData)); state.addListener( new AnimationStateAdapter() { public void event(TrackEntry entry, Event event) { ui.toast(event.getData().getName()); } }); this.skeletonFile = skeletonFile; prefs.putString("lastFile", skeletonFile.path()); prefs.flush(); lastModified = skeletonFile.lastModified(); lastModifiedCheck = checkModifiedInterval; // Populate UI. ui.window.getTitleLabel().setText(skeletonFile.name()); { Array<String> items = new Array(); for (Skin skin : skeletonData.getSkins()) items.add(skin.getName()); ui.skinList.setItems(items); } { Array<String> items = new Array(); for (Animation animation : skeletonData.getAnimations()) items.add(animation.getName()); ui.animationList.setItems(items); } ui.trackButtons.getButtons().first().setChecked(true); // Configure skeleton from UI. if (ui.skinList.getSelected() != null) skeleton.setSkin(ui.skinList.getSelected()); setAnimation(); // ui.animationList.clearListeners(); // state.setAnimation(0, "walk", true); }
protected void loadTileset( TiledMap map, Element element, FileHandle tmxFile, AtlasResolver resolver, AtlasTiledMapLoaderParameters parameter) { if (element.getName().equals("tileset")) { String name = element.get("name", null); int firstgid = element.getIntAttribute("firstgid", 1); int tilewidth = element.getIntAttribute("tilewidth", 0); int tileheight = element.getIntAttribute("tileheight", 0); int spacing = element.getIntAttribute("spacing", 0); int margin = element.getIntAttribute("margin", 0); String source = element.getAttribute("source", null); String imageSource = ""; int imageWidth = 0, imageHeight = 0; FileHandle image = null; if (source != null) { FileHandle tsx = getRelativeFileHandle(tmxFile, source); try { element = xml.parse(tsx); name = element.get("name", null); tilewidth = element.getIntAttribute("tilewidth", 0); tileheight = element.getIntAttribute("tileheight", 0); spacing = element.getIntAttribute("spacing", 0); margin = element.getIntAttribute("margin", 0); imageSource = element.getChildByName("image").getAttribute("source"); imageWidth = element.getChildByName("image").getIntAttribute("width", 0); imageHeight = element.getChildByName("image").getIntAttribute("height", 0); } catch (IOException e) { throw new GdxRuntimeException("Error parsing external tileset."); } } else { imageSource = element.getChildByName("image").getAttribute("source"); imageWidth = element.getChildByName("image").getIntAttribute("width", 0); imageHeight = element.getChildByName("image").getIntAttribute("height", 0); } // get the TextureAtlas for this tileset TextureAtlas atlas = null; String regionsName = ""; if (map.getProperties().containsKey("atlas")) { FileHandle atlasHandle = getRelativeFileHandle(tmxFile, map.getProperties().get("atlas", String.class)); atlasHandle = resolve(atlasHandle.path()); atlas = resolver.getAtlas(atlasHandle.path()); regionsName = atlasHandle.nameWithoutExtension(); if (parameter != null && parameter.forceTextureFilters) { for (Texture texture : atlas.getTextures()) { trackedTextures.add(texture); } } } TiledMapTileSet tileset = new TiledMapTileSet(); MapProperties props = tileset.getProperties(); tileset.setName(name); props.put("firstgid", firstgid); props.put("imagesource", imageSource); props.put("imagewidth", imageWidth); props.put("imageheight", imageHeight); props.put("tilewidth", tilewidth); props.put("tileheight", tileheight); props.put("margin", margin); props.put("spacing", spacing); Array<AtlasRegion> regions = atlas.findRegions(regionsName); for (AtlasRegion region : regions) { // handle unused tile ids if (region != null) { StaticTiledMapTile tile = new StaticTiledMapTile(region); if (!yUp) { region.flip(false, true); } int tileid = firstgid + region.index; tile.setId(tileid); tileset.putTile(tileid, tile); } } Array<Element> tileElements = element.getChildrenByName("tile"); for (Element tileElement : tileElements) { int localtid = tileElement.getIntAttribute("id", 0); TiledMapTile tile = tileset.getTile(firstgid + localtid); if (tile != null) { String terrain = tileElement.getAttribute("terrain", null); if (terrain != null) { tile.getProperties().put("terrain", terrain); } String probability = tileElement.getAttribute("probability", null); if (probability != null) { tile.getProperties().put("probability", probability); } Element properties = tileElement.getChildByName("properties"); if (properties != null) { loadProperties(tile.getProperties(), properties); } } } Element properties = element.getChildByName("properties"); if (properties != null) { loadProperties(tileset.getProperties(), properties); } map.getTileSets().addTileSet(tileset); } }
public SkeletonData readSkeletonData(FileHandle file) { if (file == null) throw new IllegalArgumentException("file cannot be null."); float scale = this.scale; SkeletonData skeletonData = new SkeletonData(); skeletonData.name = file.nameWithoutExtension(); DataInput input = new DataInput(file.read(512)); try { boolean nonessential = input.readBoolean(); // Bones. for (int i = 0, n = input.readInt(true); i < n; i++) { String name = input.readString(); BoneData parent = null; int parentIndex = input.readInt(true) - 1; if (parentIndex != -1) parent = skeletonData.bones.get(parentIndex); BoneData boneData = new BoneData(name, parent); boneData.x = input.readFloat() * scale; boneData.y = input.readFloat() * scale; boneData.scaleX = input.readFloat(); boneData.scaleY = input.readFloat(); boneData.rotation = input.readFloat(); boneData.length = input.readFloat() * scale; boneData.inheritScale = input.readBoolean(); boneData.inheritRotation = input.readBoolean(); if (nonessential) Color.rgba8888ToColor(boneData.getColor(), input.readInt()); skeletonData.addBone(boneData); } // Slots. for (int i = 0, n = input.readInt(true); i < n; i++) { String slotName = input.readString(); BoneData boneData = skeletonData.bones.get(input.readInt(true)); SlotData slotData = new SlotData(slotName, boneData); Color.rgba8888ToColor(slotData.getColor(), input.readInt()); slotData.attachmentName = input.readString(); slotData.additiveBlending = input.readBoolean(); skeletonData.addSlot(slotData); } // Default skin. Skin defaultSkin = readSkin(input, "default", nonessential); if (defaultSkin != null) { skeletonData.defaultSkin = defaultSkin; skeletonData.addSkin(defaultSkin); } // Skins. for (int i = 0, n = input.readInt(true); i < n; i++) skeletonData.addSkin(readSkin(input, input.readString(), nonessential)); // Events. for (int i = 0, n = input.readInt(true); i < n; i++) { EventData eventData = new EventData(input.readString()); eventData.intValue = input.readInt(false); eventData.floatValue = input.readFloat(); eventData.stringValue = input.readString(); skeletonData.addEvent(eventData); } // Animations. for (int i = 0, n = input.readInt(true); i < n; i++) readAnimation(input.readString(), input, skeletonData); } catch (IOException ex) { throw new SerializationException("Error reading skeleton file.", ex); } finally { try { input.close(); } catch (IOException ignored) { } } skeletonData.bones.shrink(); skeletonData.slots.shrink(); skeletonData.skins.shrink(); return skeletonData; }
public SkeletonData readSkeletonData(FileHandle file) { if (file == null) throw new IllegalArgumentException("file cannot be null."); SkeletonData skeletonData = new SkeletonData(); skeletonData.setName(file.nameWithoutExtension()); JsonValue root = new JsonReader().parse(file); // Bones. for (JsonValue boneMap = root.getChild("bones"); boneMap != null; boneMap = boneMap.next()) { BoneData parent = null; String parentName = boneMap.getString("parent", null); if (parentName != null) { parent = skeletonData.findBone(parentName); if (parent == null) throw new SerializationException("Parent bone not found: " + parentName); } BoneData boneData = new BoneData(boneMap.getString("name"), parent); boneData.length = boneMap.getFloat("length", 0) * scale; boneData.x = boneMap.getFloat("x", 0) * scale; boneData.y = boneMap.getFloat("y", 0) * scale; boneData.rotation = boneMap.getFloat("rotation", 0); boneData.scaleX = boneMap.getFloat("scaleX", 1); boneData.scaleY = boneMap.getFloat("scaleY", 1); boneData.inheritScale = boneMap.getBoolean("inheritScale", true); boneData.inheritRotation = boneMap.getBoolean("inheritRotation", true); skeletonData.addBone(boneData); } // Slots. for (JsonValue slotMap = root.getChild("slots"); slotMap != null; slotMap = slotMap.next()) { String slotName = slotMap.getString("name"); String boneName = slotMap.getString("bone"); BoneData boneData = skeletonData.findBone(boneName); if (boneData == null) throw new SerializationException("Slot bone not found: " + boneName); SlotData slotData = new SlotData(slotName, boneData); String color = slotMap.getString("color", null); if (color != null) slotData.getColor().set(Color.valueOf(color)); slotData.setAttachmentName(slotMap.getString("attachment", null)); slotData.additiveBlending = slotMap.getBoolean("additive", false); skeletonData.addSlot(slotData); } // Skins. for (JsonValue skinMap = root.getChild("skins"); skinMap != null; skinMap = skinMap.next()) { Skin skin = new Skin(skinMap.name()); for (JsonValue slotEntry = skinMap.child(); slotEntry != null; slotEntry = slotEntry.next()) { int slotIndex = skeletonData.findSlotIndex(slotEntry.name()); for (JsonValue entry = slotEntry.child(); entry != null; entry = entry.next()) { Attachment attachment = readAttachment(skin, entry.name(), entry); if (attachment != null) skin.addAttachment(slotIndex, entry.name(), attachment); } } skeletonData.addSkin(skin); if (skin.name.equals("default")) skeletonData.setDefaultSkin(skin); } // Animations. for (JsonValue animationMap = root.getChild("animations"); animationMap != null; animationMap = animationMap.next()) readAnimation(animationMap.name(), animationMap, skeletonData); skeletonData.bones.shrink(); skeletonData.slots.shrink(); skeletonData.skins.shrink(); skeletonData.animations.shrink(); return skeletonData; }