Search in sources :

Example 1 with ObjectMap

use of com.badlogic.gdx.utils.ObjectMap in project libgdx by libgdx.

the class JsonTest method create.

public void create() {
    json = new Json();
    // json.fromJson(Test1.class, //
    // "{byteArrayField:[-1\n,-2]}"
    // );
    // if (true) return;
    Test1 test = new Test1();
    test.booleanField = true;
    test.byteField = 123;
    test.charField = 'Z';
    test.shortField = 12345;
    test.intField = 123456;
    test.longField = 123456789;
    test.floatField = 123.456f;
    test.doubleField = 1.23456d;
    test.BooleanField = true;
    test.ByteField = -12;
    test.CharacterField = 'X';
    test.ShortField = -12345;
    test.IntegerField = -123456;
    test.LongField = -123456789l;
    test.FloatField = -123.3f;
    test.DoubleField = -0.121231d;
    test.stringField = "stringvalue";
    test.byteArrayField = new byte[] { 2, 1, 0, -1, -2 };
    test.map = new ObjectMap();
    test.map.put("one", 1);
    test.map.put("two", 2);
    test.map.put("nine", 9);
    test.stringArray = new Array();
    test.stringArray.add("meow");
    test.stringArray.add("moo");
    test.objectArray = new Array();
    test.objectArray.add("meow");
    test.objectArray.add(new Test1());
    test.someEnum = SomeEnum.b;
    roundTrip(test);
    test.someEnum = null;
    roundTrip(test);
    test = new Test1();
    roundTrip(test);
    test.stringArray = new Array();
    roundTrip(test);
    test.stringArray.add("meow");
    roundTrip(test);
    test.stringArray.add("moo");
    roundTrip(test);
    TestMapGraph objectGraph = new TestMapGraph();
    testObjectGraph(objectGraph, "exoticTypeName");
    test = new Test1();
    test.map = new ObjectMap();
    roundTrip(test);
    test.map.put("one", 1);
    roundTrip(test);
    test.map.put("two", 2);
    test.map.put("nine", 9);
    roundTrip(test);
    test.map.put("\nst\nuff\n", 9);
    test.map.put("\r\nst\r\nuff\r\n", 9);
    roundTrip(test);
    equals(json.toJson("meow"), "meow");
    equals(json.toJson("meow "), "\"meow \"");
    equals(json.toJson(" meow"), "\" meow\"");
    equals(json.toJson(" meow "), "\" meow \"");
    equals(json.toJson("\nmeow\n"), "\\nmeow\\n");
    equals(json.toJson(Array.with(1, 2, 3), null, int.class), "[1,2,3]");
    equals(json.toJson(Array.with("1", "2", "3"), null, String.class), "[1,2,3]");
    equals(json.toJson(Array.with(" 1", "2 ", " 3 "), null, String.class), "[\" 1\",\"2 \",\" 3 \"]");
    equals(json.toJson(Array.with("1", "", "3"), null, String.class), "[1,\"\",3]");
    System.out.println();
    System.out.println("Success!");
}
Also used : Array(com.badlogic.gdx.utils.Array) ObjectMap(com.badlogic.gdx.utils.ObjectMap) Json(com.badlogic.gdx.utils.Json)

Example 2 with ObjectMap

use of com.badlogic.gdx.utils.ObjectMap in project libgdx by libgdx.

the class TideMapLoader method load.

public TiledMap load(String fileName) {
    try {
        FileHandle tideFile = resolve(fileName);
        root = xml.parse(tideFile);
        ObjectMap<String, Texture> textures = new ObjectMap<String, Texture>();
        for (FileHandle textureFile : loadTileSheets(root, tideFile)) {
            textures.put(textureFile.path(), new Texture(textureFile));
        }
        DirectImageResolver imageResolver = new DirectImageResolver(textures);
        TiledMap map = loadMap(root, tideFile, imageResolver);
        map.setOwnedResources(textures.values().toArray());
        return map;
    } catch (IOException e) {
        throw new GdxRuntimeException("Couldn't load tilemap '" + fileName + "'", e);
    }
}
Also used : DirectImageResolver(com.badlogic.gdx.maps.ImageResolver.DirectImageResolver) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) ObjectMap(com.badlogic.gdx.utils.ObjectMap) FileHandle(com.badlogic.gdx.files.FileHandle) IOException(java.io.IOException) Texture(com.badlogic.gdx.graphics.Texture)

Example 3 with ObjectMap

use of com.badlogic.gdx.utils.ObjectMap in project libgdx by libgdx.

the class TmxMapLoader method load.

/** Loads the {@link TiledMap} from the given file. The file is resolved via the {@link FileHandleResolver} set in the
	 * constructor of this class. By default it will resolve to an internal file.
	 * @param fileName the filename
	 * @param parameters specifies whether to use y-up, generate mip maps etc.
	 * @return the TiledMap */
public TiledMap load(String fileName, TmxMapLoader.Parameters parameters) {
    try {
        this.convertObjectToTileSpace = parameters.convertObjectToTileSpace;
        this.flipY = parameters.flipY;
        FileHandle tmxFile = resolve(fileName);
        root = xml.parse(tmxFile);
        ObjectMap<String, Texture> textures = new ObjectMap<String, Texture>();
        Array<FileHandle> textureFiles = loadTilesets(root, tmxFile);
        textureFiles.addAll(loadImages(root, tmxFile));
        for (FileHandle textureFile : textureFiles) {
            Texture texture = new Texture(textureFile, parameters.generateMipMaps);
            texture.setFilter(parameters.textureMinFilter, parameters.textureMagFilter);
            textures.put(textureFile.path(), texture);
        }
        DirectImageResolver imageResolver = new DirectImageResolver(textures);
        TiledMap map = loadTilemap(root, tmxFile, imageResolver);
        map.setOwnedResources(textures.values().toArray());
        return map;
    } catch (IOException e) {
        throw new GdxRuntimeException("Couldn't load tilemap '" + fileName + "'", e);
    }
}
Also used : DirectImageResolver(com.badlogic.gdx.maps.ImageResolver.DirectImageResolver) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) ObjectMap(com.badlogic.gdx.utils.ObjectMap) FileHandle(com.badlogic.gdx.files.FileHandle) IOException(java.io.IOException) Texture(com.badlogic.gdx.graphics.Texture)

Example 4 with ObjectMap

use of com.badlogic.gdx.utils.ObjectMap in project libgdx by libgdx.

the class ShaderLoader method parse.

protected ObjectMap<String, String> parse(final FileHandle file) {
    ObjectMap<String, String> result = new ObjectMap<String, String>();
    BufferedReader reader = file.reader(1024);
    String line;
    String snipName = "";
    stringBuilder.setLength(0);
    int idx;
    try {
        while ((line = reader.readLine()) != null) {
            if (line.length() > 3 && line.charAt(0) == '[' && (idx = line.indexOf(']')) > 1) {
                if (snipName.length() > 0 || stringBuilder.length() > 0)
                    result.put(snipName, stringBuilder.toString());
                stringBuilder.setLength(0);
                snipName = line.substring(1, idx);
            } else
                stringBuilder.append(line.trim()).append("\r\n");
        }
    } catch (IOException e) {
        throw new GdxRuntimeException(e);
    }
    if (snipName.length() > 0 || stringBuilder.length() > 0)
        result.put(snipName, stringBuilder.toString());
    return result;
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) ObjectMap(com.badlogic.gdx.utils.ObjectMap) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 5 with ObjectMap

use of com.badlogic.gdx.utils.ObjectMap in project gdx-skineditor by cobolfoo.

the class Skin method add.

public void add(String name, Object resource, Class type) {
    // This is a hack? totally.
    if (resource instanceof TintedDrawable) {
        TintedDrawable td = (TintedDrawable) resource;
        add(name, td.drawable, Drawable.class);
    }
    if (name == null)
        throw new IllegalArgumentException("name cannot be null.");
    if (resource == null)
        throw new IllegalArgumentException("resource cannot be null.");
    ObjectMap<String, Object> typeResources = resources.get(type);
    if (typeResources == null) {
        typeResources = new ObjectMap();
        resources.put(type, typeResources);
    }
    typeResources.put(name, resource);
}
Also used : ObjectMap(com.badlogic.gdx.utils.ObjectMap)

Aggregations

ObjectMap (com.badlogic.gdx.utils.ObjectMap)15 Texture (com.badlogic.gdx.graphics.Texture)7 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)4 FileHandle (com.badlogic.gdx.files.FileHandle)3 IOException (java.io.IOException)3 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)2 DirectImageResolver (com.badlogic.gdx.maps.ImageResolver.DirectImageResolver)2 Drawable (com.badlogic.gdx.scenes.scene2d.utils.Drawable)2 SpriteDrawable (com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable)2 Array (com.badlogic.gdx.utils.Array)2 ArrayList (java.util.ArrayList)2 AssetLoader (com.badlogic.gdx.assets.loaders.AssetLoader)1 SkinLoader (com.badlogic.gdx.assets.loaders.SkinLoader)1 Color (com.badlogic.gdx.graphics.Color)1 Pixmap (com.badlogic.gdx.graphics.Pixmap)1 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)1 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)1 Page (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Page)1 Region (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Region)1 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)1