Search in sources :

Example 96 with JsonValue

use of com.badlogic.gdx.utils.JsonValue in project talos by rockbite.

the class MetaData method read.

@Override
public void read(Json json, JsonValue jsonData) {
    JsonValue arr = jsonData.get("scopeDefaults");
    int iter = 0;
    for (JsonValue item : arr) {
        NumericalValue val = new NumericalValue();
        val.set(item.get(0).asFloat(), item.get(1).asFloat(), item.get(2).asFloat(), item.get(3).asFloat());
        TalosMain.Instance().globalScope.setDynamicValue(iter++, val);
    }
    // preview widget stuff
    if (jsonData.has("previewCamPos")) {
        JsonValue camPos = jsonData.get("previewCamPos");
        TalosMain.Instance().UIStage().PreviewWidget().setCameraPos(camPos.getFloat("x", 0), camPos.getFloat("y", 0));
    } else {
        TalosMain.Instance().UIStage().PreviewWidget().setCameraPos(0, 0);
    }
    TalosMain.Instance().UIStage().PreviewWidget().setBackgroundImage(jsonData.getString("bgImagePath", null));
    TalosMain.Instance().UIStage().PreviewWidget().setGridVisible(jsonData.getBoolean("isGridVisible", true));
    TalosMain.Instance().UIStage().PreviewWidget().setImageIsBackground(jsonData.getBoolean("bgImageIsInBack", true));
    TalosMain.Instance().UIStage().PreviewWidget().setBgImageSize(jsonData.getFloat("bgImageSize", 10));
    TalosMain.Instance().UIStage().PreviewWidget().setGridSize(jsonData.getFloat("gridSize", 1));
    TalosMain.Instance().UIStage().PreviewWidget().setCameraZoom(jsonData.getFloat("previewCamZoom", 1.4285715f));
    // particle position
    ParticleEffectInstance particleEffect = TalosMain.Instance().TalosProject().getParticleEffect();
    if (particleEffect != null) {
        float pPosX = jsonData.getFloat("particlePositionX", 0);
        float pPosY = jsonData.getFloat("particlePositionY", 0);
        particleEffect.setPosition(pPosX, pPosY);
    }
    JsonValue resourcePaths = jsonData.get("resourcePaths");
    if (resourcePaths != null) {
        iter = 0;
        for (JsonValue item : resourcePaths) {
            final String filePath = item.asString();
            resourcePathStrings.add(filePath);
        }
    }
}
Also used : ParticleEffectInstance(com.talosvfx.talos.runtime.ParticleEffectInstance) NumericalValue(com.talosvfx.talos.runtime.values.NumericalValue) JsonValue(com.badlogic.gdx.utils.JsonValue)

Example 97 with JsonValue

use of com.badlogic.gdx.utils.JsonValue in project talos by rockbite.

the class BoundEffect method read.

@Override
public void read(Json json, JsonValue jsonData) {
    String effectName = jsonData.getString("effectName");
    String effectPath = parent.getWorkspace().getPath(effectName + ".p");
    FileHandle effectHandle = TalosMain.Instance().ProjectController().findFile(effectPath);
    this.name = effectName;
    if (effectHandle == null || !effectHandle.exists()) {
        throw new GdxRuntimeException("Particle effect not found");
    }
    parent.getWorkspace().registerTalosAssets(effectHandle);
    // TODO: refactor this
    ParticleEffectDescriptor descriptor = new ParticleEffectDescriptor();
    descriptor.setAssetProvider(TalosMain.Instance().TalosProject().getProjectAssetProvider());
    descriptor.load(effectHandle);
    parent.getWorkspace().getVfxLibrary().put(name, descriptor);
    // track this file
    TalosMain.Instance().FileTracker().trackFile(effectHandle, parent.getWorkspace().bvb.particleTracker);
    this.particleEffectDescriptor = descriptor;
    positionAttachment = json.readValue(AttachmentPoint.class, jsonData.get("positionAttachment"));
    JsonValue valueAttachmentsJson = jsonData.get("valueAttachments");
    for (JsonValue valueAttachmentJson : valueAttachmentsJson) {
        AttachmentPoint point = json.readValue(AttachmentPoint.class, valueAttachmentJson);
        valueAttachments.add(point);
    }
    setStartEvent(jsonData.getString("startEvent", ""));
    setCompleteEvent(jsonData.getString("completeEvent", ""));
    isStandalone = jsonData.getBoolean("isStandalone", false);
    isBehind = jsonData.getBoolean("isBehind");
    isNested = jsonData.getBoolean("isNested");
// setForever(startEvent.equals("") && completeEvent.equals(""));
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) FileHandle(com.badlogic.gdx.files.FileHandle) ParticleEffectDescriptor(com.talosvfx.talos.runtime.ParticleEffectDescriptor) JsonValue(com.badlogic.gdx.utils.JsonValue)

Example 98 with JsonValue

