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(int index) 

Source Link

Document

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

Usage

From source file:com.izacc.equipment.Item.java

public Item(JsonValue json) {
    this.file = json.getString("file");
    this.name = json.getString("name");
    this.description = json.getString("description");

    this.disable = json.has("disable") ? json.getBoolean("disable") : false;
    this.packable = json.has("packable") ? json.getBoolean("packable") : true;
    this.isPermanent = json.has("isPermanent") ? json.getBoolean("isPermanent") : true;

    this.bonus = json.has("bonus") ? json.getFloat("bonus") : 0.0f;
    this.time = json.has("time") ? json.getInt("time") : 0;
    this.buy = json.has("buy") ? json.getInt("buy") : 0;
    this.sell = json.has("sell") ? json.getInt("sell") : 0;

    this.itemType = ItemType.valueOf(json.getString("itemType"));
    this.effectType = EffectType.valueOf(json.getString("type"));
}

From source file:com.ray3k.skincomposer.data.StyleData.java

License:Open Source License

@Override
public void read(Json json, JsonValue jsonData) {
    name = jsonData.getString("name");
    properties = json.readValue("properties", OrderedMap.class, jsonData);
    deletable = jsonData.getBoolean("deletable");
    try {//  w w  w  . j a  v  a  2 s . c om
        clazz = ClassReflection.forName(jsonData.getString("clazz"));
    } catch (ReflectionException ex) {
        Gdx.app.error(getClass().toString(), "Error reading from serialized object", ex);
        main.getDialogFactory().showDialogError("Read Error...",
                "Error reading from serialized object.\n\nOpen log?");
    }
}

From source file:com.ray3k.skincomposer.data.StyleProperty.java

License:Open Source License

@Override
public void read(Json json, JsonValue jsonValue) {
    try {/*from   ww w .  j a v  a  2  s . com*/
        name = jsonValue.getString("name");
        optional = jsonValue.getBoolean("optional");
        if (jsonValue.get("value").isNumber()) {
            type = Float.TYPE;
            value = Double.parseDouble(jsonValue.getString("value"));
        } else {
            type = ClassReflection.forName(jsonValue.getString("type"));
            if (jsonValue.get("value").isNull()) {
                value = null;
            } else {
                value = jsonValue.getString("value");
            }
        }
    } catch (ReflectionException ex) {
        Gdx.app.error(getClass().toString(), "Error reading from serialized object", ex);
        DialogFactory.showDialogErrorStatic("Read Error...",
                "Error reading from serialized object.\n\nOpen log?");
    }
}

From source file:com.tnf.ptm.entities.maze.MazeConfig.java

License:Apache License

public static MazeConfig load(TextureManager textureManager, HullConfigManager hullConfigs, JsonValue mazeNode,
        ItemManager itemManager) {/*from   w w w  .  ja  v a 2  s .c o  m*/
    String dirName = "mazeTiles/" + mazeNode.name + "/";
    CollisionMeshLoader collisionMeshLoader = new CollisionMeshLoader(new ResourceUrn(mazeNode.name + "Maze"));
    CollisionMeshLoader.Model paths = collisionMeshLoader.getInternalModel();
    List<TextureAtlas.AtlasRegion> innerBgs = textureManager.getPack(dirName + "innerBg");
    List<TextureAtlas.AtlasRegion> borderBgs = textureManager.getPack(dirName + "borderBg");
    ArrayList<TextureAtlas.AtlasRegion> wallTexs = textureManager.getPack(dirName + "wall");
    ArrayList<TextureAtlas.AtlasRegion> passTexs = textureManager.getPack(dirName + "pass");

    boolean metal = mazeNode.getBoolean("isMetal");
    ArrayList<MazeTile> innerWalls = new ArrayList<>();
    buildTiles(paths, innerWalls, true, metal, innerBgs, wallTexs);
    ArrayList<MazeTile> innerPasses = new ArrayList<>();
    buildTiles(paths, innerPasses, false, metal, innerBgs, passTexs);
    ArrayList<MazeTile> borderWalls = new ArrayList<>();
    buildTiles(paths, borderWalls, true, metal, borderBgs, wallTexs);
    ArrayList<MazeTile> borderPasses = new ArrayList<>();
    buildTiles(paths, borderPasses, false, metal, borderBgs, passTexs);

    ArrayList<ShipConfig> outerEnemies = ShipConfig.loadList(mazeNode.get("outerEnemies"), hullConfigs,
            itemManager);
    ArrayList<ShipConfig> innerEnemies = ShipConfig.loadList(mazeNode.get("innerEnemies"), hullConfigs,
            itemManager);
    ArrayList<ShipConfig> bosses = ShipConfig.loadList(mazeNode.get("bosses"), hullConfigs, itemManager);

    SpaceEnvConfig envConfig = new SpaceEnvConfig(mazeNode.get("environment"), textureManager);
    return new MazeConfig(innerWalls, innerPasses, borderWalls, borderPasses, outerEnemies, innerEnemies,
            bosses, envConfig);
}

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

License:Apache License

static List<DecoConfig> load(JsonValue planetConfig, TextureManager textureManager) {
    ArrayList<DecoConfig> res = new ArrayList<DecoConfig>();
    for (JsonValue deco : planetConfig.get("decorations")) {
        float density = deco.getFloat("density");
        float szMin = deco.getFloat("szMin");
        float szMax = deco.getFloat("szMax");
        Vector2 orig = PtmMath.readV2(deco, "orig");
        boolean allowFlip = deco.getBoolean("allowFlip");
        String texName = planetConfig.getString("decorationTexs") + "/" + deco.name;
        ArrayList<TextureAtlas.AtlasRegion> texs = textureManager.getPack("decorations/" + texName);
        DecoConfig c = new DecoConfig(density, szMin, szMax, orig, allowFlip, texs);
        res.add(c);/*w ww .  jav  a 2s  .c o  m*/
    }
    return res;
}

From source file:com.trgk.touchwave.GameLogger.java

License:Open Source License

/**
 * Load game data!// w w w  .  jav  a  2 s  . c  o m
 */
public GameLogger() {
    // Try parsing existing file
    FileHandle gamelog = Gdx.files.local("gamelog.json");

    if (gamelog.exists()) {
        JsonReader reader = new JsonReader();
        JsonValue content = reader.parse(gamelog);
        try {
            for (Field field : GameLogger.class.getFields()) {
                String fieldName = field.getName();
                if (content.has(fieldName)) {
                    try {
                        if (field.getType() == boolean.class)
                            field.setBoolean(this, content.getBoolean(fieldName));
                        else if (field.getType() == int.class)
                            field.setInt(this, content.getInt(fieldName));
                        else if (field.getType() == long.class)
                            field.setLong(this, content.getLong(fieldName));
                    } catch (IllegalStateException e) {
                        MessageBox.alert("GameLogger", "IllegalStateException : " + e.getMessage());
                    } catch (IllegalArgumentException e) {
                        MessageBox.alert("GameLogger", "IllegalArgumentException : " + e.getMessage());
                    }
                }
            }
        } catch (IllegalAccessException e) {
            MessageBox.alert("Error", "IllegalAccessException : " + e.getMessage());
            throw new RuntimeException("Unexpected exception", e);
        }
    }

    saveGameLog();
}

From source file:org.destinationsol.game.maze.MazeConfig.java

License:Apache License

public static MazeConfig load(TextureManager textureManager, HullConfigManager hullConfigs, JsonValue mazeNode,
        FileHandle configFile, ItemManager itemManager) {
    String dirName = "mazeTiles/" + mazeNode.name + "/";
    PathLoader pathLoader = new PathLoader("mazes/" + mazeNode.name);
    PathLoader.Model paths = pathLoader.getInternalModel();
    List<TextureAtlas.AtlasRegion> innerBgs = textureManager.getPack(dirName + "innerBg", configFile);
    List<TextureAtlas.AtlasRegion> borderBgs = textureManager.getPack(dirName + "borderBg", configFile);
    ArrayList<TextureAtlas.AtlasRegion> wallTexs = textureManager.getPack(dirName + "wall", configFile);
    ArrayList<TextureAtlas.AtlasRegion> passTexs = textureManager.getPack(dirName + "pass", configFile);

    boolean metal = mazeNode.getBoolean("isMetal");
    ArrayList<MazeTile> innerWalls = new ArrayList<MazeTile>();
    buildTiles(paths, innerWalls, true, metal, innerBgs, wallTexs);
    ArrayList<MazeTile> innerPasses = new ArrayList<MazeTile>();
    buildTiles(paths, innerPasses, false, metal, innerBgs, passTexs);
    ArrayList<MazeTile> borderWalls = new ArrayList<MazeTile>();
    buildTiles(paths, borderWalls, true, metal, borderBgs, wallTexs);
    ArrayList<MazeTile> borderPasses = new ArrayList<MazeTile>();
    buildTiles(paths, borderPasses, false, metal, borderBgs, passTexs);

    ArrayList<ShipConfig> outerEnemies = ShipConfig.loadList(mazeNode.get("outerEnemies"), hullConfigs,
            itemManager);/* w  w  w  . j  a  va  2  s  .com*/
    ArrayList<ShipConfig> innerEnemies = ShipConfig.loadList(mazeNode.get("innerEnemies"), hullConfigs,
            itemManager);
    ArrayList<ShipConfig> bosses = ShipConfig.loadList(mazeNode.get("bosses"), hullConfigs, itemManager);

    SpaceEnvConfig envConfig = new SpaceEnvConfig(mazeNode.get("environment"), textureManager, configFile);
    return new MazeConfig(innerWalls, innerPasses, borderWalls, borderPasses, outerEnemies, innerEnemies,
            bosses, envConfig);
}

From source file:org.destinationsol.game.planet.DecoConfig.java

License:Apache License

static List<DecoConfig> load(JsonValue planetConfig, TextureManager textureManager, FileHandle configFile) {
    ArrayList<DecoConfig> res = new ArrayList<DecoConfig>();
    for (JsonValue deco : planetConfig.get("deco")) {
        float density = deco.getFloat("density");
        float szMin = deco.getFloat("szMin");
        float szMax = deco.getFloat("szMax");
        Vector2 orig = SolMath.readV2(deco, "orig");
        boolean allowFlip = deco.getBoolean("allowFlip");
        String texName = planetConfig.getString("decoTexs") + "/" + deco.name;
        ArrayList<TextureAtlas.AtlasRegion> texs = textureManager.getPack(texName, configFile);
        DecoConfig c = new DecoConfig(density, szMin, szMax, orig, allowFlip, texs);
        res.add(c);// w ww  .  j av a2 s .  c om
    }
    return res;
}