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

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

Introduction

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

Prototype

public int getInt(int index) 

Source Link

Document

Finds the child with the specified index and returns it as an int.

Usage

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

License:Apache License

public TileSet(JsonValue json) {

    firstgid = json.getInt("firstgid");

    name = json.getString("name", "");

    atlas = json.getString("atlas");

    images = new Array<String>();
    tiles = new Array<TextureRegion>();
    depths = new Array<TextureRegion>();

    for (JsonValue v : json.get("tiles")) {
        images.add(v.asString());//from   w  w  w  . ja va 2s .c  o m
        tiles.add(VOBGame.instance.getTextureManager().getSpriteFromAtlas(atlas, v.asString()));
        depths.add(VOBGame.instance.getTextureManager().getSpriteFromAtlas(atlas, v.asString() + "-depth"));
    }
}

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.izacc.equipment.SpellCard.java

public SpellCard(JsonValue json) {
    super(json);/*from  w  ww .j  a  va  2s.  c  om*/

    this.id = json.has("id") ? json.getInt("id") : 0;
    this.speed = json.has("speed") ? json.getFloat("speed") : 0.0f;
    this.damage = json.has("damage") ? json.getFloat("damage") : 0.0f;
    this.spellType = SpellType.valueOf(json.getString("spellType"));
}

From source file:com.jupiter.europa.entity.component.CollisionComponent.java

License:Open Source License

@Override
public void read(Json json, JsonValue jsonData) {
    this.bounds = new Rectangle(jsonData.getInt(X_KEY), jsonData.getInt(Y_KEY), jsonData.getInt(WIDTH_KEY),
            jsonData.getInt(HEIGHT_KEY));
}

From source file:com.jupiter.europa.entity.component.PositionComponent.java

License:Open Source License

@Override
public void read(Json json, JsonValue jsonData) {
    String worldName = jsonData.getString(WORLD_KEY);
    String levelName = jsonData.getString(LEVEL_KEY);
    int tileX = jsonData.getInt(TILE_POSITION_X_KEY);
    int tileY = jsonData.getInt(TILE_POSITION_Y_KEY);
    int zOrderValue = jsonData.getInt(Z_ORDER_KEY);

    this.setLevel(EuropaGame.game.getWorld(worldName).getLevel(levelName));
    this.setTilePosition(new Point(tileX, tileY));
    this.zOrder = zOrderValue;

    this.facing = MovementDirections.valueOf(jsonData.getString(FACING_KEY));
}

From source file:com.jupiter.europa.entity.component.RenderComponent.java

License:Open Source License

@Override
public void read(Json json, JsonValue jsonData) {
    this.setOffset(new Point(jsonData.getInt(OFFSET_X_KEY), jsonData.getInt(OFFSET_Y_KEY)));
}

From source file:com.jupiter.europa.entity.component.SizeComponent.java

License:Open Source License

@Override
public void read(Json json, JsonValue jsonData) {
    this.setSize(new Size(jsonData.getInt(WIDTH_KEY), jsonData.getInt(HEIGHT_KEY)));
}

From source file:com.jupiter.europa.entity.stats.characterclass.CharacterClass.java

License:Open Source License

@Override
public void read(Json json, JsonValue jsonData) {
    if (jsonData.has(LEVEL_KEY)) {
        this.level = jsonData.getInt(LEVEL_KEY);
    }//from ww w.jav  a  2s  .  c  o m

    if (jsonData.has(OWNER_ID_KEY)) {
        this.ownerId = jsonData.getLong(OWNER_ID_KEY);
    }

    if (jsonData.has(FEAT_POOL_KEY)) {
        if (this.featPool != null) {
            this.abilityPools.remove(this.featPool);
        }
        this.featPool = json.fromJson(FeatPool.class,
                jsonData.get(FEAT_POOL_KEY).prettyPrint(EuropaGame.PRINT_SETTINGS));
        this.featPool.addSelectionListener(this::onFeatSelection);
    }

    if (jsonData.has(AVAILABLE_SKILL_POINTS_KEY)) {
        this.availableSkillPoints = jsonData.getInt(AVAILABLE_SKILL_POINTS_KEY);
    }
}

From source file:com.jupiter.europa.entity.trait.TraitPool.java

License:Open Source License

@Override
public void read(Json json, JsonValue jsonData) {
    if (jsonData.has(CAPACITY_KEY)) {
        this.capacity = jsonData.getInt(CAPACITY_KEY);
    }/*  w w w. jav a  2 s . c o  m*/

    if (jsonData.has(SELECTED_KEY)) {
        JsonValue selectedData = jsonData.get(SELECTED_KEY);
        if (selectedData.isArray()) {
            selectedData.iterator().forEach((JsonValue value) -> {
                if (value.has(ITEM_CLASS_KEY) && value.has(ITEM_DATA_KEY)) {
                    String typeName = value.getString(ITEM_CLASS_KEY);
                    try {
                        Class<?> type = Class.forName(typeName);
                        if (Trait.class.isAssignableFrom(type)) {
                            this.selected.add((T) json.fromJson(type, value.get(ITEM_DATA_KEY).toString()));
                        }
                    } catch (ClassNotFoundException ex) {

                    }

                }
            });
        }
    }
}

From source file:com.jupiter.europa.tools.AtlasPacker.java

License:Open Source License

@Override
public void run() {
    Path configFile = FileLocations.SPRITES_DIRECTORY.resolve(CONFIGURATION_FILE);
    JsonReader reader = new JsonReader();
    String contents = "";

    try {/* w w w .j av  a2 s. c o  m*/
        contents = new String(Files.readAllBytes(configFile), StandardCharsets.UTF_8);
    } catch (IOException ex) {
        System.out.println("Atlas building failed.");
        return;
    }

    JsonValue value = reader.parse(contents);
    JsonValue atlasList = value.get("atlas");

    for (int i = 0; i < atlasList.size; i++) {
        JsonValue currentAtlas = atlasList.get(i);
        String fileName = currentAtlas.getString("name");
        String imageName = currentAtlas.getString("image");
        int size = currentAtlas.getInt("size");
        String[] rows = currentAtlas.get("rows").asStringArray();
        String[] columns = currentAtlas.get("columns").asStringArray();

        //            String imageName = fileName.replace(".atlas", ".png");
        Path output = FileLocations.SPRITES_DIRECTORY.resolve(fileName);
        try (BufferedWriter bw = Files.newBufferedWriter(output); PrintWriter pw = new PrintWriter(bw)) {
            pw.println(imageName);
            pw.println("format: RGBA8888");
            pw.println("filter: Nearest,Nearest");
            pw.println("repeat: none");

            for (int row = 0; row < rows.length; row++) {
                for (int column = 0; column < columns.length; column++) {
                    String patchName = rows[row] + "-" + columns[column];
                    int x = column * size;
                    int y = row * size;

                    pw.println(patchName);
                    pw.println("  rotate: false");
                    pw.println("  xy: " + x + ", " + y);
                    pw.println("  size: " + size + ", " + size);
                    pw.println("  orig: 0, 0");
                    pw.println("  offset: 0, 0");
                    pw.println("  index: -1");
                }
            }
        } catch (IOException ex) {
            System.out.println("Problem with atlas for " + fileName);
        }
    }

    TexturePacker.Settings settings = new TexturePacker.Settings();
    settings.maxHeight = 2048;
    settings.maxWidth = 2048;
    TexturePacker.process(settings, MAIN_MENU_SKIN_DIRECTORY.toString(), MAIN_MENU_SKIN_DIRECTORY.toString(),
            "main_menu.atlas");

    System.out.println("Atlas building completed.");
}