⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tmwservermapwriter.java

📁 tiled地图编辑器是2d的,很不错的国外软件,使用起来很方便的
💻 JAVA
字号:
/* *  The Mana World Plugin for Tiled, (c) 2004-2006 * *  This program is free software; you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation; either version 2 of the License, or *  (at your option) any later version. * *  Adam Turk <aturk@biggeruniverse.com> *  Bjorn Lindeijer <b.lindeijer@xs4all.nl> */package tiled.plugins.tmw;import java.io.*;import tiled.io.MapWriter;import tiled.io.PluginLogger;import tiled.core.*;/** * An exporter for TMW server map files, used to determine where a character * can walk. The format is very simple: * * <pre> *  short (width) *  short (height) *  char[] (data) * </pre> * * @version $Id: TMWServerMapWriter.java 683 2006-06-25 14:17:37Z bjorn $ */public class TMWServerMapWriter implements MapWriter{    private static final int FIRST_BYTE = 0x000000FF;    private PluginLogger logger;    /**     * Loads a map from a file.     *     * @param filename the filename of the map file     */    public void writeMap(Map map, String filename) throws Exception {        writeMap(map, new FileOutputStream(filename));    }    /**     * Loads a tileset from a file.     *     * @param filename the filename of the tileset file     */    public void writeTileset(TileSet set, String filename) throws Exception {        logger.error("Tilesets are not supported!");        logger.error("(asked to write " + filename + ")");    }    public void writeMap(Map map, OutputStream out) throws Exception {        ByteArrayOutputStream baos = new ByteArrayOutputStream();        MapLayer layer = map.getLayer(3);        if (layer != null && layer instanceof TileLayer) {            int width = layer.getWidth();            int height = layer.getHeight();            // Write width and height            out.write(width       & FIRST_BYTE);            out.write(width >> 8  & FIRST_BYTE);            out.write(height      & FIRST_BYTE);            out.write(height >> 8 & FIRST_BYTE);            for (int y = 0; y < height; y++) {                for (int x= 0; x < width; x++) {                    Tile tile = ((TileLayer) layer).getTileAt(x, y);                    if (tile != null && tile.getId() > 0) {                        out.write(1);                    } else {                        out.write(0);                    }                }            }            baos.writeTo(out);        } else {            throw new Exception("No collision layer 4 found!");        }    }    public void writeTileset(TileSet set, OutputStream out) throws Exception {        System.out.println("Tilesets are not supported!");    }    /**     * @see tiled.io.PluggableMapIO#getFilter()     */    public String getFilter() throws Exception {        return "*.wlk";    }    public String getDescription() {        return            "+---------------------------------------------+\n" +            "|    An exporter for The Mana World server    |\n" +            "|                  map files.                 |\n" +            "|          (c) 2005 Bjorn Lindeijer           |\n" +            "|              bjorn@lindeijer.nl             |\n" +            "+---------------------------------------------+";    }    public String getPluginPackage() {        return "The Mana World export plugin";    }    public String getName() {        return "The Mana World exporter";    }    public boolean accept(File pathname) {        try {            String path = pathname.getCanonicalPath().toLowerCase();            if (path.endsWith(".wlk")) {                return true;            }        } catch (IOException e) {}        return false;    }    public void setLogger(PluginLogger logger) {        this.logger = logger;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -