public abstract class AbstractGameObjectParser<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>> extends java.lang.Object implements GameObjectParser<G,A,R>
GameObjectParsers
. This class contains the common code for reading game
objects. Subclasses can extend the parser (parseLine(String,
GameObject)
. No support for writing is present.Modifier | Constructor and Description |
---|---|
protected |
AbstractGameObjectParser(GameObjectFactory<G,A,R> gameObjectFactory,
ArchetypeSet<G,A,R> archetypeSet)
Create a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
addModifiedFields(G gameObject,
java.util.Map<java.lang.String,java.lang.String> fields)
Adds the modified fields of a
GameObject to a map. |
void |
collectTempList(java.util.List<G> objects)
Browse first through the archetype list and attach map arches to it then
browse through the face list and try to find the pictures.
|
G |
load(java.io.BufferedReader reader,
java.util.Collection<G> objects)
Parse a game object from a stream.
|
G |
load(java.io.BufferedReader reader,
java.lang.String firstLine,
java.util.Collection<G> objects)
Parse a game object from a stream.
|
protected boolean |
parseLine(java.lang.String line,
G gameObject)
Parse one line.
|
void |
save(java.lang.Appendable appendable,
G gameObject)
Write a game object object to a stream.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getModifiedFields
protected AbstractGameObjectParser(@NotNull GameObjectFactory<G,A,R> gameObjectFactory, @NotNull ArchetypeSet<G,A,R> archetypeSet)
gameObjectFactory
- the game object factory for creating new game
object instancesarchetypeSet
- the archetype set for looking up archetypes@Nullable public G load(@NotNull java.io.BufferedReader reader, @Nullable java.util.Collection<G> objects) throws java.io.IOException
load
in interface GameObjectParser<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>
reader
- the stream to readobjects
- if non-null
, add the read game objects to this
collectionnull
if the end of the stream
was reachedjava.io.IOException
- if the stream cannot be read or if a parsing error
occurs@Nullable public G load(@NotNull java.io.BufferedReader reader, @NotNull java.lang.String firstLine, @Nullable java.util.Collection<G> objects) throws java.io.IOException
load
in interface GameObjectParser<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>
reader
- the stream to readfirstLine
- the first line to parse before reading from reader
objects
- if non-null
, add the read game objects to this
collectionnull
if the end of the stream
was reachedjava.io.IOException
- if the stream cannot be read or if a parsing error
occursprotected boolean parseLine(@NotNull java.lang.String line, @NotNull G gameObject)
line
- the line to processgameObject
- the current game objectfalse
is returned,
the default parsing is performedpublic void collectTempList(@NotNull java.util.List<G> objects)
collectTempList
in interface GameObjectParser<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>
objects
- the list of game objects to collectpublic void save(@NotNull java.lang.Appendable appendable, @NotNull G gameObject) throws java.io.IOException
save
in interface GameObjectParser<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>
appendable
- the stream to write togameObject
- the game object to writejava.io.IOException
- if the stream cannot be writtenpublic void addModifiedFields(@NotNull G gameObject, @NotNull java.util.Map<java.lang.String,java.lang.String> fields)
GameObject
to a map.addModifiedFields
in interface GameObjectParser<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>
gameObject
- the game objectfields
- the map to update