use of com.b3dgs.lionengine.io.FileReading in project lionengine by b3dgs.
the class HandlerPersisterTest method testWithMapCollidable.
/**
* Test with map and collidable.
*
* @throws IOException If error.
*/
@Test
void testWithMapCollidable() throws IOException {
services.add(new Camera());
final MapTile map = services.add(new MapTileGame());
map.create(16, 16, 5, 5);
final Featurable featurable = factory.create(Medias.create("ObjectColl.xml"));
featurable.getFeature(Transformable.class).teleport(16, 32);
handler.add(featurable);
handler.update(1.0);
final HandlerPersister persister = new HandlerPersister(services);
final Media media = Medias.create("persister.data");
try (FileWriting writing = new FileWriting(media)) {
persister.save(writing);
}
final Services services2 = new Services();
services2.add(new Camera());
services2.add(new Factory(services2));
services2.add(map);
final Handler handler2 = services2.add(new Handler(services2));
final HandlerPersister persister2 = new HandlerPersister(services2);
try (FileReading reading = new FileReading(media)) {
persister2.load(reading);
}
handler2.update(1.0);
final Featurable featurable2 = handler2.values().iterator().next();
final Transformable transformable = featurable2.getFeature(Transformable.class);
assertEquals(16.0, transformable.getX());
assertEquals(32.0, transformable.getY());
assertTrue(media.getFile().delete());
}
use of com.b3dgs.lionengine.io.FileReading in project lionengine by b3dgs.
the class UtilMapTilePersister method loadMap.
/**
* Load map from file.
*
* @param level The level media.
* @return The loaded map.
* @throws IOException If error.
*/
public static MapTileGame loadMap(Media level) throws IOException {
final MapTileGame map = new MapTileGame();
map.addFeature(new MapTilePersisterModel());
try (FileReading input = new FileReading(level)) {
map.getFeature(MapTilePersister.class).load(input);
}
return map;
}
use of com.b3dgs.lionengine.io.FileReading in project lionengine by b3dgs.
the class HandlerPersisterTest method testWithoutMap.
/**
* Test without map.
*
* @throws IOException If error.
*/
@Test
void testWithoutMap() throws IOException {
final Featurable featurable = factory.create(Medias.create("ObjectFeatures.xml"));
featurable.getFeature(Transformable.class).teleport(1, 2);
handler.add(featurable);
handler.add(factory.create(Medias.create("ObjectIdentifiable.xml")));
handler.update(1.0);
final HandlerPersister persister = new HandlerPersister(services);
final Media media = Medias.create("persister.data");
try (FileWriting writing = new FileWriting(media)) {
persister.save(writing);
}
final Services services2 = new Services();
services2.add(new Factory(services2));
final Handler handler2 = services2.add(new Handler(services2));
final HandlerPersister persister2 = new HandlerPersister(services2);
try (FileReading reading = new FileReading(media)) {
persister2.load(reading);
}
handler2.update(1.0);
final Transformable transformable = handler2.get(Transformable.class).iterator().next();
final Iterator<Featurable> iterable = handler2.values().iterator();
iterable.next();
assertTrue(iterable.hasNext());
assertEquals(1.0, transformable.getX());
assertEquals(2.0, transformable.getY());
assertTrue(media.getFile().delete());
}
use of com.b3dgs.lionengine.io.FileReading in project lionengine by b3dgs.
the class HandlerPersisterTest method testCleanLoad.
/**
* Test clean on load.
*
* @throws IOException If error.
*/
@Test
void testCleanLoad() throws IOException {
final Featurable featurable = factory.create(Medias.create("ObjectFeatures.xml"));
handler.add(featurable);
handler.update(1.0);
final HandlerPersister persister = new HandlerPersister(services);
final Media media = Medias.create("persister.data");
try (FileWriting writing = new FileWriting(media)) {
persister.save(writing);
}
final Services services2 = new Services();
services2.add(new Factory(services2));
final Handler handler2 = services2.add(new Handler(services2));
final HandlerPersister persister2 = new HandlerPersister(services2);
try (FileReading reading = new FileReading(media)) {
persister2.load(reading);
}
handler2.update(1.0);
assertEquals(1, handler2.size());
try (FileReading reading = new FileReading(media)) {
persister2.load(reading);
}
handler2.update(1.0);
assertEquals(1, handler2.size());
}
use of com.b3dgs.lionengine.io.FileReading in project lionengine by b3dgs.
the class HandlerPersisterTest method testWithMap.
/**
* Test with map.
*
* @throws IOException If error.
*/
@Test
void testWithMap() throws IOException {
services.add(new Camera());
final MapTile map = services.add(new MapTileGame());
map.create(16, 16, 5, 5);
final Featurable featurable = factory.create(Medias.create("ObjectFeatures.xml"));
featurable.getFeature(Transformable.class).teleport(16, 32);
handler.add(featurable);
handler.update(1.0);
final HandlerPersister persister = new HandlerPersister(services);
final Media media = Medias.create("persister.data");
try (FileWriting writing = new FileWriting(media)) {
persister.save(writing);
}
final Services services2 = new Services();
services2.add(new Factory(services2));
services2.add(map);
final Handler handler2 = services2.add(new Handler(services2));
final HandlerPersister persister2 = new HandlerPersister(services2);
try (FileReading reading = new FileReading(media)) {
persister2.load(reading);
}
handler2.update(1.0);
final Featurable featurable2 = handler2.values().iterator().next();
final Transformable transformable = featurable2.getFeature(Transformable.class);
assertEquals(16.0, transformable.getX());
assertEquals(32.0, transformable.getY());
assertTrue(media.getFile().delete());
}
Aggregations