Gridarta Editor
AbstractResources.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.resource;
21 
22 import java.io.File;
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.List;
33 import net.sf.japi.swing.misc.Progress;
34 import org.jetbrains.annotations.NotNull;
35 
40 public abstract class AbstractResources<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> {
41 
45  @NotNull
47 
51  @NotNull
53 
57  private boolean loaded;
58 
62  private boolean loadedFromFiles;
63 
70  this.gameObjectParser = gameObjectParser;
71  this.archetypeSet = archetypeSet;
72  }
73 
78  private void finishRead(@NotNull final List<G> invObjects) {
80  archetypeSet.connectFaces(); // attach faces to arches
81  }
82 
88  public void readFiles(@NotNull final ProjectSettings projectSettings, @NotNull final ErrorView errorView) {
89  if (loaded) {
90  throw new IllegalStateException("resources already have been loaded");
91  }
92  final List<G> invObjects = new ArrayList<>();
93  readFilesInt(projectSettings, errorView, invObjects);
94  finishRead(invObjects);
95  loadedFromFiles = true;
96  loaded = true;
97  }
98 
104  public void readCollected(@NotNull final ProjectSettings projectSettings, @NotNull final ErrorView errorView) {
105  if (loaded) {
106  throw new IllegalStateException("resources already have been loaded");
107  }
108  final List<G> invObjects = readCollectedInt(projectSettings, errorView);
109  finishRead(invObjects);
110  loadedFromFiles = false;
111  loaded = true;
112  }
113 
119  public boolean canWriteCollected() {
120  return loaded && loadedFromFiles;
121  }
122 
131  public void writeCollected(@NotNull final Progress progress, @NotNull final File collectedDirectory) throws IOException {
132  if (!canWriteCollected()) {
133  throw new IllegalStateException("can't write already collected archetypes");
134  }
135  writeCollectedInt(progress, collectedDirectory);
136  }
137 
144  protected abstract void readFilesInt(@NotNull ProjectSettings projectSettings, @NotNull ErrorView errorView, @NotNull List<G> invObjects);
145 
152  @NotNull
153  protected abstract List<G> readCollectedInt(@NotNull ProjectSettings projectSettings, @NotNull ErrorView errorView);
154 
161  protected abstract void writeCollectedInt(@NotNull Progress progress, @NotNull File collectedDirectory) throws IOException;
162 
163 }
net.sf.gridarta.model.resource.AbstractResources.AbstractResources
AbstractResources(@NotNull final GameObjectParser< G, A, R > gameObjectParser, @NotNull final ArchetypeSet< G, A, R > archetypeSet)
Creates a new instance.
Definition: AbstractResources.java:69
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.model.resource.AbstractResources.readCollected
void readCollected(@NotNull final ProjectSettings projectSettings, @NotNull final ErrorView errorView)
Reads the resources from a collection.
Definition: AbstractResources.java:104
net.sf.gridarta.model.resource.AbstractResources.writeCollected
void writeCollected(@NotNull final Progress progress, @NotNull final File collectedDirectory)
Writes the resources in collected form.
Definition: AbstractResources.java:131
net.sf
net.sf.gridarta.model.resource.AbstractResources.finishRead
void finishRead(@NotNull final List< G > invObjects)
Common code to be executed after reading resources.
Definition: AbstractResources.java:78
net.sf.gridarta.model.resource.AbstractResources.archetypeSet
final ArchetypeSet< G, A, R > archetypeSet
The ArchetypeSet to update.
Definition: AbstractResources.java:52
net.sf.gridarta.model.resource.AbstractResources.writeCollectedInt
abstract void writeCollectedInt(@NotNull Progress progress, @NotNull File collectedDirectory)
Writes the resources in collected form.
net.sf.gridarta.model.errorview.ErrorView
Interface for classes displaying error messages.
Definition: ErrorView.java:28
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.archetypeset.ArchetypeSet.connectFaces
void connectFaces()
net.sf.gridarta.model.resource.AbstractResources.readFilesInt
abstract void readFilesInt(@NotNull ProjectSettings projectSettings, @NotNull ErrorView errorView, @NotNull List< G > invObjects)
Reads the resources from individual files.
net.sf.gridarta.model.gameobject
GameObjects are the objects based on Archetypes found on maps.
Definition: AbstractGameObject.java:20
net
net.sf.gridarta.model.errorview
Definition: ErrorView.java:20
net.sf.gridarta.model.resource.AbstractResources.canWriteCollected
boolean canWriteCollected()
Whether the resources can be written in collected form.
Definition: AbstractResources.java:119
net.sf.gridarta.model.resource.AbstractResources.gameObjectParser
final GameObjectParser< G, A, R > gameObjectParser
The GameObjectParser to use.
Definition: AbstractResources.java:46
net.sf.gridarta.model.resource.AbstractResources.loaded
boolean loaded
Whether the resources have been loaded.
Definition: AbstractResources.java:57
net.sf.gridarta.model.resource.AbstractResources
Maintains resources.
Definition: AbstractResources.java:40
net.sf.gridarta.model.maparchobject.MapArchObject
Interface for MapArchObjects.
Definition: MapArchObject.java:40
net.sf.gridarta.model.resource.AbstractResources.loadedFromFiles
boolean loadedFromFiles
Whether the resources have been loaded from individual files.
Definition: AbstractResources.java:62
net.sf.gridarta.model.archetypeset.ArchetypeSet
Interface that captures similarities between different ArchetypeSet implementations.
Definition: ArchetypeSet.java:37
net.sf.gridarta.model.io
Reading and writing of maps, handling of paths.
Definition: AbstractAnimationObjectsReader.java:20
net.sf.gridarta.model.settings.ProjectSettings
Settings that apply to a project.
Definition: ProjectSettings.java:29
net.sf.gridarta.model.io.GameObjectParser.collectTempList
void collectTempList(@NotNull List< G > objects)
Browse first through the archetype list and attach map arches to it then browse through the face list...
net.sf.gridarta.model.resource.AbstractResources.readCollectedInt
abstract List< G > readCollectedInt(@NotNull ProjectSettings projectSettings, @NotNull ErrorView errorView)
Reads the resources from a collection.
net.sf.gridarta.model
net.sf.gridarta.model.archetype.Archetype
Reflects an Archetype.
Definition: Archetype.java:41
net.sf.gridarta.model.resource.AbstractResources.readFiles
void readFiles(@NotNull final ProjectSettings projectSettings, @NotNull final ErrorView errorView)
Reads the resources from individual files.
Definition: AbstractResources.java:88
net.sf.gridarta.model.maparchobject
Definition: AbstractMapArchObject.java:20
net.sf.gridarta.model.io.GameObjectParser
Interface for classes that read or write GameObject instances.
Definition: GameObjectParser.java:37
net.sf.gridarta.model.archetypeset
Definition: ArchetypeSet.java:20
net.sf.gridarta.model.settings
Definition: AbstractDefaultProjectSettings.java:20