use of com.badlogic.gdx.utils.JsonValue in project nhglib by VoidZombie.
the class InputConfigurationsJson method parse.
@Override
public void parse(JsonValue jsonValue) {
inputConfigurations = new InputConfigurations();
JsonValue configurationsJson = jsonValue.get("configurations");
JsonValue keysJson = configurationsJson.get("keys");
JsonValue sticksJson = configurationsJson.get("sticks");
JsonValue pointersJson = configurationsJson.get("pointers");
JsonValue controllersJson = configurationsJson.get("controllers");
JsonValue mouseJson = configurationsJson.get("mouse");
// Keys
for (JsonValue keyJson : keysJson) {
String name = keyJson.getString("name");
Integer keyCode = keyJson.getInt("keyCode");
InputMode inputMode = InputMode.fromString(keyJson.getString("inputMode"));
KeyInputConfiguration keyInputConfiguration = new KeyInputConfiguration();
keyInputConfiguration.setName(name);
keyInputConfiguration.setKeyCode(keyCode);
keyInputConfiguration.setInputMode(inputMode);
inputConfigurations.keyInputConfigurations.add(keyInputConfiguration);
}
// Sticks
for (JsonValue stickJson : sticksJson) {
String name = stickJson.getString("name");
Integer controllerId = stickJson.getInt("controllerId");
StickType stickType = StickType.fromString(stickJson.getString("stickType"));
StickInputConfiguration stickInputConfiguration = new StickInputConfiguration();
stickInputConfiguration.setName(name);
stickInputConfiguration.setControllerId(controllerId);
stickInputConfiguration.setStickType(stickType);
inputConfigurations.stickInputConfigurations.add(stickInputConfiguration);
}
// Pointers
for (JsonValue pointerJson : pointersJson) {
Integer pointerId = pointerJson.getInt("id");
String name = pointerJson.getString("name");
Float horizontalSensitivity = pointerJson.getFloat("horizontalSensitivity");
Float verticalSensitivity = pointerJson.getFloat("verticalSensitivity");
PointerSourceType pointerSourceType = PointerSourceType.fromString(pointerJson.getString("sourceType"));
PointerInputConfiguration pointerInputConfiguration = new PointerInputConfiguration();
pointerInputConfiguration.setId(pointerId);
pointerInputConfiguration.setName(name);
pointerInputConfiguration.setHorizontalSensitivity(horizontalSensitivity);
pointerInputConfiguration.setVerticalSensitivity(verticalSensitivity);
pointerInputConfiguration.setPointerSourceType(pointerSourceType);
inputConfigurations.pointerInputConfigurations.add(pointerInputConfiguration);
}
// Controllers
for (JsonValue controllerJson : controllersJson) {
Integer id = controllerJson.getInt("id");
JsonValue leftStickConfigurationJson = controllerJson.get("leftStick");
JsonValue rightStickConfigurationJson = controllerJson.get("rightStick");
StickConfiguration leftStick = stickConfigurationFromJson(leftStickConfigurationJson);
StickConfiguration rightStick = stickConfigurationFromJson(rightStickConfigurationJson);
ControllerConfiguration controllerConfiguration = new ControllerConfiguration();
controllerConfiguration.setId(id);
controllerConfiguration.setLeftStick(leftStick);
controllerConfiguration.setRightStick(rightStick);
inputConfigurations.controllerConfigurations.add(controllerConfiguration);
}
// Mouse
for (JsonValue mouse : mouseJson) {
Float mouseHorizontalSensitivity = mouse.getFloat("horizontalSensitivity", 0f);
Float mouseVerticalSensitivity = mouse.getFloat("verticalSensitivity", 0f);
String name = mouse.getString("name");
MouseSourceType mouseSourceType = MouseSourceType.fromString(mouse.getString("sourceType"));
MouseInputConfiguration mouseInputConfiguration = new MouseInputConfiguration();
mouseInputConfiguration.setName(name);
mouseInputConfiguration.setHorizontalSensitivity(mouseHorizontalSensitivity);
mouseInputConfiguration.setVerticalSensitivity(mouseVerticalSensitivity);
mouseInputConfiguration.setMouseSourceType(mouseSourceType);
inputConfigurations.mouseInputConfigurations.add(mouseInputConfiguration);
}
}
use of com.badlogic.gdx.utils.JsonValue in project nhglib by VoidZombie.
the class TransformJson method parse.
@Override
public void parse(JsonValue jsonValue) {
JsonValue positionJson = jsonValue.get("position");
JsonValue rotationJson = jsonValue.get("rotation");
JsonValue scaleJson = jsonValue.get("scale");
float xPosition = positionJson.getFloat("x");
float yPosition = positionJson.getFloat("y");
float zPosition = positionJson.getFloat("z");
float xRotation = rotationJson.getFloat("x");
float yRotation = rotationJson.getFloat("y");
float zRotation = rotationJson.getFloat("z");
float xScale = scaleJson.getFloat("x");
float yScale = scaleJson.getFloat("y");
float zScale = scaleJson.getFloat("z");
position.set(xPosition, yPosition, zPosition);
rotation.set(xRotation, yRotation, zRotation);
scale.set(xScale, yScale, zScale);
}
use of com.badlogic.gdx.utils.JsonValue in project nhglib by VoidZombie.
the class RigidBodyComponentJson method parse.
@Override
public void parse(JsonValue jsonValue) {
RigidBodyComponent rigidBodyComponent = entities.createComponent(entity, RigidBodyComponent.class);
JsonValue shapeJson = jsonValue.get("shape");
String activationStateString = jsonValue.getString("activationState", "wantsDeactivation");
ActivationState activationStateJson = ActivationState.fromString(activationStateString);
btCollisionShape collisionShape = getCollisionShape(shapeJson);
int activationState = activationStateJson.state;
float mass = jsonValue.getFloat("mass", 1.0f);
float friction = jsonValue.getFloat("friction", 0.5f);
float restitution = jsonValue.getFloat("restitution", 0f);
rigidBodyComponent.build(collisionShape, activationState, mass, friction, restitution);
output = rigidBodyComponent;
}
use of com.badlogic.gdx.utils.JsonValue in project gdx-skineditor by cobolfoo.
the class Skin method getJsonLoader.
protected Json getJsonLoader(final FileHandle skinFile) {
final Skin skin = this;
final Json json = new Json() {
public <T> T readValue(Class<T> type, Class elementType, JsonValue jsonData) {
// actual value by name.
if (jsonData.isString() && !ClassReflection.isAssignableFrom(CharSequence.class, type))
return get(jsonData.asString(), type);
return super.readValue(type, elementType, jsonData);
}
};
json.setTypeName(null);
json.setUsePrototypes(false);
json.setSerializer(Skin.class, new ReadOnlySerializer<Skin>() {
public Skin read(Json json, JsonValue typeToValueMap, Class ignored) {
for (JsonValue valueMap = typeToValueMap.child; valueMap != null; valueMap = valueMap.next) {
try {
readNamedObjects(json, ClassReflection.forName(valueMap.name()), valueMap);
} catch (ReflectionException ex) {
throw new SerializationException(ex);
}
}
return skin;
}
private void readNamedObjects(Json json, Class type, JsonValue valueMap) {
for (JsonValue valueEntry = valueMap.child; valueEntry != null; valueEntry = valueEntry.next) {
Object object = json.readValue(type, valueEntry);
if (object == null)
continue;
try {
add(valueEntry.name(), object, type);
} catch (Exception ex) {
throw new SerializationException("Error reading " + ClassReflection.getSimpleName(type) + ": " + valueEntry.name(), ex);
}
}
}
});
json.setSerializer(BitmapFont.class, new ReadOnlySerializer<BitmapFont>() {
public BitmapFont read(Json json, JsonValue jsonData, Class type) {
String path = json.readValue("file", String.class, jsonData);
int scaledSize = json.readValue("scaledSize", int.class, -1, jsonData);
Boolean flip = json.readValue("flip", Boolean.class, false, jsonData);
FileHandle fontFile = skinFile.parent().child(path);
if (!fontFile.exists())
fontFile = Gdx.files.internal(path);
if (!fontFile.exists())
throw new SerializationException("Font file not found: " + fontFile);
// Use a region with the same name as the font, else use
// a PNG file in the same directory as the FNT file.
String regionName = fontFile.nameWithoutExtension();
try {
BitmapFont font;
TextureRegion region = skin.optional(regionName, TextureRegion.class);
if (region != null)
font = new BitmapFont(fontFile, region, flip);
else {
FileHandle imageFile = fontFile.parent().child(regionName + ".png");
if (imageFile.exists())
font = new BitmapFont(fontFile, imageFile, flip);
else
font = new BitmapFont(fontFile, flip);
}
// the font to.
if (scaledSize != -1)
font.setScale(scaledSize / font.getCapHeight());
return font;
} catch (RuntimeException ex) {
throw new SerializationException("Error loading bitmap font: " + fontFile, ex);
}
}
});
json.setSerializer(Color.class, new ReadOnlySerializer<Color>() {
public Color read(Json json, JsonValue jsonData, Class type) {
if (jsonData.isString())
return get(jsonData.asString(), Color.class);
String hex = json.readValue("hex", String.class, (String) null, jsonData);
if (hex != null)
return Color.valueOf(hex);
float r = json.readValue("r", float.class, 0f, jsonData);
float g = json.readValue("g", float.class, 0f, jsonData);
float b = json.readValue("b", float.class, 0f, jsonData);
float a = json.readValue("a", float.class, 1f, jsonData);
return new Color(r, g, b, a);
}
});
json.setSerializer(TintedDrawable.class, new ReadOnlySerializer() {
public Object read(Json json, JsonValue jsonData, Class type) {
String name = json.readValue("name", String.class, jsonData);
Color color = json.readValue("color", Color.class, jsonData);
TintedDrawable td = new TintedDrawable();
td.name = name;
td.color = color;
td.drawable = newDrawable(name, color);
return td;
// return newDrawable(name, color);
}
});
return json;
}
use of com.badlogic.gdx.utils.JsonValue in project bdx by GoranM.
the class Scene method createModel.
public Model createModel(JsonValue model) {
ModelBuilder builder = new ModelBuilder();
builder.begin();
short idx = 0;
for (JsonValue mat : model) {
Material m = materials.get(mat.name);
if (mat.name.equals(defaultMaterial.id))
m = new Material(m);
MeshPartBuilder mpb = builder.part(model.name, GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.TextureCoordinates, m);
float[] verts = mat.asFloatArray();
mpb.vertex(verts);
int len = verts.length / Bdx.VERT_STRIDE;
try {
for (short i = 0; i < len; ++i) {
mpb.index(idx);
idx += 1;
}
} catch (Error e) {
throw new RuntimeException("MODEL ERROR: Models with more than 32767 vertices are not supported. " + model.name + " has " + Integer.toString(len) + " vertices.");
}
}
return builder.end();
}
Aggregations