001/*
002 * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
003 * Copyright (C) 2000-2010 The Gridarta Developers.
004 *
005 * This program is free software; you can redistribute it and/or modify
006 * it under the terms of the GNU General Public License as published by
007 * the Free Software Foundation; either version 2 of the License, or
008 * (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013 * GNU General Public License for more details.
014 *
015 * You should have received a copy of the GNU General Public License along
016 * with this program; if not, write to the Free Software Foundation, Inc.,
017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
018 */
019
020package net.sf.gridarta.model.io;
021
022import java.io.BufferedReader;
023import java.io.IOException;
024import java.util.Formatter;
025import net.sf.gridarta.model.direction.Direction;
026import net.sf.gridarta.model.maparchobject.TestMapArchObject;
027import org.jetbrains.annotations.NotNull;
028
029/**
030 * A {@link MapArchObjectParser} for regression tests.
031 * @author Andreas Kirschbaum
032 */
033public class TestMapArchObjectParser extends AbstractMapArchObjectParser<TestMapArchObject> {
034
035    /**
036     * {@inheritDoc}
037     */
038    @Override
039    protected boolean parseLine(@NotNull final String line, @NotNull final TestMapArchObject mapArchObject, @NotNull final BufferedReader reader) {
040        return false;
041    }
042
043    /**
044     * {@inheritDoc}
045     */
046    @Override
047    public void save(@NotNull final Appendable appendable, @NotNull final TestMapArchObject mapArchObject) throws IOException {
048        final Formatter format = new Formatter(appendable);
049        appendable.append("arch map\n");
050        if (!mapArchObject.getMapName().isEmpty()) {
051            format.format("name %s\n", mapArchObject.getMapName());
052        }
053        if (mapArchObject.getSwapTime() != 0) {
054            format.format("swap_time %d\n", mapArchObject.getSwapTime());
055        }
056        if (mapArchObject.getResetTimeout() != 0) {
057            format.format("reset_timeout %d\n", mapArchObject.getResetTimeout());
058        }
059        if (mapArchObject.isFixedReset()) {
060            appendable.append("fixed_resettime 1\n");
061        }
062        if (mapArchObject.getDifficulty() != 0) {
063            format.format("difficulty %d\n", mapArchObject.getDifficulty());
064        }
065        if (mapArchObject.getDarkness() != 0) {
066            format.format("darkness %d\n", mapArchObject.getDarkness());
067        }
068        format.format("width %d\n", mapArchObject.getMapSize().getWidth());
069        format.format("height %d\n", mapArchObject.getMapSize().getHeight());
070        if (mapArchObject.getEnterX() != 0) {
071            format.format("enter_x %d\n", mapArchObject.getEnterX());
072        }
073        if (mapArchObject.getEnterY() != 0) {
074            format.format("enter_y %d\n", mapArchObject.getEnterY());
075        }
076        if (!mapArchObject.getText().trim().isEmpty()) {
077            format.format("msg\n" + "%s\n" + "endmsg\n", mapArchObject.getText().trim());
078        }
079        if (mapArchObject.isOutdoor()) {
080            appendable.append("outdoor 1\n");
081        }
082        for (final Direction direction : Direction.values()) {
083            if (!mapArchObject.getTilePath(direction).isEmpty()) {
084                format.format("tile_path_%d %s\n", direction.ordinal() + 1, mapArchObject.getTilePath(direction));
085            }
086        }
087        appendable.append("end\n");
088    }
089
090}