Java Code Examples for org.newdawn.slick.util.ResourceLoader#getResourceAsStream()

The following examples show how to use org.newdawn.slick.util.ResourceLoader#getResourceAsStream() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PackedSpriteSheet.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Load the definition file and parse each of the sections
 * 
 * @param def The location of the definitions file
 * @param trans The color to be treated as transparent
 * @throws SlickException Indicates a failure to read or parse the definitions file
 * or referenced image.
 */
private void loadDefinition(String def, Color trans) throws SlickException {
	BufferedReader reader = new BufferedReader(new InputStreamReader(ResourceLoader.getResourceAsStream(def)));

	try {
		image = new Image(basePath+reader.readLine(), false, filter, trans);
		while (reader.ready()) {
			if (reader.readLine() == null) {
				break;
			}
			
			Section sect = new Section(reader);
			sections.put(sect.name, sect);
			
			if (reader.readLine() == null) {
				break;
			}
		}
	} catch (Exception e) {
		Log.error(e);
		throw new SlickException("Failed to process definitions file - invalid format?", e);
	}
}
 
Example 2
Source File: FEResources.java    From FEMultiPlayer-V2 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Load bitmap fonts.
 */
public static void loadBitmapFonts() {
	Scanner in = new Scanner(ResourceLoader.getResourceAsStream("res/fonts/fonts.txt"));
	while(in.hasNextLine()) {
		String line = in.nextLine();
		if(line.startsWith("#"))
			continue;
		if(line.startsWith("define")) {
			String name = line.split(":")[1];
			String texName = in.nextLine();
			char[] chars = in.nextLine().toCharArray();
			int height = Integer.parseInt(in.nextLine());
			int spacing = Integer.parseInt(in.nextLine());
			char[] widths = in.nextLine().toCharArray();
			
			BitmapFont font = new BitmapFont(texName);
			font.setHeight(height);
			font.setSpacing(spacing);
			int pos = 0;
			for(int i=0; i<chars.length; i++) {
				int width = Integer.parseInt(widths[i]+"");
				font.put(chars[i], pos, width);
				pos += width;
			}
			bitmapFonts.put(name, font);
			System.out.println(name+"(bitmap font) loaded");
		}
	}
	in.close();
}
 
Example 3
Source File: FEResources.java    From FEMultiplayer with GNU General Public License v3.0 5 votes vote down vote up
public static void loadBitmapFonts() {
	Scanner in = new Scanner(ResourceLoader.getResourceAsStream("res/fonts/fonts.txt"));
	while(in.hasNextLine()) {
		String line = in.nextLine();
		if(line.startsWith("#"))
			continue;
		if(line.startsWith("define")) {
			String name = line.split(":")[1];
			String texName = in.nextLine();
			char[] chars = in.nextLine().toCharArray();
			int height = Integer.parseInt(in.nextLine());
			int spacing = Integer.parseInt(in.nextLine());
			char[] widths = in.nextLine().toCharArray();
			
			BitmapFont font = new BitmapFont(texName);
			font.setHeight(height);
			font.setSpacing(spacing);
			int pos = 0;
			for(int i=0; i<chars.length; i++) {
				int width = Integer.parseInt(widths[i]+"");
				font.put(chars[i], pos, width);
				pos += width;
			}
			bitmapFonts.put(name, font);
			System.out.println(name+"(bitmap font) loaded");
		}
	}
	in.close();
}
 
Example 4
Source File: WeaponFactory.java    From FEMultiPlayer-V2 with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Load weapons.
 */
