org.newdawn.slick.util.ResourceLoader Java Examples

The following examples show how to use org.newdawn.slick.util.ResourceLoader. 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: SoundTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 */
public void init(GameContainer container) throws SlickException {
	SoundStore.get().setMaxSources(32);
	
	myContainer = container;
	sound = new Sound("testdata/restart.ogg");
	charlie = new Sound("testdata/cbrown01.wav");
	try {
		engine = AudioLoader.getAudio("WAV", ResourceLoader.getResourceAsStream("testdata/engine.wav"));
	} catch (IOException e) {
		throw new SlickException("Failed to load engine", e);
	}
	music = musica = new Music("testdata/SMB-X.XM");
	//music = musica = new Music("testdata/theme.ogg", true);
	musicb = new Music("testdata/kirby.ogg", true);
	burp = new Sound("testdata/burp.aif");
	
	music.play();
}
 
Example #2
Source File: SoundController.java    From opsu-dance with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Loads and returns a Clip from a resource.
 * @param ref the resource name
 * @param isMP3 true if MP3, false if WAV
 * @return the loaded and opened clip
 */
private static MultiClip loadClip(String ref, boolean isMP3) {
	try {
		URL url = ResourceLoader.getResource(ref);

		// check for 0 length files
		InputStream in = url.openStream();
		if (in.available() == 0) {
			in.close();
			return new MultiClip(ref, null);
		}
		in.close();

		AudioInputStream audioIn = AudioSystem.getAudioInputStream(url);
		return loadClip(ref, audioIn, isMP3);
	} catch (Exception e) {
		softErr(e, "Failed to load clip %s", ref);
		return null;
	}
}
 
Example #3
Source File: SoundController.java    From opsu-dance with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the sound file name, with extension, by first looking through
 * the skins directory and then the default resource locations.
 * @param filename the base file name
 * @return the full file name, or null if no file found
 */
private static String getSoundFileName(String filename) {
	String wav = String.format("%s.wav", filename), mp3 = String.format("%s.mp3", filename);
	File skinDir = SkinService.skin.getDirectory();
	if (skinDir != null) {
		File skinWAV = new File(skinDir, wav), skinMP3 = new File(skinDir, mp3);
		if (skinWAV.isFile())
			return skinWAV.getAbsolutePath();
		if (skinMP3.isFile())
			return skinMP3.getAbsolutePath();
	}
	if (ResourceLoader.resourceExists(wav))
		return wav;
	if (ResourceLoader.resourceExists(mp3))
		return mp3;
	return null;
}
 
Example #4
Source File: Fonts.java    From opsu-dance with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Initializes all fonts.
 * @throws SlickException if ASCII glyphs could not be loaded
 * @throws FontFormatException if any font stream data does not contain the required font tables
 * @throws IOException if a font stream cannot be completely read
 */
public static void init() throws SlickException, FontFormatException, IOException {
	float fontBase = 12f * GameImage.getUIscale();
	Font javaFont = Font.createFont(Font.TRUETYPE_FONT, ResourceLoader.getResourceAsStream(Constants.FONT_NAME));
	Font font = javaFont.deriveFont(Font.PLAIN, (int) (fontBase * 4 / 3));
	DEFAULT = new UnicodeFont(font);
	BOLD = new UnicodeFont(font.deriveFont(Font.BOLD));
	XLARGE = new UnicodeFont(font.deriveFont(fontBase * 3));
	LARGE = new UnicodeFont(font.deriveFont(fontBase * 2));
	MEDIUM = new UnicodeFont(font.deriveFont(fontBase * 3 / 2));
	MEDIUMBOLD = new UnicodeFont(font.deriveFont(Font.BOLD, fontBase * 3 / 2));
	SMALL = new UnicodeFont(font.deriveFont(fontBase));
	SMALLBOLD = new UnicodeFont(font.deriveFont(Font.BOLD, fontBase));
	ColorEffect colorEffect = new ColorEffect();
	loadFont(DEFAULT, colorEffect);
	loadFont(BOLD, colorEffect);
	loadFont(XLARGE, colorEffect);
	loadFont(LARGE, colorEffect);
	loadFont(MEDIUM, colorEffect);
	loadFont(MEDIUMBOLD, colorEffect);
	loadFont(SMALL, colorEffect);
	loadFont(SMALLBOLD, colorEffect);
}
 
