Java Code Examples for com.badlogic.gdx.utils.JsonValue#getString()

The following examples show how to use com.badlogic.gdx.utils.JsonValue#getString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourceManager.java    From Unlucky with MIT License 6 votes vote down vote up
private void loadWorlds() {
    // parse worlds.json
    JsonValue base = jsonReader.parse(Gdx.files.internal("maps/worlds.json"));

    int worldIndex = 0;
    for (JsonValue world : base.get("worlds")) {
        String worldName = world.getString("name");
        String shortDesc = world.getString("shortDesc");
        String longDesc = world.getString("longDesc");
        int numLevels = world.getInt("numLevels");

        int levelIndex = 0;
        Level[] temp = new Level[numLevels];
        // load levels
        for (JsonValue level : world.get("levels")) {
            temp[levelIndex] = new Level(worldIndex, levelIndex, level.getString("name"), level.getInt("avgLevel"));
            levelIndex++;
        }
        worlds.add(new World(worldName, shortDesc, longDesc, numLevels, temp));

        worldIndex++;
    }
}
 
Example 2
Source File: MG3dModelLoader.java    From Mundus with Apache License 2.0 6 votes vote down vote up
public ModelData parseModel(FileHandle handle) {
    JsonValue json = reader.parse(handle);
    ModelData model = new ModelData();
    JsonValue version = json.require("version");
    model.version[0] = version.getShort(0);
    model.version[1] = version.getShort(1);
    if (model.version[0] != VERSION_HI || model.version[1] != VERSION_LO)
        throw new GdxRuntimeException("Model version not supported");

    model.id = json.getString("id", "");
    parseMeshes(model, json);
    parseMaterials(model, json, handle.parent().path());
    parseNodes(model, json);
    parseAnimations(model, json);
    return model;
}
 
Example 3
Source File: TextureDropModuleWrapper.java    From talos with Apache License 2.0 6 votes vote down vote up
@Override
public void read(Json json, JsonValue jsonData) {
    super.read(json, jsonData);

    filePath = jsonData.getString("filePath", null);
    regionName = jsonData.getString("regionName", null);

    // hack for older version to patch broken files (we should do version transition logic and move it there later)
    if(jsonData.has("fileName")) {
        filePath = jsonData.getString("fileName");
        regionName = filePath;
        if(filePath.contains(".")) {
            regionName =  regionName.substring(0, regionName.lastIndexOf("."));
        } else {
            filePath = filePath + ".png";
        }
    }

    final TalosAssetProvider assetProvider = TalosMain.Instance().TalosProject().getProjectAssetProvider();
    final Sprite textureRegion = assetProvider.findAsset(regionName, Sprite.class);

    setModuleRegion(regionName, textureRegion);
    dropWidget.setDrawable(new TextureRegionDrawable(textureRegion));
}
 
Example 4
Source File: GjScoreboardEntry.java    From gdx-gamesvcs with Apache License 2.0 6 votes vote down vote up
protected static GjScoreboardEntry fromJson(JsonValue json, int rank, String currentPlayer) {
    GjScoreboardEntry gje = new GjScoreboardEntry();
    gje.rank = String.valueOf(rank);
    gje.score = json.getString("score");
    gje.sort = json.getLong("sort");
    gje.tag = json.getString("extra_data");
    String userId = json.getString("user_id");

    if (userId != null && !userId.isEmpty()) {
        gje.userId = userId;
        gje.displayName = json.getString("user");
        gje.currentPlayer = (currentPlayer != null && currentPlayer.equalsIgnoreCase(gje.displayName));
    } else
        gje.displayName = json.getString("guest");

    gje.stored = json.getString("stored");

    return gje;
}
 
Example 5
Source File: MetaLoader.java    From Mundus with Apache License 2.0 5 votes vote down vote up
private void parseModel(Meta meta, JsonValue jsonModel) {
    if(jsonModel == null) return;

    final MetaModel model = new MetaModel();
    final JsonValue materials = jsonModel.get(MetaModel.JSON_DEFAULT_MATERIALS);

    for(final JsonValue mat : materials) {
        System.out.println(mat.name);
        final String g3dbID = mat.name;
        final String assetUUID = materials.getString(g3dbID);
        model.getDefaultMaterials().put(g3dbID, assetUUID);
    }

    meta.setModel(model);
}
 
Example 6
Source File: FreeTypeFontData.java    From skin-composer with MIT License 5 votes vote down vote up
@Override
public void read(Json json, JsonValue jsonData) {
    name = jsonData.getString("name");
    file = jsonData.has("file") ? Gdx.files.absolute(jsonData.getString("file")) : null;
    previewTTF = jsonData.getString("previewTTF");
    useCustomSerializer = jsonData.getBoolean("useCustomSerializer", false);
    size = jsonData.getInt("size", 16);
    mono = jsonData.getBoolean("mono");
    hinting = jsonData.getString("hinting", "AutoMedium");
    color = jsonData.getString("color");
    gamma = jsonData.getFloat("gamma", 1.8f);
    renderCount = jsonData.getInt("renderCount", 2);
    borderWidth = jsonData.getFloat("borderWidth", 0);
    borderColor = jsonData.getString("borderColor");
    borderStraight = jsonData.getBoolean("borderStraight", false);
    borderGamma = jsonData.getFloat("borderGamma", 1.8f);
    shadowOffsetX = jsonData.getInt("shadowOffsetX", 0);
    shadowOffsetY = jsonData.getInt("shadowOffsetY", 0);
    shadowColor = jsonData.getString("shadowColor");
    spaceX = jsonData.getInt("spaceX");
    spaceY = jsonData.getInt("spaceY");
    characters = jsonData.getString("characters", "");
    kerning = jsonData.getBoolean("kerning", true);
    flip = jsonData.getBoolean("flip", false);
    genMipMaps = jsonData.getBoolean("genMipMaps", false);
    minFilter = jsonData.getString("minFilter", "Nearest");
    magFilter = jsonData.getString("magFilter", "Nearest");
    incremental = jsonData.getBoolean("incremental");
}
 
Example 7
Source File: FontData.java    From skin-composer with MIT License 5 votes vote down vote up
@Override
public void read(Json json, JsonValue jsonData) {
    name = jsonData.getString("name");
    if (!jsonData.get("file").isNull()) {
        file = new FileHandle(jsonData.getString("file"));
    }
}
 
Example 8
Source File: CustomStyle.java    From skin-composer with MIT License 5 votes vote down vote up
@Override
public void read(Json json, JsonValue jsonData) {
    name = jsonData.getString("name");
    properties = json.readValue("properties", Array.class, CustomProperty.class, jsonData);
    for (CustomProperty property : properties) {
        property.setParentStyle(this);
    }
    deletable = jsonData.getBoolean("deletable");
}
 
Example 9
Source File: CustomClass.java    From skin-composer with MIT License 5 votes vote down vote up
@Override
public void read(Json json, JsonValue jsonData) {
    fullyQualifiedName = jsonData.getString("fullyQualifiedName");
    displayName = jsonData.getString("displayName");
    styles = json.readValue("styles", Array.class, CustomStyle.class, jsonData);
    for (CustomStyle style : styles) {
        style.setParentClass(this);
    }
    templateStyle = json.readValue("templateStyle", CustomStyle.class, jsonData);
    templateStyle.setParentClass(this);
    declareAfterUIclasses = jsonData.getBoolean("declareAfterUIclasses", false);
}
 
Example 10
Source File: GjTrophy.java    From gdx-gamesvcs with Apache License 2.0 5 votes vote down vote up
protected static GjTrophy fromJson(JsonValue json) {
    GjTrophy trophy = new GjTrophy();
    trophy.difficulty = json.getString("difficulty");
    trophy.trophyAchieved = json.getString("achieved");
    trophy.iconUrl = json.getString("image_url");
    trophy.trophyDesc = json.getString("description");
    trophy.trophyTitle = json.getString("title");
    trophy.trophyId = json.getString("id");

    return trophy;
}
 
