Search in sources :

Example 71 with JsonValue

use of com.badlogic.gdx.utils.JsonValue in project talos by rockbite.

the class AttachmentPoint method read.

@Override
public void read(Json json, JsonValue jsonData) {
    attachedToSlot = jsonData.getInt("slotId", -1);
    type = Type.valueOf(jsonData.getString("type", Type.STATIC.name()));
    if (type == Type.ATTACHED) {
        attachmentType = AttachmentType.valueOf(jsonData.getString("attachmentType", AttachmentType.POSITION.name()));
        boneName = jsonData.getString("boneName");
        offset = json.readValue(Vector2.class, jsonData.get("offset"));
    } else {
        JsonValue arr = jsonData.get("value");
        numericalValue.set(arr.get(0).asFloat(), arr.get(1).asFloat(), arr.get(2).asFloat());
    }
}
Also used : Vector2(com.badlogic.gdx.math.Vector2) JsonValue(com.badlogic.gdx.utils.JsonValue)

Example 72 with JsonValue

use of com.badlogic.gdx.utils.JsonValue in project talos by rockbite.

the class BvbProject method loadProject.

@Override
public void loadProject(FileHandle projectFileHandle, String data, boolean fromMemory) {
    Json json = new Json();
    JsonValue jsonValue = new JsonReader().parse(data);
    bvBAddon.workspace.read(json, jsonValue);
}
Also used : JsonValue(com.badlogic.gdx.utils.JsonValue) JsonReader(com.badlogic.gdx.utils.JsonReader) Json(com.badlogic.gdx.utils.Json)

Example 73 with JsonValue

use of com.badlogic.gdx.utils.JsonValue in project talos by rockbite.

the class Prefab method load.

@Override
public void load(String data) {
    JsonValue jsonValue = new JsonReader().parse(data);
    Json json = new Json();
    root = json.readValue(GameObject.class, jsonValue.get("root"));
}
Also used : JsonValue(com.badlogic.gdx.utils.JsonValue) JsonReader(com.badlogic.gdx.utils.JsonReader) Json(com.badlogic.gdx.utils.Json)

Example 74 with JsonValue

use of com.badlogic.gdx.utils.JsonValue in project computercombat by janfic.

the class LoadingScreen method show.

@Override
public void show() {
    this.skin = new Skin(Gdx.files.internal(Assets.SKIN));
    this.camera = new OrthographicCamera(1920 / 4, 1080 / 4);
    this.stage = ComputerCombatGame.makeNewStage(camera);
    Pixmap cursor = new Pixmap(Gdx.files.internal(Assets.CURSOR));
    Gdx.graphics.setCursor(Gdx.graphics.newCursor(cursor, 0, 0));
    this.progressBar = new ProgressBar(0, 1, 0.01f, false, skin.get("default-horizontal", ProgressBarStyle.class));
    this.statusLabel = new Label("Loading Assets...", skin);
    Table table = new Table(skin);
    table.setFillParent(true);
    table.add(statusLabel).row();
    table.add(progressBar);
    Thread thread = new Thread(new Runnable() {

        @Override
        public void run() {
            int index = 0;
            int tries = 0;
            JsonReader json = new JsonReader();
            JsonValue parsed = json.parse(Gdx.files.internal("connections.json"));
            List<String> connections = new ArrayList<>();
            for (JsonValue jsonValue : parsed.child) {
                connections.add(jsonValue.getString("ip") + " " + jsonValue.getString("port"));
            }
            System.out.println(connections);
            boolean connected = false;
            while (connected == false) {
                try {
                    String[] connection = connections.get(index).split(" ");
                    game.setServerAPI(new ServerAPI(Gdx.net.newClientSocket(Net.Protocol.TCP, connection[0], Integer.parseInt(connection[1]), new SocketHints())));
                    connected = true;
                    Thread.sleep(5);
                } catch (Exception e) {
                    tries++;
                    statusLabel.setText("Failed to Connect to server. Trying again. (" + tries + ")");
                    if (tries > 4) {
                        statusLabel.setText("Trying a different server...");
                        tries = 0;
                        index++;
                        index = index % connections.size();
                    }
                }
            }
            game.getServerAPI().sendMessage(new Message(Type.CONNECTION_REQUEST, "CONNECTION_REQUEST"));
        }
    });
    thread.start();
    stage.addActor(table);
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Message(com.janfic.games.computercombat.network.Message) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) JsonValue(com.badlogic.gdx.utils.JsonValue) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) JsonReader(com.badlogic.gdx.utils.JsonReader) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) ArrayList(java.util.ArrayList) List(java.util.List) ServerAPI(com.janfic.games.computercombat.network.client.ServerAPI) SocketHints(com.badlogic.gdx.net.SocketHints) ProgressBar(com.badlogic.gdx.scenes.scene2d.ui.ProgressBar) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 75 with JsonValue

use of com.badlogic.gdx.utils.JsonValue in project computercombat by janfic.

the class MatchState method read.

@Override
public void read(Json json, JsonValue jsonData) {
    json.setTypeName("class");
    this.players = json.readValue("players", List.class, Player.class, jsonData);
    json.setTypeName(null);
    this.isGameOver = json.readValue("isGameOver", boolean.class, jsonData);
    this.winner = json.readValue("winner", String.class, jsonData);
    this.currentPlayerMove = json.readValue("currentPlayerMove", String.class, jsonData);
    this.decks = json.readValue("decks", HashMap.class, Deck.class, jsonData);
    HashMap<String, List<JsonValue>> v = json.readValue("activeEntities", HashMap.class, List.class, jsonData);
    this.activeEntities = new HashMap<>();
    for (String string : v.keySet()) {
        List<Card> cards = new ArrayList<>();
        for (JsonValue jsonValue : v.get(string)) {
            Card c = json.readValue(Card.class, jsonValue);
            cards.add(c);
        }
        activeEntities.put(string, cards);
    }
    this.computers = json.readValue("computers", HashMap.class, Card.class, jsonData);
    String boardString = json.readValue("componentBoard", String.class, jsonData);
    componentBoard = new Component[8][8];
    assert (boardString.length() == 64);
    for (int i = 0; i < boardString.length(); i++) {
        int x = i / 8;
        int y = i % 8;
        try {
            componentBoard[x][y] = new Component(Integer.parseInt("" + boardString.substring(i, i + 1)), x, y);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    json.setTypeName("class");
}
Also used : Player(com.janfic.games.computercombat.model.Player) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JsonValue(com.badlogic.gdx.utils.JsonValue) Deck(com.janfic.games.computercombat.model.Deck) Card(com.janfic.games.computercombat.model.Card) ArrayList(java.util.ArrayList) List(java.util.List) Component(com.janfic.games.computercombat.model.Component)

Aggregations

JsonValue (com.badlogic.gdx.utils.JsonValue)148 JsonReader (com.badlogic.gdx.utils.JsonReader)27 IOException (java.io.IOException)21 Array (com.badlogic.gdx.utils.Array)20 Json (com.badlogic.gdx.utils.Json)15 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)14 FileHandle (com.badlogic.gdx.files.FileHandle)11 ReflectionException (com.badlogic.gdx.utils.reflect.ReflectionException)10 BladeJson (com.bladecoder.engine.serialization.BladeJson)9 HashMap (java.util.HashMap)8 Color (com.badlogic.gdx.graphics.Color)7 GraphBoxImpl (com.gempukku.libgdx.graph.ui.graph.GraphBoxImpl)7 ArrayList (java.util.ArrayList)7 Vector2 (com.badlogic.gdx.math.Vector2)6 Actor (com.badlogic.gdx.scenes.scene2d.Actor)6 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)6 Action (com.bladecoder.engine.actions.Action)6 File (java.io.File)6 ObjectMap (com.badlogic.gdx.utils.ObjectMap)5 SerializationException (com.badlogic.gdx.utils.SerializationException)5