public static void loadWeapons() {
	Scanner in = new Scanner(ResourceLoader.getResourceAsStream("res/weapons.txt"));
	int id = 4;
	while(in.hasNextLine()){
		String line = in.nextLine();
		if(line.startsWith("#") || line.equals("")){
			continue;
		}
		String[] args = line.split("\\t+");
		String name = args[0];
		WeaponBuilder w = new WeaponBuilder();
		w.name = name;
		w.id = id++;
		w.type = Weapon.Type.valueOf(args[1].toUpperCase());
		
		
		String[] rangeArgs = args[2].split("-");
		if ("1-Mag/2".equals(args[2])) {
			w.range = new OneToHalfMagRange();
		} else if (rangeArgs.length == 1){
			w.range = new Static1Range(Integer.parseInt(rangeArgs[0]));
		} else {
			int min = Integer.parseInt(rangeArgs[0]);
			int max = Integer.parseInt(rangeArgs[1]);
			w.range = new StaticRange(min, max);
		}
		
		w.mt = Integer.parseInt(args[3]);
		w.hit = Integer.parseInt(args[4]);
		w.crit = Integer.parseInt(args[5]);
		w.maxUses = Integer.parseInt(args[6]);
		
		if(!args[7].equals("-")){
			w.cost = Integer.parseInt(args[7]);
		} else {
			w.cost = 0;
		}
		
		if(args[8].equals("Mount")){
			w.effective.addAll(mounted);
		} else if (args[8].equals("Armor")){
			w.effective.addAll(armored);
		} else if (args[8].equals("Flier")){
			w.effective.addAll(fliers);
		}
		
		if(!args[9].equals("-")){
			w.pref = args[9];
		}
		
		if(!args[10].equals("-")){
			String[] modArgs = args[10].split(" ");
			w.modifiers = w.modifiers.copy(modArgs[0], Integer.parseInt(modArgs[1]));
		}
		
		weapons.put(name, w.build());
	}
	in.close();
}
 
Example 5
Source File: UnitFactory.java    From FEMultiplayer with GNU General Public License v3.0 4 votes vote down vote up
public static void loadUnits() {
	Scanner in = new Scanner(ResourceLoader.getResourceAsStream("res/stats.txt"));
	while(in.hasNextLine()){
		String line = in.nextLine();
		if(line.equals("") || line.startsWith("#")) continue;
		String[] args = line.split("\\s+");
		String name = args[0];
		Class clazz = Class.createClass(args[1]);
		int lv = Integer.parseInt(args[2]);
		float hpBase = Integer.parseInt(args[3]);
		float strBase = Integer.parseInt(args[4]);
		float magBase = Integer.parseInt(args[5]);
		float sklBase = Integer.parseInt(args[6]);
		float spdBase = Integer.parseInt(args[7]);
		float lckBase = Integer.parseInt(args[8]);
		float defBase = Integer.parseInt(args[9]);
		float resBase = Integer.parseInt(args[10]);
		int con = Integer.parseInt(args[11]);
		int mov = Integer.parseInt(args[12]);
		int hpGrowth = Integer.parseInt(args[13]);
		int strGrowth = Integer.parseInt(args[14]);
		int magGrowth = Integer.parseInt(args[15]);
		int sklGrowth = Integer.parseInt(args[16]);
		int spdGrowth = Integer.parseInt(args[17]);
		int lckGrowth = Integer.parseInt(args[18]);
		int defGrowth = Integer.parseInt(args[19]);
		int resGrowth = Integer.parseInt(args[20]);
		char gender = args[21].charAt(0);
		
		for(int i = lv; i < 20; i++){
			hpBase += hpGrowth/100.0f;
			strBase += strGrowth/100.0f;
			magBase += magGrowth/100.0f;
			sklBase += sklGrowth/100.0f;
			spdBase += spdGrowth/100.0f;
			lckBase += lckGrowth/100.0f;
			defBase += defGrowth/100.0f;
			resBase += resGrowth/100.0f;
		}
		
		HashMap<String, Integer> bases = new HashMap<String, Integer>();
		bases.put("Lvl", 1);
		bases.put("HP", (int)hpBase);
		bases.put("Str", (int)strBase);
		bases.put("Mag", (int)magBase);
		bases.put("Skl", (int)sklBase);
		bases.put("Spd", (int)spdBase);
		bases.put("Lck", (int)lckBase);
		bases.put("Def", (int)defBase);
		bases.put("Res", (int)resBase);
		bases.put("Con", con);
		bases.put("Mov", mov);
		
		HashMap<String, Integer> growths = new HashMap<String, Integer>();
		growths.put("HP", hpGrowth);
		growths.put("Str", strGrowth);
		growths.put("Mag", magGrowth);
		growths.put("Skl", sklGrowth);
		growths.put("Spd", spdGrowth);
		growths.put("Def", defGrowth);
		growths.put("Res", resGrowth);
		growths.put("Lck", lckGrowth);
		
		if(clazz == null){
			System.err.println(line);
		}
		Unit u = new Unit(name, clazz, gender, bases, growths);
		if(name.equals("Roy")){
			u.addToInventory(WeaponFactory.getWeapon("Sealed Sword"));
		} else if (name.equals("Lyn")){
			u.addToInventory(WeaponFactory.getWeapon("Sol Katti"));
		} else if (name.equals("Eliwood")){
			u.addToInventory(WeaponFactory.getWeapon("Durandal"));
		} else if (name.equals("Hector")){
			u.addToInventory(WeaponFactory.getWeapon("Armads"));
		} else if(name.equals("Eirika")){
			u.addToInventory(WeaponFactory.getWeapon("Sieglinde"));
		} else if(name.equals("Ephraim")){
			u.addToInventory(WeaponFactory.getWeapon("Siegmund"));
		} else if(name.equals("Marth")){
			u.addToInventory(WeaponFactory.getWeapon("Falchion"));
		} else if(name.equals("Ike")){
			u.addToInventory(WeaponFactory.getWeapon("Ragnell"));
		}
		
		units.put(name, u);
	}
	in.close();
}
 
