Example usage for com.badlogic.gdx.utils ObjectMap values

List of usage examples for com.badlogic.gdx.utils ObjectMap values

Introduction

In this page you can find the example usage for com.badlogic.gdx.utils ObjectMap values.

Prototype

public Values<V> values() 

Source Link

Document

Returns an iterator for the values in the map.

Usage

From source file:com.betmansmall.game.gameLogic.mapLoader.MapLoader.java

License:Apache License

/** Loads the {@link TiledMap} from the given file. The file is resolved via the {@link FileHandleResolver} set in the
 * constructor of this class. By default it will resolve to an internal file.
 * @param fileName the filename//from w ww . j  a va 2s. com
 * @param parameters specifies whether to use y-up, generate mip maps etc.
 * @return the TiledMap */
public TiledMap load(String fileName, MapLoader.Parameters parameters) {
    try {
        this.convertObjectToTileSpace = parameters.convertObjectToTileSpace;
        this.flipY = parameters.flipY;
        FileHandle tmxFile = resolve(fileName);
        root = xml.parse(tmxFile);
        ObjectMap<String, Texture> textures = new ObjectMap<String, Texture>();
        Array<FileHandle> textureFiles = loadTilesets(root, tmxFile);
        textureFiles.addAll(loadImages(root, tmxFile));

        for (FileHandle textureFile : textureFiles) {
            Texture texture = new Texture(textureFile, parameters.generateMipMaps);
            texture.setFilter(parameters.textureMinFilter, parameters.textureMagFilter);
            textures.put(textureFile.path(), texture);
        }

        DirectImageResolver imageResolver = new DirectImageResolver(textures);
        TiledMap map = loadTilemap(root, tmxFile, imageResolver);
        map.setOwnedResources(textures.values().toArray());
        return map;
    } catch (IOException e) {
        throw new GdxRuntimeException("Couldn't load tilemap '" + fileName + "'", e);
    }
}

From source file:com.mobidevelop.maps.basic.BasicMapResources.java

License:Apache License

@Override
public void dispose() {
    for (ObjectMap<String, Object> entry : data.values()) {
        for (Object resource : entry.values()) {
            if (resource instanceof Disposable)
                ((Disposable) resource).dispose();
        }/*  w w  w  . jav  a  2 s.c  o m*/
    }
}

From source file:com.sasluca.lcl.ui.design.UIDesign.java

License:Apache License

public ObjectMap.Values getObjects() {
    return m_Objects.getValues();
}

From source file:com.sasluca.lcl.utils.collections.LCLMap.java

License:Apache License

public ObjectMap.Values<VALUE> getValues() {
    return m_ObjectMap.values();
}

From source file:com.skettios.loader.TmxMapLoaderFixed.java

License:Apache License

/**
 * Loads the {@link TiledMap} from the given file. The file is resolved via the {@link FileHandleResolver} set in the
 * constructor of this class. By default it will resolve to an internal file.
 *
 * @param fileName   the filename/*ww w  .  java  2s .  co  m*/
 * @param parameters specifies whether to use y-up, generate mip maps etc.
 * @return the TiledMap
 */
public TiledMap load(String fileName, TmxMapLoaderFixed.Parameters parameters) {
    try {
        this.convertObjectToTileSpace = parameters.convertObjectToTileSpace;
        FileHandle tmxFile = resolve(fileName);
        root = xml.parse(tmxFile);
        ObjectMap<String, Texture> textures = new ObjectMap<String, Texture>();
        Array<FileHandle> textureFiles = loadTilesets(root, tmxFile);
        textureFiles.addAll(loadImages(root, tmxFile));

        for (FileHandle textureFile : textureFiles) {
            Texture texture = new Texture(textureFile, parameters.generateMipMaps);
            texture.setFilter(parameters.textureMinFilter, parameters.textureMagFilter);
            textures.put(textureFile.path(), texture);
        }

        DirectImageResolver imageResolver = new DirectImageResolver(textures);
        TiledMap map = loadTilemap(root, tmxFile, imageResolver);
        map.setOwnedResources(textures.values().toArray());
        return map;
    } catch (IOException e) {
        throw new GdxRuntimeException("Couldn't load tilemap '" + fileName + "'", e);
    }
}

From source file:com.vlaaad.dice.game.config.abilities.Abilities.java

License:Open Source License

public Abilities(ObjectMap<String, Ability> data) {
    this.data = data;
    for (Ability a : data.values()) {
        Ability prev = byId.put(a.id, a);
        if (prev != null)
            throw new IllegalStateException("Ids of " + prev.name + " and " + a.name + " clash: " + a.id);
    }/*w  ww . j a  va2 s .  c  o  m*/
}

From source file:com.vlaaad.dice.game.config.items.Items.java

License:Open Source License

public Items(ObjectMap<String, Item> data) {
    this.data = data;
    for (Item a : data.values()) {
        if (a.id == null)
            throw new IllegalStateException("item " + a.name + " has no id!");
        Item prev = byId.put(a.id, a);/*from  ww w. j a va2  s.  c om*/
        if (prev != null)
            throw new IllegalStateException("Ids of " + prev.name + " and " + a.name + " clash: " + a.id);
    }
}

