20 package net.sf.gridarta.model.io;
22 import java.io.BufferedReader;
23 import java.io.IOException;
24 import java.util.List;
37 import net.
sf.japi.swing.action.ActionBuilder;
38 import net.
sf.japi.swing.action.ActionBuilderFactory;
39 import org.jetbrains.annotations.NotNull;
40 import org.jetbrains.annotations.Nullable;
47 public abstract class AbstractArchetypeParser<G
extends GameObject<G, A, R>, A extends
MapArchObject<A>, R extends
Archetype<G, A, R>, B extends
AbstractArchetypeBuilder<G, A, R>> implements
ArchetypeParser<G, A, R> {
53 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
86 public void parseArchetypeFromStream(@NotNull
final BufferedReader in, @Nullable
final R prototype, @Nullable
final String line, @Nullable
final String archName, @NotNull
final String panelName, @NotNull
final String folderName, @NotNull
final String archPath, @NotNull
final List<G> invObjects, @NotNull
final ErrorViewCollector errorViewCollector)
throws IOException {
88 final boolean isInternPath;
90 @Nullable
final String path;
92 final String tmpPath = archPath +
"/";
93 isInternPath = tmpPath.startsWith(
"/intern/");
102 thisLine2 = in.readLine();
108 @Nullable R firstArch =
null;
109 boolean archMore =
false;
111 boolean reportError =
true;
116 if (thisLine2 ==
null) {
120 final String thisLine = thisLine2.trim();
121 if (thisLine.startsWith(
"#") || thisLine.isEmpty()) {
122 thisLine2 = in.readLine();
126 if (thisLine.equals(
"More")) {
127 if (firstArch ==
null) {
128 firstArch = lastArch;
133 }
else if (!thisLine.isEmpty() && thisLine.charAt(0) !=
'#') {
140 thisLine2 = in.readLine();
143 final String archetypeName = archName ==
null ? thisLine2.trim().substring(7) : archName;
146 if (firstArch !=
null) {
154 @NotNull String editorFolder = archPath.isEmpty() ?
"default" : archPath;
156 thisLine2 = in.readLine();
157 if (thisLine2 ==
null) {
162 final String thisLine = thisLine2.trim();
163 if (thisLine.startsWith(
"#") || thisLine.isEmpty()) {
171 }
else if (thisLine.equals(
"end")) {
173 }
else if (thisLine.equals(
"msg")) {
175 }
else if (thisLine.equals(
"anim")) {
177 }
else if (thisLine.startsWith(
"visibility ")) {
179 }
else if (thisLine.startsWith(
"magicmap ")) {
181 }
else if (thisLine.startsWith(
"x ")) {
188 }
else if (thisLine.startsWith(
"y ")) {
195 }
else if (thisLine.startsWith(
"editor_folder ")) {
196 editorFolder = thisLine.substring(14).trim();
204 if (firstArch !=
null) {
205 firstArch.addTailPart(archetype);
206 }
else if (
addToPanel(isInternPath, editorFolder, archetype)) {
215 folder = names[names.length >= 2 ? 1 : 0];
217 archetype.setEditorFolder(panel +
"/" + folder);
230 if (archName !=
null) {
231 archetype.setArtifact();
232 if (prototype !=
null) {
237 lastArch = archetype;
240 thisLine2 = in.readLine();
243 if (firstArch !=
null) {
255 final StringBuilder msgText =
new StringBuilder();
258 final String thisLine2 = in.readLine();
259 if (thisLine2 ==
null) {
264 final String thisLine3 = thisLine2.trim();
265 if (thisLine3.equals(
"endmsg")) {
270 msgText.append(thisLine2).append(
"\n");
273 if (msgText.length() > 0) {
285 private void parseAnim(@NotNull
final BufferedReader in, @NotNull
final ErrorViewCollector errorViewCollector, @NotNull
final String path)
throws IOException {
286 final StringBuilder animText =
new StringBuilder();
289 final String thisLine2 = in.readLine();
290 if (thisLine2 ==
null) {
295 final String thisLine3 = thisLine2.trim();
296 if (thisLine3.startsWith(
"#") || thisLine3.isEmpty()) {
300 if (thisLine3.equals(
"mina")) {
304 animText.append(thisLine3).append(
"\n");
327 protected abstract boolean isStartLine(@NotNull String line);
340 protected abstract boolean processLine(@NotNull BufferedReader in, @NotNull String line, @NotNull String line2, @NotNull B
archetypeBuilder, @NotNull
ErrorViewCollector errorViewCollector, @NotNull List<G> invObjects)
throws IOException;
364 protected abstract boolean addToPanel(
boolean isInternPath, @NotNull String editorFolder, @NotNull R archetype);