20 package net.sf.gridarta.var.atrinik.model.io;
22 import java.io.BufferedReader;
23 import java.io.IOException;
24 import java.util.Formatter;
25 import java.util.regex.Matcher;
26 import java.util.regex.Pattern;
35 import org.jetbrains.annotations.NotNull;
36 import org.jetbrains.annotations.Nullable;
63 public void load(@NotNull
final BufferedReader reader, @NotNull
final MapArchObject mapArchObject)
throws IOException {
66 super.load(reader, mapArchObject);
71 public void save(@NotNull
final Appendable appendable, @NotNull
final MapArchObject mapArchObject, @Nullable
final MapFile mapFile)
throws IOException {
72 final Formatter format =
new Formatter(appendable);
73 appendable.append(
"arch map\n");
74 if (!mapArchObject.getMapName().isEmpty()) {
75 format.format(
"name %s\n", mapArchObject.getMapName());
77 format.format(
"msg\n%s%sendmsg\n", mapArchObject.getText().trim(),
"\n");
78 format.format(
"width %d\n", mapArchObject.getMapSize().getWidth());
79 format.format(
"height %d\n", mapArchObject.getMapSize().getHeight());
80 if (mapArchObject.getEnterX() != 0) {
81 format.format(
"enter_x %d\n", mapArchObject.getEnterX());
83 if (mapArchObject.getEnterY() != 0) {
84 format.format(
"enter_y %d\n", mapArchObject.getEnterY());
86 if (mapArchObject.getResetTimeout() != 0) {
87 format.format(
"reset_timeout %d\n", mapArchObject.getResetTimeout());
89 if (mapArchObject.getSwapTime() != 0) {
90 format.format(
"swap_time %d\n", mapArchObject.getSwapTime());
92 if (mapArchObject.getDifficulty() != 0) {
93 format.format(
"difficulty %d\n", mapArchObject.getDifficulty());
95 if (mapArchObject.getDarkness() != 0) {
96 format.format(
"darkness %d\n", mapArchObject.getDarkness());
98 if (mapArchObject.isFixedReset()) {
99 appendable.append(
"fixed_resettime 1\n");
101 if (mapArchObject.isOutdoor()) {
102 appendable.append(
"outdoor 1\n");
104 if (mapArchObject.isNoSave()) {
105 appendable.append(
"no_save 1\n");
107 if (mapArchObject.isNoMagic()) {
108 appendable.append(
"no_magic 1\n");
110 if (mapArchObject.isHeightDiff()) {
111 appendable.append(
"height_diff 1\n");
113 if (mapArchObject.isNoSummon()) {
114 appendable.append(
"no_summon 1\n");
116 if (mapArchObject.isNoHarm()) {
117 appendable.append(
"no_harm 1\n");
119 if (mapArchObject.isFixedLogin()) {
120 appendable.append(
"fixed_login 1\n");
122 if (mapArchObject.isUnique()) {
123 appendable.append(
"unique 1\n");
125 if (mapArchObject.isFixedResetTime()) {
126 appendable.append(
"fixed_resettime 1\n");
128 if (mapArchObject.isPlayerNoSave()) {
129 appendable.append(
"player_no_save 1\n");
131 if (mapArchObject.isPvp()) {
132 appendable.append(
"pvp 1\n");
135 if (!mapArchObject.getTilePath(direction).isEmpty() && !mapArchObject.isTilePathAuto(direction, mapFile)) {
136 format.format(
"tile_path_%d %s\n", direction.ordinal() + 1, mapArchObject.getTilePath(direction));
139 if (mapArchObject.getTilesetId() != 0) {
140 format.format(
"tileset_id %d\n", mapArchObject.getTilesetId());
141 format.format(
"tileset_x %d\n", mapArchObject.getTilesetX());
142 format.format(
"tileset_y %d\n", mapArchObject.getTilesetY());
144 final String backgroundMusic = mapArchObject.getBackgroundMusic();
145 if (!backgroundMusic.isEmpty()) {
146 format.format(
"bg_music %s\n", backgroundMusic);
148 final String region = mapArchObject.getRegion();
149 if (!region.isEmpty()) {
150 format.format(
"region %s\n", region);
152 final String weather = mapArchObject.getWeather();
153 if (!weather.isEmpty()) {
154 format.format(
"weather %s\n", weather);
156 appendable.append(
"end\n");
160 protected boolean parseLine(@NotNull
final String line, @NotNull
final String key, @NotNull
final String value, @NotNull
final MapArchObject mapArchObject, @NotNull
final BufferedReader reader)
throws IOException {
161 if (line.equals(
"msg")) {
163 final String msgLine = reader.readLine();
164 if (msgLine ==
null) {
165 throw new IOException(
"unexpected end of file in msg...endmsg field");
170 if (trimmedMsgLine.equals(
"endmsg")) {
174 if (!mapArchObject.getText().isEmpty()) {
175 mapArchObject.addText(
"\n");
177 mapArchObject.addText(trimmedMsgLine);
179 }
else if (line.startsWith(
"tile_path_")) {
187 final int index = Integer.parseInt(m.group(1));
188 if (index > 0 && index <=
Direction.values().length) {
189 mapArchObject.setTilePath(
Direction.values()[index - 1], m.group(2));
193 }
catch (
final NumberFormatException ex) {
196 }
else if (line.equals(
"end")) {
228 case "fixed_resettime":
232 case "player_no_save":
253 mapArchObject.setBackgroundMusic(value);
257 mapArchObject.setRegion(value);
261 mapArchObject.setWeather(value);
265 mapArchObject.setMapName(value);
284 case "reset_timeout":