Gridarta Editor
SmoothFacesCollectable.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2023 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.collectable;
21 
22 import java.io.BufferedWriter;
23 import java.io.File;
24 import java.io.FileOutputStream;
25 import java.io.IOException;
26 import java.io.OutputStreamWriter;
27 import java.io.Writer;
28 import java.util.Map.Entry;
31 import net.sf.gridarta.utils.IOUtils;
32 import net.sf.japi.swing.misc.Progress;
33 import org.jetbrains.annotations.NotNull;
34 
41 public class SmoothFacesCollectable implements Collectable {
42 
46  @NotNull
47  private final SmoothFaces smoothFaces;
48 
52  @NotNull
53  private final String smoothFile;
54 
60  public SmoothFacesCollectable(@NotNull final SmoothFaces smoothFaces, @NotNull final String smoothFile) {
61  this.smoothFaces = smoothFaces;
62  this.smoothFile = smoothFile;
63  }
64 
65  @Override
66  public void collect(@NotNull final Progress progress, @NotNull final File collectedDirectory) throws IOException {
67  try (FileOutputStream fos = new FileOutputStream(new File(collectedDirectory, smoothFile))) {
68  try (Writer osw = new OutputStreamWriter(fos, IOUtils.MAP_ENCODING)) {
69  try (Writer out = new BufferedWriter(osw)) {
70  out.append("default_smoothed.111 sdefault.001\n");
71  for (final Entry<String, SmoothFace> e : smoothFaces) {
72  final SmoothFace smoothFace = e.getValue();
73  out.append(smoothFace.getFace()).append(' ').append(smoothFace.getValue()).append('\n');
74  }
75  }
76  }
77  }
78  }
79 
80 }
net.sf.gridarta.model.smoothface.SmoothFace
Smoothing information for one face name.
Definition: SmoothFace.java:28
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.model.collectable.Collectable
A Collectable has information that can be collected.
Definition: Collectable.java:33
net.sf
net.sf.gridarta.model.smoothface
Definition: DuplicateSmoothFaceException.java:20
net.sf.gridarta.model.collectable.SmoothFacesCollectable.smoothFaces
final SmoothFaces smoothFaces
The SmoothFaces being collected.
Definition: SmoothFacesCollectable.java:47
net
net.sf.gridarta.model.collectable.SmoothFacesCollectable.smoothFile
final String smoothFile
The smooth file to write to.
Definition: SmoothFacesCollectable.java:53
net.sf.gridarta.model.collectable.SmoothFacesCollectable
A Collectable that creates the Crossfire specific smooth faces file.
Definition: SmoothFacesCollectable.java:41
net.sf.gridarta.model.smoothface.SmoothFace.getValue
String getValue()
Returns the smooth information.
Definition: SmoothFace.java:66
net.sf.gridarta.model.collectable.SmoothFacesCollectable.collect
void collect(@NotNull final Progress progress, @NotNull final File collectedDirectory)
Collects information.
Definition: SmoothFacesCollectable.java:66
net.sf.gridarta.model
net.sf.gridarta.model.smoothface.SmoothFaces
Collection of all smoothing information.
Definition: SmoothFaces.java:37
net.sf.gridarta.utils.IOUtils
Utility-class for Gridarta's I/O.
Definition: IOUtils.java:40
net.sf.gridarta.model.collectable.SmoothFacesCollectable.SmoothFacesCollectable
SmoothFacesCollectable(@NotNull final SmoothFaces smoothFaces, @NotNull final String smoothFile)
Creates a new instance.
Definition: SmoothFacesCollectable.java:60
net.sf.gridarta.model.smoothface.SmoothFace.getFace
String getFace()
Returns the smoothed face.
Definition: SmoothFace.java:57
net.sf.gridarta.utils
Definition: ActionBuilderUtils.java:20
net.sf.gridarta.utils.IOUtils.MAP_ENCODING
static final String MAP_ENCODING
Encoding to use for maps and other data.
Definition: IOUtils.java:52