Gridarta Editor
TestMapArchObjectParser.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2015 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.model.io;
21 
22 import java.io.BufferedReader;
23 import java.io.IOException;
24 import java.util.Formatter;
28 import org.jetbrains.annotations.NotNull;
29 import org.jetbrains.annotations.Nullable;
30 
35 public class TestMapArchObjectParser extends AbstractMapArchObjectParser<TestMapArchObject> {
36 
37  @Override
38  protected boolean parseLine(@NotNull final String line, @NotNull final TestMapArchObject mapArchObject, @NotNull final BufferedReader reader) {
39  return false;
40  }
41 
42  @Override
43  public void save(@NotNull final Appendable appendable, @NotNull final TestMapArchObject mapArchObject, @Nullable final MapFile mapFile) throws IOException {
44  final Formatter format = new Formatter(appendable);
45  appendable.append("arch map\n");
46  if (!mapArchObject.getMapName().isEmpty()) {
47  format.format("name %s\n", mapArchObject.getMapName());
48  }
49  if (mapArchObject.getSwapTime() != 0) {
50  format.format("swap_time %d\n", mapArchObject.getSwapTime());
51  }
52  if (mapArchObject.getResetTimeout() != 0) {
53  format.format("reset_timeout %d\n", mapArchObject.getResetTimeout());
54  }
55  if (mapArchObject.isFixedReset()) {
56  appendable.append("fixed_resettime 1\n");
57  }
58  if (mapArchObject.getDifficulty() != 0) {
59  format.format("difficulty %d\n", mapArchObject.getDifficulty());
60  }
61  if (mapArchObject.getDarkness() != 0) {
62  format.format("darkness %d\n", mapArchObject.getDarkness());
63  }
64  format.format("width %d\n", mapArchObject.getMapSize().getWidth());
65  format.format("height %d\n", mapArchObject.getMapSize().getHeight());
66  if (mapArchObject.getEnterX() != 0) {
67  format.format("enter_x %d\n", mapArchObject.getEnterX());
68  }
69  if (mapArchObject.getEnterY() != 0) {
70  format.format("enter_y %d\n", mapArchObject.getEnterY());
71  }
72  if (!mapArchObject.getText().trim().isEmpty()) {
73  format.format("msg\n" + "%s\n" + "endmsg\n", mapArchObject.getText().trim());
74  }
75  if (mapArchObject.isOutdoor()) {
76  appendable.append("outdoor 1\n");
77  }
78  for (final Direction direction : Direction.values()) {
79  if (!mapArchObject.getTilePath(direction).isEmpty()) {
80  format.format("tile_path_%d %s\n", direction.ordinal() + 1, mapArchObject.getTilePath(direction));
81  }
82  }
83  appendable.append("end\n");
84  }
85 
86 }
Abstract base class for classes implementing MapArchObjectParsers.
boolean parseLine(@NotNull final String line, @NotNull final TestMapArchObject mapArchObject, @NotNull final BufferedReader reader)
A MapArchObject implementation for testing purposes.
Base package of all Gridarta classes.
A MapArchObjectParser for regression tests.
void save(@NotNull final Appendable appendable, @NotNull final TestMapArchObject mapArchObject, @Nullable final MapFile mapFile)
The location of a map file with a map directory.
Definition: MapFile.java:31