20 package net.sf.gridarta.model.io;
22 import java.io.BufferedReader;
24 import java.io.FileInputStream;
25 import java.io.IOException;
26 import java.io.InputStreamReader;
27 import java.io.Reader;
36 import org.jetbrains.annotations.NotNull;
37 import org.jetbrains.annotations.Nullable;
69 try (FileInputStream fileInputStream =
new FileInputStream(animFile)) {
70 try (Reader inputStreamReader =
new InputStreamReader(fileInputStream,
IOUtils.
MAP_ENCODING)) {
71 loadAnimations(animationObjects, errorViewCollector, inputStreamReader, startKey, ignoreOtherText, path,
null);
98 if (path ==
null && animations ==
null) {
99 throw new IllegalArgumentException(
"neither path nor animations is set");
101 if (path !=
null && animations !=
null) {
102 throw new IllegalArgumentException(
"both path and animations are set");
104 try (BufferedReader in =
new BufferedReader(reader)) {
107 final String line2 = in.readLine();
111 final String line = line2.trim();
112 if (line.startsWith(
"#") || line.isEmpty()) {
114 }
else if (line.startsWith(startKey)) {
115 lineNumber +=
processAnimation(line.substring(startKey.length()), lineNumber, in, startKey, animationObjects, errorViewCollector, path, animations);
116 }
else if (line.equals(
"mina") || !ignoreOtherText) {
143 private static int processAnimation(@NotNull
final String animName,
final int startLineNumber, @NotNull
final BufferedReader in, @NotNull
final String startKey, @NotNull
final AnimationObjects animationObjects, @NotNull
final ErrorViewCollector errorViewCollector, @Nullable
final String path, @Nullable
final Map<String, String> animations)
throws AnimationParseException, IOException {
144 int lineNumber = startLineNumber;
145 final StringBuilder animText =
new StringBuilder();
148 final String line3 = in.readLine();
152 final String line4 = line3.trim();
153 if (line4.startsWith(
"#") || line4.isEmpty()) {
155 }
else if (line4.startsWith(startKey)) {
157 }
else if (line4.equals(
"mina")) {
158 processAnimationLine(animationObjects, errorViewCollector, path, animations, animName, animText.toString());
161 animText.append(line4).append(
'\n');
164 return lineNumber - startLineNumber;
179 private static void processAnimationLine(@NotNull
final AnimationObjects animationObjects, @NotNull
final ErrorViewCollector errorViewCollector, @Nullable
final String path, @Nullable
final Map<String, String> animations, @NotNull
final String animName, @NotNull
final String animText) {
180 if (path ==
null && animations ==
null) {
181 throw new IllegalArgumentException(
"neither path not animations is set");
184 final String animPath;
186 final String tmp = animations.get(animName);
189 animPath =
"/" + animName;
197 animationObjects.addAnimationObject(animName, animText, animPath);