Example usage for com.badlogic.gdx.utils JsonValue getBoolean

List of usage examples for com.badlogic.gdx.utils JsonValue getBoolean

Introduction

In this page you can find the example usage for com.badlogic.gdx.utils JsonValue getBoolean.

Prototype

public boolean getBoolean(String name, boolean defaultValue) 

Source Link

Document

Finds the child with the specified name and returns it as a boolean.

Usage

From source file:com.ahsgaming.valleyofbones.map.TileLayer.java

License:Apache License

public static TileLayer createFromJson(JsonValue value) {
    TileLayer tileLayer = new TileLayer();

    tileLayer.traversible = value.getBoolean("traversible", true);
    tileLayer.collidable = value.getBoolean("collidable", false);
    tileLayer.visible = value.getBoolean("visible", true);
    tileLayer.opacity = value.getFloat("opacity", 1);

    tileLayer.data = new Array<Integer>();
    for (JsonValue v : value.get("data")) {
        tileLayer.data.add(v.asInt());/*from   ww  w. jav  a 2  s  . co m*/
    }

    return tileLayer;
}

From source file:com.mbrlabs.mundus.runtime.SceneLoader.java

License:Apache License

private GameObject convertGameObject(SceneGraph sceneGraph, JsonValue jsonGo) {
    final GameObject go = new GameObject(sceneGraph, jsonGo.getString(JsonScene.GO_NAME, ""),
            jsonGo.getInt(JsonScene.GO_ID));
    go.active = jsonGo.getBoolean(JsonScene.GO_ACTIVE, true);
    // TODO tags//w  ww  .  j ava  2  s. c  o m

    // model component
    JsonValue modelComp = jsonGo.get(JsonScene.GO_MODEL_COMPONENT);
    if (modelComp != null) {
        ModelComponent mc = new ModelComponent(go, mundus.getShaders().getModelShader());
        mc.setModel((ModelAsset) assetManager
                .findAssetByID(modelComp.getString(JsonScene.MODEL_COMPONENT_MODEL_ID)), false);

        JsonValue mats = modelComp.get(JsonScene.MODEL_COMPONENT_MATERIALS);
        for (JsonValue mat : mats.iterator()) {
            mc.getMaterials().put(mat.name,
                    (MaterialAsset) assetManager.findAssetByID(mats.getString(mat.name)));
        }
        mc.applyMaterials();

        try {
            go.addComponent(mc);
        } catch (InvalidComponentException e) {
            e.printStackTrace();
        }
    }

    // TODO terrain component
    JsonValue terrainComp = jsonGo.get(JsonScene.GO_TERRAIN_COMPONENT);
    if (terrainComp != null) {
        TerrainComponent tc = new TerrainComponent(go, mundus.getShaders().getTerrainShader());
        tc.setTerrain((TerrainAsset) assetManager
                .findAssetByID(terrainComp.getString(JsonScene.TERRAIN_COMPONENT_TERRAIN_ID)));
        try {
            go.addComponent(tc);
        } catch (InvalidComponentException e) {
            e.printStackTrace();
        }
    }

    // transformation
    final float[] transform = jsonGo.get(JsonScene.GO_TRANSFORM).asFloatArray();
    go.setLocalPosition(transform[0], transform[1], transform[2]);
    go.setLocalRotation(transform[3], transform[4], transform[5], transform[6]);
    go.setLocalScale(transform[7], transform[8], transform[9]);

    // children
    JsonValue children = jsonGo.get(JsonScene.GO_CHILDREN);
    if (children != null) {
        for (JsonValue c : children) {
            go.addChild(convertGameObject(sceneGraph, c));
        }
    }

    return go;
}

From source file:com.siondream.core.physics.PhysicsLoader.java

License:Apache License

