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

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

Introduction

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

Prototype

public String asString() 

Source Link

Document

Returns this value as a string.

Usage

From source file:br.com.questingsoftware.libgdx.g3db.G3DBConverter.java

License:Apache License

private void writeObject(JsonValue root, UBJsonWriter writer) throws IOException {
    if (root.type() == ValueType.array) {
        if (root.name() != null) {
            writer.array(root.name());//from w ww .ja v  a  2 s.c  o  m
        } else {
            writer.array();
        }
    } else {
        if (root.name() != null) {
            writer.object(root.name());
        } else {
            writer.object();
        }
    }

    JsonValue child = root.child();
    while (child != null) {
        switch (child.type()) {
        case booleanValue:
            if (child.name() != null) {
                writer.set(child.name(), child.asBoolean());
            } else {
                writer.value(child.asBoolean());
            }
            break;

        case doubleValue:
            if (child.name() != null) {
                writer.set(child.name(), child.asDouble());
            } else {
                writer.value(child.asDouble());
            }
            break;

        case longValue:
            if (child.name() != null) {
                writer.set(child.name(), child.asLong());
            } else {
                writer.value(child.asLong());
            }
            break;

        case stringValue:
            if (child.name() != null) {
                writer.set(child.name(), child.asString());
            } else {
                writer.value(child.asString());
            }
            break;

        case nullValue:
            if (child.name() != null) {
                writer.set(child.name());
            }
            break;

        case array:
        case object:
            writeObject(child, writer);
            break;
        }

        child = child.next();
    }

    writer.pop();
}

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());
        tiles.add(VOBGame.instance.getTextureManager().getSpriteFromAtlas(atlas, v.asString()));
        depths.add(VOBGame.instance.getTextureManager().getSpriteFromAtlas(atlas, v.asString() + "-depth"));
    }//from w w w .  jav a 2s.c  o m
}

From source file:com.ahsgaming.valleyofbones.screens.MPGameSetupScreen.java

License:Apache License