Example 11
Source File: BoundEffect.java    From talos with Apache License 2.0 5 votes vote down vote up
@Override
public void read(Json json, JsonValue jsonData) {
    String effectName = jsonData.getString("effectName");
    String effectPath = parent.getWorkspace().getPath(effectName + ".p");
    FileHandle effectHandle = TalosMain.Instance().ProjectController().findFile(effectPath);
    this.name = effectName;

    if(effectHandle == null || !effectHandle.exists()) {
       throw new GdxRuntimeException("Particle effect not found");
    }

    parent.getWorkspace().registerTalosAssets(effectHandle);

    //TODO: refactor this
    ParticleEffectDescriptor descriptor = new ParticleEffectDescriptor();
    descriptor.setAssetProvider(TalosMain.Instance().TalosProject().getProjectAssetProvider());
    descriptor.load(effectHandle);
    parent.getWorkspace().getVfxLibrary().put(name, descriptor);

    // track this file
    TalosMain.Instance().FileTracker().trackFile(effectHandle, parent.getWorkspace().bvb.particleTracker);

    this.particleEffectDescriptor = descriptor;

    positionAttachment = json.readValue(AttachmentPoint.class, jsonData.get("positionAttachment"));
    JsonValue valueAttachmentsJson = jsonData.get("valueAttachments");
    for(JsonValue valueAttachmentJson: valueAttachmentsJson) {
        AttachmentPoint point = json.readValue(AttachmentPoint.class, valueAttachmentJson);
        valueAttachments.add(point);
    }

    setStartEvent(jsonData.getString("startEvent", ""));
    setCompleteEvent(jsonData.getString("completeEvent", ""));

    isBehind = jsonData.getBoolean("isBehind");

    setForever(startEvent.equals("") && completeEvent.equals(""));
}
 
Example 12
Source File: ModuleWrapperGroup.java    From talos with Apache License 2.0 5 votes vote down vote up
@Override
public void read(Json json, JsonValue jsonData) {
    init(VisUI.getSkin());
    Color color = json.readValue(Color.class, jsonData.get("color"));
    String text = jsonData.getString("text");
    wrappers = json.readValue(ObjectSet.class, jsonData.get("modules"));
    setText(text);
    setColor(color);
}
 
Example 13
Source File: PolylineModule.java    From talos with Apache License 2.0 5 votes vote down vote up
@Override
public void read (Json json, JsonValue jsonData) {
    super.read(json, jsonData);
    pointCount = jsonData.getInt("points", 0) + 2;
    polylineDrawable.setCount(pointCount - 2);
    regionName = jsonData.getString("regionName", "fire");
}
 
Example 14
Source File: FlipbookModule.java    From talos with Apache License 2.0 5 votes vote down vote up
@Override
public void read (Json json, JsonValue jsonData) {
    super.read(json, jsonData);
    regionName = jsonData.getString("regionName", "fire");

    rows = jsonData.getInt("rows", 1);
    cols = jsonData.getInt("cols", 1);
    duration = jsonData.getFloat("duration", 1);
}
 
Example 15
Source File: InputFileSerializer.java    From gdx-texture-packer-gui with Apache License 2.0 4 votes vote down vote up
@Override
public InputFile read(Json json, JsonValue jsonData, Class clazz) {
    String path = jsonData.getString("path");
    InputFile.Type type = InputFile.Type.valueOf(jsonData.getString("type"));
    String dirFilePrefix = jsonData.getString("dirFilePrefix", null);
    String regionName = jsonData.getString("regionName", null);
    boolean recursive = jsonData.getBoolean("recursive", false);
    boolean flattenPaths = jsonData.getBoolean("flattenPaths", false);

    FileHandle fileHandle;
    if (new File(path).isAbsolute()) {
        fileHandle = Gdx.files.absolute(path);
    } else {
        fileHandle = Gdx.files.absolute(new File(root, path).getAbsolutePath());
    }

    InputFile inputFile = new InputFile(fileHandle, type);
    inputFile.setDirFilePrefix(dirFilePrefix);
    inputFile.setRegionName(regionName);
    inputFile.setRecursive(recursive);
    inputFile.setFlattenPaths(flattenPaths);

    // Ninepatch
    JsonValue ninepatch = jsonData.get("ninepatch");
    if (ninepatch != null) {
        InputFile.NinePatchProps npp = inputFile.getNinePatchProps();
        int[] splits = ninepatch.get("splits").asIntArray();
        int[] pads = ninepatch.get("pads").asIntArray();
        npp.left = splits[0];
        npp.right = splits[1];
        npp.top = splits[2];
        npp.bottom = splits[3];
        npp.padLeft = pads[0];
        npp.padRight = pads[1];
        npp.padTop = pads[2];
        npp.padBottom = pads[3];
        inputFile.setProgrammaticNinePatch(true);
    }

    return inputFile;
}
 
Example 16
Source File: ClientServerMessage.java    From dice-heroes with GNU General Public License v3.0 4 votes vote down vote up
@Override public ClientServerMessage read(Json json, JsonValue jsonData, Class kind) {
    Type type = Type.valueOf(jsonData.getString("type"));
    String participant = jsonData.getString("participant", null);
    String data = jsonData.getString("data", null);
    return new ClientServerMessage(participant, type, data);
}
 
Example 17
Source File: Theme.java    From Klooni1010 with GNU General Public License v3.0 4 votes vote down vote up
private Theme update(final FileHandle handle) {
    if (skin == null) {
        throw new NullPointerException("A Theme.skin must be set before updating any Theme instance");
    }

    final JsonValue json = new JsonReader().parse(handle.readString());

    name = handle.nameWithoutExtension();
    displayName = json.getString("name");
    price = json.getInt("price");

    JsonValue colors = json.get("colors");
    // Java won't allow unsigned integers, we need to use Long
    background = new Color((int) Long.parseLong(colors.getString("background"), 16));
    foreground = new Color((int) Long.parseLong(colors.getString("foreground"), 16));

    JsonValue buttonColors = colors.get("buttons");
    Color[] buttons = new Color[buttonColors.size];
    for (int i = 0; i < buttons.length; ++i) {
        buttons[i] = new Color((int) Long.parseLong(buttonColors.getString(i), 16));
        if (buttonStyles[i] == null) {
            buttonStyles[i] = new ImageButton.ImageButtonStyle();
        }
        // Update the style. Since every button uses an instance from this
        // array, the changes will appear on screen automatically.
        buttonStyles[i].up = skin.newDrawable("button_up", buttons[i]);
        buttonStyles[i].down = skin.newDrawable("button_down", buttons[i]);
    }

    currentScore = new Color((int) Long.parseLong(colors.getString("current_score"), 16));
    highScore = new Color((int) Long.parseLong(colors.getString("high_score"), 16));
    bonus = new Color((int) Long.parseLong(colors.getString("bonus"), 16));
    bandColor = new Color((int) Long.parseLong(colors.getString("band"), 16));
    textColor = new Color((int) Long.parseLong(colors.getString("text"), 16));

    emptyCell = new Color((int) Long.parseLong(colors.getString("empty_cell"), 16));

    JsonValue cellColors = colors.get("cells");
    cells = new Color[cellColors.size];
    for (int i = 0; i < cells.length; ++i) {
        cells[i] = new Color((int) Long.parseLong(cellColors.getString(i), 16));
    }

    String cellTextureFile = json.getString("cell_texture");
    cellTexture = SkinLoader.loadPng("cells/" + cellTextureFile);

    return this;
}
 
Example 18
Source File: CustomProperty.java    From skin-composer with MIT License 4 votes vote down vote up
@Override
public void read(Json json, JsonValue jsonData) {
    name = jsonData.getString("name");
    value = json.readValue("value", null, jsonData);
    type = json.readValue("type", PropertyType.class, jsonData);
}
 
Example 19
Source File: TextureModule.java    From talos with Apache License 2.0 4 votes vote down vote up
@Override
public void read (Json json, JsonValue jsonData) {
    super.read(json, jsonData);
    regionName = jsonData.getString("regionName");
}
 
Example 20
Source File: ScriptModule.java    From talos with Apache License 2.0 4 votes vote down vote up
@Override
public void read (Json json, JsonValue jsonData) {
    super.read(json, jsonData);
    this.script = jsonData.getString("script");
}