本文整理汇总了Java中defrac.json.JSONObject类的典型用法代码示例。如果您正苦于以下问题:Java JSONObject类的具体用法?Java JSONObject怎么用?Java JSONObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JSONObject类属于defrac.json包,在下文中一共展示了JSONObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: collectResourceGroup
import defrac.json.JSONObject; //导入依赖的package包/类
@Nonnull
private static ResourceGroup<TextureData> collectResourceGroup( @Nonnull final JSONArray jsonTilesets )
{
final ResourceGroup<TextureData> textureResources = new ResourceGroup<>( jsonTilesets.length() );
for( JSON json : jsonTilesets )
{
final JSONObject jsonTileset = checkNotNull( json.asObject() );
final String image = checkNotNull( jsonTileset.getString( "image" ) );
textureResources.add( TextureDataResource.from( image ) );
}
return textureResources;
}
示例2: decode
import defrac.json.JSONObject; //导入依赖的package包/类
@Nonnull
@SuppressWarnings( "SpellCheckingInspection" )
private static MapData decode( @Nonnull final JSONObject jsonObject, @Nonnull final List<TextureData> textures )
{
final int version = jsonObject.getInt( "version" );
final int width = jsonObject.getInt( "width" );
final int height = jsonObject.getInt( "height" );
final int tileWidth = jsonObject.getInt( "tilewidth" );
final int tileHeight = jsonObject.getInt( "tileheight" );
final int nextObjectId = jsonObject.getInt( "nextobjectid" );
final int backgroundColor = Color.valueOf( jsonObject.optString( "backgroundcolor", "#FF000000" ) );
final MapOrientation mapOrientation = orientation( checkNotNull( jsonObject.getString( "orientation" ) ) );
final MapRenderOrder mapRenderOrder = renderOrder( checkNotNull( jsonObject.getString( "renderorder" ) ) );
final MapLayer[] tileMapLayers = decodeLayers( checkNotNull( jsonObject.getArray( "layers" ) ) );
final TileSet[] tileSets = decodeTileSets( checkNotNull( jsonObject.getArray( "tilesets" ) ), textures );
return new MapData( mapOrientation, mapRenderOrder, tileMapLayers, tileSets, version, width, height, tileWidth, tileHeight, nextObjectId, backgroundColor );
}
示例3: decodeObject
import defrac.json.JSONObject; //导入依赖的package包/类
@Nullable
@SuppressWarnings( "SpellCheckingInspection" )
private static MapObject decodeObject( @Nonnull final JSONObject jsonObject )
{
final int x = jsonObject.getInt( "x" );
final int y = jsonObject.getInt( "y" );
final int width = jsonObject.getInt( "width" );
final int height = jsonObject.getInt( "height" );
final boolean visible = jsonObject.getBoolean( "visible" );
final String name = checkNotNull( jsonObject.getString( "name" ) );
if( jsonObject.contains( "polyline" ) )
{
return decodePolyLine( name, checkNotNull( jsonObject.getArray( "polyline" ) ), x, y, width, height, visible, false );
}
else if( jsonObject.contains( "polygon" ) )
{
return decodePolyLine( name, checkNotNull( jsonObject.getArray( "polygon" ) ), x, y, width, height, visible, true );
}
else if( jsonObject.contains( "ellipse" ) )
{
return new ObjectEllipse( x, y, width, height, visible, name );
}
return new ObjectRectangle( x, y, width, height, visible, name );
}
示例4: decodeTileSets
import defrac.json.JSONObject; //导入依赖的package包/类
@Nonnull
private static TileSet[] decodeTileSets( @Nonnull final JSONArray jsonArray, @Nonnull final List<TextureData> textures )
{
final TileSet[] tileSets = new TileSet[ jsonArray.length() ];
int index = 0;
for( final JSON json : jsonArray )
{
final JSONObject jsonObject = json.asObject();
if( null == jsonObject )
throw new RuntimeException( "Broken Json" );
tileSets[ index ] = decodeTileSet( jsonObject, textures.get( index ) );
index++;
}
return tileSets;
}
示例5: inflate
import defrac.json.JSONObject; //导入依赖的package包/类
public Future<Void> inflate(@Nonnull final DisplayObjectContainer root,
@Nonnull final JSON layout,
@Nonnull final Dispatcher dispatcher,
final float availableWidth,
final float availableHeight) {
if(!layout.isObject()) {
Futures.failure(new LayoutException("Given layout isn't a JSON object"));
}
context.dispatcher(dispatcher);
final JSONObject layoutObject = (JSONObject)layout;
inflateConstants(layoutObject);
return inflateChildren(root, layoutObject, availableWidth, availableHeight);
}
示例6: inflateChildren
import defrac.json.JSONObject; //导入依赖的package包/类
@Nonnull
private Future<Void> inflateChildren(final @Nonnull DisplayObjectContainer root,
final @Nonnull JSONObject layout,
final float availableWidth,
final float availableHeight) {
// We push the root so that we get a valid parent width and
// height for top-level children
context.pushScope(root, availableWidth, availableHeight);
// We start inflating all the children which is an asynchronous process.
final Future<Void> future = inflateDescriptors(root, rootChildren(layout));
// Exit the root scope when we're done
future.onComplete(attempt -> context.popScope(), context.dispatcher());
return future;
}
示例7: repeatedInflate
import defrac.json.JSONObject; //导入依赖的package包/类
/**
* Inflates a descriptor repeatedly into a parent
*
* <p>This method should only be called from {@link #inflate(DisplayObjectContainer, JSONObject)}
* and not manually.
*
* @param parent The parent
* @param descriptor The descriptor
* @param repeatCount The number of repetitions
*
* @return The Future representing the completion of inflating the descriptor {@code repeatCount} times
*/
@Nonnull
private Future<Void> repeatedInflate(@Nonnull final DisplayObjectContainer parent,
@Nonnull final JSONObject descriptor,
final int repeatCount) {
final Future<Void> future;
if(repeatCount == 0) {
future = success();
} else if(repeatCount == 1) {
future = inflateRepetition(parent, descriptor, 0);
} else {
future = repeatedInflateTrampoline(parent, descriptor, 0, repeatCount);
}
return future;
}
示例8: repeatedInflateTrampoline
import defrac.json.JSONObject; //导入依赖的package包/类
/**
* Trampoline for repeated asynchronous inflation of a descriptor into a parent
*
* @param parent The parent
* @param descriptor The descriptor
* @param repeatIndex The current index in the repeated sequence
* @param repeatCount The number of repetitions
*
* @return The Future representing the completion of inflating the descriptor {@code repeatCount - repeatIndex} times
*/
@Nonnull
private Future<Void> repeatedInflateTrampoline(@Nonnull final DisplayObjectContainer parent,
@Nonnull final JSONObject descriptor,
final int repeatIndex,
final int repeatCount) {
final Future<Void> future = inflateRepetition(parent, descriptor, repeatIndex);
return future.flatMap(theVoid -> {
final int nextRepeatIndex = repeatIndex + 1;
if(nextRepeatIndex == repeatCount) {
return success();
} else {
return repeatedInflateTrampoline(parent, descriptor, nextRepeatIndex, repeatCount);
}
});
}
示例9: inflateDescriptors
import defrac.json.JSONObject; //导入依赖的package包/类
/**
* Inflates an array of descriptors into a parent
*
* <p>This method should only be called from {@link #inflateRepetition(DisplayObjectContainer, JSONObject, int)}
* and not manually.
*
* @param parent The parent
* @param descriptors The array of descriptors
*
* @return The Future representing the completion of inflating the descriptors
*/
@Nonnull
private Future<Void> inflateDescriptors(@Nonnull final DisplayObjectContainer parent,
@Nonnull final JSONArray descriptors) {
final int descriptorCount = descriptors.length();
final Future<Void> future;
if(0 == descriptorCount) {
future = success();
} else if(1 == descriptorCount) {
final JSON firstChild = descriptors.get(0);
if(firstChild == null || !firstChild.isObject()) {
future = success();
} else {
future = inflate(parent, (JSONObject)firstChild);
}
} else {
future = inflateDescriptorsTrampoline(parent, descriptors, 0, descriptorCount);
}
return future;
}
示例10: applyPropertiesUsingReflection
import defrac.json.JSONObject; //导入依赖的package包/类
private void applyPropertiesUsingReflection(@Nonnull final LayoutContext context,
@Nonnull final JSONObject properties,
@Nonnull final DisplayObject displayObject) {
for(final String property : properties.keySet()) {
// we ignore all default properties and variant properties
if(LayoutConstants.DEFAULT_PROPERTIES.contains(property) || context.isVariant(property)) {
continue;
}
// create and apply new stored procedure for this property
final StoredProcedure procedure =
getOrCreateStoredProcedure(context, property);
procedure.apply(displayObject, properties);
}
}
示例11: readCurve
import defrac.json.JSONObject; //导入依赖的package包/类
private static void readCurve(@Nonnull final CurveTimeline timeline,
final int frameIndex,
@Nonnull final JSONObject valueMap) {
final JSON curve = valueMap.opt("curve");
if(curve.isString() && "stepped".equals(curve.stringValue())) {
timeline.setSteppedAt(frameIndex);
} else if (curve.isArray()) {
final JSONArray curveArray = (JSONArray)curve;
timeline.setCurve(
frameIndex,
curveArray.getFloat(0), curveArray.getFloat(1),
curveArray.getFloat(2), curveArray.getFloat(3));
}
}
示例12: readTranslateTimeline
import defrac.json.JSONObject; //导入依赖的package包/类
private static float readTranslateTimeline(@Nonnull final Array<Timeline> timelines,
final int boneIndex,
final float duration,
@Nonnull final JSONArray timelineData,
@Nonnull final TranslateTimeline timeline,
final float timelineScale) {
timeline.boneIndex = boneIndex;
for(int frameIndex = 0, frameCount = timelineData.size(); frameIndex < frameCount; ++frameIndex) {
final JSONObject valueMap = timelineData.optObject(frameIndex);
final float x = valueMap.optFloat("x", 0.0f) * timelineScale;
final float y = valueMap.optFloat("y", 0.0f) * timelineScale;
timeline.setFrame(frameIndex, valueMap.getFloat("time"), x, y);
readCurve(timeline, frameIndex, valueMap);
}
timelines.push(timeline);
return Math.max(duration, timeline.frames()[timeline.frameCount() * 3 - 3]);
}
示例13: readFlipTimeline
import defrac.json.JSONObject; //导入依赖的package包/类
private static float readFlipTimeline(@Nonnull final Array<Timeline> timelines,
final int boneIndex,
final float duration,
@Nonnull final JSONArray timelineData,
@Nonnull final String field,
@Nonnull final FlipXTimeline timeline) {
timeline.boneIndex = boneIndex;
for(int frameIndex = 0, frameCount = timelineData.size(); frameIndex < frameCount; ++frameIndex) {
final JSONObject value = timelineData.optObject(frameIndex);
timeline.setFrame(frameIndex, value.getFloat("time"), value.optBoolean(field, false));
}
timelines.push(timeline);
return Math.max(duration, timeline.frames()[timeline.frameCount() * 3 - 3]);
}
示例14: initWithStage
import defrac.json.JSONObject; //导入依赖的package包/类
@Override
protected void initWithStage(@Nonnull final Stage stage) {
final Future<TextureAtlas> atlasFuture =
LibgdxTextureAtlasResource.from(
"raptor/raptor.atlas",
TextureDataSupplies.premultipliedResource("raptor/")
).load();
final Future<JSON> jsonFuture =
JSON.parse(StringResource.from("raptor/raptor.json"));
final Future<SkeletonData> dataFuture =
atlasFuture.
join(jsonFuture).
map(pair -> {
final SkeletonJson json = new SkeletonJson(pair.x);
json.scale(0.5f);
return json.readSkeletonData((JSONObject)pair.y);
});
dataFuture.
onSuccess(this::init).
onFailure(Procedures.printStackTrace());
}
示例15: extract
import defrac.json.JSONObject; //导入依赖的package包/类
@Nullable
private <A> A extract(@NotNull final String fieldPath,
@NotNull final Class<A> typeOfValue,
@NotNull final Function<JSON, A> flattener,
@NotNull final JSON genericConfig) throws NoSuchFieldException, IllegalAccessException {
final JSON platformConfig =
genericConfig.asObject(JSONObject.EMPTY).optObject(platform.name);
if(platformConfig != JSONObject.EMPTY) {
try {
final A value = walkPath(fieldPath, typeOfValue, flattener, platformConfig.asObject(JSONObject.EMPTY));
if(value != null) {
return value;
}
} catch(final NoSuchFieldException noSuchFieldInPlatform) {
// ignore
}
}
return walkPath(fieldPath, typeOfValue, flattener, genericConfig.asObject(JSONObject.EMPTY));
}