/*
 * JVirus is a PacMan clone, written in Java.
 *
 * Please read "http://jvirus.sourceforge.net/jvirus_licence.txt" for copyrights.
 * 
 * The sourcecode is designed and created with
 * Sun J2SDK 1.3 and Microsoft Visual J++ 6.0
 *
 * JVirus homepage: http://jvirus.sourceforge.net
 *
 * autor: Slawa Weis
 * email: slawaweis@animatronik.net
 *
 */

package org.game.JVirus;

import java.awt.*;
import java.awt.image.*;

import javax.swing.*;

import org.game.JVirus.res.*;

/**
 * static class for image loading. Only static methods here.
 *
 * @see org.game.JVirus.res.Resource
 */
public class Images implements IFields
{
 /**
  * name list for a tile
  */
 protected static String [] IM_DEFAULT = { "not_created" };
 /**
  * name list for a tile
  */
 protected static String [] IM_EMPTY   = { "empty" };
 /**
  * name list for a tile
  */
 protected static String [] IM_NOTHING = { "nothing" };
 /**
  * name list for a tile
  */
 protected static String [] IM_JGATE   = { "beam0", "beam1", "beam2", "beam3", "beam4", "beam5" };
 /**
  * name list for a tile
  */
 protected static String [] IM_LIFE    = { "life" };

 /**
  * images list
  */
 public static AnimImage imageArray [] = new AnimImage[256];

 /**
  * reference for the avatar image
  */
 public static Image avatar1 = null;
 /**
  * reference for the avatar image
  */
 public static Image avatar2 = null;
 /**
  * reference for the avatar image
  */
 public static Image avatar3 = null;
 /**
  * reference for the avatar image
  */
 public static Image avatar4 = null;

 /**
  * hidden constructor
  */
 private Images()
  {
  }

 /**
  * static initialiser. Load all images
  */
 static
  {
  AnimImage defaultImage = loadAnimImage(IM_DEFAULT);
  for(int i = 0; i < imageArray.length; i++)
     imageArray[i] = defaultImage;

  AnimImage empty = loadAnimImage(IM_EMPTY);

  imageArray[EMPTY]   = empty;
  imageArray[NOTHING] = loadAnimImage(IM_NOTHING);
  imageArray[START]   = empty;
  imageArray[END]     = loadAnimImage("end");
  imageArray[LIFE]    = loadAnimImage(IM_LIFE);

  imageArray[WALL1] = loadAnimImage("wall1");
  imageArray[WALL2] = loadAnimImage("wall1");
  imageArray[WALL3] = loadAnimImage("wall1");
  imageArray[WALL4] = loadAnimImage("wall1");
  imageArray[WALL5] = loadAnimImage("wall1");

  imageArray[STONE] = loadAnimImage("stone");

  imageArray[DATA1] = loadAnimImage("data1");
  imageArray[DATA2] = loadAnimImage("data2");
//  imageArray[DATA3] = loadAnimImage("lb");

  imageArray[REDKEY]   = loadAnimImage("redkey");
  imageArray[GREENKEY] = loadAnimImage("greenkey");
  imageArray[BLUEKEY]  = loadAnimImage("bluekey");

  imageArray[REDGATE]   = loadAnimImage("redgate");
  imageArray[GREENGATE] = loadAnimImage("greengate");
  imageArray[BLUEGATE]  = loadAnimImage("bluegate");

  imageArray[AMD]   = loadAnimImage("amd");
  imageArray[INTEL] = loadAnimImage("intel");

  Image [] jgate = loadImageArray(IM_JGATE);

  imageArray[BEAM0] = new AnimImage(jgate);
  imageArray[BEAM1] = new AnimImage(jgate);
  imageArray[BEAM2] = new AnimImage(jgate);
  imageArray[BEAM3] = new AnimImage(jgate);
  imageArray[BEAM4] = new AnimImage(jgate);
  imageArray[BEAM5] = new AnimImage(jgate);
  imageArray[BEAM6] = new AnimImage(jgate);
  imageArray[BEAM7] = new AnimImage(jgate);
  imageArray[BEAM8] = new AnimImage(jgate);
  imageArray[BEAM9] = new AnimImage(jgate);

  imageArray[BEOS]    = loadAnimImage("beos");
  imageArray[LINUX]   = loadAnimImage("linux");
  imageArray[MAC]     = loadAnimImage("macos");
  imageArray[UNIX]    = loadAnimImage("solaris");
  imageArray[WINDOWS] = loadAnimImage("windows");

  // load two avatar images and creates two mirror images
  avatar1 = loadImage("avatar1");
  avatar2 = loadImage("avatar2");

  int a1w = avatar1.getWidth(null);
  int a1h = avatar1.getHeight(null);
  int a2w = avatar2.getWidth(null);
  int a2h = avatar2.getHeight(null);

  BufferedImage i_avatar1 = new BufferedImage(a1w, a1h, BufferedImage.TYPE_INT_RGB);
  BufferedImage i_avatar2 = new BufferedImage(a2w, a2h, BufferedImage.TYPE_INT_RGB);

  i_avatar1.createGraphics().drawImage(avatar1, 0, 0, a1w, a1h, a1w, 0, 0, a1h, null);
  i_avatar2.createGraphics().drawImage(avatar2, 0, 0, a2w, a2h, a2w, 0, 0, a2h, null);

  avatar3 = i_avatar1;
  avatar4 = i_avatar2;
  }

 /**
  * load a image
  *
  * @param name Image name
  */
 protected static Image loadImage(String name)
  {
  return new ImageIcon(Resource.class.getResource(name + ".gif")).getImage();
  }

 /**
  * load a animating image
  *
  * @param name Image name
  * @see org.game.JVirus.AnimImage
  */
 protected static AnimImage loadAnimImage(String name)
  {
  Image [] array = new Image[1];
  array[0] = loadImage(name);
  return new AnimImage(array);
  }

 /**
  * load a animating image
  *
  * @param names Image names list
  * @see org.game.JVirus.AnimImage
  */
 protected static AnimImage loadAnimImage(String [] names)
  {
  Image [] array = new Image[names.length];
  for(int i = 0; i < names.length; i++)
     array[i] = loadImage(names[i]);
  return new AnimImage(array);
  }

 /**
  * load list of images
  *
  * @param names Image names list
  */
 protected static Image [] loadImageArray(String [] names)
  {
  Image [] array = new Image[names.length];
  for(int i = 0; i < names.length; i++)
     array[i] = loadImage(names[i]);
  return array;
  }
}