use of de.gurkenlabs.litiengine.graphics.Spritesheet in project litiengine by gurkenlabs.
the class CreaturePanel method loadAvailableCreatureSprites.
private void loadAvailableCreatureSprites() {
Map<String, String> m = new TreeMap<>();
for (Spritesheet s : Spritesheet.getSpritesheets()) {
String creatureSpriteName = getCreatureSpriteName(s.getName());
if (creatureSpriteName != null) {
if (!m.containsKey(creatureSpriteName)) {
m.put(creatureSpriteName, s.getName());
}
}
}
this.comboBoxSpriteSheets.removeAllItems();
for (Map.Entry<String, String> entry : m.entrySet()) {
JLabel label = new JLabel();
label.setText(entry.getKey());
String value = entry.getValue();
Spritesheet sprite = Spritesheet.find(value);
if (sprite != null && sprite.getTotalNumberOfSprites() > 0) {
BufferedImage img = sprite.getSprite(0);
BufferedImage scaled;
String cacheKey = "iconx24" + sprite.getName();
if (ImageCache.SPRITES.containsKey(cacheKey)) {
scaled = ImageCache.SPRITES.get(cacheKey);
} else {
if (img != null) {
scaled = ImageProcessing.scaleImage(img, 24, 24, true);
} else {
scaled = ImageProcessing.getCompatibleImage(24, 24);
}
ImageCache.SPRITES.put(cacheKey, scaled);
}
if (scaled != null) {
label.setIcon(new ImageIcon(scaled));
}
}
this.comboBoxSpriteSheets.addItem(label);
}
}
use of de.gurkenlabs.litiengine.graphics.Spritesheet in project litiengine by gurkenlabs.
the class Game method load.
public static void load(final String gameResourceFile) {
final GameData file = GameData.load(gameResourceFile);
if (file == null) {
return;
}
int mapCnt = 0;
for (final IMap m : file.getMaps()) {
if (getMaps().stream().anyMatch(x -> x.getFileName().equals(m.getFileName()))) {
continue;
}
getMaps().add(m);
mapCnt++;
}
log.log(Level.INFO, "{0} maps loaded from {1}", new Object[] { mapCnt, gameResourceFile });
int tileCnt = 0;
for (final ITileset tileset : file.getTilesets()) {
if (getTilesets().stream().anyMatch(x -> x.getName().equals(tileset.getName()))) {
continue;
}
getTilesets().add(tileset);
tileCnt++;
}
log.log(Level.INFO, "{0} tilesets loaded from {1}", new Object[] { tileCnt, gameResourceFile });
final List<Spritesheet> loadedSprites = new ArrayList<>();
for (final SpriteSheetInfo tileset : file.getSpriteSheets()) {
final Spritesheet sprite = Spritesheet.load(tileset);
loadedSprites.add(sprite);
}
log.log(Level.INFO, "{0} spritesheets loaded from {1}", new Object[] { loadedSprites.size(), gameResourceFile });
int spriteload = 0;
for (final Spritesheet s : loadedSprites) {
for (int i = 0; i < s.getRows() * s.getColumns(); i++) {
BufferedImage sprite = s.getSprite(i);
if (sprite != null) {
spriteload++;
}
}
}
log.log(Level.INFO, "{0} sprites loaded to memory", new Object[] { spriteload });
}
Aggregations