public void setupScreen() {

    Label gameTypeLbl = new Label("Multiplayer", getSkin(), "medium");

    Table table = new Table(getSkin());
    table.setFillParent(true);//from  www .j  a v a  2 s.  c o  m
    stage.addActor(table);

    table.add(gameTypeLbl).colspan(2).center();
    table.row().minWidth(600);

    Table playerTable = new Table(getSkin());
    playerTable.setBackground(getSkin().getDrawable("default-pane"));

    playerTable.add().padBottom(10).width(30);
    playerTable.add().padBottom(10).width(30);
    playerTable.add(new Label("Name", getSkin(), "small-grey")).padBottom(10);
    playerTable.add(new Label("Race", getSkin(), "small-grey")).padBottom(10);
    playerTable.add(new Label("Color", getSkin(), "small-grey")).padBottom(10);
    playerTable.add(new Label("Ready", getSkin(), "small-grey")).padBottom(10).row();

    pList = new Array<Player>();
    pList.addAll(game.getPlayers());

    for (final Player p : pList) {
        playerTable.add("P" + ((pList.indexOf(p, true) + 1))).padLeft(10);
        if (pList.indexOf(p, true) == 0) {
            Image host = new Image(game.getTextureManager().getSpriteFromAtlas("assets", "king-small"));
            playerTable.add(host).size(host.getWidth() / VOBGame.SCALE, host.getHeight() / VOBGame.SCALE)
                    .padLeft(10).padRight(10);
        } else {
            if (config.isHost) {
                Image btn = getRemovePlayerButton(p.getPlayerId());
                playerTable.add(btn).size(btn.getWidth() / VOBGame.SCALE, btn.getHeight() / VOBGame.SCALE)
                        .padLeft(10).padRight(10);
            } else {
                playerTable.add().padLeft(10).padRight(10);
            }
        }

        playerTable.add(new Label(String.format("%s (%d)", p.getPlayerName(), p.getPlayerId()), getSkin()))
                .left().expandX();

        if (p == client.getPlayer() || (config.isHost && p.isAI())) {

            SelectBox raceSelect = new SelectBox(Prototypes.getRaces().toArray(), getSkin());
            playerTable.add(raceSelect).expandX();
            raceSelect.setSelection(p.getRace());

            raceSelect.addListener(new ChangeListener() {
                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    KryoCommon.UpdatePlayer update = new KryoCommon.UpdatePlayer();
                    update.id = p.getPlayerId();
                    update.race = ((SelectBox) actor).getSelection();
                    update.color = 0;
                    while (update.color < Player.AUTOCOLORS.length
                            && !p.getPlayerColor().equals(Player.AUTOCOLORS[update.color])) {
                        update.color++;
                    }
                    update.ready = p.isReady();
                    if (client instanceof MPGameClient)
                        ((MPGameClient) client).sendPlayerUpdate(update);
                }
            });

        } else {
            playerTable.add(p.getRace());
        }

        Image color = new Image(getSkin().getDrawable("white-hex"));
        color.setColor(p.getPlayerColor());
        playerTable.add(color).expandX().width(color.getWidth());

        if (p == client.getPlayer() || (config.isHost && p.isAI())) {
            color.addListener(new ClickListener() {
                @Override
                public void clicked(InputEvent event, float x, float y) {
                    super.clicked(event, x, y);
                    int i = 0;
                    while (i < Player.AUTOCOLORS.length
                            && !Player.AUTOCOLORS[i].equals(event.getTarget().getColor())) {
                        i++;
                    }
                    i++;

                    i %= Player.AUTOCOLORS.length;
                    event.getTarget().setColor(Player.AUTOCOLORS[i]);

                    KryoCommon.UpdatePlayer update = new KryoCommon.UpdatePlayer();
                    update.id = p.getPlayerId();
                    update.race = p.getRace();
                    update.color = i;
                    update.ready = p.isReady();
                    if (client instanceof MPGameClient)
                        ((MPGameClient) client).sendPlayerUpdate(update);
                }
            });
        }

        CheckBox chkReady = new CheckBox("", getSkin());
        playerTable.add(chkReady).expandX();

        chkReady.setChecked(p.isReady());
        if (p != client.getPlayer())
            chkReady.setDisabled(true);

        chkReady.addListener(new ChangeListener() {
            @Override
            public void changed(ChangeEvent event, Actor actor) {
                KryoCommon.UpdatePlayer update = new KryoCommon.UpdatePlayer();
                update.id = p.getPlayerId();
                update.race = p.getRace();
                update.color = 0;
                while (update.color < Player.AUTOCOLORS.length
                        && !p.getPlayerColor().equals(Player.AUTOCOLORS[update.color])) {
                    update.color++;
                }
                update.ready = !p.isReady();
                if (client instanceof MPGameClient)
                    ((MPGameClient) client).sendPlayerUpdate(update);
            }
        });

        playerTable.row().padBottom(5).padTop(5);
    }

    if (pList.size < 2 && config.isHost) {
        TextButton addAI = new TextButton(" Add AI Player ", getSkin(), "small");
        addAI.addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
                super.clicked(event, x, y);

                game.addAIPlayer();
            }
        });
        playerTable.add();
        playerTable.add();
        playerTable.add(addAI).colspan(5).left();
    }

    table.add(playerTable).fillX().colspan(2);

    table.row();

    sList = game.getSpectators();
    if (sList.keySet().size() > 0) {
        table.add("Spectators").colspan(2).left();
        table.row();

        Table spectatorTable = new Table(getSkin());
        spectatorTable.setBackground(getSkin().getDrawable("default-pane"));

        for (Integer id : sList.keySet()) {
            if (config.isHost) {
                Image btn = getRemovePlayerButton(id);
                spectatorTable.add(btn).size(btn.getWidth() / VOBGame.SCALE, btn.getHeight() / VOBGame.SCALE)
                        .padLeft(10).padRight(10);
            }
            spectatorTable.add(sList.get(id)).expandX().left();
            spectatorTable.row().expandX().padBottom(5).padTop(5);
        }

        table.add(spectatorTable).fillX().colspan(2);
        table.row();
    }

    ChangeListener updateListener = new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            needsUpdate = true;
        }
    };

    Table setupTable = new Table(getSkin());

    chkSpectators = new CheckBox(" Allow Spectators?", getSkin());
    chkSpectators.setChecked(config.allowSpectate);
    chkSpectators.setDisabled(!config.isHost);
    chkSpectators.addListener(updateListener);
    setupTable.add(chkSpectators).colspan(2).left().padTop(4).row();

    Label mapLbl = new Label("Map:", getSkin());
    setupTable.add(mapLbl).left();

    if (config.isHost) {
        needsUpdate = true; // always send an update on setup, just so we're all on the same page

        JsonReader reader = new JsonReader();
        JsonValue val = reader.parse(Gdx.files.internal("maps/maps.json").readString());

        Array<String> maps = new Array<String>();
        for (JsonValue v : val) {
            maps.add(v.asString());
        }

        mapSelect = new SelectBox(maps.toArray(), getSkin());
        mapSelect.setSelection(config.mapName);

        mapSelect.addListener(updateListener);

        setupTable.add(mapSelect).left().padTop(4).padBottom(4).fillX();
    } else {
        lblMap = new Label(config.mapName, getSkin());
        setupTable.add(lblMap).left();
    }
    setupTable.row();

    setupTable.add("Rules:").left();
    if (config.isHost) {
        Array<VOBGame.RuleSet> ruleSets = game.getRuleSets();
        String[] items = new String[ruleSets.size];
        for (int i = 0; i < ruleSets.size; i++) {
            items[i] = ruleSets.get(i).name;
        }
        ruleSelect = new SelectBox(items, getSkin());
        setupTable.add(ruleSelect).left().padBottom(4).fillX();
        ruleSelect.setSelection(config.ruleSet);

        ruleSelect.addListener(updateListener);
    } else {
        lblRule = new Label(game.getRuleSets().get(config.ruleSet).name, getSkin());
        setupTable.add(lblRule).left();
    }
    setupTable.row();

    setupTable.add("Starting Locations:").left();
    if (config.isHost) {
        spawnSelect = new SelectBox(spawnTypes, getSkin());
        setupTable.add(spawnSelect).left().padBottom(4).fillX();
        spawnSelect.setSelection(config.spawnType);

        spawnSelect.addListener(updateListener);
    } else {
        lblSpawn = new Label(spawnTypes[config.spawnType], getSkin());
        setupTable.add(lblSpawn).left();
    }
    setupTable.row();

    setupTable.add("First Move:").left();
    if (config.isHost) {
        moveSelect = new SelectBox(firstMoves, getSkin());
        setupTable.add(moveSelect).left().padBottom(4).fillX();
        moveSelect.setSelection(config.firstMove);

        moveSelect.addListener(updateListener);
    } else {
        lblMove = new Label(firstMoves[config.firstMove], getSkin());
        setupTable.add(lblMove).left();
    }
    setupTable.row();

    setupTable.add("Timing Rules:").colspan(2).left().row();

    Table timingTable = new Table(getSkin());
    setupTable.add(timingTable).colspan(2).fillX();

    timingTable.add("Base:").left().expandX();
    if (config.isHost) {
        baseTime = new SelectBox(new String[] { "30", "60", "90" }, getSkin());
        timingTable.add(baseTime).expandX().padLeft(4);
        baseTime.setSelection(Integer.toString(config.baseTimer));
        baseTime.addListener(updateListener);
    } else {
        lblBaseTime = new Label(Integer.toString(config.baseTimer), getSkin());
        timingTable.add(lblBaseTime).expandX().padLeft(4);
    }

    timingTable.add("Action:").left().expandX().padLeft(4);
    if (config.isHost) {
        actionTime = new SelectBox(new String[] { "0", "15", "30" }, getSkin());
        timingTable.add(actionTime).expandX().padLeft(4);
        actionTime.setSelection(Integer.toString(config.actionBonusTime));
        actionTime.addListener(updateListener);
    } else {
        lblActionTime = new Label(Integer.toString(config.actionBonusTime), getSkin());
        timingTable.add(lblActionTime).expandX().padLeft(4);
    }

    timingTable.add("Unit:").left().expandX().padLeft(4);
    if (config.isHost) {
        unitTime = new SelectBox(new String[] { "0", "3", "5" }, getSkin());
        timingTable.add(unitTime).expandX().padLeft(4);
        unitTime.setSelection(Integer.toString(config.unitBonusTime));
        unitTime.addListener(updateListener);
    } else {
        lblUnitTime = new Label(Integer.toString(config.unitBonusTime), getSkin());
        timingTable.add(lblUnitTime).expandX().padLeft(4);
    }

    table.add(setupTable).fillX();

    Table controlTable = new Table(getSkin());

    Sprite mapThumb = game.getTextureManager().getSpriteFromAtlas("assets", config.mapName);
    if (mapThumb != null) {
        controlTable.add(new Image(mapThumb)).colspan(2).row();
    }

    if (config.isHost) {
        isHost = true;
        TextButton start = new TextButton("Start Game", getSkin());
        start.addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
                super.clicked(event, x, y);
                if (game.getPlayers().size >= 2)
                    game.sendStartGame();
            }
        });
        controlTable.add().expand();
        controlTable.add(start).padTop(4).right();

        controlTable.row();
    }

    TextButton cancel = new TextButton("Cancel", getSkin(), "cancel");
    cancel.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            game.setScreen(game.getMainMenuScreen());
            game.closeGame();
        }
    });

    controlTable.add();
    controlTable.add(cancel).fillX().padTop(4).right();

    table.add(controlTable).fillX().row();

    if (chatTable == null) {
        chatTable = new Table(getSkin());
        chatScroll = new ScrollPane(chatTable, getSkin());
        chatScroll.setFadeScrollBars(false);
        chatTable.padLeft(20);
    }
    table.add(chatScroll).colspan(2).fillX().height(100);

    table.row();

    Table chatBox = new Table(getSkin());
    final TextField chatMsgText = new TextField("", getSkin());
    if (chatListener != null) {
        stage.removeListener(chatListener);
    }
    stage.addListener(new InputListener() {
        @Override
        public boolean keyUp(InputEvent event, int keycode) {
            if (stage.getKeyboardFocus() == chatMsgText && keycode == Input.Keys.ENTER
                    && chatMsgText.getText().length() > 0) {
                Gdx.app.log(LOG, "Chat: " + chatMsgText.getText());
                client.sendChat(chatMsgText.getText());
                chatMsgText.setText("");
                return false;
            }
            return super.keyUp(event, keycode);
        }
    });

    chatBox.add(chatMsgText).expandX().fillX();
    TextButton chatMsgSend = new TextButton("Send", getSkin(), "small");
    chatMsgSend.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y); //To change body of overridden methods use File | Settings | File Templates.

            if (chatMsgText.getText().length() > 0) {
                Gdx.app.log(LOG, "Chat: " + chatMsgText.getText());
                client.sendChat(chatMsgText.getText());
                chatMsgText.setText("");
            }
        }
    });
    chatBox.add(chatMsgSend).fillY().fillX();
    table.add(chatBox).colspan(2).fillX();
    chatHistory = new Array<String>();
}