Example 6
Source File: WeaponFactory.java    From FEMultiplayer with GNU General Public License v3.0 4 votes vote down vote up
public static void loadWeapons() {
	Scanner in = new Scanner(ResourceLoader.getResourceAsStream("res/weapons.txt"));
	int id = 0;
	while(in.hasNextLine()){
		String line = in.nextLine();
		if(line.startsWith("#") || line.equals("")){
			continue;
		}
		String[] args = line.split("\\t+");
		String name = args[0];
		Weapon w = new Weapon(name);
		w.id = id++;
		w.type = Weapon.Type.valueOf(args[1].toUpperCase());
		
		
		List<Integer> range = new ArrayList<Integer>();
		String[] rangeArgs = args[2].split("-");
		if(rangeArgs.length == 1){
			range.add(Integer.parseInt(rangeArgs[0]));
		} else {
			int min = Integer.parseInt(rangeArgs[0]);
			int max = Integer.parseInt(rangeArgs[1]);
			for(int i = min; i <= max; i++){
				range.add(i);
			}
		}
		w.range = range;
		
		w.mt = Integer.parseInt(args[3]);
		w.hit = Integer.parseInt(args[4]);
		w.crit = Integer.parseInt(args[5]);
		w.setMaxUses(Integer.parseInt(args[6]));
		
		if(!args[7].equals("-")){
			w.setCost(Integer.parseInt(args[7]));
		}
		
		if(args[8].equals("Mount")){
			w.effective.addAll(mounted);
		} else if (args[8].equals("Armor")){
			w.effective.addAll(armored);
		} else if (args[8].equals("Flier")){
			w.effective.addAll(fliers);
		}
		
		if(!args[9].equals("-")){
			w.pref = args[9];
		}
		
		if(!args[10].equals("-")){
			String[] modArgs = args[10].split(" ");
			w.modifiers.put(modArgs[0], Integer.parseInt(modArgs[1]));
		}
		
		weapons.put(name, w);
	}
	in.close();
}
 
Example 7
Source File: InternalTextureLoader.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Get a texture from a resource location
 * 
 * @param resourceName The location to load the texture from
 * @param flipped True if we should flip the texture on the y axis while loading
 * @param filter The filter to use when scaling the texture
 * @return The texture loaded
 * @throws IOException Indicates a failure to load the image
 */
public Texture getTexture(String resourceName, boolean flipped, int filter) throws IOException {
	InputStream in = ResourceLoader.getResourceAsStream(resourceName);
	
	return getTexture(in, resourceName, flipped, filter, null);
}
 
Example 8
Source File: InternalTextureLoader.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
   * Get a texture from a resource location
   * 
   * @param resourceName The location to load the texture from
   * @param flipped True if we should flip the texture on the y axis while loading
   * @param filter The filter to use when scaling the texture
* @param transparent The colour to interpret as transparent or null if none
   * @return The texture loaded
   * @throws IOException Indicates a failure to load the image
   */
  public Texture getTexture(String resourceName, boolean flipped, int filter, int[] transparent) throws IOException {
  	InputStream in = ResourceLoader.getResourceAsStream(resourceName);
  	
  	return getTexture(in, resourceName, flipped, filter, transparent);
  }
 
Example 9
Source File: HieroSettings.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Create a new set of configuration from a file
 * 
 * @param hieroFileRef The file system or classpath location of the Hiero settings file.
 * @throws SlickException if the file could not be read.
 */
public HieroSettings(String hieroFileRef) throws SlickException {
	this(ResourceLoader.getResourceAsStream(hieroFileRef));
}