Search in sources :

Example 11 with DefaultFieldOutput

use of com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput in project gdx-graph by MarcinSc.

the class AddPipelineNodeProducer method createNode.

@Override
public PipelineNode createNode(JsonValue data, ObjectMap<String, Array<String>> inputTypes, ObjectMap<String, String> outputTypes) {
    final String resultType = outputTypes.get("output");
    final Object resultValue = createDefaultValue(resultType);
    final ObjectMap<String, PipelineNode.FieldOutput<?>> result = new ObjectMap<>();
    final DefaultFieldOutput resultOutput = new DefaultFieldOutput(resultType);
    result.put("output", resultOutput);
    return new AbstractPipelineNode(result) {

        private Array<FieldOutput<?>> inputs;

        @Override
        public void setInputs(ObjectMap<String, Array<FieldOutput<?>>> inputs) {
            this.inputs = inputs.get("inputs");
        }

        @Override
        public void executeNode(PipelineRenderingContext pipelineRenderingContext, PipelineRequirementsCallback pipelineRequirementsCallback) {
            Object returnValue = resetDefaultValue(resultType, resultValue);
            for (FieldOutput<?> input : inputs) {
                Object value = input.getValue();
                returnValue = add(returnValue, value);
            }
            resultOutput.setValue(returnValue);
        }
    };
}
Also used : Array(com.badlogic.gdx.utils.Array) AbstractPipelineNode(com.gempukku.libgdx.graph.pipeline.producer.node.AbstractPipelineNode) ObjectMap(com.badlogic.gdx.utils.ObjectMap) DefaultFieldOutput(com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput) PipelineRenderingContext(com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext) DefaultFieldOutput(com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput)

Example 12 with DefaultFieldOutput

use of com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput in project gdx-graph by MarcinSc.

the class TwoParamMathFunctionPipelineNodeProducer method createNodeForSingleInputs.

@Override
public PipelineNode createNodeForSingleInputs(JsonValue data, ObjectMap<String, String> inputTypes, ObjectMap<String, String> outputTypes) {
    final String resultType = inputTypes.get(param1);
    final Object resultValue = createResult(resultType);
    final ObjectMap<String, PipelineNode.FieldOutput<?>> result = new ObjectMap<>();
    final DefaultFieldOutput resultOutput = new DefaultFieldOutput(resultType);
    result.put(outputName, resultOutput);
    return new SingleInputsPipelineNode(result) {

        @Override
        public void executeNode(PipelineRenderingContext pipelineRenderingContext, PipelineRequirementsCallback pipelineRequirementsCallback) {
            FieldOutput<?> aFunction = inputs.get(param1);
            FieldOutput<?> bFunction = inputs.get(param2);
            Object a = aFunction.getValue();
            Object b = bFunction.getValue();
            Object returnValue;
            if (resultType.equals(PipelineFieldType.Float)) {
                returnValue = executeFunction(a, b, 0);
            } else if (resultType.equals(PipelineFieldType.Vector2)) {
                returnValue = ((Vector2) resultValue).set(executeFunction(a, b, 0), executeFunction(a, b, 1));
            } else if (resultType.equals(PipelineFieldType.Vector3)) {
                returnValue = ((Vector3) resultValue).set(executeFunction(a, b, 0), executeFunction(a, b, 1), executeFunction(a, b, 2));
            } else {
                returnValue = ((Color) resultValue).set(executeFunction(a, b, 0), executeFunction(a, b, 1), executeFunction(a, b, 2), executeFunction(a, b, 3));
            }
            resultOutput.setValue(returnValue);
        }
    };
}
Also used : ObjectMap(com.badlogic.gdx.utils.ObjectMap) Vector2(com.badlogic.gdx.math.Vector2) DefaultFieldOutput(com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput) SingleInputsPipelineNode(com.gempukku.libgdx.graph.pipeline.producer.node.SingleInputsPipelineNode) PipelineRenderingContext(com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext) DefaultFieldOutput(com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput)

Aggregations

ObjectMap (com.badlogic.gdx.utils.ObjectMap)12 PipelineRenderingContext (com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext)12 DefaultFieldOutput (com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput)12 SingleInputsPipelineNode (com.gempukku.libgdx.graph.pipeline.producer.node.SingleInputsPipelineNode)10 Vector2 (com.badlogic.gdx.math.Vector2)9 Vector3 (com.badlogic.gdx.math.Vector3)6 Color (com.badlogic.gdx.graphics.Color)5 Array (com.badlogic.gdx.utils.Array)2 AbstractPipelineNode (com.gempukku.libgdx.graph.pipeline.producer.node.AbstractPipelineNode)2