private void loadBodyDef(JsonValue root) {
    logger.info("loading BodyDef");

    physicsData.bodyDef.bullet = root.getBoolean("bullet", false);
    physicsData.bodyDef.active = root.getBoolean("active", true);
    physicsData.bodyDef.fixedRotation = root.getBoolean("fixedRotation", false);
    physicsData.bodyDef.gravityScale = root.getFloat("gravityScale", 1.0f);
    physicsData.bodyDef.linearDamping = root.getFloat("linearDamping", 0.0f);
    physicsData.bodyDef.angularDamping = root.getFloat("angularDamping", 0.0f);

    String type = root.getString("type", "dynamic");

    if (type.equals("dynamic")) {
        physicsData.bodyDef.type = BodyDef.BodyType.DynamicBody;
    } else if (type.equals("kynematic")) {
        physicsData.bodyDef.type = BodyDef.BodyType.KinematicBody;
    } else if (type.equals("static")) {
        physicsData.bodyDef.type = BodyDef.BodyType.KinematicBody;
    } else {/*from   w ww . jav  a  2 s . c  om*/
        logger.error("unknown body type " + type);
    }
}

From source file:com.siondream.core.physics.PhysicsLoader.java

License:Apache License

private void loadFixtureDefs(JsonValue root) {
    JsonValue fixtures = root.get("fixtures");
    JsonIterator fixturesIt = fixtures.iterator();
    int index = 0;

    while (fixturesIt.hasNext()) {
        JsonValue fixture = fixturesIt.next();

        FixtureDef fixtureDef = new FixtureDef();

        fixtureDef.density = fixture.getFloat("density", 1.0f);
        fixtureDef.restitution = fixture.getFloat("restitution", 0.0f);
        fixtureDef.friction = fixture.getFloat("friction", 1.0f);
        fixtureDef.isSensor = fixture.getBoolean("isSensor", false);
        fixtureDef.shape = loadShape(fixture);
        loadFilter(fixture, fixtureDef.filter);
        String id = fixture.getString("id", "");

        logger.info("loading fixture with id " + id);

        physicsData.fixtureNames.add(id);
        physicsData.fixtureIdx.put(id, index);
        physicsData.fixtureDefs.add(fixtureDef);

        ++index;//from w ww  .  j  a v  a 2 s  .com
    }
}

From source file:com.theosirian.ppioo.util.GameData.java

License:Open Source License

public GameData load() {
    Preferences state = Gdx.app.getPreferences(saveName);
    money = state.getInteger("money", money);
    victories = state.getInteger("victories", victories);
    defeats = state.getInteger("defeats", defeats);
    JsonValue json = new JsonReader().parse(Gdx.files.internal("data.json"));
    JsonValue playersJson = json.get("players");
    for (JsonValue playerJson : playersJson.iterator()) {
        Player player = new Player();
        player.setId(playerJson.getString("id"));
        player.setFirstName(playerJson.getString("first_name"));
        player.setLastName(playerJson.getString("last_name"));
        player.setAge(playerJson.getInt("age"));
        player.setCountry(playerJson.getString("country"));
        player.setPrice(playerJson.getInt("price"));
        player.setQuality(playerJson.getFloat("quality"));
        player.setConfidence(playerJson.getFloat("confidence"));
        player.setOwned(state.getBoolean(player.getId(), playerJson.getBoolean("owned", false)));
        String key = "player-" + player.getId();
        player.setDateAcquired(new Date(state.getLong(key + "-date_acquired", new Date().getTime())));
        player.setVictories(state.getInteger(key + "-victories", 0));
        player.setDefeats(state.getInteger(key + "-defeats", 0));
        players.add(player);//ww w  .  ja  va  2  s.  c o m
    }
    JsonValue fansJson = json.get("fans");
    for (JsonValue fanJson : fansJson.iterator()) {
        Fan fan = new Fan();
        fan.setId(fanJson.getString("id"));
        fan.setName(fanJson.getString("name"));
        fan.setMinSupport(fanJson.getFloat("minSupport"));
        fan.setMaxSupport(fanJson.getFloat("maxSupport"));
        fan.setMinHuff(fanJson.getFloat("minHuff"));
        fan.setMaxHuff(fanJson.getFloat("maxHuff"));
        fan.setPrice(fanJson.getInt("price"));
        String key = "fan-" + fan.getId();
        fan.setDateAcquired(new Date(state.getLong(key + "-date_acquired", new Date().getTime())));
        fan.setVictories(state.getInteger(key + "-victories", 0));
        fan.setDefeats(state.getInteger(key + "-defeats", 0));
        fans.add(fan);
    }
    return this;
}

From source file:com.tnf.ptm.entities.planet.PlanetConfig.java

