use of de.gurkenlabs.litiengine.sound.Sound in project litiengine by gurkenlabs.
the class ResourcesTests method testSoundResources.
@Test
void testSoundResources() {
Sound sound = Resources.sounds().get("de/gurkenlabs/litiengine/resources/bip.ogg");
Sound nonExisting = Resources.sounds().get("randomname.mp3");
assertNotNull(sound);
assertEquals("bip", sound.getName());
assertNull(nonExisting);
}
use of de.gurkenlabs.litiengine.sound.Sound in project litiengine by gurkenlabs.
the class SpeechBubbleTests method testSetTypeSound.
@Test
void testSetTypeSound() {
Sound s1 = Resources.sounds().get("de/gurkenlabs/litiengine/resources/bip.ogg");
Sound s2 = Resources.sounds().get("de/gurkenlabs/litiengine/resources/bop.ogg");
// act
SpeechBubble bubble = new SpeechBubble(entity, "test");
bubble.setTypeSound(s1);
// assert
assertEquals(s1, bubble.getTypeSound());
// act
bubble.setTypeSound(s2);
// assert
assertEquals(s2, bubble.getTypeSound());
assertNotEquals(s1, s2);
}
use of de.gurkenlabs.litiengine.sound.Sound in project litiengine by gurkenlabs.
the class Resources method load.
/**
* Load {@code Spritesheets}, {@code Tilesets} and {@code Maps} from a game resource file created with the utiLITI
* editor. After loading, these resources can be accessed via this API (e.g. {@code Resources.maps().get("mapname")}.
*
* @param gameResourceFile
* The URL to the game resource file
*/
public static void load(final URL gameResourceFile) {
final long loadStart = System.nanoTime();
final ResourceBundle file = ResourceBundle.load(gameResourceFile);
if (file == null) {
return;
}
file.getMaps().parallelStream().forEach(m -> Resources.maps().add(m.getName(), m));
log.log(Level.INFO, "{0} maps loaded from {1}", new Object[] { file.getMaps().size(), gameResourceFile });
file.getBluePrints().parallelStream().forEach(m -> Resources.blueprints().add(m.getName(), m));
log.log(Level.INFO, "{0} blueprints loaded from {1}", new Object[] { file.getBluePrints().size(), gameResourceFile });
int tileCnt = 0;
for (final Tileset tileset : file.getTilesets()) {
if (Resources.tilesets().contains(tileset.getName())) {
continue;
}
Resources.tilesets().add(tileset.getName(), tileset);
tileCnt++;
}
log.log(Level.INFO, "{0} tilesets loaded from {1}", new Object[] { tileCnt, gameResourceFile });
final List<Spritesheet> loadedSprites = Collections.synchronizedList(new ArrayList<>());
file.getSpriteSheets().parallelStream().forEach(spriteSheetInfo -> {
final Spritesheet sprite = Resources.spritesheets().load(spriteSheetInfo);
loadedSprites.add(sprite);
});
log.log(Level.INFO, "{0} spritesheets loaded from {1}", new Object[] { loadedSprites.size(), gameResourceFile });
final List<Sound> loadedSounds = Collections.synchronizedList(new ArrayList<>());
file.getSounds().parallelStream().forEach(soundResource -> {
final Sound sound = Resources.sounds().load(soundResource);
loadedSounds.add(sound);
});
log.log(Level.INFO, "{0} sounds loaded from {1}", new Object[] { loadedSounds.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 });
for (final EmitterData emitter : file.getEmitters()) {
EmitterLoader.load(emitter);
}
final double loadTime = TimeUtilities.nanoToMs(System.nanoTime() - loadStart);
log.log(Level.INFO, "loading game resources from {0} took {1} ms", new Object[] { gameResourceFile, loadTime });
}
use of de.gurkenlabs.litiengine.sound.Sound in project litiengine by gurkenlabs.
the class Sounds method load.
/**
* Loads a sound from the specified XML resource.
*
* @param resource
* The XML resource that contains the sound as Base64 string.
*
* @return The {@code Sound} instance loaded from the specified resource.
*
* @see Codec#decode(String)
*/
public Sound load(final SoundResource resource) {
byte[] data = Codec.decode(resource.getData());
ByteArrayInputStream input = new ByteArrayInputStream(data);
Sound sound;
try {
sound = new Sound(input, resource.getName());
this.add(resource.getName(), sound);
return sound;
} catch (IOException | UnsupportedAudioFileException e) {
log.log(Level.SEVERE, "The audio file {0} could not be loaded.", new Object[] { resource.getName() });
}
return null;
}
Aggregations