Package tiled.core

Examples of tiled.core.TileSet


    return false;
  }

  private void removeUnusedTilesets(final Map map) {
    for (final Iterator< ? > sets = map.getTilesets().iterator(); sets.hasNext();) {
      final TileSet tileset = (TileSet) sets.next();

      if (!isUsedTileset(map, tileset)) {
        sets.remove();
      }
    }
View Full Code Here


   *
   * @param map the map to be broomed
   */
  private void removeUnusedTilesets(final Map map) {
    for (final Iterator< ? > sets = map.getTilesets().iterator(); sets.hasNext();) {
      final TileSet tileset = (TileSet) sets.next();

      if (!isUsedTileset(map, tileset)) {
        sets.remove();
      }
    }
View Full Code Here

        continue;
      }
     
      if (!setByName.containsKey(name)) {
        // The tileset's not yet included. Add it to the map
        TileSet set = new TileSet();
        set.setName(constructTilesetName(name));
        BasicTileCutter cutter = new BasicTileCutter(32, 32, 0, 0);
        set.importTileBitmap(name, cutter);
       
        setByName.put(name, set);
        map.addTileset(set);
      }
    }
View Full Code Here

   * @param tile The tile to be translated
   * @return Translated tile
   */
  Tile translateTile(Tile tile) {
    int id = tile.getId();
    TileSet set = tile.getTileSet();
    TileInfo info = mapping.getTile(set.getTilebmpFile(), id);
    if (info != null) {
      TileSet newSet = setByName.get(info.file);
      tile = newSet.getTile(info.index);
    }
   
    return tile;
  }