License:Apache License

static PlanetConfig load(TextureManager textureManager, HullConfigManager hullConfigs, JsonValue rootNode,
        GameColors cols, ItemManager itemManager) {
    float minGrav = rootNode.getFloat("minGrav");
    float maxGrav = rootNode.getFloat("maxGrav");
    List<DecoConfig> deco = DecoConfig.load(rootNode, textureManager);
    ArrayList<ShipConfig> groundEnemies = ShipConfig.loadList(rootNode.get("groundEnemies"), hullConfigs,
            itemManager);//from  w w w .ja v a 2s.  co m
    ArrayList<ShipConfig> highOrbitEnemies = ShipConfig.loadList(rootNode.get("highOrbitEnemies"), hullConfigs,
            itemManager);
    ArrayList<ShipConfig> lowOrbitEnemies = ShipConfig.loadList(rootNode.get("lowOrbitEnemies"), hullConfigs,
            itemManager);
    ShipConfig stationConfig = ShipConfig.load(hullConfigs, rootNode.get("station"), itemManager);
    String cloudPackName = rootNode.getString("cloudTexs");
    ArrayList<TextureAtlas.AtlasRegion> cloudTexs = textureManager.getPack(cloudPackName);
    String groundFolder = rootNode.getString("groundTexs");
    PlanetTiles planetTiles = new PlanetTiles(textureManager, groundFolder);
    SkyConfig skyConfig = SkyConfig.load(rootNode.get("sky"), cols);
    int rowCount = rootNode.getInt("rowCount");
    boolean smoothLandscape = rootNode.getBoolean("smoothLandscape", false);
    TradeConfig tradeConfig = TradeConfig.load(itemManager, rootNode.get("trading"), hullConfigs);
    boolean hardOnly = rootNode.getBoolean("hardOnly", false);
    boolean easyOnly = rootNode.getBoolean("easyOnly", false);
    return new PlanetConfig(rootNode.name, minGrav, maxGrav, deco, groundEnemies, highOrbitEnemies,
            lowOrbitEnemies, cloudTexs, planetTiles, stationConfig, skyConfig, rowCount, smoothLandscape,
            tradeConfig, hardOnly, easyOnly);
}

From source file:com.tnf.ptm.entities.planet.SysConfigs.java

License:Apache License

private void load(TextureManager textureManager, HullConfigManager hullConfigs, boolean belts,
        ResourceUrn configName, ItemManager itemManager) {
    Json json = Assets.getJson(configName);
    JsonValue rootNode = json.getJsonValue();

    for (JsonValue sh : rootNode) {
        ArrayList<ShipConfig> tempEnemies = ShipConfig.loadList(sh.get("temporaryEnemies"), hullConfigs,
                itemManager);//from  ww  w .j a  v a 2  s  . c o m
        ArrayList<ShipConfig> innerTempEnemies = ShipConfig.loadList(sh.get("innerTemporaryEnemies"),
                hullConfigs, itemManager);
        SpaceEnvConfig envConfig = new SpaceEnvConfig(sh.get("environment"), textureManager);

        ArrayList<ShipConfig> constEnemies = null;
        ArrayList<ShipConfig> constAllies = null;
        if (!belts) {
            constEnemies = ShipConfig.loadList(sh.get("constantEnemies"), hullConfigs, itemManager);
            constAllies = ShipConfig.loadList(sh.get("constantAllies"), hullConfigs, itemManager);
        }
        TradeConfig tradeConfig = TradeConfig.load(itemManager, sh.get("trading"), hullConfigs);
        boolean hard = sh.getBoolean("hard", false);
        SysConfig c = new SysConfig(sh.name, tempEnemies, envConfig, constEnemies, constAllies, tradeConfig,
                innerTempEnemies, hard);
        Map<String, SysConfig> configs = belts ? hard ? myHardBeltConfigs : myBeltConfigs
                : hard ? myHardConfigs : myConfigs;
        configs.put(sh.name, c);
    }
}

From source file:com.tnf.ptm.entities.projectile.ProjectileConfigs.java

License:Apache License

