20 package net.sf.gridarta.model.collectable;
22 import java.io.BufferedWriter;
24 import java.io.FileOutputStream;
25 import java.io.IOException;
26 import java.io.OutputStreamWriter;
27 import java.io.Writer;
28 import java.util.Collection;
36 import net.
sf.japi.swing.action.ActionBuilder;
37 import net.
sf.japi.swing.action.ActionBuilderFactory;
38 import net.
sf.japi.swing.misc.Progress;
39 import org.jetbrains.annotations.NotNull;
53 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
78 public void collect(@NotNull
final Progress progress, @NotNull
final File collectedDirectory)
throws IOException {
79 final File file =
new File(collectedDirectory, archFile);
80 try (FileOutputStream fos =
new FileOutputStream(file)) {
82 try (Writer out =
new BufferedWriter(osw)) {
95 private void collect(@NotNull
final Progress progress, @NotNull
final Writer writer)
throws IOException {
96 final Collection<R> archetypes = archetypeSet.
getArchetypes();
98 int artifactCount = 0;
100 for (
final R archetype : archetypes) {
101 if (archetype.isArtifact()) {
105 if (archetype.isUndefinedArchetype()) {
109 if (archetype.isTail()) {
120 if (count % 100 == 0) {
121 progress.setValue(count);
126 ACTION_BUILDER.showMessageDialog(progress.getParentComponent(),
"archCollectWarningMissed", archetypeSet.
getArchetypeCount() - count - artifactCount);
128 progress.setValue(archetypes.size());
138 out.append(
"Object ").append(archetype.getArchetypeName()).append(
'\n');
141 out.append(
"x ").append(Integer.toString(archetype.getMultiX())).append(
'\n');
142 out.append(
"y ").append(Integer.toString(archetype.getMultiY())).append(
'\n');
145 out.append(archetype.getObjectText());
157 protected abstract int collectArchetype(@NotNull R archetype, @NotNull Writer out)
throws IOException;
static void collectStartArch(@NotNull final Archetype<?, ?, ?> archetype, @NotNull final Appendable out)
Processes the special archetype ArchetypeParser#START_ARCH_NAME.
Collection< R > getArchetypes()
Returns a read-only collection of all Archetypes.
Reading and writing of maps, handling of paths.
static final String MAP_ENCODING
Encoding to use for maps and other data.
void collect(@NotNull final Progress progress, @NotNull final File collectedDirectory)
Collects information.
static final ActionBuilder ACTION_BUILDER
The ActionBuilder instance.
String START_ARCH_NAME
Name of the system-archetype containing path of starting map.
A Collectable has information that can be collected.
AbstractArchetypeSetCollectable(@NotNull final ArchetypeSet< G, A, R > archetypeSet, @NotNull final String archFile)
Creates a new instance.
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
abstract int collectArchetype(@NotNull R archetype, @NotNull Writer out)
Collects an Archetype: writes its definition into a writer.
int getArchetypeCount()
Returns the number of Archetypes available.
Utility-class for Gridarta's I/O.
Abstract base class for Collectables that create the "archetypes" file.
GameObjects are the objects based on Archetypes found on maps.
void collect(@NotNull final Progress progress, @NotNull final Writer writer)
Collects the archetypes.
final ArchetypeSet< G, A, R > archetypeSet
The ArchetypeSet being collected.
Utility class for ActionBuilder related functions.
Common interface for ArchetypeParsers.
Interface that captures similarities between different ArchetypeSet implementations.
final String archFile
The collected archetype file name.
Interface for MapArchObjects.