From: <aki...@us...> - 2008-08-15 20:24:11
|
Revision: 4861 http://gridarta.svn.sourceforge.net/gridarta/?rev=4861&view=rev Author: akirschbaum Date: 2008-08-15 20:24:16 +0000 (Fri, 15 Aug 2008) Log Message: ----------- Fix animations parser in CrossfireEditor. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java trunk/src/app/net/sf/gridarta/gameobject/anim/AbstractAnimationObjects.java trunk/src/app/net/sf/gridarta/gameobject/anim/AnimationObjects.java Modified: trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2008-08-15 20:10:25 UTC (rev 4860) +++ trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2008-08-15 20:24:16 UTC (rev 4861) @@ -244,7 +244,7 @@ try { final Reader in = new BufferedReader(new FileReader(filename)); try { - animationObjects.loadAnims(in, filename); + animationObjects.loadAnims(in, "animation ", true, filename); } finally { in.close(); } Modified: trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2008-08-15 20:10:25 UTC (rev 4860) +++ trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2008-08-15 20:24:16 UTC (rev 4861) @@ -417,7 +417,7 @@ private void loadAnimsFromFiles() { for (final File animFile : animFiles) { try { - animationObjects.loadAnims(animFile); + animationObjects.loadAnims(animFile, "anim ", false); } catch (final DuplicateAnimationException e) { mainControl.handleThrowable(e); } catch (final IOException e) { @@ -436,7 +436,7 @@ try { final Reader in = IOUtils.createReader(baseDir, "animations"); try { - animationObjects.loadAnims(in, null); + animationObjects.loadAnims(in, "anim ", false, null); } finally { in.close(); } Modified: trunk/src/app/net/sf/gridarta/gameobject/anim/AbstractAnimationObjects.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/anim/AbstractAnimationObjects.java 2008-08-15 20:10:25 UTC (rev 4860) +++ trunk/src/app/net/sf/gridarta/gameobject/anim/AbstractAnimationObjects.java 2008-08-15 20:24:16 UTC (rev 4861) @@ -56,11 +56,11 @@ } /** {@inheritDoc} */ - public void loadAnims(final File animFile) throws FileNotFoundException, IOException, AnimationParseException, DuplicateAnimationException { + public void loadAnims(final File animFile, @NotNull final String startKey, final boolean ignoreOtherText) throws FileNotFoundException, IOException, AnimationParseException, DuplicateAnimationException { final Reader in = new InputStreamReader(new FileInputStream(animFile), IOUtils.MAP_ENCODING); try { final String path = (new File(PathManager.getArchPath(animFile.getPath()))).getParent().replace('\\', '/'); - loadAnims(in, path); + loadAnims(in, startKey, ignoreOtherText, path); } finally { in.close(); } @@ -117,7 +117,7 @@ /** {@inheritDoc} */ @SuppressWarnings({"IOResourceOpenedButNotSafelyClosed"}) - public void loadAnims(final Reader reader, @Nullable final String path) throws IOException, AnimationParseException, DuplicateAnimationException { + public void loadAnims(final Reader reader, @NotNull final String startKey, final boolean ignoreOtherText, @Nullable final String path) throws IOException, AnimationParseException, DuplicateAnimationException { final BufferedReader in = reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader); boolean inAnim = false; String animName = null; @@ -128,24 +128,23 @@ final String line = line2.trim(); if (line.startsWith("#")) { /* ignore comment lines. */ - } else if (line.startsWith("anim ")) { + } else if (line.startsWith(startKey)) { if (inAnim) { throw new AnimationParseException("mina", line, lineNumber); } inAnim = true; - animName = line.substring("anim ".length()); + animName = line.substring(startKey.length()); animText.setLength(0); } else if ("mina".equals(line)) { if (!inAnim) { - throw new AnimationParseException("anim ...", line, lineNumber); + throw new AnimationParseException(startKey + "...", line, lineNumber); } inAnim = false; addAnimationObject(animName, animText.toString(), path); - } else { - if (!inAnim) { - throw new AnimationParseException("anim ...", line, lineNumber); - } + } else if (inAnim) { animText.append(line).append('\n'); + } else if (!ignoreOtherText) { + throw new AnimationParseException(startKey + "...", line, lineNumber); } } if (inAnim) { Modified: trunk/src/app/net/sf/gridarta/gameobject/anim/AnimationObjects.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/anim/AnimationObjects.java 2008-08-15 20:10:25 UTC (rev 4860) +++ trunk/src/app/net/sf/gridarta/gameobject/anim/AnimationObjects.java 2008-08-15 20:24:16 UTC (rev 4861) @@ -25,6 +25,7 @@ import java.io.Reader; import net.sf.gridarta.data.NamedObjects; import net.sf.gridarta.gameobject.Collectable; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -51,13 +52,17 @@ /** * Loads animations from a file. * @param animFile file to load animations from + * @param startKey the key that begins an animation block; it must end with + * a space character + * @param ignoreOtherText if set, ignore all text outside animation + * definitions * @throws IOException in case of I/O errors * @throws FileNotFoundException in case the file couldn't be opened * @throws AnimationParseException in case parsing the animation reveals * errors * @throws DuplicateAnimationException in case an animation was not unique */ - void loadAnims(File animFile) throws FileNotFoundException, IOException, AnimationParseException, DuplicateAnimationException; + void loadAnims(File animFile, @NotNull String startKey, boolean ignoreOtherText) throws FileNotFoundException, IOException, AnimationParseException, DuplicateAnimationException; /** * Loads any number of animations from a reader. It is not neccessary to @@ -65,6 +70,10 @@ * supplied <var>reader</var> with a BufferedReader if the supplied reader * isn't already a BufferedReader itself. * @param reader Reader to load animations from + * @param startKey the key that begins an animation block; it must end with + * a space character + * @param ignoreOtherText if set, ignore all text outside animation + * definitions * @param path Path relative to the arch directory, used to create tree * information * @throws IOException in case of I/O errors @@ -72,7 +81,7 @@ * errors * @throws DuplicateAnimationException in case an animation was not unique */ - void loadAnims(Reader reader, @Nullable String path) throws IOException, AnimationParseException, DuplicateAnimationException; + void loadAnims(Reader reader, @NotNull String startKey, boolean ignoreOtherText, @Nullable String path) throws IOException, AnimationParseException, DuplicateAnimationException; /** * Loads animations from a file. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |