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

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

Introduction

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

Prototype

public V put(K key, V value) 

Source Link

Document

Returns the old value associated with the specified key, or null.

Usage

From source file:com.badlogic.gdx.tests.g3d.ShaderLoader.java

License:Apache License

protected ObjectMap<String, String> parse(final FileHandle file) {
    ObjectMap<String, String> result = new ObjectMap<String, String>();
    BufferedReader reader = file.reader(1024);
    String line;/*from w w  w  .  j av  a 2s . co m*/
    String snipName = "";
    stringBuilder.setLength(0);
    int idx;
    try {
        while ((line = reader.readLine()) != null) {
            if (line.length() > 3 && line.charAt(0) == '[' && (idx = line.indexOf(']')) > 1) {
                if (snipName.length() > 0 || stringBuilder.length() > 0)
                    result.put(snipName, stringBuilder.toString());
                stringBuilder.setLength(0);
                snipName = line.substring(1, idx);
            } else
                stringBuilder.append(line.trim()).append("\r\n");
        }
    } catch (IOException e) {
        throw new GdxRuntimeException(e);
    }
    if (snipName.length() > 0 || stringBuilder.length() > 0)
        result.put(snipName, stringBuilder.toString());
    return result;
}

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   ww w  .  jav  a2s.co m
 * @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.blindtigergames.werescrewed.graphics.TextureAtlas.java

License:Apache License

private void load(TextureAtlasData data) {
    ObjectMap<TextureAtlasData.Page, Texture> pageToTexture = new ObjectMap<TextureAtlasData.Page, Texture>();
    for (TextureAtlasData.Page page : data.pages) {
        this.collideOffsetX = page.collideOffsetX;
        this.collideOffsetY = page.collideOffsetY;
        Texture texture = null;//from   w w  w . j a  va  2s.c o m
        if (page.texture == null) {
            texture = new Texture(page.textureFile, page.format, page.useMipMaps);
            texture.setFilter(page.minFilter, page.magFilter);
            texture.setWrap(page.uWrap, page.vWrap);
        } else {
            texture = page.texture;
            texture.setFilter(page.minFilter, page.magFilter);
            texture.setWrap(page.uWrap, page.vWrap);
        }
        textures.add(texture);
        pageToTexture.put(page, texture);
    }

    for (TextureAtlasData.Region region : data.regions) {
        int width = region.width;
        int height = region.height;
        AtlasRegion atlasRegion = new AtlasRegion(pageToTexture.get(region.page), region.left, region.top,
                region.rotate ? height : width, region.rotate ? width : height);
        atlasRegion.index = region.index;
        atlasRegion.name = region.name;
        atlasRegion.offsetX = region.offsetX;
        atlasRegion.offsetY = region.offsetY;
        atlasRegion.originalHeight = region.originalHeight;
        atlasRegion.originalWidth = region.originalWidth;
        atlasRegion.rotate = region.rotate;
        atlasRegion.splits = region.splits;
        atlasRegion.pads = region.pads;
        if (region.flip)
            atlasRegion.flip(false, true);
        regions.add(atlasRegion);
    }
}

From source file:com.dongbat.game.ability.types.SplitAndJoin.java

