Rogue: Savage Rats, a retro-themed dungeon crawler
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
rogue-savage-rats/src/mightypork/rogue/fonts/FontBank.java

76 lines
1.3 KiB

package mightypork.rogue.fonts;
import java.util.HashMap;
import mightypork.rogue.AppAccess;
import mightypork.rogue.AppAdapter;
import mightypork.rogue.bus.events.ResourceLoadRequest;
import mightypork.utils.logging.Log;
import org.newdawn.slick.opengl.Texture;
/**
* Font loader and registry
*
* @author MightyPork
*/
public class FontBank extends AppAdapter {
private static final GLFont NULL_FONT = new NullFont();
public FontBank(AppAccess app) {
super(app);
}
private final HashMap<String, GLFont> fonts = new HashMap<String, GLFont>();
/**
* Load a {@link DeferredFont}
*
* @param key font key
* @param font font instance
*/
public void loadFont(String key, DeferredFont font)
{
bus().queue(new ResourceLoadRequest(font));
fonts.put(key, font);
}
/**
* Add a {@link GLFont} to the bank.
*
* @param key font key
* @param font font instance
*/
public void addFont(String key, GLFont font)
{
fonts.put(key, font);
}
/**
* Get a loaded {@link Texture}
*
* @param key texture key
* @return the texture
*/
public GLFont getFont(String key)
{
final GLFont f = fonts.get(key);
if (f == null) {
Log.w("There's no font called " + key + "!");
return NULL_FONT;
}
return f;
}
}