Gridarta Editor
AnimationObjectsCollectable.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.collectable;
21 
22 import java.io.BufferedWriter;
23 import java.io.File;
24 import java.io.FileOutputStream;
25 import java.io.IOException;
26 import java.io.OutputStreamWriter;
27 import java.io.Writer;
32 import net.sf.gridarta.utils.IOUtils;
33 import net.sf.japi.swing.action.ActionBuilder;
34 import net.sf.japi.swing.action.ActionBuilderFactory;
35 import net.sf.japi.swing.misc.Progress;
36 import org.jetbrains.annotations.NotNull;
37 
44 public class AnimationObjectsCollectable implements Collectable {
45 
49  @NotNull
50  private static final ActionBuilder ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder("net.sf.gridarta");
51 
55  @NotNull
57 
61  @NotNull
62  private final String animTreeFile;
63 
69  public AnimationObjectsCollectable(@NotNull final AnimationObjects animationObjects, @NotNull final String animTreeFile) {
70  this.animationObjects = animationObjects;
71  this.animTreeFile = animTreeFile;
72  }
73 
79  @Override
80  public void collect(@NotNull final Progress progress, @NotNull final File collectedDirectory) throws IOException {
81  collectAnimations(progress, collectedDirectory);
82  collectAnimTree(progress, collectedDirectory);
83  }
84 
91  private void collectAnimations(@NotNull final Progress progress, @NotNull final File collectedDirectory) throws IOException {
92  progress.setLabel(ActionBuilderUtils.getString(ACTION_BUILDER, "archCollectAnimations"), animationObjects.size());
93  try (Writer animations = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(collectedDirectory, "animations")), IOUtils.MAP_ENCODING))) {
94  int counter = 0; // counter for progress bar
95  for (final AnimationObject anim : animationObjects) {
96  animations.append("anim ").append(anim.getAnimName()).append('\n').append(anim.getAnimList()).append("mina\n");
97  if (counter++ % 128 == 0) {
98  progress.setValue(counter);
99  }
100  }
101  }
102  progress.setValue(animationObjects.size());
103  }
104 
111  private void collectAnimTree(@NotNull final Progress progress, @NotNull final File collectedDirectory) throws IOException {
112  progress.setLabel(ActionBuilderUtils.getString(ACTION_BUILDER, "archCollectAnimTree"), animationObjects.size());
113  try (Writer animtree = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(collectedDirectory, animTreeFile)), IOUtils.MAP_ENCODING))) {
114  int counter = 0; // counter for progress bar
115  for (final NamedObject anim : animationObjects) {
116  animtree.append(anim.getPath()).append('\n');
117  if (counter++ % 128 == 0) {
118  progress.setValue(counter);
119  }
120  }
121  }
122  progress.setValue(animationObjects.size());
123  }
124 
125 }
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.model.collectable.Collectable
A Collectable has information that can be collected.
Definition: Collectable.java:33
net.sf.gridarta.model.anim.AnimationObjects
AnimationObjects is a container for AnimationObjects.
Definition: AnimationObjects.java:30
net.sf.gridarta.model.collectable.AnimationObjectsCollectable.collectAnimTree
void collectAnimTree(@NotNull final Progress progress, @NotNull final File collectedDirectory)
Collects the animation data into the file "animations".
Definition: AnimationObjectsCollectable.java:111
net.sf
net.sf.gridarta.model.data.NamedObjects.size
int size()
Get the number of objects.
net.sf.gridarta.model.collectable.AnimationObjectsCollectable.collectAnimations
void collectAnimations(@NotNull final Progress progress, @NotNull final File collectedDirectory)
Collects the animation data into the file "animations".
Definition: AnimationObjectsCollectable.java:91
net.sf.gridarta.model.data.NamedObject
An.
Definition: NamedObject.java:32
net
net.sf.gridarta.model.collectable.AnimationObjectsCollectable.collect
void collect(@NotNull final Progress progress, @NotNull final File collectedDirectory)
Collects information.the progress to report progress to the destination directory to collect data to ...
Definition: AnimationObjectsCollectable.java:80
net.sf.gridarta.model.data
Classes for handling data that is organized in a tree.
Definition: AbstractNamedObject.java:20
net.sf.gridarta.utils.ActionBuilderUtils.getString
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
Definition: ActionBuilderUtils.java:71
net.sf.gridarta.model.collectable.AnimationObjectsCollectable.AnimationObjectsCollectable
AnimationObjectsCollectable(@NotNull final AnimationObjects animationObjects, @NotNull final String animTreeFile)
Creates a new instance.
Definition: AnimationObjectsCollectable.java:69
net.sf.gridarta.model.collectable.AnimationObjectsCollectable.animTreeFile
final String animTreeFile
The collected animation tree file.
Definition: AnimationObjectsCollectable.java:62
net.sf.gridarta.model
net.sf.gridarta.utils.IOUtils
Utility-class for Gridarta's I/O.
Definition: IOUtils.java:40
net.sf.gridarta.model.anim
Gridarta can handle frame information of animations and allow the selection of an animation using a t...
Definition: AbstractAnimationObjects.java:20
net.sf.gridarta.utils.ActionBuilderUtils
Utility class for ActionBuilder related functions.
Definition: ActionBuilderUtils.java:31
net.sf.gridarta.model.anim.AnimationObject
An AnimationObject reflects the animation ("@code anim\n @endcode " ...
Definition: AnimationObject.java:30
net.sf.gridarta.model.collectable.AnimationObjectsCollectable
a Collectable that creates the "animations" file.
Definition: AnimationObjectsCollectable.java:44
net.sf.gridarta.model.collectable.AnimationObjectsCollectable.animationObjects
final AnimationObjects animationObjects
The AnimationObjects being collected.
Definition: AnimationObjectsCollectable.java:56
net.sf.gridarta.utils
Definition: ActionBuilderUtils.java:20
net.sf.gridarta.utils.IOUtils.MAP_ENCODING
static final String MAP_ENCODING
Encoding to use for maps and other data.
Definition: IOUtils.java:52
net.sf.gridarta.model.collectable.AnimationObjectsCollectable.ACTION_BUILDER
static final ActionBuilder ACTION_BUILDER
The ActionBuilder instance.
Definition: AnimationObjectsCollectable.java:50