@Override
public void cast(World world, Entity caster, Vector2 target) {
    AbilityComponent playerAbilityList = EntityUtil.getComponent(world, caster, AbilityComponent.class);
    AbilityInfo info = playerAbilityList.getAbility("SplitAndJoin");
    if (info == null) {
        return;/*from ww w  . j a  v a 2 s.  c  o m*/
    }
    Vector2 position = PhysicsUtil.getPosition(world, caster);
    UnitMovement ms = EntityUtil.getComponent(world, caster, UnitMovement.class);
    Vector2 direction = ms.getDirectionVelocity();
    if (direction == null) {
        return;
    }
    float radius = PhysicsUtil.getRadius(world, caster);
    if (radius <= Constants.PHYSICS.MIN_RADIUS * 2) {
        return;
    }
    float newRadius = radius / 1.41f;

    //    BuffUtil.addBuff(world, caster, caster, "Forced", 1500, 1, "forceStrength", 100, "direction", direction.cpy().scl(-1));
    PhysicsUtil.setRadius(world, caster, newRadius);

    Entity bullet = UnitFactory.createProjectileUnit(world, caster,
            direction.cpy().nor().scl(radius + newRadius).add(position.cpy()), newRadius, true, true, true);
    ObjectMap<String, Object> args = new ObjectMap<String, Object>();
    //    Display display = EntityUtil.getComponent(world, caster, Display.class);
    //    TextureAtlas split = AssetUtil.getUnitAtlas().get("split");
    //    Animation animation = new Animation(0.075f, split.getRegions());
    //    animation.setPlayMode(Animation.PlayMode.LOOP);
    //    display.setGetOverridenStart(TimeUtil.getCurrentFrame(world));
    //    display.setOverridenDuration(1500);
    //    display.setOverridenAnimation(new AnimatedSprite(animation));

    //    args.put("forceStrength", 100);
    //    args.put("direction", direction.cpy().scl(1));
    //    BuffUtil.addBuff(world, caster, bullet, "DelayBuff", 0, 1, "buffName", "Forced", "duration", 3000, "args", args);
    BuffUtil.addBuff(world, caster, bullet, "Forced", 500, 1, "forceStrength", 20, "direction",
            direction.cpy().scl(1), "ignoreMass", true);

    args.put("feedPerSecond", 2f);
    BuffUtil.addBuff(world, caster, bullet, "DelayBuff", 1000, 1, "buffName", "Feed", "duration", -1, "args",
            args);
    BuffUtil.addBuff(world, bullet, bullet, "AttractFood", -1, 1);
    //    BuffUtil.addBuff(world, bullet, bullet, "Feed", -1, 1, "feedPerSecond", 0.55f);
}

From source file:com.dongbat.game.registry.AbilityRegistry.java

/**
 * Parse ability info from String that was loaded from load() function
 *
 * @param abilityString ability String need to parse
 *///from  w w w.  jav a2  s .c om
private static void parseAbility(String abilityString) {
    String[] frags = abilityString.split("\\r?\\n");
    ObjectMap<String, String> common = new ObjectMap<String, String>();
    ObjectMap<Integer, ObjectMap<String, String>> levelMaps = new ObjectMap<Integer, ObjectMap<String, String>>();
    ObjectMap<String, String> abilityData;

    for (String frag : frags) {
        String[] split = frag.split(":");
        common.put(split[0].trim(), split[1].trim());
    }
    String name = common.remove("name");
    String clazz = common.remove("class");

    for (ObjectMap.Entry<String, String> entry : common.entries()) {
        String[] phongs = entry.value.split("\\|");
        abilityData = new ObjectMap<String, String>();
        for (String phong : phongs) {
            String[] minh = phong.split("=");
            abilityData.put(minh[0].trim(), minh[1].trim());
        }
        levelMaps.put(Integer.parseInt(entry.key.trim()), abilityData);
    }

    registry.put(name, new Entry(clazz, levelMaps));

}

From source file:com.dongbat.game.registry.BuffRegistry.java

/**
 * Parse buff info from String that was loaded from load() function
 *
 * @param buffString buff String need to parse
 *//*w w w.ja v  a 2 s.  c  o  m*/
public static void parseBuffs(String buffString) {
    String[] lines = buffString.split("\\r?\\n");
    ObjectMap<String, String> common = new ObjectMap<String, String>();
    ObjectMap<Integer, ObjectMap<String, String>> levelMaps = new ObjectMap<Integer, ObjectMap<String, String>>();
    ObjectMap<String, String> buffData;

    for (String line : lines) {
        String[] split = line.split(":");
        common.put(split[0], split[1]);
    }
    String name = common.remove("name");
    String clazz = common.remove("class");

    for (ObjectMap.Entry<String, String> entry : common.entries()) {
        String[] phongs = entry.value.split("\\|");
        buffData = new ObjectMap<String, String>();
        for (String phong : phongs) {
            String[] minh = phong.split("=");
            buffData.put(minh[0].trim(), minh[1].trim());
        }
        levelMaps.put(Integer.parseInt(entry.key.trim()), buffData);
    }

    registry.put(name, new Entry(clazz, levelMaps));
}

From source file:com.dongbat.game.registry.ReflectionUtil.java

/**
 * Parse data from string to Object// ww w.  ja v  a  2  s  .c  o m
 *
 * @param clazz class name
 * @param info string want to parse
 * @return Object that was just parsed
 */
