Gridarta Editor
CrossfireArchetypeSetCollectable.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.var.crossfire.model.collectable;
21 
22 import java.io.IOException;
23 import java.io.Writer;
31 import org.jetbrains.annotations.NotNull;
32 
39 public class CrossfireArchetypeSetCollectable extends AbstractArchetypeSetCollectable<GameObject, MapArchObject, Archetype> {
40 
44  @NotNull
46 
54  super(archetypeSet, IGUIConstants.ARCH_FILE);
55  this.gameObjectParser = gameObjectParser;
56  }
57 
58  @Override
59  protected int collectArchetype(@NotNull final Archetype archetype, @NotNull final Writer out) throws IOException {
60  writeArchetype(out, archetype, true, gameObjectParser);
61 
62  // process the multi-part tails:
63  int result = 1;
64  for (Archetype tail = archetype.getMultiNext(); tail != null; tail = tail.getMultiNext()) {
65  result++;
66 
67  out.append("More\n");
68  writeArchetype(out, tail, false, gameObjectParser);
69  }
70 
71  return result;
72  }
73 
82  private static void writeArchetype(@NotNull final Appendable appendable, @NotNull final net.sf.gridarta.model.archetype.Archetype<GameObject, ?, ?> archetype, final boolean isHeadPart, @NotNull final GameObjectParser<GameObject, MapArchObject, Archetype> gameObjectParser) throws IOException {
83  appendable.append("Object ").append(archetype.getArchetypeName()).append('\n');
84 
85  if (isHeadPart) {
86  // special: add a string-attribute with the display-category
87  appendable.append("editor_folder ").append(archetype.getEditorFolder()).append('\n');
88 
89  // add message text
90  if (archetype.getMsgText() != null) {
91  appendable.append("msg\n").append(archetype.getMsgText()).append("endmsg\n");
92  }
93  }
94 
95  appendable.append(archetype.getObjectText());
96  if (isHeadPart) {
97  for (final GameObject inv : archetype) {
98  gameObjectParser.save(appendable, inv);
99  }
100  } else {
101  // position of multi relative to head
102  if (archetype.getMultiX() != 0) {
103  appendable.append("x ").append(Integer.toString(archetype.getMultiX())).append('\n');
104  }
105  if (archetype.getMultiY() != 0) {
106  appendable.append("y ").append(Integer.toString(archetype.getMultiY())).append('\n');
107  }
108  }
109 
110  appendable.append("end\n");
111  }
112 
113 }
Reading and writing of maps, handling of paths.
MapArchObject contains the specific meta data about a map that is stored in the map-arch, at the very beginning of the map file.
Handles the Crossfire variants of GameObjects and Archetypes.
Interface for classes that read or write GameObject instances.
int collectArchetype(@NotNull final Archetype archetype, @NotNull final Writer out)
Base package of all Gridarta classes.
A net.sf.gridarta.model.collectable.Collectable that creates the Crossfire specific "archetypes" file...
Abstract base class for Collectables that create the "archetypes" file.
Defines common UI constants used in different dialogs and all used icon files.
final GameObjectParser< GameObject, MapArchObject, Archetype > gameObjectParser
The GameObjectParser for writing inventory game objects.
Implements the collection process that combines individual files into collected files which are read ...
final ArchetypeSet< G, A, R > archetypeSet
The ArchetypeSet being collected.
Main package of Gridarta4Crossfire, contains all classes specific to the Crossfire version of the Gri...
CrossfireArchetypeSetCollectable(@NotNull final ArchetypeSet< GameObject, MapArchObject, Archetype > archetypeSet, @NotNull final GameObjectParser< GameObject, MapArchObject, Archetype > gameObjectParser)
Creates a new instance.
Interface that captures similarities between different ArchetypeSet implementations.
static void writeArchetype(@NotNull final Appendable appendable, @NotNull final net.sf.gridarta.model.archetype.Archetype< GameObject, ?, ?> archetype, final boolean isHeadPart, @NotNull final GameObjectParser< GameObject, MapArchObject, Archetype > gameObjectParser)
Writes an Archetype.
void save(@NotNull Appendable appendable, @NotNull G gameObject)
Write a game object object to a stream.