Search in sources :

Example 46 with JsonValue

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();
}
Also used : JsonValue(com.badlogic.gdx.utils.JsonValue) NodeComponent(io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent) Scene(io.github.voidzombie.nhglib.graphics.scenes.Scene)

Example 47 with JsonValue

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;
}
Also used : JsonValue(com.badlogic.gdx.utils.JsonValue) NodeComponent(io.github.voidzombie.nhglib.runtime.ecs.components.scenes.NodeComponent)

Example 48 with JsonValue

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);
    }
}
Also used : InputMode(io.github.voidzombie.nhglib.input.models.InputMode) StickInputConfiguration(io.github.voidzombie.nhglib.input.configuration.impls.StickInputConfiguration) JsonValue(com.badlogic.gdx.utils.JsonValue) StickType(io.github.voidzombie.nhglib.input.models.StickType) InputConfigurations(io.github.voidzombie.nhglib.input.configuration.InputConfigurations) PointerSourceType(io.github.voidzombie.nhglib.input.models.PointerSourceType) MouseInputConfiguration(io.github.voidzombie.nhglib.input.configuration.impls.MouseInputConfiguration) PointerInputConfiguration(io.github.voidzombie.nhglib.input.configuration.impls.PointerInputConfiguration) KeyInputConfiguration(io.github.voidzombie.nhglib.input.configuration.impls.KeyInputConfiguration) ControllerConfiguration(io.github.voidzombie.nhglib.input.controllers.ControllerConfiguration) StickConfiguration(io.github.voidzombie.nhglib.input.controllers.StickConfiguration) MouseSourceType(io.github.voidzombie.nhglib.input.models.MouseSourceType)

Example 49 with JsonValue

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);
}
Also used : JsonValue(com.badlogic.gdx.utils.JsonValue)

Example 50 with JsonValue

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;
}
Also used : RigidBodyComponent(io.github.voidzombie.nhglib.runtime.ecs.components.physics.RigidBodyComponent) JsonValue(com.badlogic.gdx.utils.JsonValue) ActivationState(io.github.voidzombie.nhglib.data.models.serialization.physics.ActivationState) com.badlogic.gdx.physics.bullet.collision.btCollisionShape(com.badlogic.gdx.physics.bullet.collision.btCollisionShape)

Aggregations

JsonValue (com.badlogic.gdx.utils.JsonValue)148 JsonReader (com.badlogic.gdx.utils.JsonReader)27 IOException (java.io.IOException)21 Array (com.badlogic.gdx.utils.Array)20 Json (com.badlogic.gdx.utils.Json)15 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)14 FileHandle (com.badlogic.gdx.files.FileHandle)11 ReflectionException (com.badlogic.gdx.utils.reflect.ReflectionException)10 BladeJson (com.bladecoder.engine.serialization.BladeJson)9 HashMap (java.util.HashMap)8 Color (com.badlogic.gdx.graphics.Color)7 GraphBoxImpl (com.gempukku.libgdx.graph.ui.graph.GraphBoxImpl)7 ArrayList (java.util.ArrayList)7 Vector2 (com.badlogic.gdx.math.Vector2)6 Actor (com.badlogic.gdx.scenes.scene2d.Actor)6 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)6 Action (com.bladecoder.engine.actions.Action)6 File (java.io.File)6 ObjectMap (com.badlogic.gdx.utils.ObjectMap)5 SerializationException (com.badlogic.gdx.utils.SerializationException)5