use of com.badlogic.gdx.utils.JsonValue in project nhglib by VoidZombie.
the class SceneJson method parse.
@Override
public void parse(JsonValue jsonValue) {
String name = jsonValue.getString("name");
JsonValue entitiesJson = jsonValue.get("entities");
output = new Scene(entities, "root");
output.name = name;
int rootEntity = output.sceneGraph.getRootEntity();
if (entitiesJson != null) {
for (JsonValue entity : entitiesJson) {
EntityJson entityJson = new EntityJson(entities);
entityJson.setSceneGraph(output.sceneGraph);
entityJson.setParentEntity(rootEntity);
entityJson.parse(entity);
}
}
NodeComponent nodeComponent = entities.getComponent(rootEntity, NodeComponent.class);
nodeComponent.applyTransforms();
}
use of com.badlogic.gdx.utils.JsonValue in project nhglib by VoidZombie.
the class EntityJson method parse.
@Override
public void parse(JsonValue jsonValue) {
String id = jsonValue.getString("id");
int entity = sceneGraph.addSceneEntity(id, parentEntity);
JsonValue componentsJson = jsonValue.get("components");
for (JsonValue componentJsonValue : componentsJson) {
String type = componentJsonValue.getString("type");
ComponentJson componentJson = SceneUtils.componentJsonFromType(type);
if (componentJson != null) {
componentJson.entity = entity;
componentJson.entities = entities;
componentJson.parse(componentJsonValue);
}
}
JsonValue entitiesJson = jsonValue.get("entities");
if (entitiesJson != null) {
for (JsonValue entityJsonValue : entitiesJson) {
EntityJson entityJson = new EntityJson(entities);
entityJson.sceneGraph = sceneGraph;
entityJson.parentEntity = entity;
entityJson.parse(entityJsonValue);
}
}
TransformJson transformJson = new TransformJson();
transformJson.parse(jsonValue.get("transform"));
NodeComponent nodeComponent = entities.getComponent(entity, NodeComponent.class);
nodeComponent.setTransform(transformJson.position, transformJson.rotation, transformJson.scale);
output = entity;
}
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;
}
Aggregations