From source file:com.ahsgaming.valleyofbones.screens.SPGameSetupScreen.java

License:Apache License

public void setupScreen() {

    Label gameTypeLbl = new Label("Single Player", getSkin(), "medium");

    Table table = new Table(getSkin());
    table.setFillParent(true);/*from w ww. j a va  2 s  . co  m*/
    stage.addActor(table);

    table.add(gameTypeLbl).colspan(2).center();
    table.row().minWidth(600);

    Table playerTable = new Table(getSkin());
    playerTable.setBackground(getSkin().getDrawable("default-pane"));

    playerTable.add().padBottom(10).width(30);
    playerTable.add().padBottom(10).width(30);
    playerTable.add(new Label("Name", getSkin(), "small-grey")).padBottom(10);
    playerTable.add(new Label("Race", getSkin(), "small-grey")).padBottom(10);
    playerTable.add(new Label("Color", getSkin(), "small-grey")).padBottom(10).row();

    pList = new Array<Player>();
    pList.addAll(game.getPlayers());

    for (final Player p : pList) {
        playerTable.add("P" + ((pList.indexOf(p, true) + 1))).padLeft(10);
        if (pList.indexOf(p, true) == 0) {
            Image host = new Image(game.getTextureManager().getSpriteFromAtlas("assets", "king-small"));
            playerTable.add(host).size(host.getWidth() / VOBGame.SCALE, host.getHeight() / VOBGame.SCALE)
                    .padLeft(10).padRight(10);
        } else {
            playerTable.add().padLeft(10).padRight(10);
        }

        playerTable.add(new Label(String.format("%s (%d)", p.getPlayerName(), p.getPlayerId()), getSkin()))
                .expandX().left();

        SelectBox raceSelect = new SelectBox(Prototypes.getRaces().toArray(), getSkin());
        playerTable.add(raceSelect).expandX();
        raceSelect.setSelection(p.getRace());

        raceSelect.addListener(new ChangeListener() {
            @Override
            public void changed(ChangeEvent event, Actor actor) {
                p.setRace(((SelectBox) actor).getSelection());
            }
        });

        Image color = new Image(getSkin().getDrawable("white-hex"));
        color.setColor(p.getPlayerColor());
        playerTable.add(color).expandX();

        color.addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
                super.clicked(event, x, y);
                int i = 0;
                while (i < Player.AUTOCOLORS.length
                        && !Player.AUTOCOLORS[i].equals(event.getTarget().getColor())) {
                    i++;
                }
                i++;

                i %= Player.AUTOCOLORS.length;
                event.getTarget().setColor(Player.AUTOCOLORS[i]);
                p.setPlayerColor(Player.AUTOCOLORS[i]);
            }
        });

        playerTable.row().padBottom(5).padTop(5);
    }

    table.add(playerTable).fillX().colspan(2);

    table.row();

    Table setupTable = new Table(getSkin());

    Label mapLbl = new Label("Map:", getSkin());
    setupTable.add(mapLbl).left();

    JsonReader reader = new JsonReader();
    JsonValue val = reader.parse(Gdx.files.internal("maps/maps.json").readString());

    Array<String> maps = new Array<String>();
    for (JsonValue v : val) {
        maps.add(v.asString());
    }

    mapSelect = new SelectBox(maps.toArray(), getSkin());
    mapSelect.setSelection(config.mapName);
    config.mapName = mapSelect.getSelection();

    mapSelect.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            config.mapName = ((SelectBox) actor).getSelection();
            needsUpdate = true;
        }
    });

    mapThumb = new Image(game.getTextureManager().getSpriteFromAtlas("assets", config.mapName));

    setupTable.add(mapSelect).left().padBottom(4).padTop(4).fillX();
    setupTable.row();

    setupTable.add("Rules:").left();
    SelectBox ruleSelect = new SelectBox(new String[] { "Classic" }, getSkin());

    ruleSelect.setSelection(config.ruleSet);
    ruleSelect.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            config.ruleSet = ((SelectBox) actor).getSelectionIndex();
        }
    });

    setupTable.add(ruleSelect).left().padBottom(4).fillX();
    setupTable.row();

    setupTable.add("Starting Locations:").left();
    SelectBox spawnSelect = new SelectBox(new String[] { "Normal", "Inverted", "Random" }, getSkin());

    spawnSelect.setSelection(config.spawnType);
    spawnSelect.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            config.spawnType = ((SelectBox) actor).getSelectionIndex();
        }
    });

    setupTable.add(spawnSelect).left().padBottom(4).fillX();
    setupTable.row();

    setupTable.add("First Move:").left();
    SelectBox moveSelect = new SelectBox(new String[] { "Random", "P1", "P2" }, getSkin());

    moveSelect.setSelection(config.firstMove);
    moveSelect.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            config.firstMove = ((SelectBox) actor).getSelectionIndex();
        }
    });

    setupTable.add(moveSelect).left().padBottom(4).fillX();
    setupTable.row();

    setupTable.add("Timing Rules:").colspan(2).left().row();

    Table timingTable = new Table(getSkin());
    setupTable.add(timingTable).colspan(2).fillX();

    timingTable.add("Base:").left().expandX();
    SelectBox baseTime = new SelectBox(new String[] { "30", "60", "90" }, getSkin());
    timingTable.add(baseTime).expandX();
    baseTime.setSelection(Integer.toString(config.baseTimer));
    baseTime.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            config.baseTimer = Integer.parseInt(((SelectBox) actor).getSelection());
        }
    });

    timingTable.add("Action:").left().expandX();
    SelectBox actionTime = new SelectBox(new String[] { "0", "15", "30" }, getSkin());
    timingTable.add(actionTime).expandX();
    actionTime.setSelection(Integer.toString(config.actionBonusTime));
    actionTime.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            config.actionBonusTime = Integer.parseInt(((SelectBox) actor).getSelection());
        }
    });

    timingTable.add("Unit:").left().expandX();
    SelectBox unitTime = new SelectBox(new String[] { "0", "3", "5" }, getSkin());
    timingTable.add(unitTime).expandX();
    unitTime.setSelection(Integer.toString(config.unitBonusTime));
    unitTime.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            config.unitBonusTime = Integer.parseInt(((SelectBox) actor).getSelection());
        }
    });

    setupTable.row().expandX().expandY().top().left();

    table.add(setupTable).fill();

    Table controlTable = new Table(getSkin());

    controlTable.add(mapThumb).colspan(2).row();

    isHost = true;
    TextButton start = new TextButton("Start Game", getSkin());
    start.addListener(new ClickListener() {

        /* (non-Javadoc)
         * @see com.badlogic.gdx.scenes.scene2d.utils.ClickListener#touchUp(com.badlogic.gdx.scenes.scene2d.InputEvent, float, float, int, int)
         */
        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            super.touchUp(event, x, y, pointer, button);
            if (game.getPlayers().size >= 2)
                game.sendStartGame();
        }

    });
    controlTable.add().expand();
    controlTable.add(start).padTop(4).right();

    controlTable.row();

    TextButton cancel = new TextButton("Cancel", getSkin(), "cancel");
    cancel.addListener(new ClickListener() {

        /* (non-Javadoc)
         * @see com.badlogic.gdx.scenes.scene2d.utils.ClickListener#touchUp(com.badlogic.gdx.scenes.scene2d.InputEvent, float, float, int, int)
         */
        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            super.touchUp(event, x, y, pointer, button);

            game.setScreen(game.getMainMenuScreen());
            game.closeGame();

        }

    });

    controlTable.add();
    controlTable.add(cancel).fillX().padTop(4);

    table.add(controlTable).fillX();

    table.row();
}

