本文整理匯總了Java中com.badlogic.gdx.utils.JsonReader.parse方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonReader.parse方法的具體用法?Java JsonReader.parse怎麽用?Java JsonReader.parse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.badlogic.gdx.utils.JsonReader
的用法示例。
在下文中一共展示了JsonReader.parse方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: AliasManager
import com.badlogic.gdx.utils.JsonReader; //導入方法依賴的package包/類
public AliasManager(Database.SectionAccessor aliasStorage) {
JsonReader reader = new JsonReader();
JsonValue value = aliasStorage.root;
if (value.size == 0) {
// probably empty
return;
}
JsonValue aliases = reader.parse(value.asString());
JsonValue node = aliases.child;
while (node != null) {
put(node.name, node.asString());
node = node.next;
}
}
示例2: loadArchetypes
import com.badlogic.gdx.utils.JsonReader; //導入方法依賴的package包/類
public void loadArchetypes() {
try {
JsonReader reader = new JsonReader();
JsonValue root = reader.parse(Gdx.files.internal(ARCHETYPES_FILE));
JsonIterator entitiesIt = root.iterator();
while (entitiesIt.hasNext()) {
JsonValue entity = entitiesIt.next();
loadEntityArchetype(Gdx.files.internal(entity.asString()));
}
}
catch (Exception e) {
logger.error("failed to process entity list " + ARCHETYPES_FILE);
}
}
示例3: ParticleEffectPools
import com.badlogic.gdx.utils.JsonReader; //導入方法依賴的package包/類
public ParticleEffectPools() {
logger = new Logger(TAG, Env.debugLevel);
logger.info("initialising");
pools = new ObjectMap<String, ParticleEffectPool>();
try {
JsonReader reader = new JsonReader();
JsonValue root = reader.parse(Gdx.files.internal(PARTICLES_FILE));
JsonIterator particlesIt = root.iterator();
while (particlesIt.hasNext()) {
JsonValue particleValue = particlesIt.next();
String effectName = particleValue.asString();
logger.info("loading " + effectName);
ParticleEffect effect = new ParticleEffect();
effect.load(Gdx.files.internal(effectName), Gdx.files.internal(PARTICLES_FOLDER));
pools.put(effectName, new ParticleEffectPool(effect,
Env.particlePoolInitialCapacity,
Env.particlePoolMaxCapacity));
}
}
catch (Exception e) {
logger.error("failed to list directory " + PARTICLES_FILE);
}
}
示例4: loadGroups
import com.badlogic.gdx.utils.JsonReader; //導入方法依賴的package包/類
private void loadGroups(String assetFile) {
groups = new ObjectMap<String, Array<Asset>>();
logger.info("loading file " + assetFile);
// try {
Json json = new Json();
JsonReader reader = new JsonReader();
JsonValue root = reader.parse(Gdx.files.internal(assetFile));
JsonIterator groupIt = root.iterator();
while (groupIt.hasNext()) {
JsonValue groupValue = groupIt.next();
if (groups.containsKey(groupValue.name)) {
logger.error("group " + groupValue.name + " already exists, skipping");
continue;
}
logger.info("registering group " + groupValue.name);
Array<Asset> assets = new Array<Asset>();
JsonIterator assetIt = groupValue.iterator();
while (assetIt.hasNext()) {
JsonValue assetValue = assetIt.next();
Asset asset = json.fromJson(Asset.class, assetValue.toString());
assets.add(asset);
}
groups.put(groupValue.name, assets);
}
// }
// catch (Exception e) {
// logger.error("error loading file " + assetFile + " " + e.getMessage());
// }
}
示例5: loadMaterialsFile
import com.badlogic.gdx.utils.JsonReader; //導入方法依賴的package包/類
private void loadMaterialsFile(FileHandle materialsFile) {
logger.info("adding default material");
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.density = 1.0f;
fixtureDef.friction = 1.0f;
fixtureDef.restitution = 0.0f;
materials.put("default", fixtureDef);
logger.info("loading materials file");
try {
JsonReader reader = new JsonReader();
JsonValue root = reader.parse(materialsFile);
JsonIterator materialIt = root.iterator();
while (materialIt.hasNext()) {
JsonValue materialValue = materialIt.next();
if (!materialValue.has("name")) {
logger.error("material without name");
continue;
}
String name = materialValue.getString("name");
fixtureDef = new FixtureDef();
fixtureDef.density = materialValue.getFloat("density", 1.0f);
fixtureDef.friction = materialValue.getFloat("friction", 1.0f);
fixtureDef.restitution = materialValue.getFloat("restitution", 0.0f);
logger.info("adding material " + name);
materials.put(name, fixtureDef);
}
} catch (Exception e) {
logger.error("error loading " + materialsFile.name() + " " + e.getMessage());
}
}
示例6: convert
import com.badlogic.gdx.utils.JsonReader; //導入方法依賴的package包/類
/** <p>
* Convert a text JSON file into binary JSON. The new file will be saved in the same folder as the original one with the
* {@code gd3b} extension.
* </p>
*
* @param g3djFile Handle to the original G3DJ file.
* @param overwrite If {@code true} the new file will overwrite any previous file with the same name. Otherwise append a
* counter at the end of the file name to make it unique.
* @throws IOException If there's an exception while reading the input file or writing the output file. */
public void convert (FileHandle g3djFile, boolean overwrite) throws IOException {
FileHandle newFile = new FileHandle(g3djFile.pathWithoutExtension() + ".g3db");
int noOverwriteCounter = 0;
while (!overwrite && newFile.exists()) {
newFile = new FileHandle(g3djFile.pathWithoutExtension() + "(" + (++noOverwriteCounter) + ").g3db");
}
OutputStream fileOutputStream = newFile.write(false);
UBJsonWriter writer = new UBJsonWriter(fileOutputStream);
JsonReader reader = new JsonReader();
try {
JsonValue root = reader.parse(g3djFile);
writeObject(root, writer);
} finally {
writer.close();
}
}
示例7: createMenu
import com.badlogic.gdx.utils.JsonReader; //導入方法依賴的package包/類
private void createMenu() {
root = new Table();
root.setFillParent(true);
stage.addActor(root);
FileHandle fileHandle = Gdx.files.local(Core.DATA_PATH + "/data.json");
JsonReader reader = new JsonReader();
JsonValue val = reader.parse(fileHandle);
Label title = new Label(val.getString("title"), skin, "title");
root.add(title).padTop(50.0f).padBottom(75.0f);
root.row();
BouncingImage image = new BouncingImage(getCharacter());
root.add(image);
root.row();
ImageButton imageButton = new ImageButton(skin, "play");
root.add(imageButton).padTop(75.0f).expandY().top();
imageButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
getCore().getAssetManager().get(Core.DATA_PATH + "/sfx/jump.wav", Sound.class).play();
showCharacterDialog();
}
});
}
示例8: loadData
import com.badlogic.gdx.utils.JsonReader; //導入方法依賴的package包/類
private void loadData(String fileName, FileHandle file) {
logger.info("loading " + fileName);
try {
JsonReader reader = new JsonReader();
JsonValue root = reader.parse(file);
loadBodyDef(root);
loadMassData(root);
loadFixtureDefs(root);
} catch (Exception e) {
logger.error("error loading " + fileName + "\n" + e.getStackTrace());
}
}
示例9: loadAsync
import com.badlogic.gdx.utils.JsonReader; //導入方法依賴的package包/類
@Override
public void loadAsync(AssetManager manager, String fileName, FileHandle file, AnimationStateDataLoaderParameter parameter) {
logger.info("loading " + fileName);
data = new AnimationStateData(manager.get(parameter.skeletonName, SkeletonData.class));
try {
JsonReader reader = new JsonReader();
JsonValue root = reader.parse(file);
float defaultBlend = root.get("defaultBlend").asFloat();
logger.info("default blend: " + defaultBlend + "s");
data.setDefaultMix(defaultBlend);
JsonIterator blendIt = root.get("blends").iterator();
while (blendIt.hasNext()) {
JsonValue blendValue = blendIt.next();
String from = blendValue.get("from").asString();
String to = blendValue.get("to").asString();
float duration = blendValue.get("duration").asFloat();
data.setMix(from, to , duration);
logger.info("blend: " + from + " -> " + to + " [" + duration + "s]");
}
}
catch (Exception e) {
logger.error("error loading " + fileName + " " + e.getMessage());
}
}
示例10: setGetJsonValue
import com.badlogic.gdx.utils.JsonReader; //導入方法依賴的package包/類
@Test
public void setGetJsonValue() {
JsonReader writer = new JsonReader();
JsonValue value = writer.parse("{testValue:2}");
fixture.setJsonValue(value);
assertEquals(value, fixture.getJsonValue());
}
示例11: constructorWithJsonValue
import com.badlogic.gdx.utils.JsonReader; //導入方法依賴的package包/類
@Test
public void constructorWithJsonValue() {
JsonReader writer = new JsonReader();
JsonValue value = writer.parse("{testValue:5}");
fixture = new JsonResult(value);
assertEquals(value, fixture.getJsonValue());
assertTrue(fixture.getJsonValue().has("testValue"));
assertEquals(5, fixture.getJsonValue().getInt("testValue"));
}
示例12: load
import com.badlogic.gdx.utils.JsonReader; //導入方法依賴的package包/類
public Scene load(String name) {
final JsonReader reader = new JsonReader();
final JsonValue json = reader.parse(root.child(name));
Scene scene = new Scene();
scene.setId(json.getInt(JsonScene.ID));
scene.setName(json.getString(JsonScene.NAME));
// game objects
for(JsonValue go : json.get(JsonScene.GAME_OBJECTS)) {
scene.sceneGraph.addGameObject(convertGameObject(scene.sceneGraph, go));
}
return scene;
}
示例13: loadAsync
import com.badlogic.gdx.utils.JsonReader; //導入方法依賴的package包/類
/**
* Aynchronously loads the animation data animations
*/
@Override
public void loadAsync(AssetManager manager, String fileName, FileHandle file, AnimationParameter parameter) {
logger.info("loading " + fileName);
animationData = new SpriteAnimationData();
// Retrieve texture
animationData.texture = manager.get(stripExtension(fileName) + ".png", Texture.class);
try {
JsonReader reader = new JsonReader();
JsonValue root = reader.parse(file);
animationData.rows = root.getInt("rows");
animationData.columns = root.getInt("columns");
animationData.frameDuration = root.getFloat("frameDuration");
JsonValue animations = root.get("animations");
JsonIterator animationsIt = animations.iterator();
boolean first = true;
while (animationsIt.hasNext()) {
JsonValue animationValue = animationsIt.next();
String name = animationValue.getString("name");
String frames = animationValue.getString("frames");
Animation animation = new Animation(animationData.frameDuration,
getAnimationFrames(animationData.texture, frames),
getPlayMode(animationValue.getString("mode", "normal")));
animationData.animations.put(name, animation);
logger.info("" + fileName + " loaded animation " + name);
if (first) {
animationData.defaultAnimation = animation;
first = false;
}
}
} catch (Exception e) {
logger.error("error loading file " + fileName + " " + e.getMessage());
}
}
示例14: loadData
import com.badlogic.gdx.utils.JsonReader; //導入方法依賴的package包/類
private void loadData(String fileName, FileHandle file) {
logger.info("loading " + fileName);
try {
JsonReader reader = new JsonReader();
JsonValue root = reader.parse(file);
loadBodyDef(root);
loadMassData(root);
loadFixtureDefs(root);
} catch (Exception e) {
logger.error("error loading " + fileName + " " + e.getMessage());
}
}
示例15: loadData
import com.badlogic.gdx.utils.JsonReader; //導入方法依賴的package包/類
@Override
public Array<? extends SceneGraphNode> loadData() {
Array<T> bodies = new Array<T>();
try {
JsonReader json = new JsonReader();
for (String filePath : filePaths) {
FileHandle file = Gdx.files.internal(filePath);
JsonValue model = json.parse(file.read());
JsonValue child = model.get("objects").child;
int size = 0;
while (child != null) {
size++;
String clazzName = child.getString("impl");
Class<Object> clazz = (Class<Object>) ClassReflection.forName(clazzName);
// Convert to object and add to list
T object = (T) convertJsonToObject(child, clazz);
bodies.add(object);
child = child.next;
}
Logger.info(this.getClass().getSimpleName(), I18n.bundle.format("notif.nodeloader", size, filePath));
}
} catch (Exception e) {
Logger.error(e);
}
return bodies;
}