package jsettlers.graphics.reader;

import java.io.IOException;

import jsettlers.common.images.AnimationSequence;
import jsettlers.common.images.DirectImageLink;
import jsettlers.graphics.image.GuiImage;
import jsettlers.graphics.image.Image;
import jsettlers.graphics.image.LandscapeImage;
import jsettlers.graphics.map.draw.ImageProvider;
import jsettlers.graphics.reader.bytereader.ByteReader;
import jsettlers.graphics.reader.translator.DatBitmapTranslator;
import jsettlers.graphics.sequence.Sequence;

/**
 * Different settlers versions use different image indexes.
 * <p>
 * In the game, we always reference the image indexes of the gold edition.
 * <p>
 * This utility class holds the information about which index remapping to use for which file.
 * @author michael
 *
 */
public interface DatFileIndexUtils {

	static class FakeShipsDatFile extends EmptyDatFile {
		private final ImageProvider fallback;

		private FakeShipsDatFile(ImageProvider fallback) {
			this.fallback = fallback;
		}

		@Override
		public SequenceList<Image> getSettlers() {
			return new SequenceList<Image>() {
				@Override
				public int size() {
					// TODO @andreas: Change this to the max number of sequences in the ship file
					return 1000;
				}
				
				@Override
				public Sequence<Image> get(int index) {
					// TODO @andreas: implement mapping
					// You can use your own implementation instead of WrappedAnimation if you need more complex rewrites
					if (index == 0) {
						// e.g. "cargo_ship_body", 0, 6
						// sequence length needs to be 6 (6 directions)
						return new WrappedAnimation(fallback, new AnimationSequence("ready", 0, 2));
					} else if (index == 2) {
						// e.g. "cargo_ship_front", 0, 6
						return new WrappedAnimation(fallback, new AnimationSequence("ready", 0, 2));
					} else if (index == 3) {
						// e.g. "cargo_ship_construction", 0, 6
						return new WrappedAnimation(fallback, new AnimationSequence("ready", 0, 2));
					} else {
						return new WrappedAnimation(fallback, new AnimationSequence("ready", 0, 2));
					}
				}
			};
		}
	}

	/**
	 * Returns a reader that uses gold version indexes
	 * @param fileIndex
	 * @param reader The reader, using any index (auto-detected)
	 * @return
	 */
	static DatFileReader autoTranslate(int fileIndex, DatFileReader reader, ImageProvider fallback) {
		if (fileIndex == 36 && reader.getSettlers().size() == 0) {
			// No ships available
			return new FakeShipsDatFile(fallback);
		}
		return reader;
	}
	
}

@@ -33,37 +33,8 @@
 r;%0A%0A
-import java.io.IOException;%0A%0A
 impo
@@ -100,336 +100,77 @@
 ers.
-common.images.DirectImageLink;%0Aimport jsettlers.graphics.image.GuiImage;%0Aimport jsettlers.graphics.image.Image;%0Aimport jsettlers.graphics.image.LandscapeImage;%0Aimport jsettlers.graphics.map.draw.ImageProvider;%0Aimport jsettlers.graphics.reader.bytereader.ByteReader;%0Aimport jsettlers.graphics.reader.translator.DatBitmapTranslato
+graphics.image.Image;%0Aimport jsettlers.graphics.map.draw.ImageProvide
 r;%0Ai
@@ -462,16 +462,19 @@
 h file.%0A
+ *%0A
  * @auth
@@ -484,19 +484,16 @@
 michael%0A
- *%0A
  */%0Apubl
@@ -499,16 +499,42 @@
 lic 
-interfac
+class DatFileIndexUtils %7B%0A%0A%09privat
 e Da
@@ -548,21 +548,34 @@
 dexUtils
+()
  %7B%0A
-%0A
 %09
+%7D%0A%0A%09private 
 static c
@@ -987,20 +987,16 @@
 ;%0A%09%09%09%09%7D%0A
-%09%09%09%09
 %0A%09%09%09%09@Ov
@@ -1883,16 +1883,20 @@
 indexes%0A
+%09 *%0A
 %09 * @par
@@ -1925,17 +1925,23 @@
 m reader
- 
+%0A%09 * %09%09
 The read
@@ -1994,16 +1994,23 @@
 n%0A%09 */%0A%09
+public 
 static D
@@ -2251,12 +2251,11 @@
 der;%0A%09%7D%0A
-%09
 %0A%7D%0A

Change static interface method to static class method