Example #5
Source File: FEResources.java    From FEMultiplayer with GNU General Public License v3.0 6 votes vote down vote up
public static void loadResources() {
	try {
		//Load bitmap fonts
		loadBitmapFonts();
		
		// Textures
		textures.put("whoops", new AnimationData("res/whoops.png"));
		loadTextures();	
		//load audio
		audio.put("miss", AudioLoader.getAudio("WAV",
				ResourceLoader.getResourceAsStream("res/sfx/miss.wav")));
		
	} catch (IOException e) {
		int max = GL11.glGetInteger(GL11.GL_MAX_TEXTURE_SIZE);
		System.out.println(max);
		e.printStackTrace();
	}
	System.gc();
}
 
Example #6
Source File: FEResources.java    From FEMultiPlayer-V2 with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Load resources.
 */
public static void loadResources() {
	try {
		//Load bitmap fonts
		loadBitmapFonts();
		
		// Textures
		textures.put("whoops", new AnimationData("res/whoops.png"));
		loadTextures();	
		//load audio
		audio.put("miss", AudioLoader.getAudio("WAV",
				ResourceLoader.getResourceAsStream("res/sfx/miss.wav")));
		
	} catch (IOException e) {
		int max = GL11.glGetInteger(GL11.GL_MAX_TEXTURE_SIZE);
		System.out.println(max);
		e.printStackTrace();
	}
	System.gc();
}
 
Example #7
Source File: FEResources.java    From FEMultiPlayer-V2 with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the texture data.
 *
 * @param string the string
 * @return the texture data
 */
public static AnimationData getTextureData(String string) {
	AnimationData t = textures.get(string);
	if(t != null) {
		return t;
	} else {
		//try to get it, in case we forgot
		System.err.println("Warn: " + string + " not explicitly defined");
		for(String loc: searchFolders){
			if(ResourceLoader.resourceExists("res/" + loc + "/" + string + ".png")){
				AnimationData txt = new AnimationData("res/" + loc + "/" + string + ".png");
				textures.put(string, txt);
				return txt;
			}
			
		}
		return textures.get("whoops");
	}
}
 
Example #8
Source File: FEResources.java    From FEMultiPlayer-V2 with GNU General Public License v3.0 6 votes vote down vote up
/**
	 * Gets the audio.
	 *
	 * @param name the name
	 * @return the audio
	 */
	public static Audio getAudio(String name) {
		Audio a = audio.get(name);
		if(a == null) {
//			System.err.println("Warn: " + name + " not explicitly defined");
			try{
				Audio b = AudioLoader.getAudio("WAV",
						ResourceLoader.getResourceAsStream("res/sfx/"+name+".wav"));
				audio.put(name, b);
				return b;
			} catch (Exception e){
				return null;
			}
		} else {
			return a;
		}
	}
 
Example #9
Source File: Options.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Loads the skin given by the current skin directory.
 * If the directory is invalid, the default skin will be loaded.
 */
public static void loadSkin() {
	File skinDir = getSkinDir();
	if (skinDir == null)  // invalid skin name
		skinName = Skin.DEFAULT_SKIN_NAME;

	// set skin and modify resource locations
	ResourceLoader.removeAllResourceLocations();
	if (skinDir == null)
		skin = new Skin(null);
	else {
		// load the skin
		skin = SkinLoader.loadSkin(skinDir);
		ResourceLoader.addResourceLocation(new FileSystemLocation(skinDir));
	}
	ResourceLoader.addResourceLocation(new ClasspathLocation());
	ResourceLoader.addResourceLocation(new FileSystemLocation(new File(".")));
	ResourceLoader.addResourceLocation(new FileSystemLocation(new File("./res/")));
}
 
Example #10
Source File: SoundController.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the sound file name, with extension, by first looking through
 * the skins directory and then the default resource locations.
 * @param filename the base file name
 * @return the full file name, or null if no file found
 */
