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

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

Introduction

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

Prototype

public long getLong(int index) 

Source Link

Document

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

Usage

From source file:com.jupiter.europa.entity.EuropaEntity.java

License:Open Source License

@Override
public void read(Json json, JsonValue jsonData) {
    if (jsonData.has(OLD_ID_KEY)) {
        long oldID = jsonData.getLong(OLD_ID_KEY);
        EuropaGame.game.lastIdMapping.put(oldID, this);
    }/*from www.  j av  a 2  s  . co  m*/

    if (jsonData.has(COMPONENTS_KEY)) {
        JsonValue componentsValue = jsonData.get(COMPONENTS_KEY);

        componentsValue.iterator().forEach((JsonValue value) -> {
            try {
                if (value.has(COMPONENT_CLASS_KEY)) {
                    Class<?> type = Class.forName(value.getString(COMPONENT_CLASS_KEY));
                    if (Component.class.isAssignableFrom(type)) {
                        this.add((Component) json.fromJson(type,
                                value.get(COMPONENT_DATA_KEY).prettyPrint(EuropaGame.PRINT_SETTINGS)));
                    }
                }
            } catch (ClassNotFoundException ex) {

            }
        });

        this.initializeComponents();
    }
}

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 w  w  w  .  jav a2 s  . co 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.mbrlabs.mundus.commons.assets.meta.MetaLoader.java

License:Apache License

private void parseBasics(Meta meta, JsonValue jsonRoot) {
    meta.setVersion(jsonRoot.getInt(Meta.JSON_VERSION));
    meta.setLastModified(jsonRoot.getLong(Meta.JSON_LAST_MOD));
    meta.setUuid(jsonRoot.getString(Meta.JSON_UUID));
    meta.setType(AssetType.valueOf(jsonRoot.getString(Meta.JSON_TYPE)));
}

From source file:com.trgk.touchwave.facebook.FBService.java

License:Open Source License

/**
 * Update user information./* w  w w .ja  v a2  s  .c  o  m*/
 */
void updateUserInfo() {
    startWorking();

    GDXFacebookGraphRequest request = new GDXFacebookGraphRequest().setNode("me").useCurrentAccessToken();
    fbHandle.graph(request, new GDXFacebookCallback<JsonResult>() {
        @Override
        public void onSuccess(JsonResult result) {
            // Success
            JsonValue root = result.getJsonValue();
            userID = root.getLong("id");
            username = root.getString("name");
            lastActionResult = Result.SUCCESS;
        }

        @Override
        public void onError(GDXFacebookError error) {
            // Error
            lastActionResult = Result.FAILED;
            logout();
        }

        @Override
        public void onFail(Throwable t) {
            // Fail
            lastActionResult = Result.FAILED;
            logout();
        }

        @Override
        public void onCancel() {
            // Cancel
            lastActionResult = Result.CANCELED;
            logout();
        }
    });
}

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

License:Open Source License

/**
 * Load game data!//from  w  w w  . j a  va2  s . co  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();
}