From source file:com.ahsgaming.valleyofbones.Utils.java

License:Apache License

public static Array<Object> jsonAsArray(JsonValue json) {
    Array<Object> returnVal = new Array<Object>();
    for (JsonValue v : json) {
        returnVal.add((v.isValue() ? v.asString() : (v.isObject() ? v : jsonAsArray(v))));
    }//from  www. ja va  2  s .c o m
    return returnVal;
}

From source file:com.company.minery.utils.spine.SkeletonJson.java

License:Open Source License

void readCurve(CurveTimeline timeline, int frameIndex, JsonValue valueMap) {
    JsonValue curve = valueMap.get("curve");
    if (curve == null)
        return;//from   w  w w .j  av a  2 s.c o  m
    if (curve.isString() && curve.asString().equals("stepped"))
        timeline.setStepped(frameIndex);
    else if (curve.isArray()) {
        timeline.setCurve(frameIndex, curve.getFloat(0), curve.getFloat(1), curve.getFloat(2),
                curve.getFloat(3));
    }
}

From source file:com.esotericsoftware.spine.JsonRollback.java

License:Open Source License

static Array<JsonValue> find(JsonValue current, Array<JsonValue> values, int index, String... path) {
    String name = path[index];//from ww w.  j  a  v a2s. c om
    if (current.name == null) {
        if (name.equals("*") && index == path.length - 1)
            values.add(current);
        else if (current.has(name))
            return find(current.get(name), values, index, path);
    } else if (name.equals("*") || current.name.equals(name)) {
        if (++index == path.length
                || (index == path.length - 1 && current.isString() && current.asString().equals(path[index])))
            values.add(current);
        else {
            for (JsonValue child = current.child; child != null; child = child.next)
                find(child, values, index, path);
        }
    }
    return values;
}

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

License:Open Source License

public void readFile(FileHandle fileHandle) throws Exception {
    main.getProjectData().setChangesSaved(false);

    //read drawables from texture atlas file
    FileHandle atlasHandle = fileHandle.sibling(fileHandle.nameWithoutExtension() + ".atlas");
    if (atlasHandle.exists()) {
        main.getProjectData().getAtlasData().readAtlas(atlasHandle);
    }/*w  ww  . j a  v  a  2s  .co  m*/

    //folder for critical files to be copied to
    FileHandle saveFile = main.getProjectData().getSaveFile();
    FileHandle targetDirectory;
    if (saveFile != null) {
        targetDirectory = saveFile.sibling(saveFile.nameWithoutExtension() + "_data");
    } else {
        targetDirectory = Gdx.files.local("temp/" + main.getProjectData().getId() + "_data");
    }

    //read json file and create styles
    JsonReader reader = new JsonReader();
    JsonValue val = reader.parse(fileHandle);

    for (JsonValue child : val.iterator()) {
        //fonts
        if (child.name().equals(BitmapFont.class.getName())) {
            for (JsonValue font : child.iterator()) {
                FileHandle fontFile = fileHandle.sibling(font.getString("file"));
                FileHandle fontCopy = targetDirectory.child(font.getString("file"));
                if (!fontCopy.parent().equals(fontFile.parent())) {
                    fontFile.copyTo(fontCopy);
                }
                FontData fontData = new FontData(font.name(), fontCopy);

                //delete fonts with the same name
                for (FontData originalData : new Array<>(fonts)) {
                    if (originalData.getName().equals(fontData.getName())) {
                        fonts.removeValue(originalData, true);
                    }
                }

                fonts.add(fontData);

                BitmapFont.BitmapFontData bitmapFontData = new BitmapFont.BitmapFontData(fontCopy, false);
                for (String path : bitmapFontData.imagePaths) {
                    FileHandle file = new FileHandle(path);
                    main.getProjectData().getAtlasData()
                            .getDrawable(file.nameWithoutExtension()).visible = false;
                }
            }
        } //colors
        else if (child.name().equals(Color.class.getName())) {
            for (JsonValue color : child.iterator()) {
                ColorData colorData = new ColorData(color.name, new Color(color.getFloat("r", 0.0f),
                        color.getFloat("g", 0.0f), color.getFloat("b", 0.0f), color.getFloat("a", 0.0f)));

                //delete colors with the same name
                for (ColorData originalData : new Array<>(colors)) {
                    if (originalData.getName().equals(colorData.getName())) {
                        colors.removeValue(originalData, true);
                    }
                }

                colors.add(colorData);
            }
        } //tinted drawables
        else if (child.name().equals(TintedDrawable.class.getName())) {
            for (JsonValue tintedDrawable : child.iterator()) {
                DrawableData drawableData = new DrawableData(main.getProjectData().getAtlasData()
                        .getDrawable(tintedDrawable.getString("name")).file);
                drawableData.name = tintedDrawable.name;

                if (!tintedDrawable.get("color").isString()) {
                    drawableData.tint = new Color(tintedDrawable.get("color").getFloat("r", 0.0f),
                            tintedDrawable.get("color").getFloat("g", 0.0f),
                            tintedDrawable.get("color").getFloat("b", 0.0f),
                            tintedDrawable.get("color").getFloat("a", 0.0f));
                } else {
                    drawableData.tintName = tintedDrawable.getString("color");
                }

                //todo:test overwriting a base drawable that is depended on by another tint
                //delete drawables with the same name
                for (DrawableData originalData : new Array<>(
                        main.getProjectData().getAtlasData().getDrawables())) {
                    if (originalData.name.equals(drawableData.name)) {
                        main.getProjectData().getAtlasData().getDrawables().removeValue(originalData, true);
                    }
                }

                main.getProjectData().getAtlasData().getDrawables().add(drawableData);
            }
        } //styles
        else {
            int classIndex = 0;
            Class matchClass = ClassReflection.forName(child.name);
            for (Class clazz : Main.STYLE_CLASSES) {
                if (clazz.equals(matchClass)) {
                    break;
                } else {
                    classIndex++;
                }
            }

            Class clazz = Main.BASIC_CLASSES[classIndex];
            for (JsonValue style : child.iterator()) {
                StyleData data = newStyle(clazz, style.name);
                for (JsonValue property : style.iterator()) {
                    StyleProperty styleProperty = data.properties.get(property.name);
                    if (styleProperty.type.equals(Float.TYPE)) {
                        styleProperty.value = (double) property.asFloat();
                    } else if (styleProperty.type.equals(Color.class)) {
                        if (property.isString()) {
                            styleProperty.value = property.asString();
                        } else {
                            Gdx.app.error(getClass().getName(),
                                    "Can't import JSON files that do not use predefined colors.");
                        }
                    } else {
                        if (property.isString()) {
                            styleProperty.value = property.asString();
                        } else {
                            Gdx.app.error(getClass().getName(),
                                    "Can't import JSON files that do not use String names for field values.");
                        }
                    }
                }
            }
        }
    }
}

From source file:com.strategames.engine.storage.GameMetaData.java

License:Open Source License

@Override
public void read(Json json, JsonValue jsonData) {
    JsonValue child = jsonData.child();

    while (child != null) {
        if (child.name.contentEquals("uuid")) {
            uuid = child.asString();
        } else if (child.name.contentEquals("name")) {
            name = child.asString();//from   www  . jav a 2 s  . c o m
        } else if (child.name.contentEquals("designer")) {
            designer = child.asString();
        } else if (child.name.contentEquals("info")) {
            parseAdditionalInfo(child.asString());
        }

        child = child.next();
    }
}

From source file:com.tnf.ptm.common.GameColors.java

License:Apache License

public GameColors() {
    Json json = Assets.getJson(new ResourceUrn("core:colorsConfig"));
    JsonValue rootNode = json.getJsonValue();

    for (JsonValue colVal : rootNode) {
        Color c = load(colVal.asString());
        colors.put(colVal.name, c);//from  www . ja  v  a 2  s  .c om
    }

    json.dispose();

    fire = get("fire");
    smoke = get("smoke");
    hullLights = get("hullLights");
}