Package com.pointcliki.io

Source Code of com.pointcliki.io.ResourceManager

package com.pointcliki.io;

import java.awt.Color;
import java.awt.Font;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

import org.newdawn.slick.Animation;
import org.newdawn.slick.Image;
import org.newdawn.slick.SpriteSheet;
import org.newdawn.slick.UnicodeFont;
import org.newdawn.slick.font.effects.ColorEffect;

import com.pointcliki.core.Manager;

public class ResourceManager extends Manager {
  /**
   * Serial Key
   */
  private static final long serialVersionUID = 1L;
  private static UnicodeFont sUIFont;
  protected String fRootDir;
 
  public ResourceManager(String rootDir) {
    super(null);
    fRootDir = rootDir;
  }

  @Override
  public void cleanup() {
    // TODO Auto-generated method stub
  }

  public InputStream getStream(String string) {
    try {
      FileInputStream stream = new FileInputStream(string);
      return stream;
    } catch (FileNotFoundException e) {
      System.err.println("Couldn't find resource: " + string);
      return null;
    }
  }

  public Image image(String string) {
    try {
      return new Image(fRootDir + "/" + string + ".png");
    } catch (Exception e) {
      System.err.println("Couldn't find resource: " + string);
      return null;
    }
  }

  public Animation animation(String string) {
    try {
      return new Animation(new SpriteSheet(fRootDir + "/" + string + ".png", 32, 32), 100);
    } catch (Exception e) {
      System.err.println("Couldn't find resource: " + string);
      return null;
    }
  }
 
  public SpriteSheet spritesheet(String string, int x, int y) {
    try {
      return new SpriteSheet(fRootDir + "/" + string + ".png", x, y);
    } catch (Exception e) {
      System.err.println("Couldn't find resource: " + string);
      return null;
    }
  }
 
  @SuppressWarnings("unchecked")
  public UnicodeFont UIFont() {
    if (sUIFont != null) return sUIFont;
    sUIFont = new UnicodeFont(new Font("Arial", 0, 14));
    try {
      sUIFont.getEffects().add(new ColorEffect(Color.white));
      sUIFont.addAsciiGlyphs();
      sUIFont.loadGlyphs();
    } catch (Exception e) {
      System.err.println("Unable to load UI font");
      return null;
    }
    return sUIFont;
  }

  /**
   * This method is not used as the manager is parented to the game, not scene
   */
  @Override
  public Manager snapshot() throws CloneNotSupportedException {
    // TODO Auto-generated method stub
    return null;
  }
  /**
   * This method is not used as the manager is parented to the game, not scene
   */
  @Override
  public void restore(Manager from) {
    // TODO Auto-generated method stub
   
  }
}
TOP

Related Classes of com.pointcliki.io.ResourceManager

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.