From source file:com.vlaaad.dice.game.config.professions.Professions.java

License:Open Source License

public Professions(ObjectMap<String, ProfessionDescription> data) {
    this.data = data;
    for (ProfessionDescription a : data.values()) {
        ProfessionDescription prev = byId.put(a.id, a);
        if (prev != null)
            throw new IllegalStateException("Ids of " + prev.name + " and " + a.name + " clash: " + a.id);
    }/*w  ww. j av  a  2s.  co  m*/
}

From source file:com.vlaaad.dice.game.config.purchases.PurchaseData.java

License:Open Source License

public static ObjectMap.Values<PurchaseInfo> infos() {
    return purchaseInfo.values();
}

From source file:com.vlaaad.dice.game.world.controllers.PveLoadLevelController.java

License:Open Source License

@Override
protected void start() {
    LevelDescription description = world.level;
    for (Map.Entry<Grid2D.Coordinate, String> entry : description.getElements(LevelElementType.tile)) {
        world.dispatcher.dispatch(LOAD_TILE,
                new TileInfo(entry.getKey().x(), entry.getKey().y(), entry.getValue()));
    }/*from   w  ww.  j av  a2 s.  co m*/
    ObjectMap<Grid2D.Coordinate, Creature> creatures = new ObjectMap<Grid2D.Coordinate, Creature>();
    Array<Creature> dropCreatures = new Array<Creature>();
    ObjectMap<Creature, ObjectIntMap<Item>> drop = new ObjectMap<Creature, ObjectIntMap<Item>>();
    Player antagonist = world.players.get(PlayerHelper.antagonist);
    for (Map.Entry<Grid2D.Coordinate, Die> entry : description.getElements(LevelElementType.enemy)) {
        Creature creature = antagonist.addCreature(entry.getValue());
        creatures.put(entry.getKey(), creature);
    }
    for (Creature creature : creatures.values()) {
        dropCreatures.add(creature);
    }
    final ObjectIntMap<Creature> weights = new ObjectIntMap<Creature>();
    int total = 0;
    for (Creature creature : dropCreatures) {
        int cost = ExpHelper.getTotalCost(creature);
        weights.put(creature, cost);
        total += cost;
    }
    dropCreatures.sort(new Comparator<Creature>() {
        @Override
        public int compare(Creature o1, Creature o2) {
            return weights.get(o2, 0) - weights.get(o1, 0);
        }
    });
    if (dropCreatures.size > 1) {
        dropCreatures.truncate(Math.max(1, dropCreatures.size * 3 / 5));
    }

    for (Creature creature : dropCreatures) {
        drop.put(creature, new ObjectIntMap<Item>());
    }
    //        Logger.debug("drop: " + world.level.drop);
    ObjectIntMap<Item> droppedItems = world.level.drop.roll();
    //        Logger.debug("rolled: " + droppedItems);
    for (Item item : droppedItems.keys()) {
        int count = droppedItems.get(item, 1);
        float factor = count / (float) total;
        int distributedCount = 0;
        for (Creature creature : dropCreatures) {
            int creatureItemCount = (int) (weights.get(creature, 0) * factor);
            drop.get(creature).put(item, creatureItemCount);
            distributedCount += creatureItemCount;
        }
        if (distributedCount > count)
            throw new IllegalStateException("OMG! distributed " + item + " more than should! drop: " + drop
                    + ", to distribute: " + droppedItems);
        if (distributedCount < count) {
            while (distributedCount < count) {
                Creature random = dropCreatures.random();
                drop.get(random).getAndIncrement(item, 0, 1);
                //                    Logger.debug("added lost 1 " + item + " to " + random + "!");
                distributedCount++;
            }
        }
    }
    for (Creature creature : drop.keys()) {
        creature.setDrop(drop.get(creature));
        //            Logger.debug("set drop: " + creature + " => " + creature.drop);
    }
    for (Grid2D.Coordinate coordinate : creatures.keys()) {
        world.add(coordinate.x(), coordinate.y(), creatures.get(coordinate));
    }
    for (Map.Entry<Grid2D.Coordinate, Obstacle> entry : description.getElements(LevelElementType.obstacle)) {
        world.add(entry.getKey().x(), entry.getKey().y(), entry.getValue());
    }
    for (Map.Entry<Grid2D.Coordinate, StepDetector> entry : description
            .getElements(LevelElementType.stepDetector)) {
        world.add(entry.getKey().x(), entry.getKey().y(), entry.getValue());
    }
    for (Map.Entry<Grid2D.Coordinate, Fraction> entry : description.getElements(LevelElementType.spawn)) {
        world.dispatcher.dispatch(ADD_SPAWN_POINT,
                new SpawnPoint(entry.getKey().x(), entry.getKey().y(), entry.getValue()));
    }
    world.dispatcher.dispatch(LEVEL_LOADED, null);
}