use of com.badlogic.gdx.utils.JsonValue in project talos by rockbite.

the class OffsetModule method read.

@Override
public void read(Json json, JsonValue jsonData) {
    super.read(json, jsonData);
    points.clear();
    final JsonValue points = jsonData.get("points");
    for (JsonValue point : points) {
        createPoint(point.get(0).asFloat(), point.get(1).asFloat());
    }
    final JsonValue low = jsonData.get("low");
    final JsonValue high = jsonData.get("high");
    lowEdge = low.getBoolean("edge");
    highEdge = high.getBoolean("edge");
    lowShape = low.getInt("shape");
    highShape = high.getInt("shape");
    lowSide = low.getInt("side");
    highSide = high.getInt("side");
    final JsonValue lowRect = low.get("rect");
    final JsonValue highRect = high.get("rect");
    lowPos.set(lowRect.getFloat("x"), lowRect.getFloat("y"));
    lowSize.set(lowRect.getFloat("width"), lowRect.getFloat("height"));
    highPos.set(highRect.getFloat("x"), highRect.getFloat("y"));
    highSize.set(highRect.getFloat("width"), highRect.getFloat("height"));
}
Also used : JsonValue(com.badlogic.gdx.utils.JsonValue)

Example 99 with JsonValue

use of com.badlogic.gdx.utils.JsonValue in project bladecoder-adventure-engine by bladecoder.

the class ElementUtils method cloneElement.

public static Object cloneElement(Object e) {
    Json json = new BladeJson(Ctx.project.getWorld(), Mode.MODEL);
    if (e instanceof Action) {
        StringWriter buffer = new StringWriter();
        json.setWriter(buffer);
        ActionUtils.writeJson((Action) e, json);
        String str = buffer.toString();
        EditorLogger.debug(str);
        JsonValue root = new JsonReader().parse(str);
        return ActionUtils.readJson(Ctx.project.getWorld(), json, root);
    } else if (e instanceof Scene) {
        String str = json.toJson(e, (Class<?>) null);
        Scene s = new Scene(((Scene) e).getWorld());
        JsonValue root = new JsonReader().parse(str);
        s.read(json, root);
        return s;
    } else {
        String str = json.toJson(e, (Class<?>) null);
        return json.fromJson(e.getClass(), str);
    }
}
Also used : Action(com.bladecoder.engine.actions.Action) StringWriter(java.io.StringWriter) BladeJson(com.bladecoder.engine.serialization.BladeJson) JsonValue(com.badlogic.gdx.utils.JsonValue) JsonReader(com.badlogic.gdx.utils.JsonReader) Json(com.badlogic.gdx.utils.Json) BladeJson(com.bladecoder.engine.serialization.BladeJson) Scene(com.bladecoder.engine.model.Scene)

Example 100 with JsonValue

use of com.badlogic.gdx.utils.JsonValue in project bladecoder-adventure-engine by bladecoder.

the class ModelTools method extractInkTexts.

public static void extractInkTexts(String file, String lang) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
    StringBuilder sb = new StringBuilder();
    try {
        String line = br.readLine();
        // Replace the BOM mark
        if (line != null)
            line = line.replace('\uFEFF', ' ');
        while (line != null) {
            sb.append(line);
            sb.append("\n");
            line = br.readLine();
        }
    } finally {
        br.close();
    }
    JsonValue root = new JsonReader().parse(sb.toString());
    // .tsv generation to help in translation
    StringBuilder tsvString = new StringBuilder();
    // .md generation to have a better readable document of texts
    StringBuilder mdString = new StringBuilder();
    OrderedPropertiesBuilder builder = new OrderedPropertiesBuilder();
    builder.withSuppressDateInComment(true);
    OrderedProperties prop = builder.build();
    extractInkTextsInternal(root, tsvString, mdString, prop);
    FileUtils.writeStringToFile(new File(file + ".tsv"), tsvString.toString());
    FileUtils.writeStringToFile(new File(file + ".txt"), mdString.toString());
    String json = root.toJson(OutputType.json);
    FileUtils.writeStringToFile(new File(file), json);
    try {
        String file2 = file.substring(0, file.length() - EngineAssetManager.INK_EXT.length());
        if (lang == null || lang.isEmpty() || lang.equals("default"))
            file2 += "-ink.properties";
        else
            file2 += "-ink" + "_" + lang + ".properties";
        FileOutputStream os = new FileOutputStream(file2);
        Writer out = new OutputStreamWriter(os, I18N.ENCODING);
        prop.store(out, null);
    } catch (IOException e) {
        EditorLogger.error("ERROR WRITING BUNDLE: " + file + ".properties");
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) JsonValue(com.badlogic.gdx.utils.JsonValue) OrderedPropertiesBuilder(com.bladecoder.engineeditor.common.OrderedProperties.OrderedPropertiesBuilder) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) JsonReader(com.badlogic.gdx.utils.JsonReader) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

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