Gridarta Editor
AtrinikArchetypeSetCollectable.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.atrinik.model.collectable;
21 
22 import java.io.IOException;
23 import java.io.Writer;
31 import org.jetbrains.annotations.NotNull;
32 
39 public class AtrinikArchetypeSetCollectable 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, MapArchObject, Archetype> 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 (archetype.getMultiShapeID() > 0) {
86  appendable.append("mpart_id ").append(Integer.toString(archetype.getMultiShapeID())).append('\n');
87  }
88  if (archetype.getMultiPartNr() > 0) {
89  appendable.append("mpart_nr ").append(Integer.toString(archetype.getMultiPartNr())).append('\n');
90  }
91 
92  if (archetype.getMsgText() != null) {
93  appendable.append("msg\n").append(archetype.getMsgText()).append("endmsg\n");
94  }
95 
96  if (isHeadPart) {
97  // special: add a string-attribute with the display-category
98  appendable.append("editor_folder ").append(archetype.getEditorFolder()).append('\n');
99  }
100 
101  appendable.append(archetype.getObjectText());
102 
103  if (isHeadPart) {
104  for (final GameObject inv : archetype) {
105  gameObjectParser.save(appendable, inv);
106  }
107  } else {
108  // position of multi relative to head
109  if (archetype.getMultiX() != 0) {
110  appendable.append("x ").append(Integer.toString(archetype.getMultiX())).append('\n');
111  }
112  if (archetype.getMultiY() != 0) {
113  appendable.append("y ").append(Integer.toString(archetype.getMultiY())).append('\n');
114  }
115  }
116 
117  appendable.append("end\n");
118  }
119 
120 }
Reading and writing of maps, handling of paths.
Handles the Atrinik variants of GameObjects and Archetypes.
Interface for classes that read or write GameObject instances.
final GameObjectParser< GameObject, MapArchObject, Archetype > gameObjectParser
The GameObjectParser for writing inventory game objects.
Base package of all Gridarta classes.
Main package of Gridarta4Atrinik, contains all classes specific to the Atrinik version of the Gridart...
Defines common UI constants used in different dialogs and all used icon files.
Abstract base class for Collectables that create the "archetypes" file.
MapArchObject contains the specific meta data about a map that is stored in the map-arch, at the very beginning of the map file.
static void writeArchetype(@NotNull final Appendable appendable, @NotNull final net.sf.gridarta.model.archetype.Archetype< GameObject, MapArchObject, Archetype > archetype, final boolean isHeadPart, @NotNull final GameObjectParser< GameObject, MapArchObject, Archetype > gameObjectParser)
Writes an Archetype.
Implements the collection process that combines individual files into collected files which are read ...
final ArchetypeSet< G, A, R > archetypeSet
The ArchetypeSet being collected.
int collectArchetype(@NotNull final Archetype archetype, @NotNull final Writer out)
Interface that captures similarities between different ArchetypeSet implementations.
A net.sf.gridarta.model.collectable.Collectable that creates the Atrinik specific "archetypes" file...
void save(@NotNull Appendable appendable, @NotNull G gameObject)
Write a game object object to a stream.
AtrinikArchetypeSetCollectable(@NotNull final ArchetypeSet< GameObject, MapArchObject, Archetype > archetypeSet, @NotNull final GameObjectParser< GameObject, MapArchObject, Archetype > gameObjectParser)
Creates a new instance.