private static String getSoundFileName(String filename) {
	String wav = String.format("%s.wav", filename), mp3 = String.format("%s.mp3", filename);
	File skinDir = Options.getSkin().getDirectory();
	if (skinDir != null) {
		File skinWAV = new File(skinDir, wav), skinMP3 = new File(skinDir, mp3);
		if (skinWAV.isFile())
			return skinWAV.getAbsolutePath();
		if (skinMP3.isFile())
			return skinMP3.getAbsolutePath();
	}
	if (ResourceLoader.resourceExists(wav))
		return wav;
	if (ResourceLoader.resourceExists(mp3))
		return mp3;
	return null;
}
 
Example #11
Source File: FEResources.java    From FEMultiplayer with GNU General Public License v3.0 6 votes vote down vote up
public static AnimationData getTextureData(String string) {
	AnimationData t = textures.get(string);
	if(t != null) {
		return t;
	} else {
		//try to get it, in case we forgot
		System.err.println("Warn: " + string + " not explicitly defined");
		for(String loc: searchFolders){
			if(ResourceLoader.resourceExists("res/" + loc + "/" + string + ".png")){
				AnimationData txt = new AnimationData("res/" + loc + "/" + string + ".png");
				textures.put(string, txt);
				return txt;
			}
			
		}
		return textures.get("whoops");
	}
}
 
Example #12
Source File: FEResources.java    From FEMultiplayer with GNU General Public License v3.0 6 votes vote down vote up
public static Audio getAudio(String name) {
		Audio a = audio.get(name);
		if(a == null) {
//			System.err.println("Warn: " + name + " not explicitly defined");
			try{
				Audio b = AudioLoader.getAudio("WAV",
						ResourceLoader.getResourceAsStream("res/sfx/"+name+".wav"));
				audio.put(name, b);
				return b;
			} catch (Exception e){
				return null;
			}
		} else {
			return a;
		}
	}
 
Example #13
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 #14
Source File: XMLPackedSheet.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Create a new XML packed sheet from the XML output by the slick tool
 * 
 * @param imageRef The reference to the image
 * @param xmlRef The reference to the XML
 * @throws SlickException Indicates a failure to parse the XML or read the image
 */
public XMLPackedSheet(String imageRef, String xmlRef) throws SlickException
{
	image = new Image(imageRef, false, Image.FILTER_NEAREST);

	try {
		DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
		Document doc = builder.parse(ResourceLoader.getResourceAsStream(xmlRef));
		
		NodeList list = doc.getElementsByTagName("sprite");
		for (int i=0;i<list.getLength();i++) {
			Element element = (Element) list.item(i);
			
			String name = element.getAttribute("name");
			int x = Integer.parseInt(element.getAttribute("x"));
			int y = Integer.parseInt(element.getAttribute("y"));
			int width = Integer.parseInt(element.getAttribute("width"));
			int height = Integer.parseInt(element.getAttribute("height"));
			
			sprites.put(name, image.getSubImage(x,y,width,height));
		}
	} catch (Exception e) {
		throw new SlickException("Failed to parse sprite sheet XML", e);
	}
}
 
Example #15
Source File: SkinService.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Loads the skin given by the current skin directory.
 * If the directory is invalid, the default skin will be loaded.
 */
public void loadSkin() {
	File skinDir = getCurrentSkinDirectory();
	if (skinDir == null) {
		// invalid skin name
		usedSkinName = Skin.DEFAULT_SKIN_NAME;
	}

	// create available skins list
	File[] dirs = SkinLoader.getSkinDirectories(config.skinRootDir);
	availableSkinDirectories = new String[dirs.length + 1];
	availableSkinDirectories[0] = Skin.DEFAULT_SKIN_NAME;
	for (int i = 0; i < dirs.length; i++) {
		availableSkinDirectories[i + 1] = dirs[i].getName();
	}

	if (this.lastSkinLocation != null) {
		ResourceLoader.removeResourceLocation(this.lastSkinLocation);
		this.lastSkinLocation = null;
	}
	if (skinDir == null) {
		skin = new Skin(null);
		return;
	}

	// load the skin
	skin = SkinLoader.loadSkin(skinDir);
	this.lastSkinLocation = new FileSystemLocation(skinDir);
	ResourceLoader.addPrimaryResourceLocation(this.lastSkinLocation);
}
 
Example #16
Source File: FEMultiplayer.java    From FEMultiPlayer-V2 with GNU General Public License v3.0 5 votes vote down vote up
public void init(int width, int height, String name) {
	super.init(width, height, name);
	Player p1 = new Player("Player", (byte) 0);
	localPlayer = p1;
	ByteBuffer icon16, icon32;
	icon16 = icon32 = null;
	try {
		icon16 = ByteBuffer.wrap(TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/gui/icon16.png")).getTextureData());
		icon32 = ByteBuffer.wrap(TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/gui/icon32.png")).getTextureData());
	} catch (IOException e) {
		e.printStackTrace();
	}
	Display.setIcon(new ByteBuffer[]{icon16, icon32});
	FEResources.loadResources();
	FEResources.loadBitmapFonts();
	WeaponFactory.loadWeapons();
	UnitFactory.loadUnits();
	p1.getParty().setColor(Party.TEAM_BLUE);
	
	/* OpenGL final setup */
	glEnable(GL_LINE_SMOOTH);
	
	UnitFactory.getUnit("Lyn");
	connect = new ConnectStage();
	setCurrentStage(new TitleStage());
	SoundTrack.loop("main");
	
}
 
Example #17
Source File: BitmapFont.java    From FEMultiplayer with GNU General Public License v3.0 5 votes vote down vote up
public BitmapFont(String texName) {
	try {
		texture = TextureLoader.getTexture("PNG", 
				ResourceLoader.getResourceAsStream("res/fonts/"+texName+".png"));
	} catch (IOException e) {
		e.printStackTrace();
	}
	glyphs = new HashMap<Character, Glyph>();
}
 
Example #18
Source File: Tileset.java    From FEMultiplayer with GNU General Public License v3.0 5 votes vote down vote up
public Tileset(String path, int tileWidth, int tileHeight) {
	try {
		tileset = TextureLoader.getTexture("PNG",
				ResourceLoader.getResourceAsStream(path));
		System.out.println("Loaded: "+path);
	} catch (IOException e) {
		e.printStackTrace();
	}
	this.tileWidth = tileWidth;
	this.tileHeight = tileHeight;
	width = tileset.getImageWidth();
	height = tileset.getImageHeight();
}
 
Example #19
Source File: GameContainer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Get the build number of slick 
 * 
 * @return The build number of slick
 */
public static int getBuildVersion() {
	try {
		Properties props = new Properties();
		props.load(ResourceLoader.getResourceAsStream("version"));
		
		int build = Integer.parseInt(props.getProperty("build"));
		Log.info("Slick Build #"+build);
		
		return build;
	} catch (Exception e) {
		Log.error("Unable to determine Slick build number");
		return -1;
	}
}
 
Example #20
Source File: CursorLoader.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Get a cursor based on a image reference on the classpath
 * 
 * @param ref The reference to the image to be loaded
 * @param x The x-coordinate of the cursor hotspot (left -> right)
 * @param y The y-coordinate of the cursor hotspot (bottom -> top)
 * @return The create cursor
 * @throws IOException Indicates a failure to load the image
 * @throws LWJGLException Indicates a failure to create the hardware cursor
 */
public Cursor getCursor(String ref,int x,int y) throws IOException, LWJGLException {
	LoadableImageData imageData = null;
	
	imageData = ImageDataFactory.getImageDataFor(ref);
	imageData.configureEdging(false);
	
	ByteBuffer buf = imageData.loadImage(ResourceLoader.getResourceAsStream(ref), true, true, null);
	for (int i=0;i<buf.limit();i+=4) {
		byte red = buf.get(i);
		byte green = buf.get(i+1);
		byte blue = buf.get(i+2);
		byte alpha = buf.get(i+3);
		
		buf.put(i+2, red);
		buf.put(i+1, green);
		buf.put(i, blue);
		buf.put(i+3, alpha);
	}
	
	try {
		int yspot = imageData.getHeight() - y - 1;
		if (yspot < 0) {
			yspot = 0;
		}
		
		return new Cursor(imageData.getTexWidth(), imageData.getTexHeight(), x, yspot, 1, buf.asIntBuffer(), null);
	} catch (Throwable e) {
		Log.info("Chances are you cursor is too small for this platform");
		throw new LWJGLException(e);
	}
}
 
Example #21
Source File: SoundURLTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 */
public void init(GameContainer container) throws SlickException {
	sound = new Sound(ResourceLoader.getResource("testdata/restart.ogg"));
	charlie = new Sound(ResourceLoader.getResource("testdata/cbrown01.wav"));
	engine = new Sound(ResourceLoader.getResource("testdata/engine.wav"));
	//music = musica = new Music("testdata/SMB-X.XM");
	music = musica = new Music(ResourceLoader.getResource("testdata/restart.ogg"), false);
	musicb = new Music(ResourceLoader.getResource("testdata/kirby.ogg"), false);
	burp = new Sound(ResourceLoader.getResource("testdata/burp.aif"));
}
 
Example #22
Source File: BigImage.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Create a new big image by loading it from the specified reference
 * 
 * @param ref The reference to the image to load
 * @param filter The image filter to apply (@see #Image.FILTER_NEAREST)
 * @param tileSize The maximum size of the tiles to use to build the bigger image
 * @throws SlickException Indicates we were unable to locate the resource
 */
private void build(String ref, int filter, int tileSize) throws SlickException {
	try {
		final LoadableImageData data = ImageDataFactory.getImageDataFor(ref);
		final ByteBuffer imageBuffer = data.loadImage(ResourceLoader.getResourceAsStream(ref), false, null);
		build(data, imageBuffer, filter, tileSize);
	} catch (IOException e) {
		throw new SlickException("Failed to load: "+ref, e);
	}
}
 
Example #23
Source File: MiscUtils.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Properties get() {
	Properties props = new Properties();
	try {
		props.load(ResourceLoader.getResourceAsStream(Constants.VERSION_FILE));
	} catch (IOException e) {
		Log.error("Could not read version file", e);
	}
	return props;
}
 
Example #24
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 #25
Source File: SoundTrack.java    From FEMultiplayer with GNU General Public License v3.0 5 votes vote down vote up
public static void restart(){
	if(!enabled) return;
	try {
		Audio a = AudioLoader.getStreamingAudio("OGG", 
				ResourceLoader.getResource("res/music/"+current+".ogg"));
		a.playAsMusic(1, 1, true);
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
}
 
Example #26
Source File: SoundTrack.java    From FEMultiplayer with GNU General Public License v3.0 5 votes vote down vote up
public static void loop(String name){
	if(!enabled) return;
	if(name.equals(current)) return;
	try {
		current = name;
		Audio a = AudioLoader.getStreamingAudio("OGG", 
				ResourceLoader.getResource("res/music/"+name+".ogg"));
		a.playAsMusic(1, 1, true);
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
Example #27
Source File: FEMultiplayer.java    From FEMultiplayer with GNU General Public License v3.0 5 votes vote down vote up
public void init(int width, int height, String name) {
	super.init(width, height, name);
	Player p1 = new Player("Player", (byte) 0);
	localPlayer = p1;
	ByteBuffer icon16, icon32;
	icon16 = icon32 = null;
	try {
		icon16 = ByteBuffer.wrap(TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/gui/icon16.png")).getTextureData());
		icon32 = ByteBuffer.wrap(TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/gui/icon32.png")).getTextureData());
	} catch (IOException e) {
		e.printStackTrace();
	}
	Display.setIcon(new ByteBuffer[]{icon16, icon32});
	FEResources.loadResources();
	FEResources.loadBitmapFonts();
	WeaponFactory.loadWeapons();
	UnitFactory.loadUnits();
	p1.getParty().setColor(Party.TEAM_BLUE);
	
	/* OpenGL final setup */
	glEnable(GL_LINE_SMOOTH);
	
	UnitFactory.getUnit("Lyn");
	connect = new ConnectStage();
	setCurrentStage(new TitleStage());
	messages = new CopyOnWriteArrayList<Message>();
	SoundTrack.loop("main_theme");
	
}
 
Example #28
Source File: MusicController.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Plays an audio file at the preview position.
 * If the audio file is already playing, then nothing will happen.
 * @param beatmap the beatmap to play
 * @param loop whether or not to loop the track
 * @param preview whether to start at the preview time (true) or beginning (false)
 */
public static void play(final Beatmap beatmap, final boolean loop, final boolean preview) {
	// new track: load and play
	if (lastBeatmap == null || !beatmap.audioFilename.equals(lastBeatmap.audioFilename)) {
		final File audioFile = beatmap.audioFilename;
		if (!audioFile.isFile() && !ResourceLoader.resourceExists(audioFile.getPath())) {
			UI.getNotificationManager().sendBarNotification(String.format("Could not find track '%s'.", audioFile.getName()));
			return;
		}

		reset();
		Utils.gc(false);

		switch (BeatmapParser.getExtension(beatmap.audioFilename.getName())) {
		case "ogg":
		case "mp3":
			trackLoader = new Thread() {
				@Override
				public void run() {
					loadTrack(audioFile, (preview) ? beatmap.previewTime : 0, loop);
				}
			};
			trackLoader.start();
			break;
		default:
			break;
		}
	}

	// new track position: play at position
	else if (beatmap.previewTime != lastBeatmap.previewTime)
		playAt(beatmap.previewTime, loop);

	lastBeatmap = beatmap;
}
 
Example #29
Source File: Fonts.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Initializes all fonts.
 * @throws SlickException if ASCII glyphs could not be loaded
 * @throws FontFormatException if any font stream data does not contain the required font tables
 * @throws IOException if a font stream cannot be completely read
 */
public static void init() throws SlickException, FontFormatException, IOException {
	float fontBase = 12f * GameImage.getUIscale();
	Font javaFontMain = Font.createFont(Font.TRUETYPE_FONT, ResourceLoader.getResourceAsStream(Options.FONT_MAIN));
	Font javaFontBold = Font.createFont(Font.TRUETYPE_FONT, ResourceLoader.getResourceAsStream(Options.FONT_BOLD));
	Font javaFontCJK = Font.createFont(Font.TRUETYPE_FONT, ResourceLoader.getResourceAsStream(Options.FONT_CJK));
	Font fontMain = javaFontMain.deriveFont(Font.PLAIN, (int) (fontBase * 4 / 3));
	Font fontBold = javaFontBold.deriveFont(Font.PLAIN, (int) (fontBase * 4 / 3));
	Font fontCJK = javaFontCJK.deriveFont(Font.PLAIN, (int) (fontBase * 4 / 3));
	DEFAULT = new UnicodeFont(fontMain);
	BOLD = new UnicodeFont(fontBold.deriveFont(Font.BOLD));
	XLARGE = new UnicodeFont(fontMain.deriveFont(fontBase * 3));
	LARGE = new UnicodeFont(fontMain.deriveFont(fontBase * 2));
	MEDIUM = new UnicodeFont(fontMain.deriveFont(fontBase * 3 / 2));
	MEDIUMBOLD = new UnicodeFont(fontBold.deriveFont(Font.BOLD, fontBase * 3 / 2));
	SMALL = new UnicodeFont(fontMain.deriveFont(fontBase));
	SMALLBOLD = new UnicodeFont(fontBold.deriveFont(Font.BOLD, fontBase));
	ColorEffect colorEffect = new ColorEffect();
	loadFont(DEFAULT, colorEffect, new UnicodeFont(fontCJK));
	loadFont(BOLD, colorEffect, new UnicodeFont(fontCJK.deriveFont(Font.BOLD)));
	loadFont(XLARGE, colorEffect, new UnicodeFont(fontCJK.deriveFont(fontBase * 3)));
	loadFont(LARGE, colorEffect, new UnicodeFont(fontCJK.deriveFont(fontBase * 2)));
	loadFont(MEDIUM, colorEffect, new UnicodeFont(fontCJK.deriveFont(fontBase * 3 / 2)));
	loadFont(MEDIUMBOLD, colorEffect, new UnicodeFont(fontCJK.deriveFont(Font.BOLD, fontBase * 3 / 2)));
	loadFont(SMALL, colorEffect, new UnicodeFont(fontCJK.deriveFont(fontBase)));
	loadFont(SMALLBOLD, colorEffect, new UnicodeFont(fontCJK.deriveFont(Font.BOLD, fontBase)));
}
 
Example #30
Source File: AnimationData.java    From FEMultiplayer with GNU General Public License v3.0 5 votes vote down vote up
public Texture getTexture() {
	try {
		Texture t = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(path));
		System.out.println("Loaded "+path);
		return t;
	} catch (IOException e) {
		System.err.println("Texture not found: "+path);
		e.printStackTrace();
		return null;
	}
}