20 package net.sf.gridarta.project;
23 import java.io.FileNotFoundException;
24 import java.io.IOException;
25 import java.net.URISyntaxException;
27 import java.util.Collections;
108 import net.
sf.japi.swing.action.ActionBuilder;
109 import net.
sf.japi.swing.action.ActionBuilderFactory;
110 import nu.xom.Document;
111 import nu.xom.ParsingException;
112 import nu.xom.xinclude.XIncludeException;
113 import org.apache.log4j.Category;
114 import org.apache.log4j.Logger;
115 import org.jetbrains.annotations.NotNull;
116 import org.jetbrains.annotations.Nullable;
117 import org.xml.sax.SAXException;
208 final int doubleFaceOffset = projectFactory.getDoubleFaceOffset();
211 faceObjectProviders =
new FaceObjectProviders(doubleFaceOffset, faceObjects, resourceIcons);
213 final ArchetypeFactory<G, A, R> archetypeFactory = projectFactory.newArchetypeFactory(faceObjectProviders, animationObjects);
214 gameObjectFactory = projectFactory.newGameObjectFactory(faceObjectProviders, animationObjects, archetypeTypeSet);
215 archetypeSet = projectFactory.newArchetypeSet(projectSettings, archetypeFactory);
216 final GameObjectParserFactory<G, A, R> gameObjectParserFactory = projectFactory.newGameObjectParserFactory(gameObjectFactory, archetypeSet, archetypeTypeSet);
218 final AbstractArchetypeParser<G, A, R, ?> archetypeParser = projectFactory.newArchetypeParser(errorView, gameObjectParser, animationObjects, archetypeSet, gameObjectFactory, projectSettings, smoothFaces);
220 resources = projectFactory.newResources(gameObjectParser, archetypeSet, archetypeParser, faceObjects, animationObjects, archFaceProvider, faceObjectProviders, smoothFaces);
221 loadArchetypes(errorView, projectSettings, archetypeSet, archetypeChooserModel, resources, configSource);
224 mapArchObjectFactory = projectFactory.newMapArchObjectFactory(projectSettings);
229 validators = loadValidators(errorView, projectFactory, projectSettings, gameObjectMatchers, archetypeTypeSet, validatorPreferences, mapWriter);
232 final MapControlFactory<G, A, R> mapControlFactory = projectFactory.newMapControlFactory(mapWriter, projectSettings, mapModelFactory);
238 scriptsFile =
new File(projectSettings.getMapsDirectory(), projectFactory.getScriptsDir());
243 pluginModel =
PluginModelLoader.loadPlugins(pluginParameterFactory, pluginModelParser, errorView, scriptsFile);
256 return archetypeTypeSetParser.
loadTypesFromXML(typesErrorViewCollector, document);
257 }
catch (
final IOException ex) {
259 }
catch (
final ParsingException ex) {
261 }
catch (
final SAXException ex) {
263 }
catch (
final URISyntaxException ex) {
265 }
catch (
final XIncludeException ex) {
271 private static <G extends GameObject<G, A, R>, A extends
MapArchObject<A>, R extends
Archetype<G, A, R>>
void loadArchetypes(@NotNull
final ErrorView errorView, @NotNull
final ProjectSettings projectSettings, @NotNull
final ArchetypeSet<G, A, R> archetypeSet, @NotNull
final ArchetypeChooserModel<G, A, R> archetypeChooserModel, @NotNull
final AbstractResources<G, A, R> resources, @NotNull
final ConfigSource configSource) {
272 final long timeStart = System.currentTimeMillis();
273 if (LOG.isInfoEnabled()) {
274 LOG.info(
"Start to load archetypes...");
276 configSource.read(projectSettings, resources, errorView);
277 addArchetypes(archetypeChooserModel, archetypeSet);
278 if (LOG.isInfoEnabled()) {
279 LOG.info(
"Archetype loading took " + (
double) (System.currentTimeMillis() - timeStart) / 1000.0 +
" seconds.");
283 private static <G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends
Archetype<G, A, R>>
void addArchetypes(@NotNull
final ArchetypeChooserModel<G, A, R> archetypeChooserModel, @NotNull
final ArchetypeSet<G, A, R> archetypeSet) {
284 for (
final R archetype : archetypeSet.getArchetypes()) {
285 final CharSequence editorFolder = archetype.getEditorFolder();
288 if (tmp.length == 2) {
289 final String panelName = tmp[0];
290 final String folderName = tmp[1];
291 archetypeChooserModel.addArchetype(panelName, folderName, archetype);
302 url =
IOUtils.
getResource(projectSettings.getConfigurationDirectory(),
"GameObjectMatchers.xml");
303 }
catch (
final IOException ex) {
311 }
catch (
final IOException ex) {
313 }
catch (
final ParsingException ex) {
315 }
catch (
final SAXException ex) {
317 }
catch (
final URISyntaxException ex) {
319 }
catch (
final XIncludeException ex) {
337 public static <G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends
Archetype<G, A, R>>
DelegatingMapValidator<G, A, R> loadValidators(@NotNull
final ErrorView errorView, @NotNull
final ProjectFactory<G, A, R> projectFactory, @NotNull
final ProjectSettings projectSettings, @NotNull
final GameObjectMatchers gameObjectMatchers, @NotNull
final ArchetypeTypeSet archetypeTypeSet, @NotNull
final ValidatorPreferences validatorPreferences, @NotNull
final MapWriter<G, A, R> mapWriter) {
341 loadValidators(validators, validatorFactory, errorView);
345 ArchetypeTypeChecks.addChecks(archetypeTypeSet, attributeRangeChecker, environmentChecker);
346 final GameObjectMatcher shopSquareMatcher = gameObjectMatchers.getMatcher(
"system_shop_square",
"shop_square");
347 if (shopSquareMatcher != null) {
348 final GameObjectMatcher noSpellsMatcher = gameObjectMatchers.getMatcher(
"system_no_spells",
"no_spells");
349 if (noSpellsMatcher != null) {
350 final GameObjectMatcher blockedMatcher = gameObjectMatchers.getMatcher(
"system_blocked",
"blocked");
354 final GameObjectMatcher paidItemMatcher = gameObjectMatchers.getMatcher(
"system_paid_item");
355 if (paidItemMatcher != null) {
369 private static <G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends
Archetype<G, A, R>>
void loadValidators(@NotNull
final DelegatingMapValidator<G, A, R> validators, @NotNull
final ValidatorFactory<G, A, R> validatorFactory, @NotNull
final ErrorView errorView) {
370 final ActionBuilder actionBuilder = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
373 final String spec = actionBuilder.getString(
"validator." +
id);
378 validators.addValidator(validatorFactory.newValidator(spec));
384 if (LOG.isInfoEnabled()) {
385 LOG.info(
"Loaded " +
id +
" map validators.");
390 public static <G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends
Archetype<G, A, R>>
Spells<GameObjectSpell<G, A, R>> loadArchetypeSpells(
final int spellType, @NotNull
final GameObjectFactory<G, A, R> gameObjectFactory, @NotNull
final ArchetypeSet<G, A, R> archetypeSet) {
392 if (spellType != 0) {
394 gameObjectSpells.
sort();
402 if (spellFile == null) {
407 final URL url =
IOUtils.
getResource(projectSettings.getConfigurationDirectory(), spellFile);
411 }
catch (
final IOException ex) {
413 }
catch (
final ParsingException ex) {
415 }
catch (
final SAXException ex) {
417 }
catch (
final URISyntaxException ex) {
419 }
catch (
final XIncludeException ex) {
428 Map<String, TreasureTreeNode> specialTreasureLists;
430 final URL url =
IOUtils.
getResource(projectSettings.getConfigurationDirectory(),
"TreasureLists.xml");
435 }
catch (
final IOException ex) {
437 specialTreasureLists = Collections.emptyMap();
438 }
catch (
final ParsingException ex) {
440 specialTreasureLists = Collections.emptyMap();
441 }
catch (
final SAXException ex) {
443 specialTreasureLists = Collections.emptyMap();
444 }
catch (
final URISyntaxException ex) {
446 specialTreasureLists = Collections.emptyMap();
447 }
catch (
final XIncludeException ex) {
449 specialTreasureLists = Collections.emptyMap();
451 }
catch (
final FileNotFoundException ex) {
453 specialTreasureLists = Collections.emptyMap();
455 return specialTreasureLists;
598 return pluginParameters;
A factory for creating MapModel instances.
A validator that checks for suspicious attribute values.
Default implementation of MapWriter.
static GameObjectMatchers loadGameObjectMatchers(@NotNull final ErrorView errorView, @NotNull final ProjectSettings projectSettings)
static Map< String, TreasureTreeNode > loadSpecialTreasureLists(@NotNull final ErrorView errorView, @NotNull final ProjectSettings projectSettings)
Utility class for parsing ArchetypeAttributes.
Utility class for string manipulation.
final PluginModel< G, A, R > pluginModel
MapModelFactory< G, A, R > getMapModelFactory()
MapReaderFactory< G, A > getMapReaderFactory()
This class contains methods for converting relative map paths to absolute map paths and vice versa...
Convenience class for adding messages to a ErrorView instance using a fixed category name...
A MapManager manages all opened maps.
final MapArchObjectFactory< A > mapArchObjectFactory
Loader for AutojoinLists instances from files.
Manages all opened pickmaps.
Reading and writing of maps, handling of paths.
Interface for classes that match GameObjects.
Spells< GameObjectSpell< G, A, R > > getGameObjectSpells()
This package contains classes related to matching GameObjects, so called GameObjectMatchers.
Factory for Plugin Parameters.
Interface for classes implementing ArchetypeAttribute factories.
Settings that apply to a project.
final TreasureTree treasureTree
final ArchetypeSet< G, A, R > archetypeSet
Manages ArchetypeType instances, list, and bitmask definitions.
Interface for classes that write map files.
This package contains the framework for validating maps.
Utility class for parsing XML files.
A net.sf.gridarta.model.validation.MapValidator to detect shop squares which allow magic or prayers...
void addWarning(@NotNull final ErrorViewCategory category)
Adds a warning message.
final DefaultMapReaderFactory< G, A, R > mapReaderFactory
final MapManager< G, A, R > pickmapManager
A factory for creating MapReader instances.
Gridarta can handle frame information of animations and allow the selection of an animation using a t...
final ArchetypeChooserModel< G, A, R > archetypeChooserModel
Extract spell definitions from an archetype set.
Parser for the GameObjectMatchers.xml file.
Utility class for loading plugins.
final MapModelFactory< G, A, R > mapModelFactory
GameObjectFactory< G, A, R > getGameObjectFactory()
GameObjectParser< G, A, R > getGameObjectParser()
Utility class for parsing ArchetypeType instances.
Factory for creating MapArchObject instances.
static Spells< NumberSpell > loadSpellFile(@Nullable final String spellFile, @NotNull final ErrorView errorView, @NotNull final ProjectSettings projectSettings)
Interface for classes that read or write GameObject instances.
final GameObjectFactory< G, A, R > gameObjectFactory
final FaceObjectProviders faceObjectProviders
GameObjectMatchers getGameObjectMatchers()
ArchetypeTypeSet loadTypesFromXML(@NotNull final ErrorViewCollector errorViewCollector, @NotNull final Document document)
Loads a types.xml file.
Describes a numbered in-game spell.
Class with constants used in Gridarta and derivates.
void addPluginParameter(@NotNull final String name, @Nullable final Object value)
Defines a variable to be passed to plugins.
A factory for creating GameObjectParser instances.
AbstractMapManager< G, A, R > getMapManager()
final Spells< GameObjectSpell< G, A, R > > gameObjectSpells
Factory for creating MapArchObjectParser instances.
Defines possible error categories for ErrorView instances.
An ErrorHandler that adds all reported problems to an ErrorViewCollector instance.
void addFaceObjectProvidersListener(@NotNull final FaceObjectProvidersListener listener)
Adds a FaceObjectProvidersListener to be notified about changes.
Default implementation of MapReaderFactory.
final SmoothFaces smoothFaces
Abstract base class for MapManager implementations.
ArchetypeTypeSet getArchetypeTypeSet()
Interface for classes displaying error messages.
A factory for creating Archetype instances.
A GameObjectValidator that checks for valid environment.
Base package of all Gridarta classes.
ProjectModel(@NotNull final ErrorView errorView, @NotNull final ProjectSettings projectSettings, @NotNull final ProjectFactory< G, A, R > projectFactory, @NotNull final ResourceIcons resourceIcons, @NotNull final ConfigSource configSource)
Common base class for spells and spell lists.
TreasureTree getTreasureTree()
Reflects a game object (object on a map).
PluginParameters newPluginParameters(@NotNull final Object rendererFactory)
Creates a new PluginParameters instance for this project model.
Abstract factory for creating GameObject instances.
static Document readXmlUrl(@NotNull final URL url, @NotNull final String rootElement, @NotNull final String systemId, @NotNull final String resourceName, @Nullable final ErrorHandler errorHandler)
Reads an XML file from an URL.
static ArchetypeTypeSet loadArchetypeTypeSet(@NotNull final ErrorView errorView, @NotNull final ProjectSettings projectSettings)
FaceObjects getFaceObjects()
Utility-class for Gridarta's I/O.
Converter for Plugin instances to or from XML representation.
GAMEOBJECTMATCHERS_FILE_INVALID
final AbstractResources< G, A, R > resources
Possible source locations for configuration files.
Collection of all smoothing information.
final FaceObjects faceObjects
Load spell definitions from an XML file.
Exception thrown if a map validator cannot be created.
final PathManager pathManager
final GameObjectParser< G, A, R > gameObjectParser
Spells< NumberSpell > getNumberSpells()
MapArchObjectFactory< A > getMapArchObjectFactory()
AnimationObjects is a container for AnimationObjects.
Configuration parameters for Validators.
GameObjects are the objects based on Archetypes found on maps.
void sort()
Sort the added spells after loading is finished.
static void load(@NotNull final ErrorViewCollector errorViewCollector, @NotNull final Document document, @NotNull final Spells< NumberSpell > spells)
Load an XML spell definitions file.
AnimationObjects getAnimationObjects()
ProjectSettings getProjectSettings()
Maintains GameObjectMatcher instances.
static URL getResource(@Nullable final File dir, @NotNull final String fileName)
Get the URL of a resource.
InsertionMode< G, A, R > getTopmostInsertionMode()
PluginModel< G, A, R > getPluginModel()
Utility class for loadings the TreasureLists.xml file.
MapManager< G, A, R > getPickmapManager()
final InsertionMode< G, A, R > topmostInsertionMode
Describes a numbered in-game spell.
final ProjectSettings projectSettings
FaceObjects is a container for FaceObjects.
final Spells< NumberSpell > numberSpells
Makes basic Gridarta classes available to scripts.
ArchetypeSet< G, A, R > getArchetypeSet()
Parser for ArchetypeTypeSets ("types.xml" files).
Default implementation of ArchetypeAttributeFactory.
MAP_VALIDATOR_ENTRY_INVALID
A Map Validator that delegates to other MapValidators.
SmoothFaces getSmoothFaces()
A factory for creating Validator instances from string representation.
Stores all defined treasure lists.
Provider for faces of GameObjects and Archetypes.
A net.sf.gridarta.model.validation.MapValidator to detect shop squares that contain paid items...
The face is the appearance of an object.
The view of the archetype chooser.
GameObjectParser< G, A, R > newGameObjectParser()
Creates a new GameObjectParser instance.
Manages a mapping between archetypes to AutojoinLists.
static void readGameObjectMatchers(@NotNull final Document document, @NotNull final GameObjectMatchers gameObjectMatchers, @NotNull final ErrorViewCollector errorViewCollector)
Parses a .xml file defining game object matchers.
final GameObjectMatchers gameObjectMatchers
ArchetypeChooserModel< G, A, R > getArchetypeChooserModel()
Abstract base implementation of AnimationObjects.
final DelegatingMapValidator< G, A, R > validators
Creates ImageIcon instances from resources.
static Map< String, TreasureTreeNode > parseTreasureLists(@NotNull final Document specialTreasureListsDocument)
This method fills the 'specialTreasureLists' hash table with the names of all treasurelists which are...
Creates checks from ArchetypeTypes.
final AbstractMapManager< G, A, R > mapManager
Subclass: Nodes in the CFTreasureListTree.
Abstract base implementation of FaceObjects.
This package contains the checks for validating maps.
Interface that captures similarities between different ArchetypeSet implementations.
Implementation of FaceProvider which reads images from the arch directory.
Default ValidatorPreferences implementations.
Loader for treasure list files.
PathManager getPathManager()
Abstract base implementation of ArchetypeParser.
final AnimationObjects animationObjects
Defines types of GameObjects with corresponding attributes.
AbstractResources< G, A, R > getResources()
String EDITOR_FOLDER_INTERN
The editor folder name for server-internal archetypes.
DelegatingMapValidator< G, A, R > getValidators()
static TreasureTree parseTreasures(@NotNull final ErrorView errorView, @NotNull final Map< String, TreasureTreeNode > specialTreasureLists, @NotNull final ConfigSource configSource, @NotNull final ProjectSettings projectSettings)
Parses a treasure file into a TreasureTree instance.
Interface for MapArchObjects.
static final Category LOG
The Logger for printing log messages.
Factory for creating MapControl instances.
void addValidator(@NotNull final Validator< G, A, R > validator)
Add a Validator that might to be queried.
static final String TYPEDEF_FILE
Name of the file that contains the type definitions.
FaceObjectProviders getFaceObjectProviders()
final ArchetypeTypeSet archetypeTypeSet
static final Pattern PATTERN_SLASH
The pattern that matches a single slash ("/").