public ProjectileConfigs(TextureManager textureManager, OggSoundManager soundManager, EffectTypes effectTypes,
        GameColors cols) {/*from   w ww.  jav  a  2  s  .  co m*/
    myConfigs = new HashMap<>();

    Json json = Assets.getJson(new ResourceUrn("core:projectilesConfig"));
    JsonValue rootNode = json.getJsonValue();

    for (JsonValue sh : rootNode) {
        String texName = "smallGameObjects/projectiles/" + sh.getString("texName");
        TextureAtlas.AtlasRegion tex = textureManager.getTexture(texName);
        float texSz = sh.getFloat("texSz");
        float spdLen = sh.getFloat("spdLen");
        float physSize = sh.getFloat("physSize", 0);
        boolean stretch = sh.getBoolean("stretch", false);
        DmgType dmgType = DmgType.forName(sh.getString("dmgType"));
        String collisionSoundUrn = sh.getString("collisionSound", "");
        OggSound collisionSound = collisionSoundUrn.isEmpty() ? null : soundManager.getSound(collisionSoundUrn);
        float lightSz = sh.getFloat("lightSz", 0);
        EffectConfig trailEffect = EffectConfig.load(sh.get("trailEffect"), effectTypes, textureManager, cols);
        EffectConfig bodyEffect = EffectConfig.load(sh.get("bodyEffect"), effectTypes, textureManager, cols);
        EffectConfig collisionEffect = EffectConfig.load(sh.get("collisionEffect"), effectTypes, textureManager,
                cols);
        EffectConfig collisionEffectBg = EffectConfig.load(sh.get("collisionEffectBg"), effectTypes,
                textureManager, cols);
        float guideRotSpd = sh.getFloat("guideRotSpd", 0);
        boolean zeroAbsSpd = sh.getBoolean("zeroAbsSpd", false);
        Vector2 origin = PtmMath.readV2(sh.getString("texOrig", "0 0"));
        float acc = sh.getFloat("acceleration", 0);
        String workSoundUrn = sh.getString("workSound", "");
        OggSound workSound = workSoundUrn.isEmpty() ? null : soundManager.getSound(workSoundUrn);
        boolean bodyless = sh.getBoolean("massless", false);
        float density = sh.getFloat("density", -1);
        float dmg = sh.getFloat("dmg");
        float emTime = sh.getFloat("emTime", 0);
        ProjectileConfig c = new ProjectileConfig(tex, texSz, spdLen, stretch, physSize, dmgType,
                collisionSound, lightSz, trailEffect, bodyEffect, collisionEffect, collisionEffectBg,
                zeroAbsSpd, origin, acc, workSound, bodyless, density, guideRotSpd, dmg, emTime);
        myConfigs.put(sh.name, c);
    }

    json.dispose();
}

From source file:com.tnf.ptm.gfx.particle.EffectConfig.java

License:Apache License

public static EffectConfig load(JsonValue node, EffectTypes types, TextureManager textureManager,
        GameColors cols) {/*from w  w  w  .  j  a v a2 s .  c o  m*/
    if (node == null) {
        return null;
    }
    String effectFileName = node.getString("effectFile");
    EffectType effectType = types.forName(new ResourceUrn(effectFileName));
    float sz = node.getFloat("size", 0);
    String texName = node.getString("tex");
    boolean floatsUp = node.getBoolean("floatsUp", false);
    Color tint = cols.load(node.getString("tint"));
    TextureAtlas.AtlasRegion tex = textureManager.getTexture("smallGameObjects/particles/" + texName);
    return new EffectConfig(effectType, sz, tex, floatsUp, tint);
}

From source file:com.tnf.ptm.handler.files.HullConfigManager.java

License:Apache License

private void parseGunSlotList(JsonValue containerNode, HullConfig.Data configData) {
    Vector2 builderOrigin = new Vector2(configData.shipBuilderOrigin);

    for (JsonValue gunSlotNode : containerNode) {
        Vector2 position = readVector2(gunSlotNode, "position", null);
        position.sub(builderOrigin).scl(configData.size);

        boolean isUnderneathHull = gunSlotNode.getBoolean("isUnderneathHull", false);
        boolean allowsRotation = gunSlotNode.getBoolean("allowsRotation", true);

        configData.gunSlots.add(new GunSlot(position, isUnderneathHull, allowsRotation));
    }/*from w  ww.  j a  v a 2  s. c  o m*/
}