Package com.badlogic.gdx.files

Examples of com.badlogic.gdx.files.FileHandle


    // Set the directory variables to a default when they weren't given in the variables
    if (imageDir == null) imageDir = atlasParentPath;
    if (outputDir == null) outputDir = (new File(atlasParentPath, DEFAULT_OUTPUT_PATH)).getAbsolutePath();

    // Opens the atlas file from the specified filename
    TextureAtlasData atlas = new TextureAtlasData(new FileHandle(atlasFile), new FileHandle(imageDir), false);
    unpacker.splitAtlas(atlas, outputDir);
  }
View Full Code Here


    private void loadImage (ParticleEmitter emitter) {
      final String imagePath = emitter.getImagePath();
      String imageName = new File(imagePath.replace('\\', '/')).getName();
      try {
        FileHandle file;
        if (imagePath.equals(ParticleEditor.DEFAULT_PARTICLE) || imagePath.equals(ParticleEditor.DEFAULT_PREMULT_PARTICLE))
          file = Gdx.files.classpath(imagePath);
        else
          file = Gdx.files.absolute(imagePath);
        emitter.setSprite(new Sprite(new Texture(file)));
View Full Code Here

      if (properties != null) {
        for (Element property : properties.getChildrenByName("property")) {
          String name = property.getAttribute("name");
          String value = property.getAttribute("value");
          if (name.startsWith("atlas")) {
            FileHandle atlasHandle = getRelativeFileHandle(tmxFile, value);
            dependencies.add(new AssetDescriptor(atlasHandle, TextureAtlas.class));
          }
        }
      }
    } catch (IOException e) {
View Full Code Here

        yUp = parameter.yUp;
      } else {
        yUp = true;
      }

      FileHandle tmxFile = resolve(fileName);
      root = xml.parse(tmxFile);
      ObjectMap<String, TextureAtlas> atlases = new ObjectMap<String, TextureAtlas>();
      FileHandle atlasFile = loadAtlas(root, tmxFile);
      if (atlasFile == null) {
        throw new GdxRuntimeException("Couldn't load atlas");
      }

      TextureAtlas atlas = new TextureAtlas(atlasFile);
      atlases.put(atlasFile.path(), atlas);

      AtlasResolver.DirectAtlasResolver atlasResolver = new AtlasResolver.DirectAtlasResolver(atlases);
      TiledMap map = loadMap(root, tmxFile, atlasResolver, parameter);
      map.setOwnedResources(atlases.values().toArray());
      setTextureFilters(parameter.textureMinFilter, parameter.textureMagFilter);
View Full Code Here

      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);
      }

      if (!map.getProperties().containsKey("atlas")) {
        throw new GdxRuntimeException("The map is missing the 'atlas' property");
      }

      // get the TextureAtlas for this tileset
      FileHandle atlasHandle = getRelativeFileHandle(tmxFile, map.getProperties().get("atlas", String.class));
      atlasHandle = resolve(atlasHandle.path());
      TextureAtlas atlas = resolver.getAtlas(atlasHandle.path());
      String regionsName = atlasHandle.nameWithoutExtension();

      if (parameter != null && parameter.forceTextureFilters) {
        for (Texture texture : atlas.getTextures()) {
          trackedTextures.add(texture);
        }
View Full Code Here

    return cell;
  }
 
  public static FileHandle getRelativeFileHandle (FileHandle file, String path) {
    StringTokenizer tokenizer = new StringTokenizer(path, "\\/");
    FileHandle result = file.parent();
    while (tokenizer.hasMoreElements()) {
      String token = tokenizer.nextToken();
      if (token.equals(".."))
        result = result.parent();
      else {
        result = result.child(token);
      }
    }
    return result;
  }
View Full Code Here

   *
   * @param inputDir the input directory containing the tmx files (and tile sets, relative to the path listed in the tmx file)
   * @param outputDir The output directory for the TMX files, <strong>should be empty before running</strong>.
   * @param settings the settings used in the TexturePacker */
  public void processMaps (File inputDir, File outputDir, Settings settings) throws IOException {
    FileHandle inputDirHandle = new FileHandle(inputDir.getAbsolutePath());
    File[] files = inputDir.listFiles(new TmxFilter());
    ObjectMap<String, TiledMapTileSet> tilesetsToPack = new ObjectMap<String, TiledMapTileSet>();

    for (File file : files) {
      map = mapLoader.load(file.getAbsolutePath());

      // if enabled, build a list of used tileids for the tileset used by this map
      if (this.settings.stripUnusedTiles) {
        int mapWidth = map.getProperties().get("width", Integer.class);
        int mapHeight = map.getProperties().get("height", Integer.class);
        int numlayers = map.getLayers().getCount();
        int bucketSize = mapWidth * mapHeight * numlayers;

        Iterator<MapLayer> it = map.getLayers().iterator();
        while (it.hasNext()) {
          MapLayer layer = it.next();

          // some layers can be plain MapLayer instances (ie. object groups), just ignore them
          if (layer instanceof TiledMapTileLayer) {
            TiledMapTileLayer tlayer = (TiledMapTileLayer)layer;

            for (int y = 0; y < mapHeight; ++y) {
              for (int x = 0; x < mapWidth; ++x) {
                if (tlayer.getCell(x, y) != null) {
                  int tileid = tlayer.getCell(x, y).getTile().getId() & ~0xE0000000;
                  String tilesetName = tilesetNameFromTileId(map, tileid);
                  IntArray usedIds = getUsedIdsBucket(tilesetName, bucketSize);
                  usedIds.add(tileid);

                  // track this tileset to be packed if not already tracked
                  if (!tilesetsToPack.containsKey(tilesetName)) {
                    tilesetsToPack.put(tilesetName, map.getTileSets().getTileSet(tilesetName));
                  }
                }
              }
            }
          }
        }
      } else {
        for (TiledMapTileSet tileset : map.getTileSets()) {
          String tilesetName = tileset.getName();
          if (!tilesetsToPack.containsKey(tilesetName)) {
            tilesetsToPack.put(tilesetName, tileset);
          }
        }
      }

      FileHandle tmxFile = new FileHandle(file.getAbsolutePath());
      writeUpdatedTMX(map, outputDir, tmxFile);
    }

    packTilesets(tilesetsToPack, inputDirHandle, outputDir, settings);
  }
View Full Code Here

    public PackerFileHandleResolver () {
    }

    @Override
    public FileHandle resolve (String fileName) {
      return new FileHandle(fileName);
    }
View Full Code Here

  static int filesChanged;
  static class HeaderFileProcessor extends FileProcessor {
    final String header;

    public HeaderFileProcessor () {
      header = new FileHandle("assets/licence-header.txt").readString();
      addInputSuffix(".java");
      setFlattenOutput(false);
      setRecursive(true);
    }
View Full Code Here

    }

    @Override
    protected void processFile (Entry inputFile) throws Exception {
      filesScanned++;
      String content = new FileHandle(inputFile.inputFile).readString();
      if (content.trim().startsWith("package")) {
        System.out.println("File '" + inputFile.inputFile + "' header fixed");
        filesChanged++;
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileHandle(inputFile.outputFile).write(false)));

        writer.write(header + "\n\n" + content);
        writer.close();
      }
    }
View Full Code Here

TOP

Related Classes of com.badlogic.gdx.files.FileHandle

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.