Gridarta Editor
TestParser.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.model.artifact;
21 
22 import java.io.BufferedReader;
23 import java.io.File;
24 import java.io.IOException;
25 import java.io.Reader;
26 import java.io.StringReader;
49 import org.jetbrains.annotations.NotNull;
50 
55 public class TestParser {
56 
60  @NotNull
62 
66  @NotNull
68 
72  @NotNull
74 
78  @NotNull
80 
84  @NotNull
86 
90  public TestParser() {
91  this(new TestErrorView());
92  }
93 
98  public TestParser(@NotNull final TestErrorView errorView) {
99  final ResourceIcons resourceIcons = new ResourceIcons();
100  final File file = new File("*string*");
101  errorViewCollector = new ErrorViewCollector(errorView, file);
102  final FaceObjects faceObjects = new TestFaceObjects();
103  faceObjectProviders = new FaceObjectProviders(0, faceObjects, resourceIcons);
104  final TestArchetypeFactory archetypeFactory = new TestArchetypeFactory(faceObjectProviders, animationObjects);
105  final TestGameObjectFactory gameObjectFactory = new TestGameObjectFactory(faceObjectProviders, animationObjects);
106  archetypeSet = new DefaultArchetypeSet<>(archetypeFactory, null);
107  final TestArchetypeBuilder archetypeBuilder = new TestArchetypeBuilder(gameObjectFactory);
108  final AbstractArchetypeParser<TestGameObject, TestMapArchObject, TestArchetype, TestArchetypeBuilder> archetypeParser = new TestArchetypeParser(archetypeBuilder, animationObjects, archetypeSet);
109  artifactParser = new ArtifactParser<>(archetypeSet, errorView, archetypeParser);
110  }
111 
118  public void addArchetype(@NotNull final String archetypeName, @NotNull final String... attributes) throws DuplicateArchetypeException {
119  final TestArchetype baseArchetype = new TestDefaultArchetype(archetypeName, faceObjectProviders, animationObjects);
120  final StringBuilder objectText = new StringBuilder();
121  for (final String attribute : attributes) {
122  objectText.append(attribute);
123  objectText.append('\n');
124  }
125  baseArchetype.setObjectText(objectText.toString());
126  archetypeSet.addArchetype(baseArchetype);
127  }
128 
134  public void parseArtifacts(@NotNull final String artifacts) throws IOException {
135  final Reader reader = new StringReader(artifacts);
136  try (BufferedReader bufferedReader = new BufferedReader(reader)) {
137  artifactParser.loadArtifact(bufferedReader, errorViewCollector, "", "panel", "folder");
138  }
139  }
140 
147  @NotNull
149  return archetypeSet.getArchetype(archetypeName);
150  }
151 
156  public int getArchetypeCount() {
157  return archetypeSet.getArchetypeCount();
158  }
159 
160 }
int getArchetypeCount()
Returns the number of defined archetypes.
A FaceObjects for regression tests.
Convenience class for adding messages to a ErrorView instance using a fixed category name...
void parseArtifacts(@NotNull final String artifacts)
Parses artifacts definitions.
An ArchetypeParser for regression tests.
Reading and writing of maps, handling of paths.
TestParser()
Creates a new instance.
Definition: TestParser.java:90
TestParser(@NotNull final TestErrorView errorView)
Creates a new instance.
Definition: TestParser.java:98
Gridarta can handle frame information of animations and allow the selection of an animation using a t...
final AnimationObjects animationObjects
The AnimationObjects instance.
Definition: TestParser.java:73
An AnimationObjects for regression tests.
A MapArchObject implementation for testing purposes.
Base package of all Gridarta classes.
An Archetype implementation for testing purposes.
int getArchetypeCount()
Returns the number of Archetypes available.
R getArchetype(@NotNull String archetypeName)
Returns an Archetype by its name.
An Exception indicating that an Archetype name is not unique.
void loadArtifact(@NotNull final ErrorViewCollector errorViewCollector, @NotNull final File f, @NotNull final String archPath, @NotNull final String panelName, @NotNull final String folderName)
Loads one artifact.
AnimationObjects is a container for AnimationObjects.
final ArchetypeSet< TestGameObject, TestMapArchObject, TestArchetype > archetypeSet
The ArchetypeSet instance.
Definition: TestParser.java:67
void addArchetype(@NotNull final String archetypeName, @NotNull final String... attributes)
Adds a new archetype.
GameObjects are the objects based on Archetypes found on maps.
Archetype< TestGameObject, TestMapArchObject, TestArchetype > getArchetype(@NotNull final String archetypeName)
Returns an Archetype by name.
FaceObjects is a container for FaceObjects.
void addArchetype(@NotNull R archetype)
Adds an Archetype to this Set.
An ArchetypeFactory implementation for testing purposes.
final FaceObjectProviders faceObjectProviders
The FaceObjectProviders instance.
Definition: TestParser.java:61
Provider for faces of GameObjects and Archetypes.
The face is the appearance of an object.
final ErrorViewCollector errorViewCollector
The ErrorViewCollector instance.
Definition: TestParser.java:79
Parser for artifacts definitions.
Definition: TestParser.java:55
Creates ImageIcon instances from resources.
An Archetype implementation for testing purposes.
A GameObject implementation for testing purposes.
Interface that captures similarities between different ArchetypeSet implementations.
Abstract base implementation of ArchetypeParser.
Parser for artifact definitions.
An ErrorView suitable for unit tests.
final ArtifactParser< TestGameObject, TestMapArchObject, TestArchetype > artifactParser
The ArtifactParser instance.
Definition: TestParser.java:85
An AbstractArchetypeBuilder for regression tests.