Gridarta Editor
DefaultMapWriter.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.io;
21 
22 import java.awt.Point;
23 import java.io.IOException;
24 import java.io.Writer;
29 import net.sf.gridarta.utils.Size2D;
30 import org.jetbrains.annotations.NotNull;
31 
36 public class DefaultMapWriter<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements MapWriter<G, A, R> {
37 
41  @NotNull
43 
47  @NotNull
49 
57  this.mapArchObjectParserFactory = mapArchObjectParserFactory;
58  this.gameObjectParser = gameObjectParser;
59  }
60 
61  @Override
62  public void encodeMapFile(@NotNull final MapModel<G, A, R> mapModel, @NotNull final Writer writer) throws IOException {
63  final A mapArch = mapModel.getMapArchObject();
64 
65  mapArchObjectParserFactory.newMapArchObjectParser().save(writer, mapArch, mapModel.getMapFile());
66 
67  // first, write all one tile parts
68  final Size2D mapSize = mapArch.getMapSize();
69  final int width = mapSize.getWidth();
70  final int height = mapSize.getHeight();
71  final Point pos = new Point();
72  for (pos.x = 0; pos.x < width; pos.x++) {
73  for (pos.y = 0; pos.y < height; pos.y++) {
74  for (final G gameObject : mapModel.getMapSquare(pos)) {
75  if (gameObject.isHead()) {
76  gameObjectParser.save(writer, gameObject);
77  }
78  }
79  }
80  }
81  }
82 
83 }
net.sf.gridarta.utils.Size2D.getWidth
int getWidth()
Returns the width of the area.
Definition: Size2D.java:96
net.sf.gridarta.model.mapmodel.MapModel
A MapModel reflects the data of a map.
Definition: MapModel.java:75
net.sf.gridarta.model.io.GameObjectParser.save
void save(@NotNull Appendable appendable, @NotNull G gameObject)
Write a game object object to a stream.
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.model.io.DefaultMapWriter.gameObjectParser
final GameObjectParser< G, A, R > gameObjectParser
The GameObjectParser to use.
Definition: DefaultMapWriter.java:48
net.sf.gridarta.model.io.MapArchObjectParser.save
void save(@NotNull Appendable appendable, @NotNull A mapArchObject, @Nullable MapFile mapFile)
Write a map arch object to a stream.
net.sf.gridarta.model.io.DefaultMapWriter.mapArchObjectParserFactory
final MapArchObjectParserFactory< A > mapArchObjectParserFactory
The MapArchObjectParserFactory to use.
Definition: DefaultMapWriter.java:42
net.sf
net.sf.gridarta.model.io.MapArchObjectParserFactory< A >
net.sf.gridarta.model.mapmodel
Definition: AboveFloorInsertionMode.java:20
net.sf.gridarta.model.archetype
Definition: AbstractArchetype.java:20
net.sf.gridarta.model.gameobject.GameObject
Reflects a game object (object on a map).
Definition: GameObject.java:36
net.sf.gridarta.model.io.DefaultMapWriter.DefaultMapWriter
DefaultMapWriter(@NotNull final MapArchObjectParserFactory< A > mapArchObjectParserFactory, @NotNull final GameObjectParser< G, A, R > gameObjectParser)
Creates a new instance.
Definition: DefaultMapWriter.java:56
net.sf.gridarta.model.io.DefaultMapWriter.encodeMapFile
void encodeMapFile(@NotNull final MapModel< G, A, R > mapModel, @NotNull final Writer writer)
Definition: DefaultMapWriter.java:62
net.sf.gridarta.model.gameobject
GameObjects are the objects based on Archetypes found on maps.
Definition: AbstractGameObject.java:20
net.sf.gridarta.model.io.MapArchObjectParserFactory.newMapArchObjectParser
MapArchObjectParser< A > newMapArchObjectParser()
Creates a new MapArchObjectParser instance.
net
net.sf.gridarta.utils.Size2D.getHeight
int getHeight()
Returns the height of the area.
Definition: Size2D.java:104
net.sf.gridarta.model.io.MapWriter
Interface for classes that write map files.
Definition: MapWriter.java:34
net.sf.gridarta.model.maparchobject.MapArchObject
Interface for MapArchObjects.
Definition: MapArchObject.java:40
net.sf.gridarta.model.io.DefaultMapWriter
Default implementation of MapWriter.
Definition: DefaultMapWriter.java:36
net.sf.gridarta.model
net.sf.gridarta.model.archetype.Archetype
Reflects an Archetype.
Definition: Archetype.java:41
net.sf.gridarta.model.maparchobject
Definition: AbstractMapArchObject.java:20
net.sf.gridarta.model.io.GameObjectParser< G, A, R >
net.sf.gridarta.utils.Size2D
The class Size2D represents a 2d rectangular area.
Definition: Size2D.java:30
net.sf.gridarta.utils
Definition: ActionBuilderUtils.java:20