本文整理匯總了Java中com.badlogic.gdx.utils.Json類的典型用法代碼示例。如果您正苦於以下問題:Java Json類的具體用法?Java Json怎麽用?Java Json使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Json類屬於com.badlogic.gdx.utils包,在下文中一共展示了Json類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: write
import com.badlogic.gdx.utils.Json; //導入依賴的package包/類
@Override
public void write(Json json) {
super.write(json);
StringBuilder sb = new StringBuilder();
for(int x = 0; x < pixmap.getWidth(); x++) {
for(int y = 0; y < pixmap.getHeight(); y++) {
int color = pixmap.getPixel(x, y);
if(color == Color.rgba8888(47f / 255f, 86f / 255f, 118f / 255f, 1f)) {
sb.append("d");
} else if(color == Color.rgba8888(62f / 255f, 120f / 255f, 160f / 255f, 1f)) {
sb.append("o");
} else if(color == Color.rgba8888(146f / 255f, 209f / 255f, 135f / 255f, 1f)) {
sb.append("l");
}
}
}
json.writeValue("texture", sb.toString());
}
示例2: process
import com.badlogic.gdx.utils.Json; //導入依賴的package包/類
/**
* Converts json string into java object.
*
* @param wantedType Wanted type
* @param genericTypeKeeper Object with wanted type inside generic argument
* @param jsonString Json string data
* @param <R> Return type
* @return
*/
public static <R> R process(Class<?> wantedType, Object genericTypeKeeper, String jsonString)
{
Json json = new Json();
json.setIgnoreUnknownFields(true);
json.setTypeName(null);
R result = null;
if (ClassReflection.isAssignableFrom(List.class, wantedType)
|| ClassReflection.isAssignableFrom(Map.class, wantedType)) {
NestedGenericType nestedGenericType = AnnotationProcessor.getNestedGenericTypeAnnotation(genericTypeKeeper);
if (nestedGenericType == null) throw new NestedGenericTypeAnnotationMissingException();
json.setDefaultSerializer(new JsonListMapDeserializer(wantedType, nestedGenericType.value()));
result = (R) json.fromJson(wantedType, jsonString);
} else {
result = (R) json.fromJson(wantedType, jsonString);
}
return result;
}
示例3: write
import com.badlogic.gdx.utils.Json; //導入依賴的package包/類
@Override
public void write (Json json) {
json.writeValue("name", name);
json.writeArrayStart("components");
for (int i = 0; i < components.size; i++)
if (components.get(i) instanceof Rigidbody) {
Rigidbody rigidbody = (Rigidbody)components.get(i);
components.removeIndex(i);
components.insert(1, rigidbody);
}
for (int i = 0; i < components.size; i++) {
GameComponent component = components.get(i);
json.writeObjectStart();
json.writeValue("componentType", component.getType());
component.write(json);
json.writeObjectEnd();
}
json.writeArrayEnd();
}
示例4: read
import com.badlogic.gdx.utils.Json; //導入依賴的package包/類
@Override
public void read(Json json, JsonValue jsonValue) {
try {
name = jsonValue.getString("name");
optional = jsonValue.getBoolean("optional");
if (jsonValue.get("value").isNumber()) {
type = Float.TYPE;
value = Double.parseDouble(jsonValue.getString("value"));
} else {
type = ClassReflection.forName(jsonValue.getString("type"));
if (jsonValue.get("value").isNull()) {
value = null;
} else {
value = jsonValue.getString("value");
}
}
} catch (ReflectionException ex) {
Gdx.app.error(getClass().toString(), "Error reading from serialized object" , ex);
DialogFactory.showDialogErrorStatic("Read Error...","Error reading from serialized object.\n\nOpen log?");
}
}
示例5: read
import com.badlogic.gdx.utils.Json; //導入依賴的package包/類
@Override
public void read(Json json, JsonValue jsonData) {
try {
colors = json.readValue("colors", Array.class, jsonData);
fonts = json.readValue("fonts", Array.class, jsonData);
classStyleMap = new OrderedMap<>();
for (JsonValue data : jsonData.get("classStyleMap").iterator()) {
classStyleMap.put(ClassReflection.forName(data.name), json.readValue(Array.class, data));
}
for (Array<StyleData> styleDatas : classStyleMap.values()) {
for (StyleData styleData : styleDatas) {
styleData.jsonData = this;
}
}
customClasses = json.readValue("customClasses", Array.class, CustomClass.class, new Array<>(), jsonData);
for (CustomClass customClass : customClasses) {
customClass.setMain(main);
}
} catch (ReflectionException e) {
Gdx.app.log(getClass().getName(), "Error parsing json data during file read", e);
main.getDialogFactory().showDialogError("Error while reading file...", "Error while attempting to read save file.\nPlease ensure that file is not corrupted.\n\nOpen error log?");
}
}
示例6: read
import com.badlogic.gdx.utils.Json; //導入依賴的package包/類
@Override
public ScaleFactorModel read(Json json, JsonValue jsonData, Class type) {
String suffix = "";
float factor = 1f;
JsonValue.JsonIterator iterator = jsonData.iterator();
while (iterator.hasNext()) {
JsonValue value = iterator.next();
switch (value.name) {
case "suffix":
suffix = value.asString();
break;
case "factor":
factor = value.asFloat();
break;
}
}
return new ScaleFactorModel(suffix, factor);
}
示例7: getRequest
import com.badlogic.gdx.utils.Json; //導入依賴的package包/類
@Override
protected void getRequest(Json json) {
boolean hasStart = false;
try {
json.writeObjectStart();
} catch (IllegalStateException e) {
hasStart = true;
}
//write GC codes
json.writeObjectStart("CacheCode");
json.writeArrayStart("CacheCodes");
for (String gcCode : gcCodes) {
json.writeValue(gcCode);
}
json.writeArrayEnd();
json.writeObjectEnd();
super.getRequest(json);
if (!hasStart) json.writeObjectEnd();
}
示例8: getRequest
import com.badlogic.gdx.utils.Json; //導入依賴的package包/類
@Override
protected void getRequest(Json json) {
boolean hasStart = false;
try {
json.writeObjectStart();
} catch (IllegalStateException e) {
hasStart = true;
}
json.writeObjectStart("PointRadius");
json.writeValue("DistanceInMeters", this.distanceInMeters);
json.writeObjectStart("Point");
json.writeValue("Latitude", pos.getLatitude());
json.writeValue("Longitude", pos.getLongitude());
json.writeObjectEnd();
json.writeObjectEnd();
super.getRequest(json);
if (!hasStart) json.writeObjectEnd();
}
示例9: getRequest
import com.badlogic.gdx.utils.Json; //導入依賴的package包/類
@Test
void getRequest() throws IOException {
String expected = TestUtils.getResourceRequestString("testsResources/SearchGcOwner_request.txt",
isDummy ? null : apiKey);
Coordinate searchCoord = new CoordinateGPS(52.581892, 13.398128); // Home of Katipa(like Longri)
SearchGCOwner searchGC = new SearchGCOwner(apiKey, 30, searchCoord, 50000, "bros", (byte) 2);
StringWriter writer = new StringWriter();
Json json = new Json(JsonWriter.OutputType.json);
json.setWriter(writer);
searchGC.getRequest(json);
String actual = writer.toString();
assertEquals(expected, actual);
}
示例10: readReplayData
import com.badlogic.gdx.utils.Json; //導入依賴的package包/類
/**
* リプレイデータを読み込む
*
* @param model
* 対象のBMS
* @param lnmode
* LNモード
* @return リプレイデータ
*/
public ReplayData readReplayData(BMSModel model, int lnmode, int index) {
if (existsReplayData(model, lnmode, index)) {
Json json = new Json();
json.setIgnoreUnknownFields(true);
try {
String path = this.getReplayDataFilePath(model, lnmode, index);
if (Files.exists(Paths.get(path + ".brd"))) {
return json.fromJson(ReplayData.class, new BufferedInputStream(
new GZIPInputStream(Files.newInputStream(Paths.get(path + ".brd")))));
}
if (Files.exists(Paths.get(path + ".json"))) {
return json.fromJson(ReplayData.class, new FileReader(path + ".json"));
}
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
示例11: read
import com.badlogic.gdx.utils.Json; //導入依賴的package包/類
@Override
public void read (Json json, JsonValue jsonData) {
for (int i = 0; i < jsonData.get("animations").size; i++) {
JsonValue animationValue = jsonData.get("animations").get(i);
Animation animation = new TweenAnimation();
animation.setAnimator(this);
animations.put(animationValue.name, animation);
animation.read(json, animationValue);
}
if (animations.size == 0) {
animations.put("Default", new TweenAnimation());
setAnimation("Default");
currentAnimation.setAnimator(this);
} else
setAnimation(jsonData.getString("currentAnimation"));
}
示例12: read
import com.badlogic.gdx.utils.Json; //導入依賴的package包/類
@Override
public void read (Json json, JsonValue jsonData) {
if (jsonData.has("time"))
time = jsonData.getInt("time");
if (jsonData.get("value").isNumber())
value = jsonData.getFloat("value");
else
value = new Color();
JsonValue curveValue = jsonData.get("curve");
JsonValue constraintsValue = curveValue.get("constraints");
int c1, c2, c3, c4;
c1 = constraintsValue.getInt("c1");
c2 = constraintsValue.getInt("c2");
c3 = constraintsValue.getInt("c3");
c4 = constraintsValue.getInt("c4");
curve = new Curve();
curve.constraints.set(c1, c2, c3, c4);
if (curveValue.has("type"))
curve.setType(json.readValue(Type.class, curveValue.get("type")));
}
示例13: reload
import com.badlogic.gdx.utils.Json; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public void reload () {
RavTech.files.loadAsset("keybindings.json", String.class);
RavTech.files.finishLoading();
if ((!RavTech.settings.has("keybindings")))
RavTech.settings.setValue("keybindings", RavTech.files.getAsset("keybindings.json", String.class));
this.actionMaps.clear();
Json json = new Json();
ObjectMap<String, JsonValue> serializedActionMaps = json.fromJson(ObjectMap.class,
RavTech.settings.getString("keybindings"));
for (ObjectMap.Entry<String, JsonValue> entry : serializedActionMaps.entries()) {
ActionMap actionMap = new ActionMap();
actionMap.read(json, entry.value);
this.actionMaps.put(entry.key, actionMap);
}
this.actionMaps.putAll(actionMaps);
this.players.clear();
Player player = new Player();
for (int i = 0; i < inputDevices.size; i++)
player.assignDevice(inputDevices.get(i), this.getActionMapForDevice(inputDevices.get(i)));
players.add(player);
}
示例14: undo
import com.badlogic.gdx.utils.Json; //導入依賴的package包/類
@Override
public void undo () {
JsonValue jsonData = new JsonReader().parse(gameComponent);
Json json = new Json();
GameObject tempObject = new GameObject();
tempObject.readValue(json, jsonData);
GameComponent toAddComponent = tempObject.getComponentByName(componentType);
tempObject.getComponents().removeValue(tempObject.getComponentByName(componentType), true);
tempObject.destroy();
if (pathToComponent.lastIndexOf('/') == 0) {
toAddComponent.setParent(null);
RavTech.currentScene.addGameObject((GameObject)toAddComponent);
} else {
GameObject component = (GameObject)GameObjectTraverseUtil
.gameComponentFromPath(pathToComponent.substring(0, pathToComponent.lastIndexOf('/')));
toAddComponent.setParent(component);
component.addComponent(toAddComponent);
}
}
示例15: redo
import com.badlogic.gdx.utils.Json; //導入依賴的package包/類
@Override
public void redo () {
GameComponent parent = GameObjectTraverseUtil.gameComponentFromPath(pathToComponent);
JsonValue jsonData = new JsonReader().parse(gameComponent);
Json json = new Json();
if (parent != null) {
((GameObject)parent).readValue(json, jsonData);
removePath = GameObjectTraverseUtil
.pathFromGameComponent(((GameObject)parent).getComponents().get(((GameObject)parent).getComponents().size - 1));
} else {
GameObject object = new GameObject();
object.readValue(json, jsonData);
GameObject newObject = (GameObject)object.getComponents().get(1);
newObject.setParent(null);
removePath = GameObjectTraverseUtil.pathFromGameComponent(newObject);
RavTech.currentScene.addGameObject(newObject);
}
componentType = jsonData.getString("componenttype");
}