static Object parseData(Class clazz, String info) {
    String[] frags = info.split("\\r?\\n\\r?\\n");
    String data = null;

    if (frags.length == 2) {
        data = frags[1];
    }
    Object object = null;

    try {
        object = clazz.newInstance();

        // process params
        String[] params = frags[0].split("\\r?\\n");
        for (String param : params) {
            String[] split = param.split("=");
            String fieldName = split[0];
            String value = split[1];

            setFieldValue(clazz, fieldName, object, value);
        }

        if (data != null) {
            // process data
            frags = data.split("\\r?\\n");
            ObjectMap<String, String> dataMap = new ObjectMap<String, String>();
            for (String frag : frags) {
                String[] split = frag.split("=");

                dataMap.put(split[0], split[1]);
            }
            Method setData = clazz.getMethod("setData", ObjectMap.class);
            setData.invoke(object, dataMap);
        }
    } catch (InstantiationException ex) {
        Logger.getLogger(ReflectionUtil.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        Logger.getLogger(ReflectionUtil.class.getName()).log(Level.SEVERE, null, ex);
    } catch (NoSuchMethodException ex) {
        Logger.getLogger(ReflectionUtil.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        Logger.getLogger(ReflectionUtil.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IllegalArgumentException ex) {
        Logger.getLogger(ReflectionUtil.class.getName()).log(Level.SEVERE, null, ex);
    } catch (InvocationTargetException ex) {
        Logger.getLogger(ReflectionUtil.class.getName()).log(Level.SEVERE, null, ex);
    }

    return object;
}

From source file:com.dongbat.game.util.AbilityUtil.java

public static ObjectMap<String, AbilityInfo> getAbilityMapsByString(String abilities) {
    String[] abilityArray = abilities.split(",");
    ObjectMap<String, AbilityInfo> abilityMaps = new ObjectMap<String, AbilityInfo>();
    for (String abilityName : abilityArray) {
        AbilityInfo ability = AbilityRegistry.getAbility(abilityName, 1);
        abilityMaps.put(abilityName, ability);
    }/* www.  j av a 2s. com*/
    return abilityMaps;
}

From source file:com.dongbat.game.util.networkUtil.SaveLoadUtil.java

public static WorldState save(World world) {
    ObjectMap<String, Object> data = new ObjectMap<String, Object>();
    com.badlogic.gdx.physics.box2d.World physicsWorld = PhysicsUtil.getPhysicsWorld(world);
    //    data.put("physicsWorld", Box2dJsonUtil.toString(physicsWorld));
    data.put("physicsWorld", Box2dStateUtil.fromWorld(physicsWorld));

    Array<EntityState> entityStates = new Array<EntityState>();
    IntBag entities = getAllEntities(world);
    for (int i = 0; i < entities.size(); i++) {
        int id = entities.get(i);
        Entity entity = world.getEntity(id);
        Array<Component> allComponents = getAllComponents(world, entity);
        EntityState entityState = new EntityState(getUuid(entity), allComponents,
                new ObjectMap<String, Object>());
        entityStates.add(entityState);//from   w w  w  . j a  v a2s .  com
    }

    WorldState worldState = new WorldState(getFrame(world), data, entityStates);
    return WorldStateUtil.copy(worldState);
}

From source file:com.dongbat.game.util.networkUtil.WorldStateUtil.java

public static WorldState save(World world) {
    ObjectMap<String, Object> data = new ObjectMap<String, Object>();
    com.badlogic.gdx.physics.box2d.World physicsWorld = PhysicsUtil.getPhysicsWorld(world);
    //    data.put("physicsWorld", Box2dJsonUtil.toString(physicsWorld));
    data.put("physicsWorld", Box2dStateUtil.fromWorld(physicsWorld));
    data.put("seed", getRandom(world).getSeed());

    Array<EntityState> entityStates = new Array<EntityState>();
    IntBag entities = getAllEntities(world);
    for (int i = 0; i < entities.size(); i++) {
        int id = entities.get(i);
        Entity entity = world.getEntity(id);
        Array<Component> allComponents = getAllComponents(world, entity);
        EntityState entityState = new EntityState(getUuid(entity), allComponents,
                new ObjectMap<String, Object>());
        entityStates.add(entityState);/*ww w. ja v a  2 s .c  o m*/
    }

    WorldState worldState = new WorldState(getFrame(world), data, entityStates);
    return WorldStateUtil.copy(worldState);
}