Gridarta Editor
Loader.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.gui.mapfiles;
21 
22 import java.io.File;
23 import java.util.Arrays;
33 import org.jetbrains.annotations.NotNull;
34 import org.jetbrains.annotations.Nullable;
35 
40 public class Loader<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> {
41 
45  @NotNull
46  private final ErrorView errorView;
47 
51  @NotNull
53 
57  @NotNull
59 
63  @NotNull
65 
69  @NotNull
71 
81  this.errorView = errorView;
82  this.mapFolderTree = mapFolderTree;
83  this.mapReaderFactory = mapReaderFactory;
84  this.pickmapManager = pickmapManager;
85  this.mapViewsManager = mapViewsManager;
86  }
87 
91  public void load() {
92  final MapFolder<G, A, R> mapFolder = load(null, "");
93  if (mapFolder != null) {
95  }
96  }
97 
105  @Nullable
106  private MapFolder<G, A, R> load(@Nullable final MapFolder<G, A, R> parent, @NotNull final String folderName) {
107  final File baseDir = mapFolderTree.getBaseDir();
108  final File dir = parent == null ? baseDir : new File(parent.getDir(), folderName);
109  final ErrorViewCollector errorViewCollector = new ErrorViewCollector(errorView, dir);
110  final File[] files = dir.listFiles();
111  if (files == null) {
113  return null;
114  }
115 
116  final MapFolder<G, A, R> mapFolder;
117  try {
118  mapFolder = new MapFolder<>(parent, folderName, baseDir, mapViewsManager);
119  } catch (final InvalidNameException ex) {
120  errorViewCollector.addWarning(ErrorViewCategory.PICKMAPS_DIR_INVALID, "ignoring pickmap folder with invalid name: " + ex.getMessage());
121  return null;
122  }
123  try {
124  mapFolderTree.addMapFolder(mapFolder);
125  } catch (final DuplicateMapFolderException ex) {
126  errorViewCollector.addWarning(ErrorViewCategory.PICKMAPS_DIR_INVALID, "cannot add folder: " + ex.getMessage());
127  return null;
128  }
129 
130  Arrays.sort(files);
131  MapFolder<G, A, R> result = null;
132  for (final File file : files) {
133  if (file.isFile()) {
134  try {
135  mapFolder.addPickmap(file.getName(), mapReaderFactory, pickmapManager);
136  } catch (final InvalidNameException ex) {
137  errorViewCollector.addWarning(ErrorViewCategory.PICKMAPS_FILE_INVALID, "ignoring pickmap with invalid name: " + ex.getMessage());
138  }
139  } else if (file.isDirectory()) {
140  if (!file.getName().startsWith(".")) {
141  final MapFolder<G, A, R> tmp = load(mapFolder, file.getName());
142  if (result == null && tmp != null && tmp.getPickmaps() > 0) {
143  result = tmp;
144  }
145  }
146  }
147  }
148 
149  return mapFolder.getPickmaps() > 0 ? mapFolder : result;
150  }
151 
152 }
net.sf.gridarta.model.mapmanager
Definition: AbstractMapManager.java:20
net.sf.gridarta.model.errorview.ErrorViewCollector.addWarning
void addWarning(@NotNull final ErrorViewCategory category)
Definition: ErrorViewCollector.java:68
net.sf.gridarta.model.mapmanager.MapManager
Definition: MapManager.java:37
net.sf.gridarta.gui.mapfiles.Loader
Definition: Loader.java:40
net.sf.gridarta
net.sf.gridarta.gui.mapfiles.Loader.Loader
Loader(@NotNull final ErrorView errorView, @NotNull final MapFolderTree< G, A, R > mapFolderTree, @NotNull final MapReaderFactory< G, A > mapReaderFactory, @NotNull final MapManager< G, A, R > pickmapManager, @NotNull final MapViewsManager< G, A, R > mapViewsManager)
Definition: Loader.java:80
net.sf.gridarta.model.io.MapReaderFactory
Definition: MapReaderFactory.java:32
net.sf.gridarta.gui.mapfiles.MapFolderTree< G, A, R >
net.sf
net.sf.gridarta.model.errorview.ErrorView
Definition: ErrorView.java:28
net.sf.gridarta.model.archetype
Definition: AbstractArchetype.java:20
net.sf.gridarta.gui.mapfiles.MapFolderTree.addMapFolder
synchronized void addMapFolder(@NotNull final MapFolder< G, A, R > mapFolder)
Definition: MapFolderTree.java:90
net.sf.gridarta.model.gameobject.GameObject
Definition: GameObject.java:36
net.sf.gridarta.gui.mapfiles.Loader.mapViewsManager
final MapViewsManager< G, A, R > mapViewsManager
Definition: Loader.java:70
net.sf.gridarta.gui.mapfiles.Loader.mapReaderFactory
final MapReaderFactory< G, A > mapReaderFactory
Definition: Loader.java:58
net.sf.gridarta.gui
net.sf.gridarta.gui.mapfiles.Loader.load
MapFolder< G, A, R > load(@Nullable final MapFolder< G, A, R > parent, @NotNull final String folderName)
Definition: Loader.java:106
net.sf.gridarta.model.gameobject
Definition: AbstractGameObject.java:20
net
net.sf.gridarta.model.errorview
Definition: ErrorView.java:20
net.sf.gridarta.gui.mapfiles.Loader.pickmapManager
final MapManager< G, A, R > pickmapManager
Definition: Loader.java:64
net.sf.gridarta.model.errorview.ErrorViewCollector
Definition: ErrorViewCollector.java:31
net.sf.gridarta.gui.mapfiles.MapFolder.getName
String getName()
Definition: MapFolder.java:130
net.sf.gridarta.gui.mapfiles.InvalidNameException
Definition: InvalidNameException.java:28
net.sf.gridarta.model.errorview.ErrorViewCategory
Definition: ErrorViewCategory.java:28
net.sf.gridarta.model.maparchobject.MapArchObject
Definition: MapArchObject.java:40
net.sf.gridarta.gui.map.mapview
Definition: AbstractMapView.java:20
net.sf.gridarta.gui.mapfiles.MapFolder< G, A, R >
net.sf.gridarta.gui.mapfiles.MapFolder.addPickmap
PickmapState< G, A, R > addPickmap(@NotNull final String name, @NotNull final MapReaderFactory< G, A > mapReaderFactory, @NotNull final MapManager< G, A, R > pickmapManager)
Definition: MapFolder.java:155
net.sf.gridarta.gui.mapfiles.Loader.mapFolderTree
final MapFolderTree< G, A, R > mapFolderTree
Definition: Loader.java:52
net.sf.gridarta.model.io
Definition: AbstractArchetypeParser.java:20
net.sf.gridarta.gui.mapfiles.DuplicateMapFolderException
Definition: DuplicateMapFolderException.java:28
net.sf.gridarta.model.errorview.ErrorViewCategory.PICKMAPS_DIR_INVALID
PICKMAPS_DIR_INVALID
Definition: ErrorViewCategory.java:74
net.sf.gridarta.model
net.sf.gridarta.model.archetype.Archetype
Definition: Archetype.java:41
net.sf.gridarta.model.errorview.ErrorViewCategory.PICKMAPS_FILE_INVALID
PICKMAPS_FILE_INVALID
Definition: ErrorViewCategory.java:76
net.sf.gridarta.gui.map
Definition: AbstractPerMapDialogManager.java:20
net.sf.gridarta.gui.mapfiles.Loader.errorView
final ErrorView errorView
Definition: Loader.java:46
net.sf.gridarta.gui.mapfiles.MapFolderTree.getBaseDir
File getBaseDir()
Definition: MapFolderTree.java:79
net.sf.gridarta.gui.mapfiles.Loader.load
void load()
Definition: Loader.java:91
net.sf.gridarta.model.maparchobject
Definition: AbstractMapArchObject.java:20
net.sf.gridarta.gui.mapfiles.MapFolder.getPickmaps
int getPickmaps()
Definition: MapFolder.java:221
net.sf.gridarta.gui.mapfiles.MapFolderTree.setActiveMapFolder
synchronized void setActiveMapFolder(@NotNull final MapFolder< G, A, R > mapFolder)
Definition: MapFolderTree.java:157
net.sf.gridarta.gui.map.mapview.MapViewsManager
Definition: MapViewsManager.java:47