View Full Code Here

    }

    private TileSet unmarshalTilesetFile(InputStream in, String filename)
        throws Exception
    {
        TileSet set = null;
        Node tsNode;

        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        try {
            DocumentBuilder builder = factory.newDocumentBuilder();
            //builder.setErrorHandler(new XMLErrorHandler());
            Document tsDoc = builder.parse(in, ".");

            String xmlPathSave = xmlPath;
            if (filename.indexOf(File.separatorChar) >= 0) {
                xmlPath = filename.substring(0,
                        filename.lastIndexOf(File.separatorChar) + 1);
            }

            NodeList tsNodeList = tsDoc.getElementsByTagName("tileset");

            // There can be only one tileset in a .tsx file.
            tsNode = tsNodeList.item(0);
            if (tsNode != null) {
                set = unmarshalTileset(tsNode);
                if (set.getSource() != null) {
                    System.out.println("Recursive external tilesets are not supported.");
                }
                set.setSource(filename);
            }

            xmlPath = xmlPathSave;
        } catch (SAXException e) {
            error = "Failed while loading " + filename + ": " +
View Full Code Here

            String filename = tilesetBaseDir + source;
            //if (checkRoot(source)) {
            //    filename = makeUrl(source);
            //}

            TileSet ext = null;

            try {
                InputStream in = new URL(makeUrl(filename)).openStream();
                ext = unmarshalTilesetFile(in, filename);
                setFirstGidForTileset(ext, firstGid);
            } catch (FileNotFoundException fnf) {
                error = "Could not find external tileset file " + filename;
            }

            if (ext == null) {
                error = "Tileset " + source + " was not loaded correctly!";
            }

            return ext;
        }
        else {
            final int tileWidth = getAttribute(t, "tilewidth", map != null ? map.getTileWidth() : 0);
            final int tileHeight = getAttribute(t, "tileheight", map != null ? map.getTileHeight() : 0);
            final int tileSpacing = getAttribute(t, "spacing", 0);
            final int tileMargin = getAttribute(t, "margin", 0);

            final String name = getAttributeValue(t, "name");

            TileSet set;
            if (settings.reuseCachedTilesets) {
                set = cachedTilesets.get(name);
                if (set != null) {
                    setFirstGidForTileset(set, firstGid);
                    return set;
                }
                set = new TileSet();
                cachedTilesets.put(name, set);
            } else {
                set = new TileSet();
            }

            set.setName(name);
            set.setBaseDir(basedir);
            setFirstGidForTileset(set, firstGid);

            boolean hasTilesetImage = false;
            NodeList children = t.getChildNodes();

            for (int i = 0; i < children.getLength(); i++) {
                Node child = children.item(i);

                if (child.getNodeName().equalsIgnoreCase("image")) {
                    if (hasTilesetImage) {
                        System.out.println("Ignoring illegal image element after tileset image.");
                        continue;
                    }

                    String imgSource = getAttributeValue(child, "source");
                    String transStr = getAttributeValue(child, "trans");

                    if (imgSource != null) {
                        // Not a shared image, but an entire set in one image
                        // file. There should be only one image element in this
                        // case.
                        hasTilesetImage = true;

                        // FIXME: importTileBitmap does not fully support URLs
                        String sourcePath = imgSource;
                        if (! new File(imgSource).isAbsolute()) {
                            sourcePath = tilesetBaseDir + imgSource;
                        }

                        if (transStr != null) {
                            if (transStr.startsWith("#"))
                                transStr = transStr.substring(1);

                            int colorInt = Integer.parseInt(transStr, 16);
                            Color color = new Color(colorInt);
                            set.setTransparentColor(color);
                        }

                        set.importTileBitmap(sourcePath, new BasicTileCutter(
                                tileWidth, tileHeight, tileSpacing, tileMargin));
                    }
                }
                else if (child.getNodeName().equalsIgnoreCase("tile")) {
                    Tile tile = unmarshalTile(set, child, tilesetBaseDir);
                    if (!hasTilesetImage || tile.getId() > set.getMaxTileId()) {
                        set.addTile(tile);
                    } else {
                        Tile myTile = set.getTile(tile.getId());
                        myTile.setProperties(tile.getProperties());
                        //TODO: there is the possibility here of overlaying images,
                        //      which some people may want
                    }
                }
View Full Code Here

        if (tilesets != null) {
            // Add a new tab for each tileset of the map
            for (Iterator it = tilesets.iterator(); it.hasNext();)
            {
                TileSet tileset = (TileSet) it.next();
                if (tileset != null) {
                    addTabForTileset(tileset);
                }
            }
        }
View Full Code Here

    private Vector cells;

    public TileMergeHelper(Map map) {
        myMap = map;
        cells = new Vector();
        myTs = new TileSet();
        myTs.setName("Merged Set");
    }
View Full Code Here

        OutputStream out = chunk.getOutputStream();
        String ver = map.getProperties().getProperty("version");
        if (ver == null || ver.length() < 3) {
            ver = "0.3";                            // default the value
        }
        TileSet set = (TileSet) map.getTilesets().get(0);

        //FIXME
        //out.write(Integer.parseInt(ver.substring(0,ver.indexOf('.')-1)));
        //out.write(Integer.parseInt(ver.substring(ver.indexOf('.')+1)));
        out.write(0);
        out.write(3);
        out.write(1); out.write(0);                 // LSB, reserved
        Util.writeShort(map.getWidth(), out);
        Util.writeShort(map.getHeight(), out);
        out.write(0); out.write(0); out.write(0); out.write(0);     // reserved
        Util.writeShort(map.getTileWidth(), out);
        Util.writeShort(map.getTileHeight(), out);
        Util.writeShort(16, out);                   // tile bitdepth
        Util.writeShort(32, out);                   // blkstr bytewidth
        Util.writeShort(findAllBlocks(map).size(), out);
        Util.writeShort(set.getMaxTileId(), out);

        chunks.add(chunk);
    }
View Full Code Here

     * @return A new TileSet, loaded from the specified file by a plugin
     * @throws Exception
     * @see MapReader#readTileset(String)
     */
    public static TileSet loadTileset(String file) throws Exception {
        TileSet ret = null;
        try {
            MapReader mr;
            if (file.endsWith(".tsx")) {
                // Override, so people can't overtake our format
                mr = new XMLMapTransformer();
            } else {
                mr = (MapReader)pluginLoader.getReaderFor(file);
            }

            if (mr != null) {
              PluginLogger logger = new PluginLogger();
                mr.setLogger(logger);
                ret = mr.readTileset(file);
                ret.setSource(file);
                reportPluginMessages(logger);
            } else {
                throw new Exception("Unsupported tileset format");
            }
        } catch (IOException e) {
View Full Code Here

TOP

Related Classes of tiled.core.TileSet

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.