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!");
}
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);
}
}
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);
}
}
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;
}
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);
}
Aggregations