Search in sources :

Example 1 with MapObjectsDecoder

use of org.apollo.cache.map.MapObjectsDecoder in project apollo by apollo-rsps.

the class WorldObjectsDecoder method run.

/**
 * Decode the {@code MapObject}s from the cache and register them with the world.
 */
@Override
public void run() {
    Map<Integer, MapIndex> mapIndices = MapIndex.getIndices();
    try {
        for (MapIndex index : mapIndices.values()) {
            MapObjectsDecoder decoder = MapObjectsDecoder.create(fs, index);
            List<MapObject> objects = decoder.decode();
            int mapX = index.getX(), mapY = index.getY();
            for (MapObject object : objects) {
                Position position = new Position(mapX + object.getLocalX(), mapY + object.getLocalY(), object.getHeight());
                StaticGameObject gameObject = new StaticGameObject(world, object.getId(), position, object.getType(), object.getOrientation());
                regionRepository.fromPosition(position).addEntity(gameObject, false);
            }
        }
    } catch (IOException ex) {
        throw new UncheckedIOException(ex);
    }
}
Also used : Position(org.apollo.game.model.Position) MapObjectsDecoder(org.apollo.cache.map.MapObjectsDecoder) UncheckedIOException(java.io.UncheckedIOException) MapIndex(org.apollo.cache.map.MapIndex) StaticGameObject(org.apollo.game.model.entity.obj.StaticGameObject) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) MapObject(org.apollo.cache.map.MapObject)

Aggregations

IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 MapIndex (org.apollo.cache.map.MapIndex)1 MapObject (org.apollo.cache.map.MapObject)1 MapObjectsDecoder (org.apollo.cache.map.MapObjectsDecoder)1 Position (org.apollo.game.model.Position)1 StaticGameObject (org.apollo.game.model.entity.obj.StaticGameObject)1